From 35d586fc3a735dfd8caf303188bb3a89c9d197ae Mon Sep 17 00:00:00 2001 From: Pulse Monitor Date: Sun, 17 Aug 2025 07:27:08 +0000 Subject: [PATCH] fix: webhook templates for grouped alerts not being used - Fixed same template overwriting bug in sendGroupedWebhook function - Grouped alerts now properly use custom templates - Telegram webhooks now work for both individual and grouped alerts - Successfully tested Telegram webhook delivery --- internal/notifications/notifications.go | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/internal/notifications/notifications.go b/internal/notifications/notifications.go index b8dc6f8f9..8b1e2ed84 100644 --- a/internal/notifications/notifications.go +++ b/internal/notifications/notifications.go @@ -446,17 +446,10 @@ func (n *NotificationManager) sendGroupedWebhook(webhook WebhookConfig, alertLis data := n.prepareWebhookData(alert, nil) - // For Telegram, extract chat_id from URL if present - if webhook.Service == "telegram" { - if chatID, err := extractTelegramChatID(webhook.URL); err == nil && chatID != "" { - data.ChatID = chatID - } else if err != nil { - log.Error(). - Err(err). - Str("webhook", webhook.Name). - Msg("Failed to extract Telegram chat_id for grouped notification") - return // Skip this webhook - } + // For Telegram webhooks (check URL pattern since service might be empty) + if strings.Contains(webhook.URL, "api.telegram.org") { + // Don't need to extract chat_id from URL since it's in the template + // The template already has the chat_id embedded } jsonData, err = n.generatePayloadFromTemplate(enhanced.PayloadTemplate, data) @@ -536,7 +529,8 @@ func (n *NotificationManager) sendGroupedWebhook(webhook WebhookConfig, alertLis } // Use generic payload if no service or template not found - if webhook.Service == "" || webhook.Service == "generic" || jsonData == nil { + // But ONLY if jsonData hasn't been set yet (from custom template) + if jsonData == nil && (webhook.Service == "" || webhook.Service == "generic") { // Use generic payload for other services payload := map[string]interface{}{ "alerts": alertList,