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