Alerting: Fix width of Adapative Cards in Teams notifications (#53996)

This commit is contained in:
George Robinson 2022-08-22 16:04:22 +01:00 committed by GitHub
parent 2caaa7fba2
commit e163a976fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 5 deletions

View File

@ -69,10 +69,10 @@ type AdaptiveCardsAttachment struct {
// AdapativeCard repesents an Adaptive Card. // AdapativeCard repesents an Adaptive Card.
// https://adaptivecards.io/explorer/AdaptiveCard.html // https://adaptivecards.io/explorer/AdaptiveCard.html
type AdaptiveCard struct { type AdaptiveCard struct {
Body []AdaptiveCardItem `json:"body"` Body []AdaptiveCardItem
Schema string `json:"$schema"` Schema string
Type string `json:"type"` Type string
Version string `json:"version"` Version string
} }
// NewAdaptiveCard returns a prepared Adaptive Card. // 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. // AppendItem appends an item, such as text or an image, to the Adaptive Card.
func (c *AdaptiveCard) AppendItem(i AdaptiveCardItem) { func (c *AdaptiveCard) AppendItem(i AdaptiveCardItem) {
c.Body = append(c.Body, i) c.Body = append(c.Body, i)

View File

@ -70,6 +70,9 @@ func TestTeamsNotifier(t *testing.T) {
}}, }},
"type": "AdaptiveCard", "type": "AdaptiveCard",
"version": "1.4", "version": "1.4",
"msTeams": map[string]interface{}{
"width": "Full",
},
}, },
"contentType": "application/vnd.microsoft.card.adaptive", "contentType": "application/vnd.microsoft.card.adaptive",
}}, }},
@ -123,6 +126,9 @@ func TestTeamsNotifier(t *testing.T) {
}}, }},
"type": "AdaptiveCard", "type": "AdaptiveCard",
"version": "1.4", "version": "1.4",
"msTeams": map[string]interface{}{
"width": "Full",
},
}, },
"contentType": "application/vnd.microsoft.card.adaptive", "contentType": "application/vnd.microsoft.card.adaptive",
}}, }},
@ -176,6 +182,9 @@ func TestTeamsNotifier(t *testing.T) {
}}, }},
"type": "AdaptiveCard", "type": "AdaptiveCard",
"version": "1.4", "version": "1.4",
"msTeams": map[string]interface{}{
"width": "Full",
},
}, },
"contentType": "application/vnd.microsoft.card.adaptive", "contentType": "application/vnd.microsoft.card.adaptive",
}}, }},
@ -228,6 +237,9 @@ func TestTeamsNotifier(t *testing.T) {
}}, }},
"type": "AdaptiveCard", "type": "AdaptiveCard",
"version": "1.4", "version": "1.4",
"msTeams": map[string]interface{}{
"width": "Full",
},
}, },
"contentType": "application/vnd.microsoft.card.adaptive", "contentType": "application/vnd.microsoft.card.adaptive",
}}, }},

View File

@ -2224,7 +2224,10 @@ var expNonEmailNotifications = map[string][]string{
} }
], ],
"type": "AdaptiveCard", "type": "AdaptiveCard",
"version": "1.4" "version": "1.4",
"msTeams": {
"width": "Full"
}
}, },
"contentType": "application/vnd.microsoft.card.adaptive" "contentType": "application/vnd.microsoft.card.adaptive"
} }