2021-10-11 09:20:09 +00:00
|
|
|
const NotificationProvider = require("./notification-provider");
|
|
|
|
const axios = require("axios");
|
|
|
|
const { DOWN, UP } = require("../../src/util");
|
|
|
|
|
|
|
|
class Feishu extends NotificationProvider {
|
|
|
|
name = "Feishu";
|
|
|
|
|
2023-08-11 07:46:41 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2021-10-11 09:20:09 +00:00
|
|
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
2024-03-14 13:21:15 +00:00
|
|
|
const okMsg = "Sent Successfully.";
|
2021-10-11 09:20:09 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
if (heartbeatJSON == null) {
|
|
|
|
let testdata = {
|
|
|
|
msg_type: "text",
|
|
|
|
content: {
|
2021-10-11 09:53:13 +00:00
|
|
|
text: msg,
|
2021-10-11 09:20:09 +00:00
|
|
|
},
|
|
|
|
};
|
2024-03-14 13:21:15 +00:00
|
|
|
await axios.post(notification.feishuWebHookUrl, testdata);
|
2021-10-11 09:20:09 +00:00
|
|
|
return okMsg;
|
|
|
|
}
|
|
|
|
|
2022-04-17 07:43:03 +00:00
|
|
|
if (heartbeatJSON["status"] === DOWN) {
|
2021-10-11 09:20:09 +00:00
|
|
|
let downdata = {
|
2024-05-29 10:20:33 +00:00
|
|
|
msg_type: "interactive",
|
|
|
|
card: {
|
|
|
|
config: {
|
2024-05-29 14:22:05 +00:00
|
|
|
update_multi: false,
|
2024-05-29 10:20:33 +00:00
|
|
|
wide_screen_mode: true,
|
|
|
|
},
|
|
|
|
header: {
|
|
|
|
title: {
|
|
|
|
tag: "plain_text",
|
|
|
|
content: "UptimeKuma Alert: [Down] " + monitorJSON["name"],
|
2021-10-11 09:20:09 +00:00
|
|
|
},
|
2024-05-29 10:20:33 +00:00
|
|
|
template: "red",
|
2021-10-11 09:20:09 +00:00
|
|
|
},
|
2024-05-29 10:20:33 +00:00
|
|
|
elements: [
|
|
|
|
{
|
|
|
|
tag: "div",
|
|
|
|
text: {
|
|
|
|
tag: "lark_md",
|
|
|
|
content: getContent(heartbeatJSON),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2021-10-11 09:20:09 +00:00
|
|
|
};
|
2024-03-14 13:21:15 +00:00
|
|
|
await axios.post(notification.feishuWebHookUrl, downdata);
|
2021-10-11 09:20:09 +00:00
|
|
|
return okMsg;
|
|
|
|
}
|
|
|
|
|
2022-04-17 07:43:03 +00:00
|
|
|
if (heartbeatJSON["status"] === UP) {
|
2021-10-11 09:20:09 +00:00
|
|
|
let updata = {
|
2024-05-29 10:20:33 +00:00
|
|
|
msg_type: "interactive",
|
|
|
|
card: {
|
|
|
|
config: {
|
2024-05-29 14:22:05 +00:00
|
|
|
update_multi: false,
|
2024-05-29 10:20:33 +00:00
|
|
|
wide_screen_mode: true,
|
|
|
|
},
|
|
|
|
header: {
|
|
|
|
title: {
|
|
|
|
tag: "plain_text",
|
|
|
|
content: "UptimeKuma Alert: [UP] " + monitorJSON["name"],
|
2021-10-11 09:20:09 +00:00
|
|
|
},
|
2024-05-29 10:20:33 +00:00
|
|
|
template: "green",
|
2021-10-11 09:20:09 +00:00
|
|
|
},
|
2024-05-29 10:20:33 +00:00
|
|
|
elements: [
|
|
|
|
{
|
|
|
|
tag: "div",
|
|
|
|
text: {
|
|
|
|
tag: "lark_md",
|
|
|
|
content: getContent(heartbeatJSON),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
|
|
|
}
|
2021-10-11 09:20:09 +00:00
|
|
|
};
|
2024-03-14 13:21:15 +00:00
|
|
|
await axios.post(notification.feishuWebHookUrl, updata);
|
2021-10-11 09:20:09 +00:00
|
|
|
return okMsg;
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
this.throwGeneralAxiosError(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-29 10:20:33 +00:00
|
|
|
/**
|
|
|
|
* Get content
|
|
|
|
* @param {?object} heartbeatJSON Heartbeat details (For Up/Down only)
|
|
|
|
* @returns {string} Return Successful Message
|
|
|
|
*/
|
|
|
|
function getContent(heartbeatJSON) {
|
|
|
|
return [
|
|
|
|
"**Message**: " + heartbeatJSON["msg"],
|
|
|
|
"**Ping**: " + (heartbeatJSON["ping"] == null ? "N/A" : heartbeatJSON["ping"] + " ms"),
|
|
|
|
`**Time (${heartbeatJSON["timezone"]})**: ${heartbeatJSON["localDateTime"]}`
|
|
|
|
].join("\n");
|
|
|
|
}
|
|
|
|
|
2021-10-11 09:20:09 +00:00
|
|
|
module.exports = Feishu;
|