diff --git a/server/notification-providers/smseagle.js b/server/notification-providers/smseagle.js new file mode 100644 index 000000000..c431297ec --- /dev/null +++ b/server/notification-providers/smseagle.js @@ -0,0 +1,71 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); + +class SMSEagle extends NotificationProvider { + + name = "SMSEagle"; + + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + let okMsg = "Sent Successfully."; + + try { + let config = { + headers: { + "Content-Type": "application/json", + } + }; + + let postData; + let sendMethod; + let recipientType; + + let encoding = (notification.smseagleEncoding) ? "1" : "0"; + let priority = (notification.smseaglePriority) ? notification.smseaglePriority : "0"; + + if (notification.smseagleRecipientType === "smseagle-contact") { + recipientType = "contactname"; + sendMethod = "sms.send_tocontact"; + } + if (notification.smseagleRecipientType === "smseagle-group") { + recipientType = "groupname"; + sendMethod = "sms.send_togroup"; + } + if (notification.smseagleRecipientType === "smseagle-to") { + recipientType = "to"; + sendMethod = "sms.send_sms"; + } + + let params = { + access_token: notification.smseagleToken, + [recipientType]: notification.smseagleRecipient, + message: msg, + responsetype: "extended", + unicode: encoding, + highpriority: priority + }; + + postData = { + method: sendMethod, + params: params + }; + + let resp = await axios.post(notification.smseagleUrl + "/jsonrpc/sms", postData, config); + + if ((JSON.stringify(resp.data)).indexOf("message_id") === -1) { + let error = ""; + if (resp.data.result && resp.data.result.error_text) { + error = `SMSEagle API returned error: ${JSON.stringify(resp.data.result.error_text)}`; + } else { + error = "SMSEagle API returned an unexpected response"; + } + throw new Error(error); + } + + return okMsg; + } catch (error) { + this.throwGeneralAxiosError(error); + } + } +} + +module.exports = SMSEagle; diff --git a/server/notification.js b/server/notification.js index aed92e5dc..9069601b4 100644 --- a/server/notification.js +++ b/server/notification.js @@ -32,6 +32,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 SMSEagle = require("./notification-providers/smseagle"); const SMTP = require("./notification-providers/smtp"); const Squadcast = require("./notification-providers/squadcast"); const Stackfield = require("./notification-providers/stackfield"); @@ -89,6 +90,7 @@ class Notification { new Signal(), new SMSManager(), new Slack(), + new SMSEagle(), new SMTP(), new Squadcast(), new Stackfield(), diff --git a/src/components/notifications/SMSEagle.vue b/src/components/notifications/SMSEagle.vue new file mode 100644 index 000000000..ec781313a --- /dev/null +++ b/src/components/notifications/SMSEagle.vue @@ -0,0 +1,40 @@ + + + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index bca4a510d..0c220b717 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -33,6 +33,7 @@ import Signal from "./Signal.vue"; import SMSManager from "./SMSManager.vue"; import Slack from "./Slack.vue"; import Squadcast from "./Squadcast.vue"; +import SMSEagle from "./SMSEagle.vue"; import Stackfield from "./Stackfield.vue"; import STMP from "./SMTP.vue"; import Teams from "./Teams.vue"; @@ -83,6 +84,7 @@ const NotificationFormList = { "SMSManager": SMSManager, "slack": Slack, "squadcast": Squadcast, + "SMSEagle": SMSEagle, "smtp": STMP, "stackfield": Stackfield, "teams": Teams, diff --git a/src/languages/en.js b/src/languages/en.js index f7434d39c..18529d703 100644 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -378,6 +378,16 @@ export default { serwersmsAPIPassword: "API Password", serwersmsPhoneNumber: "Phone number", serwersmsSenderName: "SMS Sender Name (registered via customer portal)", + smseagle: "SMSEagle", + smseagleTo: "Phone number(s)", + smseagleGroup: "Phonebook group name(s)", + smseagleContact: "Phonebook contact name(s)", + smseagleRecipientType: "Recipient type", + smseagleRecipient: "Recipient(s) (multiple must be separated with comma)", + smseagleToken: "API Access token", + smseagleUrl: "Your SMSEagle device URL", + smseagleEncoding: "Send as Unicode", + smseaglePriority: "Message priority (0-9, default = 0)", stackfield: "Stackfield", Customize: "Customize", "Custom Footer": "Custom Footer", diff --git a/src/languages/pl.js b/src/languages/pl.js index 3e962746e..e18b50eb0 100644 --- a/src/languages/pl.js +++ b/src/languages/pl.js @@ -359,6 +359,16 @@ export default { serwersmsAPIPassword: "Hasło API", serwersmsPhoneNumber: "Numer telefonu", serwersmsSenderName: "Nazwa nadawcy (zatwierdzona w panelu klienta)", + smseagle: "SMSEagle", + smseagleTo: "Numer/y telefonu", + smseagleGroup: "Grupa/y z Książki adresowej", + smseagleContact: "Kontakt/y z Książki adresowej", + smseagleRecipientType: "Typ odbiorcy", + smseagleRecipient: "Odbiorca/y (wiele musi być oddzielone przecinkami)", + smseagleToken: "Klucz dostępu API", + smseagleUrl: "URL Twojego urządzenia SMSEagle", + smseagleEncoding: "Wyślij jako Unicode", + smseaglePriority: "Priorytet wiadomości (0-9, domyślnie = 0)", stackfield: "Stackfield", Customize: "Dostosuj", "Custom Footer": "Niestandardowa stopka",