Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I post multiline message using Teams Webhooks?

I have a webhook setup to post a message to one of our Teams Team channels. I'm using one of the teams webhook examples given here: https://learn.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-reference#hero-card .

The problem I have is that I am unable to display multiple lines. In the example below, I'd like to separate out 'Test1' and 'Test2' on separate lines. However, using \n or \n in the JSON didn't translate to multi line format in Teams. Screenshot outcome attached below.

    "type": "message",
    "attachments": [
        {
            "contentType": "application/vnd.microsoft.card.hero",
            "content": {
                "title": "Alerts",
                "text": "*Test1 \n *Test\n",
                "buttons": [
                    {
                        "type": "openUrl",
                        "title": "Open in SumoLogic",
                        "value": ""
                    }
                ]
            }
        }
    ]
}

What is the way to send a multi-line message to Teams using webhook? Any guidance here is appreciated.

how the result in teams look like at the moment

like image 819
anoj-cha Avatar asked Oct 21 '25 04:10

anoj-cha


2 Answers

Please try using \n\n and check.

like image 88
Saonti-MSFT Avatar answered Oct 23 '25 20:10

Saonti-MSFT


This worked in a bash script.

# Replace newline with <br>
MULTILINE_STRING_BR=$(echo "$MULTILINE_STRING" | sed 's/$/<br>/g')
cat <<EOF >/tmp/msg.txt
{
    "text": "Some introductory text:<br>
${MULTILINE_STRING_BR}"
}
EOF

# Send to teams channel
curl --request POST \
    --silent \
    --header "Content-Type: application/json" \
    --data @/tmp/msg.txt \
    "${TEAMS_WEBHOOK}"
like image 25
ptsw Avatar answered Oct 23 '25 21:10

ptsw