github-actionsworkflowmicrosoft-teams

Displaying values instead of variable names on a adaptive card posted in teams


We are using Github Actions to post our test results after a run in our Teams channel. We are using normal connectors as of now but that won't be possible anymore in the future. That is why I am trying to understand how to work with Teams Workflows and these adaptive card. I can trigger the workflow via Postman and via GHA but the card always shows the variables instead of the values I am sending. Can someone of you see what I am doing wrong? The adaptive card designer is working, and I even used a template from their side.

What I am sending:

{
    "title": "Please confirm your order:",
    "customer": [
        {
            "firstName": "John",
            "lastName": "Smith",
            "phone": "(555) 555-5555"
        }
    ]
}

What I am getting is a card that displays the variable names:

${title}

Name ${customer[0].firstName} ${customer[0].lastName}

Phone number ${customer[0].phone}

1x Steak

2x Side Rice

1x Soft Drink

What I expected is a card which uses the values I sent.

Please confirm your order:

Name John Smith

Phone number (555) 555-5555

1x Steak

2x Side Rice

1x Soft Drink

Setup Workflow looks like this:

Teams Workflow and this is the template I have configured:

{
    "type": "AdaptiveCard",
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.2",
    "body": [
        {
            "type": "TextBlock",
            "text": "${title}",
            "wrap": true,
            "style": "heading"
        },
        {
            "type": "FactSet",
            "facts": [
                {
                    "title": "Name",
                    "value": "${customer[0].firstName} ${customer[0].lastName}"
                },
                {
                    "title": "Phone number",
                    "value": "${customer[0].phone}"
                }
            ]
        },
        {
            "type": "Container",
            "items": [
                {
                    "type": "FactSet",
                    "facts": [
                        {
                            "title": "1x",
                            "value": "Steak"
                        },
                        {
                            "title": "2x",
                            "value": "Side Rice"
                        },
                        {
                            "title": "1x",
                            "value": "Soft Drink"
                        }
                    ],
                    "spacing": "Small"
                }
            ],
            "spacing": "Small"
        }
    ]
}

Solution

  • We got access to ChatGPT 4.o within our company and it helped me to find the solution. I have tested it and changed the template to a more complex one and it is still working. So the answer is not generated fully by ai. There is still some trial and error from my side involved

    Template

    {
    "type": "AdaptiveCard",
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.3",
    "body": [
        {
            "type": "TextBlock",
            "text": "@{triggerOutputs()?['body/title']}",
            "wrap": true
        },
        {
            "type": "FactSet",
            "facts": [
                {
                    "title": "Passed",
                    "value": "@{triggerOutputs()?['body/results'][0]['passed_tests']}"
                },
                {
                    "title": "Failed",
                    "value": "@{triggerOutputs()?['body/results'][0]['failed_tests']}"
                },
                {
                    "title": "Total",
                    "value": "@{triggerOutputs()?['body/results'][0]['executed_tests']}"
                }
            ]
        }
    ],
    "actions": [
        {
            "type": "Action.OpenUrl",
            "title": "View GHA Run",
            "url": "@{triggerOutputs()?['body/run_url']}"
            }
        ]
    }
    

    Example Request

    {
    "title": "Test run results",
    "results": [
        {
            "passed_tests": "100",
            "failed_tests": "11",
            "executed_tests": "111"
        }
    ],
    "run_url": "https://www.google.com"
    }
    

    The result

    Test run results
    Passed  100
    Failed   11
    Total   111
    Sabine used a Workflow template to send this card. Get template
    View GHA Run