From 909a0d081ea896406fe3a1c0ae978c3e0b3d3971 Mon Sep 17 00:00:00 2001 From: Czarek Date: Thu, 21 Nov 2024 20:29:33 +0100 Subject: [PATCH 1/3] ceredpl sms --- package-lock.json | 4 +-- 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 | 2 ++ src/lang/pl.json | 4 ++- 7 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 server/notification-providers/ceredsms.js create mode 100644 src/components/notifications/CeredSMS.vue diff --git a/package-lock.json b/package-lock.json index 100cdcd88..328b1d287 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "uptime-kuma", - "version": "2.0.0-dev", + "version": "2.0.0-beta.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "uptime-kuma", - "version": "2.0.0-dev", + "version": "2.0.0-beta.0", "license": "MIT", "dependencies": { "@grpc/grpc-js": "~1.8.22", 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 e7977eb4a..de14d67ad 100644 --- a/server/notification.js +++ b/server/notification.js @@ -69,6 +69,7 @@ const Cellsynt = require("./notification-providers/cellsynt"); const Onesender = require("./notification-providers/onesender"); const Wpush = require("./notification-providers/wpush"); const SendGrid = require("./notification-providers/send-grid"); +const CeredSMS = require("./notification-providers/ceredsms"); class Notification { @@ -154,7 +155,8 @@ class Notification { new GtxMessaging(), new Cellsynt(), new Wpush(), - new SendGrid() + new SendGrid(), + new CeredSMS() ]; for (let item of list) { if (! item.name) { diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index f6d728029..5d6c0fde2 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -183,6 +183,7 @@ export default { "ServerChan": "ServerChan (Serveré…±)", "smsc": "SMSC", "WPush": "WPush(wpush.cn)", + "ceredsms": "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 efa2af5c4..c3a915750 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -67,6 +67,7 @@ import Cellsynt from "./Cellsynt.vue"; import WPush from "./WPush.vue"; import SIGNL4 from "./SIGNL4.vue"; import SendGrid from "./SendGrid.vue"; +import CeredSMS from "./CeredSMS.vue"; /** * Manage all notification form. @@ -142,6 +143,7 @@ const NotificationFormList = { "Cellsynt": Cellsynt, "WPush": WPush, "SendGrid": SendGrid, + "ceredsms": CeredSMS, }; export default NotificationFormList; diff --git a/src/lang/pl.json b/src/lang/pl.json index 82517a1d7..6ceeb6c81 100644 --- a/src/lang/pl.json +++ b/src/lang/pl.json @@ -1088,5 +1088,7 @@ "Clear": "Clear", "Elevator": "Elevator", "Guitar": "Guitar", - "Pop": "Pop" + "Pop": "Pop", + "ceredsmsSenderName": "Nadpis", + "ceredsmsPhoneNumber": "Numer telefonu" } From e13a67acb3666bed1b2c410a219b1872b4aa9d4c Mon Sep 17 00:00:00 2001 From: czarek Date: Thu, 21 Nov 2024 23:33:45 +0100 Subject: [PATCH 2/3] add doc --- server/notification-providers/ceredsms.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/notification-providers/ceredsms.js b/server/notification-providers/ceredsms.js index 203d92dcc..3823cf0e2 100644 --- a/server/notification-providers/ceredsms.js +++ b/server/notification-providers/ceredsms.js @@ -5,6 +5,9 @@ class CeredSMS extends NotificationProvider { name = "ceredsms"; + /** + * @inheritdoc + */ async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { let okMsg = "Sent Successfully."; From 7c67daf7ccc9ff24f47c6c11d12099d591d0fd10 Mon Sep 17 00:00:00 2001 From: czarek Date: Thu, 21 Nov 2024 23:50:08 +0100 Subject: [PATCH 3/3] lang fix --- src/components/notifications/CeredSMS.vue | 4 ++-- src/lang/pl.json | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/components/notifications/CeredSMS.vue b/src/components/notifications/CeredSMS.vue index 0579a3880..9eeb1a878 100644 --- a/src/components/notifications/CeredSMS.vue +++ b/src/components/notifications/CeredSMS.vue @@ -4,11 +4,11 @@
- +
- +
diff --git a/src/lang/pl.json b/src/lang/pl.json index 6ceeb6c81..82517a1d7 100644 --- a/src/lang/pl.json +++ b/src/lang/pl.json @@ -1088,7 +1088,5 @@ "Clear": "Clear", "Elevator": "Elevator", "Guitar": "Guitar", - "Pop": "Pop", - "ceredsmsSenderName": "Nadpis", - "ceredsmsPhoneNumber": "Numer telefonu" + "Pop": "Pop" }