|
|
@ -1,21 +1,40 @@
|
|
|
|
const NotificationProvider = require("./notification-provider");
|
|
|
|
const NotificationProvider = require("./notification-provider");
|
|
|
|
const axios = require("axios");
|
|
|
|
const axios = require("axios");
|
|
|
|
|
|
|
|
const { setSettings, setting } = require("../util-server");
|
|
|
|
|
|
|
|
const { getMonitorRelativeURL } = require("../../src/util");
|
|
|
|
|
|
|
|
|
|
|
|
class Slack extends NotificationProvider {
|
|
|
|
class Slack extends NotificationProvider {
|
|
|
|
|
|
|
|
|
|
|
|
name = "slack";
|
|
|
|
name = "slack";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Deprecated property notification.slackbutton
|
|
|
|
|
|
|
|
* Set it as primary base url if this is not yet set.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
static async deprecateURL(url) {
|
|
|
|
|
|
|
|
let currentPrimaryBaseURL = await setting("primaryBaseURL");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!currentPrimaryBaseURL) {
|
|
|
|
|
|
|
|
console.log("Move the url to be the primary base URL");
|
|
|
|
|
|
|
|
await setSettings("general", {
|
|
|
|
|
|
|
|
primaryBaseURL: url,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
console.log("Already there, no need to move the primary base URL");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
|
|
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
|
|
|
let okMsg = "Sent Successfully. ";
|
|
|
|
let okMsg = "Sent Successfully. ";
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (heartbeatJSON == null) {
|
|
|
|
if (heartbeatJSON == null) {
|
|
|
|
let data = {
|
|
|
|
let data = {
|
|
|
|
"text": "Uptime Kuma Slack testing successful.",
|
|
|
|
"text": msg,
|
|
|
|
"channel": notification.slackchannel,
|
|
|
|
"channel": notification.slackchannel,
|
|
|
|
"username": notification.slackusername,
|
|
|
|
"username": notification.slackusername,
|
|
|
|
"icon_emoji": notification.slackiconemo,
|
|
|
|
"icon_emoji": notification.slackiconemo,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
await axios.post(notification.slackwebhookURL, data)
|
|
|
|
await axios.post(notification.slackwebhookURL, data);
|
|
|
|
return okMsg;
|
|
|
|
return okMsg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -42,26 +61,35 @@ class Slack extends NotificationProvider {
|
|
|
|
"type": "mrkdwn",
|
|
|
|
"type": "mrkdwn",
|
|
|
|
"text": "*Time (UTC)*\n" + time,
|
|
|
|
"text": "*Time (UTC)*\n" + time,
|
|
|
|
}],
|
|
|
|
}],
|
|
|
|
},
|
|
|
|
}],
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (notification.slackbutton) {
|
|
|
|
|
|
|
|
await Slack.deprecateURL(notification.slackbutton);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const baseURL = await setting("primaryBaseURL");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Button
|
|
|
|
|
|
|
|
if (baseURL) {
|
|
|
|
|
|
|
|
data.blocks.push({
|
|
|
|
"type": "actions",
|
|
|
|
"type": "actions",
|
|
|
|
"elements": [
|
|
|
|
"elements": [{
|
|
|
|
{
|
|
|
|
|
|
|
|
"type": "button",
|
|
|
|
"type": "button",
|
|
|
|
"text": {
|
|
|
|
"text": {
|
|
|
|
"type": "plain_text",
|
|
|
|
"type": "plain_text",
|
|
|
|
"text": "Visit Uptime Kuma",
|
|
|
|
"text": "Visit Uptime Kuma",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"value": "Uptime-Kuma",
|
|
|
|
"value": "Uptime-Kuma",
|
|
|
|
"url": notification.slackbutton || "https://github.com/louislam/uptime-kuma",
|
|
|
|
"url": baseURL + getMonitorRelativeURL(monitorJSON.id),
|
|
|
|
},
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
}],
|
|
|
|
}],
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
await axios.post(notification.slackwebhookURL, data)
|
|
|
|
|
|
|
|
|
|
|
|
await axios.post(notification.slackwebhookURL, data);
|
|
|
|
return okMsg;
|
|
|
|
return okMsg;
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
this.throwGeneralAxiosError(error)
|
|
|
|
this.throwGeneralAxiosError(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|