2021-12-02 07:53:45 +00:00
|
|
|
const NotificationProvider = require("./notification-provider");
|
|
|
|
const axios = require("axios");
|
2024-10-08 23:43:44 +00:00
|
|
|
const { setting } = require("../util-server");
|
2021-12-02 07:53:45 +00:00
|
|
|
const { getMonitorRelativeURL } = require("../../src/util");
|
|
|
|
|
|
|
|
class Stackfield extends NotificationProvider {
|
|
|
|
name = "stackfield";
|
|
|
|
|
2023-08-11 07:46:41 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2024-03-14 13:21:15 +00:00
|
|
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
|
|
|
const okMsg = "Sent Successfully.";
|
|
|
|
|
2021-12-02 07:53:45 +00:00
|
|
|
try {
|
|
|
|
// Stackfield message formatting: https://www.stackfield.com/help/formatting-messages-2001
|
|
|
|
|
|
|
|
let textMsg = "+Uptime Kuma Alert+";
|
|
|
|
|
|
|
|
if (monitorJSON && monitorJSON.name) {
|
|
|
|
textMsg += `\n*${monitorJSON.name}*`;
|
|
|
|
}
|
|
|
|
|
|
|
|
textMsg += `\n${msg}`;
|
|
|
|
|
2024-10-08 23:43:44 +00:00
|
|
|
const baseURL = await setting("primaryBaseURL");
|
2021-12-02 07:53:45 +00:00
|
|
|
if (baseURL) {
|
|
|
|
textMsg += `\n${baseURL + getMonitorRelativeURL(monitorJSON.id)}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
const data = {
|
|
|
|
"Title": textMsg,
|
|
|
|
};
|
|
|
|
|
|
|
|
await axios.post(notification.stackfieldwebhookURL, data);
|
|
|
|
return okMsg;
|
|
|
|
} catch (error) {
|
|
|
|
this.throwGeneralAxiosError(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Stackfield;
|