Skip to content
Open
Show file tree
Hide file tree
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
17 changes: 10 additions & 7 deletions receivers/discord/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ type discordMessage struct {

// discordLinkEmbed implements https://discord.com/developers/docs/resources/channel#embed-object
Copy link
Copy Markdown
Collaborator

@yuri-tceretian yuri-tceretian Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please change to https://discord.com/developers/docs/resources/message#embed-object-embed-structure

type discordLinkEmbed struct {
Title string `json:"title,omitempty"`
Type discordEmbedType `json:"type,omitempty"`
URL string `json:"url,omitempty"`
Color int64 `json:"color,omitempty"`
Title string `json:"title,omitempty"`
Type discordEmbedType `json:"type,omitempty"`
Description string `json:"description,omitempty"`
URL string `json:"url,omitempty"`
Color int64 `json:"color,omitempty"`

Footer *discordFooter `json:"footer,omitempty"`

Expand Down Expand Up @@ -110,21 +111,22 @@ func (d Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
var tmplErr error
tmpl, _ := templates.TmplText(ctx, d.tmpl, as, l, &tmplErr)

msg.Content = tmpl(d.settings.Message)
messageContent := tmpl(d.settings.Message)
if tmplErr != nil {
level.Warn(l).Log("msg", "failed to template Discord notification content", "err", tmplErr.Error())
// Reset tmplErr for templating other fields.
tmplErr = nil
}
truncatedMsg, truncated := receivers.TruncateInRunes(msg.Content, discordMaxMessageLen)
truncatedMsg, truncated := receivers.TruncateInRunes(messageContent, discordMaxMessageLen)
if truncated {
key, err := notify.ExtractGroupKey(ctx)
if err != nil {
return false, err
}
level.Warn(l).Log("msg", "Truncated content", "key", key, "max_runes", discordMaxMessageLen)
msg.Content = truncatedMsg
messageContent = truncatedMsg
}
msg.Content = ""

if d.settings.AvatarURL != "" {
msg.AvatarURL = tmpl(d.settings.AvatarURL)
Expand All @@ -148,6 +150,7 @@ func (d Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
// Reset tmplErr for templating other fields.
tmplErr = nil
}
linkEmbed.Description = messageContent
linkEmbed.Footer = footer
linkEmbed.Type = discordRichEmbed

Expand Down
6 changes: 4 additions & 2 deletions receivers/discord/discord_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ func TestNotify(t *testing.T) {
},
},
expMsg: map[string]interface{}{
"content": "**Firing**\n\nValue: [no value]\nLabels:\n - alertname = alert1\n - lbl1 = val1\nAnnotations:\n - ann1 = annv1\nSilence: http://localhost/alerting/silence/new?alertmanager=grafana&matcher=alertname%3Dalert1&matcher=lbl1%3Dval1\nDashboard: http://localhost/d/abcd\nPanel: http://localhost/d/abcd?viewPanel=efgh\n",
"content": "",
"embeds": []interface{}{map[string]interface{}{
"color": 1.4037554e+07,
"description": "**Firing**\n\nValue: [no value]\nLabels:\n - alertname = alert1\n - lbl1 = val1\nAnnotations:\n - ann1 = annv1\nSilence: http://localhost/alerting/silence/new?alertmanager=grafana&matcher=alertname%3Dalert1&matcher=lbl1%3Dval1\nDashboard: http://localhost/d/abcd\nPanel: http://localhost/d/abcd?viewPanel=efgh\n",
"footer": map[string]interface{}{
"icon_url": "https://grafana.com/static/assets/img/fav32.png",
"text": "Grafana v" + appVersion,
Expand Down Expand Up @@ -94,9 +95,10 @@ func TestNotify(t *testing.T) {
},
},
expMsg: map[string]interface{}{
"content": "**Firing**\n\nValue: [no value]\nLabels:\n - alertname = alert1\n - lbl1 = val1\nAnnotations:\n - ann1 = annv1\nSilence: http://localhost/alerting/silence/new?alertmanager=grafana&matcher=alertname%3Dalert1&matcher=lbl1%3Dval1\nDashboard: http://localhost/d/abcd\nPanel: http://localhost/d/abcd?viewPanel=efgh\n",
"content": "",
"embeds": []interface{}{map[string]interface{}{
"color": 1.4037554e+07,
"description": "**Firing**\n\nValue: [no value]\nLabels:\n - alertname = alert1\n - lbl1 = val1\nAnnotations:\n - ann1 = annv1\nSilence: http://localhost/alerting/silence/new?alertmanager=grafana&matcher=alertname%3Dalert1&matcher=lbl1%3Dval1\nDashboard: http://localhost/d/abcd\nPanel: http://localhost/d/abcd?viewPanel=efgh\n",
"footer": map[string]interface{}{
"icon_url": "https://grafana.com/static/assets/img/fav32.png",
"text": "Grafana v" + appVersion,
Expand Down