diff --git a/package.json b/package.json index 03112518a..1dd79e905 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "update-language-files": "cd extra/update-language-files && node index.js && eslint ../../src/languages/**.js --fix" }, "dependencies": { + "@alicloud/pop-core": "^1.7.10", "@fortawesome/fontawesome-svg-core": "~1.2.36", "@fortawesome/free-regular-svg-icons": "~5.15.4", "@fortawesome/free-solid-svg-icons": "~5.15.4", diff --git a/server/notification-providers/aliyun-sms.js b/server/notification-providers/aliyun-sms.js new file mode 100644 index 000000000..9111c429a --- /dev/null +++ b/server/notification-providers/aliyun-sms.js @@ -0,0 +1,70 @@ +const NotificationProvider = require("./notification-provider"); +const { DOWN, UP } = require("../../src/util"); +const Core = require("@alicloud/pop-core"); + +class AliyunSMS extends NotificationProvider { + name = "AliyunSMS"; + + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + let okMsg = "Sent Successfully."; + + try { + var client = new Core({ + accessKeyId: notification.accessKeyId, + accessKeySecret: notification.secretAccessKey, + endpoint: "https://dysmsapi.aliyuncs.com", + apiVersion: "2017-05-25", + }); + + var params = { + PhoneNumbers: notification.phonenumber, + TemplateCode: notification.templateCode, + SignName: notification.signName, + TemplateParam: JSON.stringify({ + name: "", + time: "", + status: "", + msg: msg, + }), + }; + + if (heartbeatJSON != null) { + params.TemplateParam = JSON.stringify({ + name: monitorJSON["name"], + time: heartbeatJSON["time"], + status: this.statusToString(heartbeatJSON["status"]), + msg: heartbeatJSON["msg"], + }); + } + + var requestOption = { + method: "POST", + }; + + await client.request("SendSms", params, requestOption).then( + (result) => { + console.log(JSON.stringify(result)); + return okMsg; + }, + (ex) => { + console.log(ex); + } + ); + } catch (error) { + this.throwGeneralAxiosError(error); + } + } + + statusToString(status) { + switch (status) { + case DOWN: + return "DOWN"; + case UP: + return "UP"; + default: + return status; + } + } +} + +module.exports = AliyunSMS; diff --git a/server/notification.js b/server/notification.js index 41a0063c3..21bd2b1e6 100644 --- a/server/notification.js +++ b/server/notification.js @@ -19,6 +19,7 @@ const Teams = require("./notification-providers/teams"); const Telegram = require("./notification-providers/telegram"); const Webhook = require("./notification-providers/webhook"); const Feishu = require("./notification-providers/feishu"); +const AliyunSms = require("./notification-providers/aliyun-sms"); class Notification { @@ -31,6 +32,7 @@ class Notification { const list = [ new Apprise(), + new AliyunSms(), new Discord(), new Teams(), new Gotify(), diff --git a/src/components/notifications/AliyunSms.vue b/src/components/notifications/AliyunSms.vue new file mode 100644 index 000000000..07dca8bbb --- /dev/null +++ b/src/components/notifications/AliyunSms.vue @@ -0,0 +1,24 @@ + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index 140c1180c..74fe0df38 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -18,6 +18,7 @@ import Pushbullet from "./Pushbullet.vue"; import Line from "./Line.vue"; import Mattermost from "./Mattermost.vue"; import Matrix from "./Matrix.vue"; +import AliyunSMS from "./AliyunSms.vue"; /** * Manage all notification form. @@ -40,6 +41,7 @@ const NotificationFormList = { "promosms": PromoSMS, "lunasea": LunaSea, "Feishu": Feishu, + "AliyunSMS":AliyunSMS, "apprise": Apprise, "pushbullet": Pushbullet, "line": Line,