Skip to content

Commit a6c84aa

Browse files
committed
support multiple targets for telegram
1 parent e94a050 commit a6c84aa

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

internal/platform/repositories/alert/telegram.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@ func (r *Repository) CreateTelegramMessage(alert models.Alert) error {
2222
continue
2323
}
2424

25-
params := url.Values{}
26-
params.Add("chat_id", team[0].Chat)
27-
params.Add("parse_mode", "markdownv2")
28-
if team[0].Topic != "" {
29-
params.Add("message_thread_id", team[0].Topic)
25+
// Create a list of URLs for every targets in the team.
26+
// For example, a team needs to send a message to 2 chats, so we create 2 URLs.
27+
for _, t := range team {
28+
params := url.Values{}
29+
params.Add("chat_id", t.Chat)
30+
params.Add("parse_mode", "markdownv2")
31+
if t.Topic != "" {
32+
params.Add("message_thread_id", t.Topic)
33+
}
34+
url := r.config.Notifier.Telegram.Host + r.config.Notifier.Telegram.Token + "/sendMessage?" + params.Encode()
35+
urls = append(urls, url)
3036
}
31-
url := r.config.Notifier.Telegram.Host + r.config.Notifier.Telegram.Token + "/sendMessage?" + params.Encode()
32-
urls = append(urls, url)
3337
}
3438

3539
payload := formatTelegramMessage(alert)

0 commit comments

Comments
 (0)