2022-09-23 08:27:22 -07: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 00:46:41 -07:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2022-09-23 08:27:22 -07:00
|
|
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
2024-03-14 06:21:15 -07:00
|
|
|
const okMsg = "Sent Successfully.";
|
|
|
|
|
2022-09-23 08:27:22 -07: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 14:19:05 -08:00
|
|
|
/**
|
|
|
|
* Get the formatted title for message
|
2023-08-11 00:46:41 -07:00
|
|
|
* @param {?object} heartbeatJSON Heartbeat details (For Up/Down only)
|
|
|
|
* @param {?object} monitorJSON Monitor details (For Up/Down only)
|
2023-01-05 14:19:05 -08:00
|
|
|
* @returns {string} Formatted title
|
|
|
|
*/
|
2022-09-23 08:27:22 -07: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;
|