From 2661054fe8009704c55646c551e3bca7ed6ea6fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=A4ggmark?= Date: Tue, 14 Apr 2020 15:02:58 +0200 Subject: [PATCH] Hangouts: fixes notifications for alerts with empty message (#23559) * Hangouts: fixes notifications for alerts with empty message * Update pkg/services/alerting/notifiers/googlechat.go Co-Authored-By: Marcus Efraimsson Co-authored-by: Marcus Efraimsson --- pkg/services/alerting/notifiers/googlechat.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/services/alerting/notifiers/googlechat.go b/pkg/services/alerting/notifiers/googlechat.go index 4778e86e560..c69a72fc5c5 100644 --- a/pkg/services/alerting/notifiers/googlechat.go +++ b/pkg/services/alerting/notifiers/googlechat.go @@ -126,13 +126,15 @@ func (gcn *GoogleChatNotifier) Notify(evalContext *alerting.EvalContext) error { gcn.log.Error("evalContext returned an invalid rule URL") } - // add a text paragraph widget for the message - widgets := []widget{ - textParagraphWidget{ + widgets := []widget{} + if len(evalContext.Rule.Message) > 0 { + // add a text paragraph widget for the message if there is a message + // Google Chat API doesn't accept an empty text property + widgets = append(widgets, textParagraphWidget{ Text: text{ Text: evalContext.Rule.Message, }, - }, + }) } // add a text paragraph widget for the fields