Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 28 additions & 18 deletions server/notification-providers/discord.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,8 @@ class Discord extends NotificationProvider {
webhookHasAvatar = true;
}

// If heartbeatJSON is null, assume we're testing.
if (heartbeatJSON == null) {
let discordtestdata = {
username: discordDisplayName,
content: msg,
};
if (!webhookHasAvatar) {
discordtestdata.avatar_url = "https://github.com/louislam/uptime-kuma/raw/master/public/icon.png";
}
if (notification.discordChannelType === "createNewForumPost") {
discordtestdata.thread_name = notification.postName;
}
await axios.post(webhookUrl.toString(), discordtestdata, config);
return okMsg;
}

// If heartbeatJSON is not null, we go into the normal alerting loop.
if (heartbeatJSON["status"] === DOWN) {
if (heartbeatJSON?.status === DOWN) {
let discorddowndata = {
username: discordDisplayName,
embeds: [{
Expand Down Expand Up @@ -86,7 +70,7 @@ class Discord extends NotificationProvider {
await axios.post(webhookUrl.toString(), discorddowndata, config);
return okMsg;

} else if (heartbeatJSON["status"] === UP) {
} else if (heartbeatJSON.status === UP) {
let discordupdata = {
username: discordDisplayName,
embeds: [{
Expand Down Expand Up @@ -127,6 +111,32 @@ class Discord extends NotificationProvider {

await axios.post(webhookUrl.toString(), discordupdata, config);
return okMsg;
} else if (!heartbeatJSON) {
// If the heartbeat json is undefined, that means the notification is either a test notification or a cert expiry notification
let discordunknowndata = {
username: discordDisplayName,
embeds: [{
title: "New notification!",
color: 16225888,
// Replace [name][url] with [name](url) to work with discord markdowns
// This pattern is only found in cert expiry notifications and it won't cause any issues with other stuff (like test notificatins)
description: msg.replace(/\[([^\]]+)\]\[([^\]]+)\]/g, "[$1]($2)"),
}],
};
if (!webhookHasAvatar) {
discordunknowndata.avatar_url = "https://github.com/louislam/uptime-kuma/raw/master/public/icon.png";
}

if (notification.discordChannelType === "createNewForumPost") {
discordunknowndata.thread_name = notification.postName;
}

if (notification.discordPrefixMessage) {
discordunknowndata.content = notification.discordPrefixMessage;
}

await axios.post(webhookUrl.toString(), discordunknowndata, config);
return okMsg;
}
} catch (error) {
this.throwGeneralAxiosError(error);
Expand Down
Loading