2022-09-23 15:27:22 +00:00
|
|
|
const NotificationProvider = require("./notification-provider");
|
|
|
|
const axios = require("axios");
|
|
|
|
const { DOWN, UP } = require("../../src/util");
|
|
|
|
|
|
|
|
class ServerChan extends NotificationProvider {
|
|
|
|
name = "ServerChan";
|
|
|
|
|
2023-08-11 07:46:41 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2022-09-23 15:27:22 +00:00
|
|
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
2024-03-14 13:21:15 +00:00
|
|
|
const okMsg = "Sent Successfully.";
|
|
|
|
|
2022-09-23 15:27:22 +00:00
|
|
|
try {
|
|
|
|
await axios.post(`https://sctapi.ftqq.com/${notification.serverChanSendKey}.send`, {
|
|
|
|
"title": this.checkStatus(heartbeatJSON, monitorJSON),
|
|
|
|
"desp": msg,
|
|
|
|
});
|
|
|
|
|
|
|
|
return okMsg;
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
this.throwGeneralAxiosError(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-05 22:19:05 +00:00
|
|
|
/**
|
|
|
|
* Get the formatted title for message
|
2023-08-11 07:46:41 +00:00
|
|
|
* @param {?object} heartbeatJSON Heartbeat details (For Up/Down only)
|
|
|
|
* @param {?object} monitorJSON Monitor details (For Up/Down only)
|
2023-01-05 22:19:05 +00:00
|
|
|
* @returns {string} Formatted title
|
|
|
|
*/
|
2022-09-23 15:27:22 +00:00
|
|
|
checkStatus(heartbeatJSON, monitorJSON) {
|
|
|
|
let title = "UptimeKuma Message";
|
|
|
|
if (heartbeatJSON != null && heartbeatJSON["status"] === UP) {
|
|
|
|
title = "UptimeKuma Monitor Up " + monitorJSON["name"];
|
|
|
|
}
|
|
|
|
if (heartbeatJSON != null && heartbeatJSON["status"] === DOWN) {
|
|
|
|
title = "UptimeKuma Monitor Down " + monitorJSON["name"];
|
|
|
|
}
|
|
|
|
return title;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = ServerChan;
|