1

So I'm making request to Slack api to get messsage history of a particular channel. Everything works fine except the messages that are returned are still in slack format. Is there any way to convert it to HTML format?

Thanks.

Erik Kalkoken
  • 30,467
  • 8
  • 79
  • 114
Mayank
  • 17
  • 4

1 Answers1

0

No. The Slack api will give you the messages in Slack markup only. If you want them in html you need to convert them yourself or find a library.

Here is how to parse the Slack markup in order to convert it into another format like HTML:

If you're retrieving messages, we've included some extra details in the sections above to help you parse the formatting syntax. This will let you properly format it for display on a different service, or to help your app fully understand the intent of a message. Here are the general steps involved for detecting advanced formatting syntax:

  1. Detect all sub-strings matching <(.*?)>

  2. Within those sub-strings, format content starting with #C as a channel link

  3. Format content starting with @U or @W as a user mention

  4. Format content starting with !subteam as a user group mention

  5. Format content starting with ! according to the rules for special mentions

  6. For any other content within those sub-strings, format as a URL link

  7. Once the format has been determined, check for a pipe (|) - if present, use the text following the pipe as the label for the link or mention.

From official Slack documentation on Formatting.

Erik Kalkoken
  • 30,467
  • 8
  • 79
  • 114
  • The link does not mention anything about converting markup to html. It is better practice on SO to copy the relevant passage along with the link, precisely in the case that the documentation changes. – Ulysse Mizrahi Dec 03 '20 at 09:53
  • @UlysseMizrahi Thank you for the hint. The link had changed in the meantime, so I have now included the relevant content in the answer as you suggested. – Erik Kalkoken Dec 03 '20 at 17:36