fylzero's avatar
Level 67

Issue with new line using markdown in Slack notification...

According to the Laravel docs you can parse markdown in Slack using...

$attachment->title('Exception: File Not Found', $url)
    ->content('File [background.jpg] was *not found*.')
    ->markdown(['text']);

Also in the documentation you are directed to Slack's formatting page for more info on how to format Slack notifications here:

https://api.slack.com/reference/surfaces/formatting#message_formatting

There is says you can add new lines of text by doing this...

You can use multi-line text in app-generated text. Insert a newline by including the string \n in your text.

$attachment->title('Exception: File Not Found', $url)
    ->content('This is a line of text.\nAnd this is another one.')
    ->markdown(['text']);

Suffice it to say this doesn't work. No new line, it just outputs "This is a line of text.\nAnd this is another one." in the Slack message. =T

Does anyone know how I can add a new line in my Slack notification content? Is it possible?

0 likes
3 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Can you try using "" around content instead of ''

$attachment->title('Exception: File Not Found', $url)
    ->content("This is a line of text.\nAnd this is another one.")
    ->markdown(['text']);

Please or to participate in this conversation.