@ -34,11 +34,23 @@ class Discord extends NotificationProvider {
webhookHasAvatar = true ;
}
const messageFormat =
notification . discordMessageFormat || ( notification . discordUseMessageTemplate ? "custom" : "normal" ) ;
// If heartbeatJSON is null, assume we're testing.
if ( heartbeatJSON == null ) {
let content = msg ;
if ( messageFormat === "minimalist" ) {
content = "Test: " + msg ;
} else if ( messageFormat === "custom" ) {
const customMessage = notification . discordMessageTemplate ? . trim ( ) || "" ;
if ( customMessage !== "" ) {
content = await this . renderTemplate ( customMessage , msg , monitorJSON , heartbeatJSON ) ;
}
}
let discordtestdata = {
username : discordDisplayName ,
content : msg ,
content : content ,
} ;
if ( ! webhookHasAvatar ) {
discordtestdata . avatar _url = "https://github.com/louislam/uptime-kuma/raw/master/public/icon.png" ;
@ -55,6 +67,57 @@ class Discord extends NotificationProvider {
// If heartbeatJSON is not null, we go into the normal alerting loop.
let addess = this . extractAddress ( monitorJSON ) ;
// Minimalist: status + name only (is down / is up; no "back up" — may be first trigger)
if ( messageFormat === "minimalist" ) {
const content =
heartbeatJSON [ "status" ] === DOWN
? "🔴 " + monitorJSON [ "name" ] + " is down."
: "🟢 " + monitorJSON [ "name" ] + " is up." ;
let payload = {
username : discordDisplayName ,
content : content ,
} ;
if ( ! webhookHasAvatar ) {
payload . avatar _url = "https://github.com/louislam/uptime-kuma/raw/master/public/icon.png" ;
}
if ( notification . discordChannelType === "createNewForumPost" ) {
payload . thread _name = notification . postName ;
}
if ( notification . discordSuppressNotifications ) {
payload . flags = SUPPRESS _NOTIFICATIONS _FLAG ;
}
await axios . post ( webhookUrl . toString ( ) , payload , config ) ;
return okMsg ;
}
// Custom template: send only content (no embeds)
const useCustomTemplate =
messageFormat === "custom" && ( notification . discordMessageTemplate ? . trim ( ) || "" ) !== "" ;
if ( useCustomTemplate ) {
const content = await this . renderTemplate (
notification . discordMessageTemplate . trim ( ) ,
msg ,
monitorJSON ,
heartbeatJSON
) ;
let payload = {
username : discordDisplayName ,
content : content ,
} ;
if ( ! webhookHasAvatar ) {
payload . avatar _url = "https://github.com/louislam/uptime-kuma/raw/master/public/icon.png" ;
}
if ( notification . discordChannelType === "createNewForumPost" ) {
payload . thread _name = notification . postName ;
}
if ( notification . discordSuppressNotifications ) {
payload . flags = SUPPRESS _NOTIFICATIONS _FLAG ;
}
await axios . post ( webhookUrl . toString ( ) , payload , config ) ;
return okMsg ;
}
if ( heartbeatJSON [ "status" ] === DOWN ) {
const wentOfflineTimestamp = Math . floor ( new Date ( heartbeatJSON [ "time" ] ) . getTime ( ) / 1000 ) ;