Taslim Oseni
Taslim Oseni

Reputation: 6273

Slack API: Escape asterisk character in payload

I have a web app that triggers a Slack notification. I intend to send the formatted text below on Slack:

500 * 2 = 1000

To achieve this, I post the data below to Slack PostMessage API:

{
    "channel": "CHANNEL_ID",
    "type": "mrkdwn",
    "text": "500 * 2 = *1000*"
}

Clearly, there is a markdown issue as the first asterisk is not escaped. To fix this, I tried passing the text as shown below:

"text": "500 \\* 2" = *1000*

..and then, I got this output:

500 \* 2 = 1000

Using only one backslash returns this error:

{
    "ok": false,
    "error": "invalid_json",
    "warning": "missing_charset",
    "response_metadata": {
        "warnings": [
            "missing_charset"
        ]
    }
}

How do I fix this?

Upvotes: 3

Views: 2724

Answers (1)

glyvox
glyvox

Reputation: 58149

Try using U+2217, the Asterisk Operation character. Here it is for copy-pasting:

Upvotes: 4

Related Questions