Search code examples
slack-apislack

white spaces - slack (webhook)


It looks like there is no option post a message containing a table on to slack. I am trying to build a table using text formatting. In the below example the text isn't aligned because first row has text ROW1 and second row has text ROW. Is there a way to add a white space after ROW in order to align this text?

{"text" : "ROW1\t\t\t\tCOL1\nROW\t\t\t\tCOL2"}


Solution

  • Generally speaking, you can use Slack's message builder to test the rendering of your messages.

    This being said, while I dont think you can simply "push" spaces to the right, you could use the pipe symbol like this :

    "text": "ROW1|\t\t\t\tCOL1\nROW   |\t\t\t\tCOL2"
    

    Another possibility, with minor changes, is to use attachements with fields like this

    "attachments": [
            {
                "fields": [
                    {
                        "title": "Col1",
                        "value": "text1",
                        "short": true
                    },
                    {
                        "title": "Col2",
                        "value": "text2",
                        "short": true
                    }
                ]
            }
        ]