Rocket.chat: How to send to incoming webhook with linebreaks?

Created on 23 Sep 2016  路  11Comments  路  Source: RocketChat/Rocket.Chat

Your Rocket.Chat version: 0.35.0

When sending back a payload to incoming webhook integration, I tried to send this:

"text": "This is first line. \nThis is second line"

And the result I received:

This is first line. This is second line

Did I do it right or am I missing something?

EDIT: Typo from /n to \n

webhooks support

Most helpful comment

Resolved: I was trying this in a non text field; in the text fields, \n works.

All 11 comments

It seems to me that you want to send \n instead of /n to mean a line break.

@olafleur sorry my bad, I actually tried with \n

@casper-gh try \r\n or \r

It's been a while, has anybody succeeded with this since then? I am facing exactly the same problem. I have tried:

  • \n
  • \\n
  • \r
  • \r\n
  • /n (well well)
  • <br>

And none of those work as I want to.

Resolved: I was trying this in a non text field; in the text fields, \n works.

Looks like a solution was found. Going to go ahead and close this.

If you have any further questions please join our community server in the #support channel or ask your question on stackoverflow with the rocket.chat tag

its curious, if u put the new-line-tag \n at the end without any character afterwards - it won't will work.

eg.
works not

  'text' => "Lorem ipsum \n\n",

works

  'text' => "Lorem ipsum \n\n anychar",

furthermore:

in the pretext of a field:

nothing works
either \n or \r or anything else

eg.

'attachments' => [[
            'color' => 'good',
            'pretext' => "Lorem ipsum:\n anychar",
            'fields' => [
              [
                "title" => "title 1" ",
                "value" => $request->title,
                "short" => false
              ],
...

@graywolf336 any ideas on the pretext field?

As to why text at the end won't allow you to do a new line. I think it strips them off at the end. Which I think is probably intentional.

Where is solution?
I'm trying to send webhook to Rocket from PHP
I'm trying and \n\n, and \n, and \r and \r\n

and all time have

(
    [0] => <!DOCTYPE html>
    [1] => <html lang="en">
    [2] => <head>
    [3] => <meta charset="utf-8">
    [4] => <title>Error</title>
    [5] => </head>
    [6] => <body>
    [7] => <pre>Bad Request</pre>
    [8] => </body>
    [9] => </html>
)

What i need to use in string like
$command = 'Hello Bro!'."\n".'How are you?';

I found some interesting method
$command = 'Hello Bro!\\nHow are you?';

I am using a linux bash script to send messages to rocket.chat. but i nothing worked for me to display break lines, instead of sending a second message. I tried this

./postToRocketChat.sh -b "Notification send\\nNew Line"

and i will get this from server

{"text:" "Notification sendnNew Line"}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

antn89 picture antn89  路  3Comments

tanc picture tanc  路  3Comments

mddvul22 picture mddvul22  路  3Comments

marceloschmidt picture marceloschmidt  路  3Comments

djeber picture djeber  路  3Comments