diff --git a/server/notification-providers/sms-planet.js b/server/notification-providers/sms-planet.js new file mode 100644 index 000000000..97e9e715e --- /dev/null +++ b/server/notification-providers/sms-planet.js @@ -0,0 +1,40 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); + +class SMSPlanet extends NotificationProvider { + name = "SMSPlanet"; + + /** + * @inheritdoc + */ + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + const okMsg = "Sent Successfully."; + const url = "https://api2.smsplanet.pl/sms"; + + try { + let config = { + headers: { + "Authorization": "Bearer " + notification.smsplanetApiToken, + "content-type": "multipart/form-data" + } + }; + + let data = { + "from": notification.smsplanetSenderName, + "to": notification.smsplanetPhoneNumbers, + "msg": msg.replace(/🔴/, "❌") + }; + + let response = await axios.post(url, data, config); + if (!response.data?.messageId) { + throw new Error(response.data?.errorMsg ?? "SMSPlanet server did not respond with the expected result"); + } + + return okMsg; + } catch (error) { + this.throwGeneralAxiosError(error); + } + } +} + +module.exports = SMSPlanet; diff --git a/server/notification.js b/server/notification.js index 0c222d932..537f7d137 100644 --- a/server/notification.js +++ b/server/notification.js @@ -72,6 +72,7 @@ const Onesender = require("./notification-providers/onesender"); const Wpush = require("./notification-providers/wpush"); const SendGrid = require("./notification-providers/send-grid"); const YZJ = require("./notification-providers/yzj"); +const SMSPlanet = require("./notification-providers/sms-planet"); class Notification { @@ -160,7 +161,8 @@ class Notification { new Cellsynt(), new Wpush(), new SendGrid(), - new YZJ() + new YZJ(), + new SMSPlanet(), ]; for (let item of list) { if (! item.name) { diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index 56cae66c8..20e611418 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -185,7 +185,8 @@ export default { "PushPlus": "PushPlus (推送加)", "smsc": "SMSC", "WPush": "WPush(wpush.cn)", - "YZJ": "YZJ (云之家自定义机器人)" + "YZJ": "YZJ (云之家自定义机器人)", + "SMSPlanet": "SMSPlanet.pl" }; // Sort by notification name diff --git a/src/components/notifications/SMSPlanet.vue b/src/components/notifications/SMSPlanet.vue new file mode 100644 index 000000000..bbf070461 --- /dev/null +++ b/src/components/notifications/SMSPlanet.vue @@ -0,0 +1,46 @@ + + + {{ $t('smsplanetApiToken') }} + + + + {{ $t("the smsplanet documentation") }} + + + + + {{ $t("Phone numbers") }} + + + + {{ $t("Sender name") }} + + {{ $t("smsplanetNeedToApproveName") }} + + + + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index cbd6f2b68..14989c45f 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -70,6 +70,7 @@ import WPush from "./WPush.vue"; import SIGNL4 from "./SIGNL4.vue"; import SendGrid from "./SendGrid.vue"; import YZJ from "./YZJ.vue"; +import SMSPlanet from "./SMSPlanet.vue"; /** * Manage all notification form. @@ -148,6 +149,7 @@ const NotificationFormList = { "WPush": WPush, "SendGrid": SendGrid, "YZJ": YZJ, + "SMSPlanet": SMSPlanet, }; export default NotificationFormList; diff --git a/src/lang/en.json b/src/lang/en.json index c32bebaae..b53fa1350 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -1068,5 +1068,11 @@ "Plain Text": "Plain Text", "Message Template": "Message Template", "Template Format": "Template Format", - "Font Twemoji by Twitter licensed under": "Font Twemoji by Twitter licensed under" + "Font Twemoji by Twitter licensed under": "Font Twemoji by Twitter licensed under", + "smsplanetApiToken": "Token for the SMSPlanet API", + "smsplanetApiDocs": "Detailed information on obtaining API tokens can be found in {the_smsplanet_documentation}.", + "the smsplanet documentation": "the smsplanet documentation", + "Phone numbers": "Phone numbers", + "Sender name": "Sender name", + "smsplanetNeedToApproveName": "Needs to be approved in the client panel" }