diff --git a/server/notification-providers/sms-planet.js b/server/notification-providers/sms-planet.js new file mode 100644 index 000000000..275771040 --- /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..391470f55 --- /dev/null +++ b/src/components/notifications/SMSPlanet.vue @@ -0,0 +1,43 @@ + + + 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..190e32c10 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -1068,5 +1068,9 @@ "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 the API token can be found in the documentation available at {0}.", + "smsplanetPhoneNumber": "Phone numbers", + "smsplanetSenderName": "Sender name (approved in the client panel)" } diff --git a/src/lang/pl.json b/src/lang/pl.json index 9832fb7c1..493cec73c 100644 --- a/src/lang/pl.json +++ b/src/lang/pl.json @@ -1098,5 +1098,9 @@ "RabbitMQ Username": "Nazwa użytkownika RabbitMQ", "RabbitMQ Password": "Hasło RabbitMQ", "SendGrid API Key": "Klucz API SendGrid", - "Separate multiple email addresses with commas": "Oddziel wiele adresów e-mail przecinkami" -} + "Separate multiple email addresses with commas": "Oddziel wiele adresów e-mail przecinkami", + "smsplanetApiToken": "Token do Api SMSPlanet", + "smsplanetApiDocs": "Szczegółowe informacje o uzyskaniu API tokena znajdziesz w dokumentacji dostępnej {0}.", + "smsplanetPhoneNumber": "Numery telefonów", + "smsplanetSenderName": "Nazwa nadawcy (zatwierdzona w panelu klienta)" +} \ No newline at end of file