From 12b5489eb5314dc9c464113fe1a92284704e11bb Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 7 Oct 2021 21:56:32 +0200 Subject: [PATCH 1/3] PromoSMS as Notification Provider Add PromoSMS (Polish SMS Gateway) as new notification provider --- server/notification-providers/promosms.js | 41 +++++++++++++++++++++++ server/notification.js | 2 ++ src/components/notifications/PromoSMS.vue | 39 +++++++++++++++++++++ src/components/notifications/index.js | 2 ++ src/languages/bg-BG.js | 1 + src/languages/da-DK.js | 1 + src/languages/de-DE.js | 1 + src/languages/en.js | 7 ++++ src/languages/es-ES.js | 1 + src/languages/et-EE.js | 1 + src/languages/fa.js | 1 + src/languages/fr-FR.js | 1 + src/languages/hu.js | 1 + src/languages/it-IT.js | 1 + src/languages/ja.js | 1 + src/languages/ko-KR.js | 1 + src/languages/nl-NL.js | 1 + src/languages/pl.js | 1 + src/languages/pt-BR.js | 1 + src/languages/ru-RU.js | 1 + src/languages/sr-latn.js | 1 + src/languages/sr.js | 1 + src/languages/sv-SE.js | 1 + src/languages/tr-TR.js | 1 + src/languages/zh-CN.js | 1 + src/languages/zh-HK.js | 1 + 26 files changed, 112 insertions(+) create mode 100644 server/notification-providers/promosms.js create mode 100644 src/components/notifications/PromoSMS.vue diff --git a/server/notification-providers/promosms.js b/server/notification-providers/promosms.js new file mode 100644 index 000000000..97d046910 --- /dev/null +++ b/server/notification-providers/promosms.js @@ -0,0 +1,41 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); + +class PromoSMS extends NotificationProvider { + + name = "promosms"; + + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + let okMsg = "Sent Successfully."; + + try { + let buffer = new Buffer(notification.promosmsLogin + ":" + notification.promosmsPassword); + let promosmsAuth = buffer.toString('base64'); + let config = { + headers: { + "Authorization": "Basic" + promosmsAuth, + "Content-Type": "application/x-www-form-urlencoded", + "Accept": "text/json" + } + }; + let data = { + "recipients": [ + { + "recipients": notification.promosmsPhoneNumber + } + ], + //Lets remove non ascii char + "text": msg.replace(/[^\x00-\x7F]/g, ""), + "type": notification.promosmsSMSType, + "sender": notification.promosmsSenderName + }; + await axios.post("https://promosms.com/api/rest/v3_2/sms", data, config) + + return okMsg; + } catch (error) { + this.throwGeneralAxiosError(error); + } + } +} + +module.exports = PromoSMS; diff --git a/server/notification.js b/server/notification.js index 207e0a37f..5b104bf8a 100644 --- a/server/notification.js +++ b/server/notification.js @@ -7,6 +7,7 @@ const LunaSea = require("./notification-providers/lunasea"); const Mattermost = require("./notification-providers/mattermost"); const Matrix = require("./notification-providers/matrix"); const Octopush = require("./notification-providers/octopush"); +const PromoSMS = require("./notification-providers/promosms"); const Pushbullet = require("./notification-providers/pushbullet"); const Pushover = require("./notification-providers/pushover"); const Pushy = require("./notification-providers/pushy"); @@ -37,6 +38,7 @@ class Notification { new Mattermost(), new Matrix(), new Octopush(), + new PromoSMS(), new Pushbullet(), new Pushover(), new Pushy(), diff --git a/src/components/notifications/PromoSMS.vue b/src/components/notifications/PromoSMS.vue new file mode 100644 index 000000000..640360d08 --- /dev/null +++ b/src/components/notifications/PromoSMS.vue @@ -0,0 +1,39 @@ + + + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index fab4075e7..7d70eea17 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -10,6 +10,7 @@ import Teams from "./Teams.vue"; import Pushover from "./Pushover.vue"; import Pushy from "./Pushy.vue"; import Octopush from "./Octopush.vue"; +import PromoSMS from "./PromoSMS.vue"; import LunaSea from "./LunaSea.vue"; import Apprise from "./Apprise.vue"; import Pushbullet from "./Pushbullet.vue"; @@ -35,6 +36,7 @@ const NotificationFormList = { "pushover": Pushover, "pushy": Pushy, "octopush": Octopush, + "promosms": PromoSMS, "lunasea": LunaSea, "apprise": Apprise, "pushbullet": Pushbullet, diff --git a/src/languages/bg-BG.js b/src/languages/bg-BG.js index 0e915255d..bcf1b573b 100644 --- a/src/languages/bg-BG.js +++ b/src/languages/bg-BG.js @@ -190,6 +190,7 @@ export default { pushover: "Pushover", pushy: "Pushy", octopush: "Octopush", + promosms: "PromoSMS", lunasea: "LunaSea", apprise: "Apprise (Поддържа 50+ услуги за инвестяване)", pushbullet: "Pushbullet", diff --git a/src/languages/da-DK.js b/src/languages/da-DK.js index ad156aefe..66e7cb3d4 100644 --- a/src/languages/da-DK.js +++ b/src/languages/da-DK.js @@ -192,6 +192,7 @@ export default { pushover: "Pushover", pushy: "Pushy", octopush: "Octopush", + promosms: "PromoSMS", lunasea: "LunaSea", apprise: "Apprise (Support 50+ Notification services)", pushbullet: "Pushbullet", diff --git a/src/languages/de-DE.js b/src/languages/de-DE.js index a6cc42b3b..20beb626e 100644 --- a/src/languages/de-DE.js +++ b/src/languages/de-DE.js @@ -191,6 +191,7 @@ export default { pushover: "Pushover", pushy: "Pushy", octopush: "Octopush", + promosms: "PromoSMS", lunasea: "LunaSea", apprise: "Apprise (Support 50+ Notification services)", pushbullet: "Pushbullet", diff --git a/src/languages/en.js b/src/languages/en.js index 219040033..2ce8f46be 100644 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -235,6 +235,7 @@ export default { pushover: "Pushover", pushy: "Pushy", octopush: "Octopush", + promosms: "PromoSMS", lunasea: "LunaSea", apprise: "Apprise (Support 50+ Notification services)", pushbullet: "Pushbullet", @@ -273,5 +274,11 @@ export default { aboutIconURL: "You can provide a link to a picture in \"Icon URL\" to override the default profile picture. Will not be used if Icon Emoji is set.", aboutMattermostChannelName: "You can override the default channel that webhook posts to by entering the channel name into \"Channel Name\" field. This needs to be enabled in Mattermost webhook settings. Ex: #other-channel", "matrix": "Matrix", + promosmsTypeEco: "SMS ECO - cheap but slow and often overloaded. Limited only to Polish recipients.", + promosmsTypeFlash: "SMS FLASH - Message will automatically show on recipient device. Limited only to Polish recipients.", + promosmsTypeFull: "SMS FULL - Premium tier of SMS, You can use Your Sender Name (You need to register name first). Reliable for alerts.", + promosmsTypeFull: "SMS SPEED - Highest priority in system. Very quick and reliable but costly (about twice of SMS FULL price).", + promosmsPhoneNumber: "Phone number (for Polish recipient You can skip area codes)", + promosmsSMSSender: "SMS Sender Name : Pre-registred name or one of defaults: InfoSMS, SMS Info, MaxSMS, INFO, SMS", // End notification form }; diff --git a/src/languages/es-ES.js b/src/languages/es-ES.js index 2558a6863..3fa207339 100644 --- a/src/languages/es-ES.js +++ b/src/languages/es-ES.js @@ -192,6 +192,7 @@ export default { pushover: "Pushover", pushy: "Pushy", octopush: "Octopush", + promosms: "PromoSMS", lunasea: "LunaSea", apprise: "Apprise (Support 50+ Notification services)", pushbullet: "Pushbullet", diff --git a/src/languages/et-EE.js b/src/languages/et-EE.js index a6be8232e..52439f5f6 100644 --- a/src/languages/et-EE.js +++ b/src/languages/et-EE.js @@ -191,6 +191,7 @@ export default { pushover: "Pushover", pushy: "Pushy", octopush: "Octopush", + promosms: "PromoSMS", lunasea: "LunaSea", apprise: "Apprise (vahendab üle 65 teavitusteenust)", pushbullet: "Pushbullet", diff --git a/src/languages/fa.js b/src/languages/fa.js index d686488ff..7eed151ad 100644 --- a/src/languages/fa.js +++ b/src/languages/fa.js @@ -199,6 +199,7 @@ export default { pushover: "Pushover", pushy: "Pushy", octopush: "Octopush", + promosms: "PromoSMS", lunasea: "LunaSea", apprise: "Apprise (Support 50+ Notification services)", pushbullet: "Pushbullet", diff --git a/src/languages/fr-FR.js b/src/languages/fr-FR.js index 6ef69f0a5..9f234f7aa 100644 --- a/src/languages/fr-FR.js +++ b/src/languages/fr-FR.js @@ -192,6 +192,7 @@ export default { pushover: "Pushover", pushy: "Pushy", octopush: "Octopush", + promosms: "PromoSMS", lunasea: "LunaSea", apprise: "Apprise (Support 50+ Notification services)", pushbullet: "Pushbullet", diff --git a/src/languages/hu.js b/src/languages/hu.js index 039cf6707..47ac72d64 100644 --- a/src/languages/hu.js +++ b/src/languages/hu.js @@ -190,6 +190,7 @@ export default { pushover: "Pushover", pushy: "Pushy", octopush: "Octopush", + promosms: "PromoSMS", lunasea: "LunaSea", apprise: "Apprise (Support 50+ Notification services)", pushbullet: "Pushbullet", diff --git a/src/languages/it-IT.js b/src/languages/it-IT.js index b318c97e4..5ddc414f7 100644 --- a/src/languages/it-IT.js +++ b/src/languages/it-IT.js @@ -191,6 +191,7 @@ export default { pushover: "Pushover", pushy: "Pushy", octopush: "Octopush", + promosms: "PromoSMS", lunasea: "LunaSea", apprise: "Apprise (Support 50+ Notification services)", pushbullet: "Pushbullet", diff --git a/src/languages/ja.js b/src/languages/ja.js index 5042d18b9..f96028e42 100644 --- a/src/languages/ja.js +++ b/src/languages/ja.js @@ -192,6 +192,7 @@ export default { pushover: "Pushover", pushy: "Pushy", octopush: "Octopush", + promosms: "PromoSMS", lunasea: "LunaSea", apprise: "Apprise (Support 50+ Notification services)", pushbullet: "Pushbullet", diff --git a/src/languages/ko-KR.js b/src/languages/ko-KR.js index 6cb86ed20..9d5cb5bdf 100644 --- a/src/languages/ko-KR.js +++ b/src/languages/ko-KR.js @@ -192,6 +192,7 @@ export default { pushover: "Pushover", pushy: "Pushy", octopush: "Octopush", + promosms: "PromoSMS", lunasea: "LunaSea", apprise: "Apprise (Support 50+ Notification services)", pushbullet: "Pushbullet", diff --git a/src/languages/nl-NL.js b/src/languages/nl-NL.js index 1303a0960..5c3225530 100644 --- a/src/languages/nl-NL.js +++ b/src/languages/nl-NL.js @@ -192,6 +192,7 @@ export default { pushover: "Pushover", pushy: "Pushy", octopush: "Octopush", + promosms: "PromoSMS", lunasea: "LunaSea", apprise: "Apprise (Support 50+ Notification services)", pushbullet: "Pushbullet", diff --git a/src/languages/pl.js b/src/languages/pl.js index 9a079a9ce..05101c6aa 100644 --- a/src/languages/pl.js +++ b/src/languages/pl.js @@ -192,6 +192,7 @@ export default { pushover: "Pushover", pushy: "Pushy", octopush: "Octopush", + promosms: "PromoSMS", lunasea: "LunaSea", apprise: "Apprise (obsługuje 50+ usług powiadamiania)", pushbullet: "Pushbullet", diff --git a/src/languages/pt-BR.js b/src/languages/pt-BR.js index 201314bb6..70647fd9f 100644 --- a/src/languages/pt-BR.js +++ b/src/languages/pt-BR.js @@ -191,6 +191,7 @@ export default { pushover: "Pushover", pushy: "Pushy", octopush: "Octopush", + promosms: "PromoSMS", lunasea: "LunaSea", apprise: "Apprise (Support 50+ Notification services)", pushbullet: "Pushbullet", diff --git a/src/languages/ru-RU.js b/src/languages/ru-RU.js index f466ff793..2dd3eafbb 100644 --- a/src/languages/ru-RU.js +++ b/src/languages/ru-RU.js @@ -196,6 +196,7 @@ export default { pushover: "Pushover", pushy: "Pushy", octopush: "Octopush", + promosms: "PromoSMS", lunasea: "LunaSea", apprise: "Apprise (Support 50+ Notification services)", pushbullet: "Pushbullet", diff --git a/src/languages/sr-latn.js b/src/languages/sr-latn.js index f249f568d..9e66aa541 100644 --- a/src/languages/sr-latn.js +++ b/src/languages/sr-latn.js @@ -192,6 +192,7 @@ export default { pushover: "Pushover", pushy: "Pushy", octopush: "Octopush", + promosms: "PromoSMS", lunasea: "LunaSea", apprise: "Apprise (Support 50+ Notification services)", pushbullet: "Pushbullet", diff --git a/src/languages/sr.js b/src/languages/sr.js index 8ea651b74..df8e98997 100644 --- a/src/languages/sr.js +++ b/src/languages/sr.js @@ -192,6 +192,7 @@ export default { pushover: "Pushover", pushy: "Pushy", octopush: "Octopush", + promosms: "PromoSMS", lunasea: "LunaSea", apprise: "Apprise (Support 50+ Notification services)", pushbullet: "Pushbullet", diff --git a/src/languages/sv-SE.js b/src/languages/sv-SE.js index 997d94a7a..e29d355c2 100644 --- a/src/languages/sv-SE.js +++ b/src/languages/sv-SE.js @@ -192,6 +192,7 @@ export default { pushover: "Pushover", pushy: "Pushy", octopush: "Octopush", + promosms: "PromoSMS", lunasea: "LunaSea", apprise: "Apprise (Support 50+ Notification services)", pushbullet: "Pushbullet", diff --git a/src/languages/tr-TR.js b/src/languages/tr-TR.js index 614ab0ee5..8c404a7dc 100644 --- a/src/languages/tr-TR.js +++ b/src/languages/tr-TR.js @@ -191,6 +191,7 @@ export default { pushover: "Pushover", pushy: "Pushy", octopush: "Octopush", + promosms: "PromoSMS", lunasea: "LunaSea", apprise: "Apprise (Support 50+ Notification services)", pushbullet: "Pushbullet", diff --git a/src/languages/zh-CN.js b/src/languages/zh-CN.js index 65e8909ac..40db94e23 100644 --- a/src/languages/zh-CN.js +++ b/src/languages/zh-CN.js @@ -192,6 +192,7 @@ export default { pushover: "Pushover", pushy: "Pushy", octopush: "Octopush", + promosms: "PromoSMS", lunasea: "LunaSea", apprise: "Apprise (Support 50+ Notification services)", pushbullet: "Pushbullet", diff --git a/src/languages/zh-HK.js b/src/languages/zh-HK.js index ea81f7f33..7f5e2259b 100644 --- a/src/languages/zh-HK.js +++ b/src/languages/zh-HK.js @@ -192,6 +192,7 @@ export default { pushover: "Pushover", pushy: "Pushy", octopush: "Octopush", + promosms: "PromoSMS", lunasea: "LunaSea", apprise: "Apprise (支援 50 多種通知)", pushbullet: "Pushbullet", From dfd63386ba367f442b11379776a56cd8290a5153 Mon Sep 17 00:00:00 2001 From: Lukas <35193662+NixNotCastey@users.noreply.github.com> Date: Fri, 8 Oct 2021 09:11:13 +0200 Subject: [PATCH 2/3] Make PromoSMS actually working Make PromoSMS actually working and inform on success only when API return 0 --- server/notification-providers/promosms.js | 24 +++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/server/notification-providers/promosms.js b/server/notification-providers/promosms.js index 97d046910..23d6a4502 100644 --- a/server/notification-providers/promosms.js +++ b/server/notification-providers/promosms.js @@ -9,28 +9,28 @@ class PromoSMS extends NotificationProvider { let okMsg = "Sent Successfully."; try { - let buffer = new Buffer(notification.promosmsLogin + ":" + notification.promosmsPassword); - let promosmsAuth = buffer.toString('base64'); let config = { headers: { - "Authorization": "Basic" + promosmsAuth, - "Content-Type": "application/x-www-form-urlencoded", - "Accept": "text/json" + "Content-Type": "application/json", + "Authorization": "Basic " + Buffer.from(notification.promosmsLogin + ":" + notification.promosmsPassword).toString('base64'), + "Accept": "text/json", } }; let data = { - "recipients": [ - { - "recipients": notification.promosmsPhoneNumber - } - ], + "recipients": [ notification.promosmsPhoneNumber ], //Lets remove non ascii char "text": msg.replace(/[^\x00-\x7F]/g, ""), - "type": notification.promosmsSMSType, + "type": Number(notification.promosmsSMSType), "sender": notification.promosmsSenderName }; - await axios.post("https://promosms.com/api/rest/v3_2/sms", data, config) + await axios.post("https://promosms.com/api/rest/v3_2/sms", data, config).then(resp => { + if (resp.data.response.status !== 0) { + let error = "Something gone wrong. Api returned " + resp.data.response.status + "."; + this.throwGeneralAxiosError(error); + } + }); + return okMsg; } catch (error) { this.throwGeneralAxiosError(error); From db791c880a57971a1afe38bb7188e5d937e0a4ce Mon Sep 17 00:00:00 2001 From: Lukas <35193662+NixNotCastey@users.noreply.github.com> Date: Fri, 8 Oct 2021 11:49:12 +0200 Subject: [PATCH 3/3] Don't use then with await. --- server/notification-providers/promosms.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/server/notification-providers/promosms.js b/server/notification-providers/promosms.js index 23d6a4502..362ef714a 100644 --- a/server/notification-providers/promosms.js +++ b/server/notification-providers/promosms.js @@ -24,12 +24,12 @@ class PromoSMS extends NotificationProvider { "sender": notification.promosmsSenderName }; - await axios.post("https://promosms.com/api/rest/v3_2/sms", data, config).then(resp => { - if (resp.data.response.status !== 0) { - let error = "Something gone wrong. Api returned " + resp.data.response.status + "."; - this.throwGeneralAxiosError(error); - } - }); + let resp = await axios.post("https://promosms.com/api/rest/v3_2/sms", data, config); + + if (resp.data.response.status !== 0) { + let error = "Something gone wrong. Api returned " + resp.data.response.status + "."; + this.throwGeneralAxiosError(error); + } return okMsg; } catch (error) {