Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Markdown doesn't work in attachments

Tags:

slack-api

I'm creating a Slack integration with the Slack API. I followed the documentation but the markdown formatting doesn't work on my attachments...

Here is my response object:

{
  response_type: "in_channel",
  text: "List:",
  attachments: [
    { 
      text: "*pseudo*:\nbla bla bla",
      mrkdwn: true
    }
  ]
}

The "*" are displayed and not evaluated. Did I make a mistake?

like image 790
Tristan Libersat Avatar asked Jan 31 '16 18:01

Tristan Libersat


2 Answers

Set the attribute mrkdwn_in in attachments:

"attachments": [
    { 
      "text": "*pseudo*:\nbla bla bla",
      "mrkdwn_in": ["text"]
    }
]

See https://api.slack.com/docs/formatting for more information.

like image 134
Nikhil Mohadikar Avatar answered Oct 27 '22 13:10

Nikhil Mohadikar


Rep limit for commenting to an answer is stupid ... how are people supposed to get reputation if they cannot even interact with the forum. Also sorry for necroing the old post, but it's the closest one to my issue that I've found so far.

Anyways, the mrkdwn_in property doesn't help much with the stars * problem in the attachments.

"attachments": [
    {
      "fallback": "Required plain-text summary of the attachment.",
      "color": "#000000",
      "mrkdwn_in": ["fields", "text"],
      "fields": [
        {
          "title": "XXXXXX",
          "value": "*PVC* avg: xxs, max: xxxs, avg-diff: xx% \n*EPH* avg: xxs, max: xxxs, avg-diff: xx%",
          "short": true
        },
        {
          "title": "XXXXXX",
          "value": "*PVC* avg: xxs, max: xxxs, avg-diff: xx% \n*EPH* avg: xxs, max: xxxs, avg-diff: xx%",
          "short": true
        }
      ]
    },
    .
    .
    .

After avg-diff: I'm inserting a string " *↑* " and concatenating it with the rest of the message. For some reason the downwards arrow " _↓_ " gets translated to HTML correctly. It's just the bold that's broken.

As a result, the message still contains the * around the ASCII arrow, but the rest of the text like *PVC* gets translated into HTML correctly

Screenshot of the attachment from Slack

like image 41
Tibor Dancs Avatar answered Oct 27 '22 13:10

Tibor Dancs