From c1267e9b3b654765a62d09e3c5201ba85e75d2e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Kuffel?= Date: Thu, 25 Nov 2021 18:24:36 +0100 Subject: [PATCH 1/3] feat: add SerwerSMS notification provider --- server/notification-providers/serwersms.js | 44 ++++++++++++++++++++++ server/notification.js | 2 + src/components/notifications/SerwerSMS.vue | 28 ++++++++++++++ src/components/notifications/index.js | 4 +- src/languages/en.js | 5 +++ src/languages/pl.js | 5 +++ 6 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 server/notification-providers/serwersms.js create mode 100644 src/components/notifications/SerwerSMS.vue diff --git a/server/notification-providers/serwersms.js b/server/notification-providers/serwersms.js new file mode 100644 index 000000000..9f75982fe --- /dev/null +++ b/server/notification-providers/serwersms.js @@ -0,0 +1,44 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); + +class SerwerSMS extends NotificationProvider { + + name = "serwersms"; + + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + let okMsg = "Sent Successfully."; + + try { + let config = { + headers: { + "Content-Type": "application/json", + } + }; + let data = { + "username": notification.serwersmsUsername, + "password": notification.serwersmsPassword, + "phone": notification.serwersmsPhoneNumber, + "text": msg.replace(/[^\x00-\x7F]/g, ""), + "sender": notification.serwersmsSenderName + }; + + let resp = await axios.post("https://api2.serwersms.pl/messages/send_sms", data, config); + + if (!resp.data.success) { + if (resp.data.error) { + let error = `SerwerSMS.pl API returned error code ${resp.data.error.code} (${resp.data.error.type}) with error message: ${resp.data.error.message}`; + this.throwGeneralAxiosError(error); + } else { + let error = "SerwerSMS.pl API returned an unexpected response"; + this.throwGeneralAxiosError(error); + } + } + + return okMsg; + } catch (error) { + this.throwGeneralAxiosError(error); + } + } +} + +module.exports = SerwerSMS; diff --git a/server/notification.js b/server/notification.js index 18c823b2b..e2cfb193d 100644 --- a/server/notification.js +++ b/server/notification.js @@ -23,6 +23,7 @@ const Feishu = require("./notification-providers/feishu"); const AliyunSms = require("./notification-providers/aliyun-sms"); const DingDing = require("./notification-providers/dingding"); const Bark = require("./notification-providers/bark"); +const SerwerSMS = require("./notification-providers/serwersms"); class Notification { @@ -58,6 +59,7 @@ class Notification { new Telegram(), new Webhook(), new Bark(), + new SerwerSMS(), ]; for (let item of list) { diff --git a/src/components/notifications/SerwerSMS.vue b/src/components/notifications/SerwerSMS.vue new file mode 100644 index 000000000..f2c3463b8 --- /dev/null +++ b/src/components/notifications/SerwerSMS.vue @@ -0,0 +1,28 @@ + + + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index 4b51569a2..9ade03a14 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -22,6 +22,7 @@ import Matrix from "./Matrix.vue"; import AliyunSMS from "./AliyunSms.vue"; import DingDing from "./DingDing.vue"; import Bark from "./Bark.vue"; +import SerwerSMS from "./SerwerSMS.vue"; /** * Manage all notification form. @@ -52,7 +53,8 @@ const NotificationFormList = { "mattermost": Mattermost, "matrix": Matrix, "DingDing": DingDing, - "Bark": Bark + "Bark": Bark, + "serwersms": SerwerSMS } export default NotificationFormList diff --git a/src/languages/en.js b/src/languages/en.js index 0667509f3..a6ad95101 100644 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -308,4 +308,9 @@ export default { "Current User": "Current User", recent: "Recent", shrinkDatabaseDescription: "Trigger database VACUUM for SQLite. If your database is created after 1.10.0, AUTO_VACUUM is already enabled and this action is not needed.", + serwersms: "SerwerSMS.pl", + serwersmsAPIUser: "API Username (incl. webapi_ prefix)", + serwersmsAPIPassword: "API Password", + serwersmsPhoneNumber: "Phone number", + serwersmsSenderName: "SMS Sender Name (registered via customer portal)", }; diff --git a/src/languages/pl.js b/src/languages/pl.js index 082980d3b..9c11a3232 100644 --- a/src/languages/pl.js +++ b/src/languages/pl.js @@ -307,4 +307,9 @@ export default { recent: "Ostatnie", clicksendsms: "ClickSend SMS", apiCredentials: "Poświadczenia API", + serwersms: "SerwerSMS.pl", + serwersmsAPIUser: "Nazwa Użytkownika API (z prefiksem webapi_)", + serwersmsAPIPassword: "Hasło API", + serwersmsPhoneNumber: "Numer Telefonu", + serwersmsSenderName: "Nazwa Nadawcy (zatwierdzona w panelu klienta)", }; From 186c11540f800160abcb9624dba7a9e3f8e7f5bb Mon Sep 17 00:00:00 2001 From: kffl Date: Sat, 27 Nov 2021 13:16:17 +0100 Subject: [PATCH 2/3] style(serwersms): add missing trailing commas Co-authored-by: Adam Stachowicz --- server/notification-providers/serwersms.js | 2 +- src/components/notifications/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/notification-providers/serwersms.js b/server/notification-providers/serwersms.js index 9f75982fe..14fe691a8 100644 --- a/server/notification-providers/serwersms.js +++ b/server/notification-providers/serwersms.js @@ -19,7 +19,7 @@ class SerwerSMS extends NotificationProvider { "password": notification.serwersmsPassword, "phone": notification.serwersmsPhoneNumber, "text": msg.replace(/[^\x00-\x7F]/g, ""), - "sender": notification.serwersmsSenderName + "sender": notification.serwersmsSenderName, }; let resp = await axios.post("https://api2.serwersms.pl/messages/send_sms", data, config); diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index 9ade03a14..bb71fba09 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -54,7 +54,7 @@ const NotificationFormList = { "matrix": Matrix, "DingDing": DingDing, "Bark": Bark, - "serwersms": SerwerSMS + "serwersms": SerwerSMS, } export default NotificationFormList From 64ec7664238e861d9db6e63cfdb56c5d7525ebeb Mon Sep 17 00:00:00 2001 From: kffl Date: Sat, 27 Nov 2021 13:22:54 +0100 Subject: [PATCH 3/3] translate(serwersms): fix pl translation capitalization Co-authored-by: Adam Stachowicz --- src/languages/pl.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/languages/pl.js b/src/languages/pl.js index 9c11a3232..69d68193e 100644 --- a/src/languages/pl.js +++ b/src/languages/pl.js @@ -308,8 +308,8 @@ export default { clicksendsms: "ClickSend SMS", apiCredentials: "Poświadczenia API", serwersms: "SerwerSMS.pl", - serwersmsAPIUser: "Nazwa Użytkownika API (z prefiksem webapi_)", + serwersmsAPIUser: "Nazwa użytkownika API (z prefiksem webapi_)", serwersmsAPIPassword: "Hasło API", - serwersmsPhoneNumber: "Numer Telefonu", - serwersmsSenderName: "Nazwa Nadawcy (zatwierdzona w panelu klienta)", + serwersmsPhoneNumber: "Numer telefonu", + serwersmsSenderName: "Nazwa nadawcy (zatwierdzona w panelu klienta)", };