Facebook Messenger API:how to break line in a message

流过昼夜 提交于 2019-11-29 05:37:09

If you are using php, You should be use chr(10) . Its working as like '\n' or '<br>'. Also you can use <center></center> . Its working for me.

tyrex

Turns out Line break in Facebook status update via Graph API might give you what you are looking for:

Use \u000A

For me it solved my similar issue I had with Facebook SendApi for a Facebook Messenger Bot.

I'm not 100% sure what language you're using to build your bot, but if you're using PHP then \n needs to be wrapped in double quote strings e.g

  $message = "Message \n with a line break";

using single quotes (') won't work.

Though a better solution if using PHP would be to use the PHP_EOL constant

Whatever language you're using to build your bot may have similar quirks

I was trying to get a line break in the welcome text that shows up before users touch Get Started in my Messenger bot. I found that "\n" worked but ONLY in the mobile version of Messenger. It doesn't work on the web at the moment. Assuming that will get fixed at some point because Facebook shows line breaks in their blog post this week (9/12/2016) https://messengerblog.com/bots/messenger-platform-1-2-link-ads-to-messenger-enhanced-mobile-websites-payments-and-more

Though it is not documented, but I suppose "\r\n" would work. Graph api returns the json response as "\r\n" for messages or posts having a line break.

Use language specific line separators.

Java System.lineseprator 

php PHP_EOL 

Python os.linesep 

Nodejs os.EOL 

When we use special character in string then JSON conversion understand it as part of string.

In Python \\n breaks the line as expected.

Patrick Sierak

I had to use \n\n for the line break to work.

e.g.

"Sorry, We don't have any information ragarding this.\n\nSay 'Hi' to startover"

shows following in facebook messenger

Sorry, We don't have any information ragarding this.
Say 'Hi' to startover

Convert "\n" in your text to "\n" => it working... With Php this is my code: (tested)

$_text = str_replace(array("\r\n", "\r", "\n"), "\\n", $_text); 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!