1
0
mirror of https://github.com/louislam/uptime-kuma.git synced 2024-12-24 22:14:47 +02:00
uptime-kuma/server/notification-providers/wecom.js

57 lines
1.6 KiB
JavaScript
Raw Normal View History

2021-12-25 19:33:47 +02:00
const NotificationProvider = require("./notification-provider");
const axios = require("axios");
const { DOWN, UP } = require("../../src/util");
class WeCom extends NotificationProvider {
name = "WeCom";
/**
* @inheritdoc
*/
2021-12-25 19:33:47 +02:00
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
let okMsg = "Sent Successfully.";
try {
let WeComUrl = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=" + notification.weComBotKey;
let config = {
headers: {
"Content-Type": "application/json"
}
};
let body = this.composeMessage(heartbeatJSON, msg);
await axios.post(WeComUrl, body, config);
return okMsg;
} catch (error) {
this.throwGeneralAxiosError(error);
}
}
/**
* Generate the message to send
* @param {object} heartbeatJSON Heartbeat details (For Up/Down only)
* @param {string} msg General message
* @returns {object} Message
*/
2021-12-25 19:33:47 +02:00
composeMessage(heartbeatJSON, msg) {
let title;
2022-04-17 09:43:03 +02:00
if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] === UP) {
2021-12-25 19:33:47 +02:00
title = "UptimeKuma Monitor Up";
}
2022-04-17 09:43:03 +02:00
if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] === DOWN) {
2021-12-25 19:33:47 +02:00
title = "UptimeKuma Monitor Down";
}
if (msg != null) {
title = "UptimeKuma Message";
}
return {
msgtype: "text",
text: {
content: title + msg
}
};
}
}
module.exports = WeCom;