mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-08-08 17:13:08 +08:00
Add aliyun sms notification
This commit is contained in:
70
server/notification-providers/aliyun-sms.js
Normal file
70
server/notification-providers/aliyun-sms.js
Normal file
@@ -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;
|
@@ -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(),
|
||||
|
Reference in New Issue
Block a user