diff --git a/pkg/services/ngalert/notifier/channels/teams.go b/pkg/services/ngalert/notifier/channels/teams.go index 7a40fb60857..51535bcbcb4 100644 --- a/pkg/services/ngalert/notifier/channels/teams.go +++ b/pkg/services/ngalert/notifier/channels/teams.go @@ -69,10 +69,10 @@ type AdaptiveCardsAttachment struct { // AdapativeCard repesents an Adaptive Card. // https://adaptivecards.io/explorer/AdaptiveCard.html type AdaptiveCard struct { - Body []AdaptiveCardItem `json:"body"` - Schema string `json:"$schema"` - Type string `json:"type"` - Version string `json:"version"` + Body []AdaptiveCardItem + Schema string + Type string + Version string } // NewAdaptiveCard returns a prepared Adaptive Card. @@ -85,6 +85,22 @@ func NewAdaptiveCard() AdaptiveCard { } } +func (c *AdaptiveCard) MarshalJSON() ([]byte, error) { + return json.Marshal(struct { + Body []AdaptiveCardItem `json:"body"` + Schema string `json:"$schema"` + Type string `json:"type"` + Version string `json:"version"` + MsTeams map[string]interface{} `json:"msTeams,omitempty"` + }{ + Body: c.Body, + Schema: c.Schema, + Type: c.Type, + Version: c.Version, + MsTeams: map[string]interface{}{"width": "Full"}, + }) +} + // AppendItem appends an item, such as text or an image, to the Adaptive Card. func (c *AdaptiveCard) AppendItem(i AdaptiveCardItem) { c.Body = append(c.Body, i) diff --git a/pkg/services/ngalert/notifier/channels/teams_test.go b/pkg/services/ngalert/notifier/channels/teams_test.go index f924b6194eb..3d0c28a10a7 100644 --- a/pkg/services/ngalert/notifier/channels/teams_test.go +++ b/pkg/services/ngalert/notifier/channels/teams_test.go @@ -70,6 +70,9 @@ func TestTeamsNotifier(t *testing.T) { }}, "type": "AdaptiveCard", "version": "1.4", + "msTeams": map[string]interface{}{ + "width": "Full", + }, }, "contentType": "application/vnd.microsoft.card.adaptive", }}, @@ -123,6 +126,9 @@ func TestTeamsNotifier(t *testing.T) { }}, "type": "AdaptiveCard", "version": "1.4", + "msTeams": map[string]interface{}{ + "width": "Full", + }, }, "contentType": "application/vnd.microsoft.card.adaptive", }}, @@ -176,6 +182,9 @@ func TestTeamsNotifier(t *testing.T) { }}, "type": "AdaptiveCard", "version": "1.4", + "msTeams": map[string]interface{}{ + "width": "Full", + }, }, "contentType": "application/vnd.microsoft.card.adaptive", }}, @@ -228,6 +237,9 @@ func TestTeamsNotifier(t *testing.T) { }}, "type": "AdaptiveCard", "version": "1.4", + "msTeams": map[string]interface{}{ + "width": "Full", + }, }, "contentType": "application/vnd.microsoft.card.adaptive", }}, diff --git a/pkg/tests/api/alerting/api_notification_channel_test.go b/pkg/tests/api/alerting/api_notification_channel_test.go index fb87067b6f0..d70e015fb5c 100644 --- a/pkg/tests/api/alerting/api_notification_channel_test.go +++ b/pkg/tests/api/alerting/api_notification_channel_test.go @@ -2224,7 +2224,10 @@ var expNonEmailNotifications = map[string][]string{ } ], "type": "AdaptiveCard", - "version": "1.4" + "version": "1.4", + "msTeams": { + "width": "Full" + } }, "contentType": "application/vnd.microsoft.card.adaptive" }