Search code examples
slack-apislack

Slack API not accepting \n for new line when using slash commands


I've built a simple slack integration (slash command) to return names from my table. The result should look like

Name1

Name2

Name3

For this i simply generate a text string like this:

foreach($names as $name) {
    $text .= $name . ' \n';
}

The integration itself is working fine, however the result looks like this

Name1 \nName2\n


Solution

  • Looks like this is an issue in slack.

    Apparently it can be solved by using double quotes as such: "\n".

    Your code will become:

    foreach($names as $name) {
        $text .= $name . "\n";
    }