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
posta 2 anni fa467 visualizzazioni
2 Risposte
0
Risposta accettata

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
con risposta 2 anni fa
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
con risposta 2 anni fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande