diff --git a/server/notification-providers/smspartner.js b/server/notification-providers/smspartner.js new file mode 100644 index 00000000..5595217a --- /dev/null +++ b/server/notification-providers/smspartner.js @@ -0,0 +1,46 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); + +class SMSPartner extends NotificationProvider { + name = "SMSPartner"; + + /** + * @inheritdoc + */ + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + const okMsg = "Sent Successfully."; + const url = "https://api.smspartner.fr/v1/send"; + + try { + // smspartner does not support non ascii characters and only a maximum 639 characters + let cleanMsg = msg.replace(/[^\x00-\x7F]/g, "").substring(0, 639); + + let data = { + "apiKey": notification.smspartnerApikey, + "sender": notification.smspartnerSenderName.substring(0, 11), + "phoneNumbers": notification.smspartnerPhoneNumber, + "message": cleanMsg, + }; + + let config = { + headers: { + "Content-Type": "application/json", + "cache-control": "no-cache", + "Accept": "application/json", + } + }; + + let resp = await axios.post(url, data, config); + + if (resp.data.success !== true) { + throw Error(`Api returned ${resp.data.response.status}.`); + } + + return okMsg; + } catch (error) { + this.throwGeneralAxiosError(error); + } + } +} + +module.exports = SMSPartner; diff --git a/server/notification.js b/server/notification.js index efb5e408..8feb5bd9 100644 --- a/server/notification.js +++ b/server/notification.js @@ -43,6 +43,7 @@ const RocketChat = require("./notification-providers/rocket-chat"); const SerwerSMS = require("./notification-providers/serwersms"); const Signal = require("./notification-providers/signal"); const Slack = require("./notification-providers/slack"); +const SMSPartner = require("./notification-providers/smspartner"); const SMSEagle = require("./notification-providers/smseagle"); const SMTP = require("./notification-providers/smtp"); const Squadcast = require("./notification-providers/squadcast"); @@ -123,6 +124,7 @@ class Notification { new SerwerSMS(), new Signal(), new SMSManager(), + new SMSPartner(), new Slack(), new SMSEagle(), new SMTP(), diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index ebef7c9f..1c4636d5 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -147,6 +147,7 @@ export default { "slack": "Slack", "squadcast": "SquadCast", "SMSEagle": "SMSEagle", + "SMSPartner": "SMS Partner", "smtp": this.$t("smtp"), "stackfield": "Stackfield", "teams": "Microsoft Teams", diff --git a/src/components/notifications/SMSPartner.vue b/src/components/notifications/SMSPartner.vue new file mode 100644 index 00000000..be1905e2 --- /dev/null +++ b/src/components/notifications/SMSPartner.vue @@ -0,0 +1,39 @@ + + + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index cb6a96bf..0fcdf050 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -43,6 +43,7 @@ import ServerChan from "./ServerChan.vue"; import SerwerSMS from "./SerwerSMS.vue"; import Signal from "./Signal.vue"; import SMSManager from "./SMSManager.vue"; +import SMSPartner from "./SMSPartner.vue"; import Slack from "./Slack.vue"; import Squadcast from "./Squadcast.vue"; import SMSEagle from "./SMSEagle.vue"; @@ -110,6 +111,7 @@ const NotificationFormList = { "serwersms": SerwerSMS, "signal": Signal, "SMSManager": SMSManager, + "SMSPartner": SMSPartner, "slack": Slack, "squadcast": Squadcast, "SMSEagle": SMSEagle, diff --git a/src/lang/en.json b/src/lang/en.json index d3752706..aebeff18 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -753,6 +753,11 @@ "smseagleUrl": "Your SMSEagle device URL", "smseagleEncoding": "Send as Unicode", "smseaglePriority": "Message priority (0-9, default = 0)", + "smspartnerApiurl": "You can find your API key in your dashboard at {0}", + "smspartnerPhoneNumber": "Phone number(s)", + "smspartnerPhoneNumberHelptext": "The number must be in the international format {0}, {1}. Multiple numbers must be separated by {2}", + "smspartnerSenderName": "SMS Sender Name", + "smspartnerSenderNameInfo": "Must be between 3..=11 regular characters", "Recipient Number": "Recipient Number", "From Name/Number": "From Name/Number", "Leave blank to use a shared sender number.": "Leave blank to use a shared sender number.",