From 0f4991c0a45d6b902a024cea2c10b56b58dc2f27 Mon Sep 17 00:00:00 2001 From: Nicolas Verlhiac Date: Fri, 17 May 2024 13:18:20 +0200 Subject: [PATCH 1/8] New notification provider: SMS Partner API From 11baceb2fb71502f3146c3b008e52de91b76ad3d Mon Sep 17 00:00:00 2001 From: Nicolas Verlhiac Date: Tue, 21 May 2024 15:26:13 +0200 Subject: [PATCH 2/8] Add support of SMS Partner --- server/notification-providers/smspartner.js | 48 +++++++++++++++++++++ server/notification.js | 2 + src/components/NotificationDialog.vue | 1 + src/components/notifications/SMSPartner.vue | 31 +++++++++++++ src/components/notifications/index.js | 2 + src/lang/en.json | 5 +++ 6 files changed, 89 insertions(+) create mode 100644 server/notification-providers/smspartner.js create mode 100644 src/components/notifications/SMSPartner.vue diff --git a/server/notification-providers/smspartner.js b/server/notification-providers/smspartner.js new file mode 100644 index 0000000000..763612e73e --- /dev/null +++ b/server/notification-providers/smspartner.js @@ -0,0 +1,48 @@ +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 { + //Lets remove non ascii char + let cleanMsg = msg.replace(/[^\x00-\x7F]/g, ""); + + let data = { + "apiKey": notification.smspartnerApikey, + "gamme": 1, + "sender": notification.smspartnerSenderName.substring(0, 11), + "phoneNumbers": notification.smspartnerPhoneNumber, + "message": cleanMsg.substring(0, 639) + }; + + 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) { + let error = "Something gone wrong. Api returned " + resp.data.response.status + "."; + this.throwGeneralAxiosError(error); + } + + return okMsg; + } catch (error) { + this.throwGeneralAxiosError(error); + } + } +} + +module.exports = SMSPartner; diff --git a/server/notification.js b/server/notification.js index 03bd368ede..8d0faffec4 100644 --- a/server/notification.js +++ b/server/notification.js @@ -42,6 +42,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"); @@ -121,6 +122,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 09646d599a..3c6b67e1c7 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -146,6 +146,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 0000000000..02e956df7f --- /dev/null +++ b/src/components/notifications/SMSPartner.vue @@ -0,0 +1,31 @@ + + + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index 52bebf83da..0160b60414 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -42,6 +42,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"; @@ -108,6 +109,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 d4a0997c2a..e95a8b6189 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -741,6 +741,11 @@ "smseagleUrl": "Your SMSEagle device URL", "smseagleEncoding": "Send as Unicode", "smseaglePriority": "Message priority (0-9, default = 0)", + "smspartnerApikey": "API Key", + "smspartnerApiurl": "Find your API key in your dashboard: ", + "smspartnerPhoneNumber": "Phone number(s) (multiple numbers, separate by `,`)", + "smspartnerSenderName": "SMS Sender Name", + "smspartnerSenderNameInfo": "Must be between 3 and 11 inclusive and must not contain any special 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.", From c3be362ebe45a1f03a8ff94f6eebc4a61c3d555f Mon Sep 17 00:00:00 2001 From: Nicolas Verlhiac Date: Tue, 21 May 2024 23:44:21 +0200 Subject: [PATCH 3/8] Apply suggestions from code review Co-authored-by: Frank Elsinga --- server/notification-providers/smspartner.js | 9 ++++----- src/components/notifications/SMSPartner.vue | 7 +++---- src/lang/en.json | 8 ++++---- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/server/notification-providers/smspartner.js b/server/notification-providers/smspartner.js index 763612e73e..108a7e7abf 100644 --- a/server/notification-providers/smspartner.js +++ b/server/notification-providers/smspartner.js @@ -12,15 +12,15 @@ class SMSPartner extends NotificationProvider { const url = "https://api.smspartner.fr/v1/send"; try { - //Lets remove non ascii char - let cleanMsg = msg.replace(/[^\x00-\x7F]/g, ""); + // 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, "gamme": 1, "sender": notification.smspartnerSenderName.substring(0, 11), "phoneNumbers": notification.smspartnerPhoneNumber, - "message": cleanMsg.substring(0, 639) + "message": cleanMsg, }; let config = { @@ -34,8 +34,7 @@ class SMSPartner extends NotificationProvider { let resp = await axios.post(url, data, config); if (resp.data.success !== true) { - let error = "Something gone wrong. Api returned " + resp.data.response.status + "."; - this.throwGeneralAxiosError(error); + throw Error(`Api returned ${resp.data.response.status}.`); } return okMsg; diff --git a/src/components/notifications/SMSPartner.vue b/src/components/notifications/SMSPartner.vue index 02e956df7f..66c74b8b3c 100644 --- a/src/components/notifications/SMSPartner.vue +++ b/src/components/notifications/SMSPartner.vue @@ -1,11 +1,10 @@