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
preguntada hace 2 años467 visualizaciones
2 Respuestas
0
Respuesta aceptada

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
respondido hace 2 años
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
respondido hace 2 años

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas