CodePipeline activity notification JSON ends up malformed at Microsoft Teams

0

Has anybody else tried to send CodePipeline events over to a Microsoft Teams channel using the following examples

https://aws.amazon.com/premiumsupport/knowledge-center/sns-lambda-webhooks-chime-slack-teams/

and end up with the displayed JSON having no value for the additionalAttributes property? It is supposed to be an empty {} object.

{
"account": "ACCOUNTNUMBER",
"detailType": "CodePipeline Pipeline Execution State Change",
"region": "REGION",
"source": "aws.codepipeline",
"time": "2022-01-17T08:59:36Z",
"notificationRuleArn": "RULEARN",
"detail": {
"pipeline": "PIPELINE",
"execution-id": "GUID",
"execution-trigger": {
"trigger-type": "Webhook",
"trigger-detail": "CODESTARARN"
},
"state": "STARTED",
"version": 1.0
},
"resources": [
"PIPELINEARN"
],
"additionalAttributes": 
}

I logged down the Python formatting statements and the resultant encoded string does include the {} so I guess somehow the Teams side does not like empty objects and drops it off?

icelava
已提問 2 年前檢視次數 467 次
2 個答案
0
已接受的答案

We are sending to Microsoft Teams that payload format.

{ "text": "STRINGYFIED_JSON" }

Where STRINGYFIED_JSON = the serialised SNS message object.

I tested further by adding a placeholder property to the blank object for additionalAttributes and Teams did accept that and rendered proper JSON in the post.

# Add placeholder property to potentially empty object {} in additionalAttributes
# Microsoft Teams may not like it and not render in rendered post text.
snsMessage['additionalAttributes']['placeholder'] = "Prevent empty object."
icelava
已回答 2 年前
0

As described in the Knowledge Center Article, the minimum payload for TEAMS has to be:

{"text": "Some Text"}

Just {} won't work.

The article simply uses the JSON payload of the SNS message and forwards it to the TEAMS Webhook, however they support Adaptive Cards and their legacy format Actionable Message which allows you to format your information quite nicely. Our team uses the Python module pyadaptivecards to make the layout of our cards easier.

wolfadr
已回答 2 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南