From 2c5f8cb14df2e2ab28afc6b85b18b930dd7df725 Mon Sep 17 00:00:00 2001 From: Czarek Date: Thu, 21 Nov 2024 12:43:08 +0100 Subject: [PATCH] add cered.pl sms notification --- server/notification-providers/ceredsms.js | 42 +++++++++++++++++++++++ server/notification.js | 4 ++- src/components/NotificationDialog.vue | 1 + src/components/notifications/CeredSMS.vue | 24 +++++++++++++ src/components/notifications/index.js | 4 ++- src/lang/pl.json | 4 ++- 6 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 server/notification-providers/ceredsms.js create mode 100644 src/components/notifications/CeredSMS.vue diff --git a/server/notification-providers/ceredsms.js b/server/notification-providers/ceredsms.js new file mode 100644 index 000000000..203d92dcc --- /dev/null +++ b/server/notification-providers/ceredsms.js @@ -0,0 +1,42 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); + +class CeredSMS extends NotificationProvider { + + name = "ceredsms"; + + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + let okMsg = "Sent Successfully."; + + try { + let config = { + headers: { + "Content-Type": "application/json", + } + }; + let data = { + "key": notification.ceredsmsApiKey, + "from": notification.ceredsmsSenderName, + "phone_number": notification.ceredsmsPhoneNumber, + "message": msg.replace(/[^\x00-\x7F]/g, "") + }; + + let resp = await axios.post("https://sms.cered.pl/api/send", data, config); + if (!resp.data.message_id) { + if (resp.data.message) { + let error = `CeredSMS.pl API returned error message: ${resp.data.error.message}`; + this.throwGeneralAxiosError(error); + } else { + let error = "CeredSMS.pl API returned an unexpected response"; + this.throwGeneralAxiosError(error); + } + } + + return okMsg; + } catch (error) { + this.throwGeneralAxiosError(error); + } + } +} + +module.exports = CeredSMS; diff --git a/server/notification.js b/server/notification.js index 570c440df..964c080ab 100644 --- a/server/notification.js +++ b/server/notification.js @@ -53,6 +53,7 @@ const GoAlert = require("./notification-providers/goalert"); const SMSManager = require("./notification-providers/smsmanager"); const ServerChan = require("./notification-providers/serverchan"); const ZohoCliq = require("./notification-providers/zoho-cliq"); +const CeredSMS = require("./notification-providers/ceredsms"); class Notification { @@ -117,7 +118,8 @@ class Notification { new Webhook(), new WeCom(), new GoAlert(), - new ZohoCliq() + new ZohoCliq(), + new CeredSMS() ]; for (let item of list) { if (! item.name) { diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index f7fce0d31..0b90cffc1 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -167,6 +167,7 @@ export default { "WeCom": "WeCom (企业微信群机器人)", "ServerChan": "ServerChan (Server酱)", "smsc": "SMSC", + "ceredsms": "sms.cered.pl", }; // Sort by notification name diff --git a/src/components/notifications/CeredSMS.vue b/src/components/notifications/CeredSMS.vue new file mode 100644 index 000000000..0579a3880 --- /dev/null +++ b/src/components/notifications/CeredSMS.vue @@ -0,0 +1,24 @@ + + + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index 05b82a103..9afd976f9 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -51,6 +51,7 @@ import WeCom from "./WeCom.vue"; import GoAlert from "./GoAlert.vue"; import ZohoCliq from "./ZohoCliq.vue"; import Splunk from "./Splunk.vue"; +import CeredSMS from "./CeredSMS.vue"; /** * Manage all notification form. @@ -110,7 +111,8 @@ const NotificationFormList = { "WeCom": WeCom, "GoAlert": GoAlert, "ServerChan": ServerChan, - "ZohoCliq": ZohoCliq + "ZohoCliq": ZohoCliq, + "ceredsms": CeredSMS, }; export default NotificationFormList; diff --git a/src/lang/pl.json b/src/lang/pl.json index aa0b0a67c..0710a9d87 100644 --- a/src/lang/pl.json +++ b/src/lang/pl.json @@ -838,5 +838,7 @@ "noOrBadCertificate": "Brak/zły certyfikat", "Invert Keyword": "Odwróć słowo kluczowe", "Expected Value": "Oczekiwana wartość", - "Json Query": "Zapytanie Json" + "Json Query": "Zapytanie Json", + "ceredsmsSenderName": "Nadpis", + "ceredsmsPhoneNumber": "Numer telefonu" }