Microsoft Teams webhook from gitlab.

Jacob Thompson 15 Reputation points
2024-06-21T19:26:40.6566667+00:00

Hello,

My team is trying to set up Gitlab event webhooks to be sent to a Microsoft Teams channel. This was previously working until we updated to the new Microsoft Teams.

We created the webhook by going to channel->workflows->Post to a channel when a webhook request is received->selected a team and channel we want->add workflow->copied the webhook url

We then posted it into the gitlab integrations menu, following this guide: https://docs.gitlab.com/ee/user/project/integrations/microsoft_teams.html#configure-your-gitlab-project

We also tested the webhook with the following command and received a message in our chat:

curl -X POST $WEBHOOK_URL --header "Content-Type: application/json" --data '{     "type":"message",     "attachments":[        {           "contentType":"application/vnd.microsoft.card.adaptive",           "contentUrl":null,           "content":{              "$schema":"http://adaptivecards.io/schemas/adaptive-card.json",              "type":"AdaptiveCard",              "version":"1.2",              "body":[                  {                  "type": "TextBlock",                  "text": "For Samples and Templates, see https://adaptivecards.io/samples"                  },                  {                      "type": "Image",        "url": "https://adaptivecards.io/content/cats/1.png"                      }              ]           }        }     ]  }'

However, when we get a webhook request from Gitlab we get the following error:

The execution of template action 'Apply_to_each' failed: the result of the evaluation of 'foreach' expression '@triggerBody()?['attachments']' is of type 'Null'. The result must be a valid array.

 

What can we do to resolve this error?

Microsoft Teams
Microsoft Teams
A Microsoft customizable chat-based workspace.
10,323 questions
Microsoft Teams Development
Microsoft Teams Development
Microsoft Teams: A Microsoft customizable chat-based workspace.Development: The process of researching, productizing, and refining new or existing technologies.
3,343 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Allen Yu 10 Reputation points
    2024-07-25T07:08:12.26+00:00

    Was able to setup a working flow as follows

    1. When a Teams webhook request is received
    2. Parse JSON (or import the sample gitlab json)
         {
             "type": "object",
             "properties": {
                 "sections": {
                     "type": "array",
                     "items": {
                         "type": "object",
                         "properties": {
                             "activityTitle": {
                                 "type": "string"
                             },
                             "activitySubtitle": {
                                 "type": "string"
                             },
                             "activityText": {
                                 "type": "string"
                             },
                             "activityImage": {
                                 "type": "string"
                             },
                             "text": {
                                 "type": "string"
                             }
                         },
                         "required": []
                     }
                 },
                 "title": {
                     "type": "string"
                 },
                 "summary": {
                     "type": "string"
                 }
             }
         }
      
    3. Initialize variable commits
    4. For loop and Set variable concat text into commits
         concat(item()?['text'], '\n\n')
      
    5. Configure Post card in a chat or channel with target channel/group and AdaptiveCard
         {
             "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
             "type": "AdaptiveCard",
             "version": "1.2",
             "body": [
                 {
                     "type": "Container",
                     "items": [
                         {
                             "type": "TextBlock",
                             "size": "Medium",
                             "weight": "Bolder",
                             "text": "GitLab Update - @{body('Parse_JSON')?['title']}"
                         },
                         {
                             "type": "ColumnSet",
                             "columns": [
                                 {
                                     "type": "Column",
                                     "items": [
                                         {
                                             "type": "Image",
                                             "url": "@{first(body('Parse_JSON')?['sections'])['activityImage']}",
                                             "size": "Small",
                                             "style": "Person"
                                         }
                                     ],
                                     "width": "auto"
                                 },
                                 {
                                     "type": "Column",
                                     "items": [
                                         {
                                             "type": "TextBlock",
                                             "text": "@{first(body('Parse_JSON')?['sections'])['activityTitle']}",
                                             "wrap": true,
                                             "weight": "Bolder"
                                         },
                                         {
                                             "type": "TextBlock",
                                             "text": "@{first(body('Parse_JSON')?['sections'])['activitySubTitle']}",
                                             "isSubtle": true,
                                             "wrap": true
                                         }
                                     ],
                                     "width": "stretch"
                                 }
                             ]
                         },
                         {
                             "type": "TextBlock",
                             "text": "@{first(body('Parse_JSON')?['sections'])['activityText']}",
                             "wrap": true
                         },
                         {
                             "type": "TextBlock",
                             "text": "@{variables('commits')}",
                             "wrap": true
                         }
                     ]
                 }
             ]
         }
         
      
    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.