microsoft teams : escaping underscores in text posting to webhook

Viewed 3834

I am posting a list of Azure resource groups to a channel in teams using incoming webhook.

Some Azure resource groups have underscores in them, these are getting parsed and the text between two underscores is italicized. From the docs I could gather that it's Markdown behavior but I am unable to escape underscores using a \ (backslash) similar to how you would do in Markdown.

What is the right way to post text with underscores such that its rendered correctly?

(Would be nice to know what variant of Markdown is being used.)

Sample payload:

{
  "text": "<br/><h1>Some text (some azure subscription id)</h1><br/>some text (more text): <br/>['resource_group_name_1', 'resource_group_name_2', 'resourcegroup-rg-foo-bar']<br/><br/>some text (more text): <br/>['resourcegroupname']<br/><br/>See <a href="https://someaccount.visualstudio.com/_git/reponame?path=%2FREADME.md">documentation</a> and <a href="https://someaccount.visualstudio.com/someproject/_build?definitionId=1234&_a=summary">sometext</a>."
}

resourcegroup-rg-foo-bar appears as is, but resource_group_name_1 appears like resourcegroupname1.

2 Answers

Disabling markdown at a section level is now supported in Cards. You can set markdown to false.

Details here

Example

{
    "@type": "MessageCard",
    "@context": "https://schema.org/extensions",
    "summary": "Office 365 Notification",
    "title": "Office 365 Service Degradations",
    "sections": [
        {
            "markdown": false,
            "facts": [
                {
                    "name": "Service Incident:",
                    "value": "ID"
                },
                {
                    "name": "Start time:",
                    "value": "check_disk_critical"
                },
                {
                    "name": "Service:",
                    "value": "SERVICENAME"
                },
                {
                    "name": "Description:",
                    "value": "MESSAGE"
                }
            ],
            "title": "Office 365 Service Problem"
        }
    ]
}

It works with markdown set to false. No need to escape the underscores if you set markdown to false. Hope this helps

Related