mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-12-04 23:11:24 +03:00
8a92054c2b
* Added JSDoc to eslint rules Signed-off-by: Matthew Nickson <mnickson@sidingsmedia.com> * Fixed JSDoc eslint errors Signed-off-by: Matthew Nickson <mnickson@sidingsmedia.com> * Update the check-linters workflow to Node.js 20 --------- Signed-off-by: Matthew Nickson <mnickson@sidingsmedia.com> Co-authored-by: Louis Lam <louislam@users.noreply.github.com>
56 lines
1.6 KiB
JavaScript
56 lines
1.6 KiB
JavaScript
const NotificationProvider = require("./notification-provider");
|
|
const axios = require("axios");
|
|
const { DOWN, UP } = require("../../src/util");
|
|
|
|
class WeCom extends NotificationProvider {
|
|
|
|
name = "WeCom";
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
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
|
|
*/
|
|
composeMessage(heartbeatJSON, msg) {
|
|
let title;
|
|
if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] === UP) {
|
|
title = "UptimeKuma Monitor Up";
|
|
}
|
|
if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] === DOWN) {
|
|
title = "UptimeKuma Monitor Down";
|
|
}
|
|
if (msg != null) {
|
|
title = "UptimeKuma Message";
|
|
}
|
|
return {
|
|
msgtype: "text",
|
|
text: {
|
|
content: title + msg
|
|
}
|
|
};
|
|
}
|
|
}
|
|
|
|
module.exports = WeCom;
|