diff --git a/server/notification-providers/mobivatesms.js b/server/notification-providers/mobivatesms.js new file mode 100644 index 0000000000..7a03e62c78 --- /dev/null +++ b/server/notification-providers/mobivatesms.js @@ -0,0 +1,51 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); + +class MobivateSMS extends NotificationProvider { + name = "MobivateSMS"; + + /** + * @inheritdoc + */ + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + const okMsg = "Sent Successfully."; + const url = "https://vortex.mobivatebulksms.com/send/batch"; + + 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 = { + originator: notification.mobivateOriginator.substring(0, 15), + recipients: notification.mobivateRecipients + .split(",") + .map((n) => n.replace(/[^0-9]/g, "")) + .filter((n) => n.length >= 9) + .map((recipient) => ({ recipient })), + text: cleanMsg, + }; + + let config = { + headers: { + "Content-Type": "application/json", + "cache-control": "no-cache", + Accept: "application/json", + Authorization: "Bearer " + notification.mobivateApikey, + }, + }; + config = this.getAxiosConfigWithProxy(config); + + 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 = MobivateSMS; diff --git a/server/notification.js b/server/notification.js index de429388c0..74798bf820 100644 --- a/server/notification.js +++ b/server/notification.js @@ -28,6 +28,7 @@ const Line = require("./notification-providers/line"); const LunaSea = require("./notification-providers/lunasea"); const Matrix = require("./notification-providers/matrix"); const Mattermost = require("./notification-providers/mattermost"); +const MobivateSMS = require("./notification-providers/mobivatesms"); const NextcloudTalk = require("./notification-providers/nextcloudtalk"); const Nostr = require("./notification-providers/nostr"); const Ntfy = require("./notification-providers/ntfy"); @@ -128,6 +129,7 @@ class Notification { new LunaSea(), new Matrix(), new Mattermost(), + new MobivateSMS(), new NextcloudTalk(), new Nostr(), new Ntfy(), diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index 6d915255a3..16ed1aea13 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -267,6 +267,7 @@ export default { Elks: "46elks", Cellsynt: "Cellsynt", gtxmessaging: "GtxMessaging", + MobivateSMS: "Mobivate SMS", octopush: "Octopush", Onesender: "Onesender", SevenIO: "SevenIO", diff --git a/src/components/notifications/MobivateSMS.vue b/src/components/notifications/MobivateSMS.vue new file mode 100644 index 0000000000..d5c44bc942 --- /dev/null +++ b/src/components/notifications/MobivateSMS.vue @@ -0,0 +1,53 @@ + + + + {{ $t("API Key") }} + * + + + + + {{ $t("Recipients") }} + + + {{ $t("Comma separated list of numbers in international format. (eg. 447930000000,447930000001)") }} + + + + {{ $t("Originator") }} + + + + + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index 1a8f6dba35..00f05cc91a 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -27,6 +27,7 @@ import Line from "./Line.vue"; import LunaSea from "./LunaSea.vue"; import Matrix from "./Matrix.vue"; import Mattermost from "./Mattermost.vue"; +import MobivateSMS from "./MobivateSMS.vue"; import NextcloudTalk from "./NextcloudTalk.vue"; import Nostr from "./Nostr.vue"; import Ntfy from "./Ntfy.vue"; @@ -116,6 +117,7 @@ const NotificationFormList = { lunasea: LunaSea, matrix: Matrix, mattermost: Mattermost, + MobivateSMS: MobivateSMS, nextcloudtalk: NextcloudTalk, nostr: Nostr, ntfy: Ntfy,
{{ $t("Comma separated list of numbers in international format. (eg. 447930000000,447930000001)") }}