Skip to content

Commit

Permalink
feat: update feishu notification template (louislam#4800)
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm authored May 29, 2024
2 parents 9f35290 + 30bf7a5 commit 40d24e7
Showing 1 changed file with 55 additions and 34 deletions.
89 changes: 55 additions & 34 deletions server/notification-providers/feishu.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,51 +25,59 @@ class Feishu extends NotificationProvider {

if (heartbeatJSON["status"] === DOWN) {
let downdata = {
msg_type: "post",
content: {
post: {
zh_cn: {
title: "UptimeKuma Alert: [Down] " + monitorJSON["name"],
content: [
[
{
tag: "text",
text:
"[Down] " +
heartbeatJSON["msg"] +
`\nTime (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`
},
],
],
msg_type: "interactive",
card: {
config: {
update_multi: false,
wide_screen_mode: true,
},
header: {
title: {
tag: "plain_text",
content: "UptimeKuma Alert: [Down] " + monitorJSON["name"],
},
template: "red",
},
},
elements: [
{
tag: "div",
text: {
tag: "lark_md",
content: getContent(heartbeatJSON),
},
}
]
}
};
await axios.post(notification.feishuWebHookUrl, downdata);
return okMsg;
}

if (heartbeatJSON["status"] === UP) {
let updata = {
msg_type: "post",
content: {
post: {
zh_cn: {
title: "UptimeKuma Alert: [Up] " + monitorJSON["name"],
content: [
[
{
tag: "text",
text:
"[Up] " +
heartbeatJSON["msg"] +
`\nTime (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`,
},
],
],
msg_type: "interactive",
card: {
config: {
update_multi: false,
wide_screen_mode: true,
},
header: {
title: {
tag: "plain_text",
content: "UptimeKuma Alert: [UP] " + monitorJSON["name"],
},
template: "green",
},
},
elements: [
{
tag: "div",
text: {
tag: "lark_md",
content: getContent(heartbeatJSON),
},
},
]
}
};
await axios.post(notification.feishuWebHookUrl, updata);
return okMsg;
Expand All @@ -80,4 +88,17 @@ class Feishu extends NotificationProvider {
}
}

/**
* 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");
}

module.exports = Feishu;

0 comments on commit 40d24e7

Please sign in to comment.