25

I have a slack application that responds with formatted data in mrkdwn but it would be nice to have the information presented in table form like so

sample view from ipushpull

Am trying to implement this but cant quite find how to format this message. The only close solution i have is taking a screen grab of the table and sending it instead but that affects the applications response time. Any help would be appreciated thanks

Caleb Njiiri
  • 1,563
  • 1
  • 11
  • 20

4 Answers4

28

Slack has no built-in support to render tables in messages.

Your workaround options are:

  • Draw table with chars in the message using a monospace font (Example)

  • Draw table with chars and upload as plain text snippet with files.upload

  • Render table as image and attach to a message or upload as image

Erik Kalkoken
  • 30,467
  • 8
  • 79
  • 114
8

I used tabluate in python for create a formatted table from pandas dataframe then I posted the table using slack python client's chat_postMessage method using below technique:

client.chat_postMessage(channel="#dummy-channel",text="```\n" + table + "\n```")

Note "```\n" + table + "```\n" is being used to convert table into code block just like we as users do in slack.

Vikas Shaw
  • 155
  • 1
  • 8
3

First convert to markdown

markdown_table = df.to_markdown()

Prepare data to send to the webhook url via requests.post

slack_data = {"text":"```\n" + markdown_table + "\n```"}
nipy
  • 5,138
  • 5
  • 31
  • 72
-3

If your data is simple with up to one text column and some number columns, try this.


Landing page report (views, buys)

1754 17 https://example.com/variant-a

1834 23 https://example.com/variant-b

user229044
  • 232,980
  • 40
  • 330
  • 338
William Entriken
  • 37,208
  • 23
  • 149
  • 195