From 99fb5836e24a953f4ed66701474b4734fb347dcd Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Fri, 14 Jul 2023 14:29:35 +0800 Subject: [PATCH] =?UTF-8?q?Add=20SMSC=20(=D0=A1=D0=9C=D0=A1=D0=A6=D0=B5?= =?UTF-8?q?=D0=BD=D1=82=D1=80)=20provider=20notification=20(#3335)=20By=20?= =?UTF-8?q?@FlatronBuda?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add SMSC, code from #3334 Co-authored-by: FlatronBuda <> * Update server/notification-providers/smsc.js Co-authored-by: Frank Elsinga * Update server/notification-providers/smsc.js Co-authored-by: Frank Elsinga * Update server/notification-providers/smsc.js Co-authored-by: Frank Elsinga * Update according to @FlatronBuda * Move to the regional list --------- Co-authored-by: Frank Elsinga --- server/notification-providers/smsc.js | 42 ++++++++++++++++++++++++++ server/notification.js | 2 ++ src/components/NotificationDialog.vue | 1 + src/components/notifications/SMSC.vue | 43 +++++++++++++++++++++++++++ src/components/notifications/index.js | 2 ++ 5 files changed, 90 insertions(+) create mode 100644 server/notification-providers/smsc.js create mode 100644 src/components/notifications/SMSC.vue diff --git a/server/notification-providers/smsc.js b/server/notification-providers/smsc.js new file mode 100644 index 00000000..251bc455 --- /dev/null +++ b/server/notification-providers/smsc.js @@ -0,0 +1,42 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); + +class SMSC extends NotificationProvider { + name = "smsc"; + + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + let okMsg = "Sent Successfully."; + try { + let config = { + headers: { + "Content-Type": "application/json", + "Accept": "text/json", + } + }; + + let getArray = [ + "fmt=3", + "translit=" + notification.smscTranslit, + "login=" + notification.smscLogin, + "psw=" + notification.smscPassword, + "phones=" + notification.smscToNumber, + "mes=" + encodeURIComponent(msg.replace(/[^\x00-\x7F]/g, "")), + ]; + if (notification.smscSenderName !== "") { + getArray.push("sender=" + notification.smscSenderName); + } + + let resp = await axios.get("https://smsc.kz/sys/send.php?" + getArray.join("&"), config); + if (resp.data.id === undefined) { + let error = `Something gone wrong. Api returned code ${resp.data.error_code}: ${resp.data.error}`; + this.throwGeneralAxiosError(error); + } + + return okMsg; + } catch (error) { + this.throwGeneralAxiosError(error); + } + } +} + +module.exports = SMSC; diff --git a/server/notification.js b/server/notification.js index 9bfa371d..ea5c8ee0 100644 --- a/server/notification.js +++ b/server/notification.js @@ -6,6 +6,7 @@ const AliyunSms = require("./notification-providers/aliyun-sms"); const Apprise = require("./notification-providers/apprise"); const Bark = require("./notification-providers/bark"); const ClickSendSMS = require("./notification-providers/clicksendsms"); +const SMSC = require("./notification-providers/smsc"); const DingDing = require("./notification-providers/dingding"); const Discord = require("./notification-providers/discord"); const Feishu = require("./notification-providers/feishu"); @@ -68,6 +69,7 @@ class Notification { new Apprise(), new Bark(), new ClickSendSMS(), + new SMSC(), new DingDing(), new Discord(), new Feishu(), diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index 856d6f53..f977225f 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -164,6 +164,7 @@ export default { "SMSManager": "SmsManager (smsmanager.cz)", "WeCom": "WeCom (企业微信群机器人)", "ServerChan": "ServerChan (Server酱)", + "smsc": "SMSC", }; // Sort by notification name diff --git a/src/components/notifications/SMSC.vue b/src/components/notifications/SMSC.vue new file mode 100644 index 00000000..36a0a895 --- /dev/null +++ b/src/components/notifications/SMSC.vue @@ -0,0 +1,43 @@ + + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index 7b5e6b6c..673a84a9 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -4,6 +4,7 @@ import AliyunSMS from "./AliyunSms.vue"; import Apprise from "./Apprise.vue"; import Bark from "./Bark.vue"; import ClickSendSMS from "./ClickSendSMS.vue"; +import SMSC from "./SMSC.vue"; import DingDing from "./DingDing.vue"; import Discord from "./Discord.vue"; import Feishu from "./Feishu.vue"; @@ -61,6 +62,7 @@ const NotificationFormList = { "apprise": Apprise, "Bark": Bark, "clicksendsms": ClickSendSMS, + "smsc": SMSC, "DingDing": DingDing, "discord": Discord, "Feishu": Feishu,