SwapnilKumbhar
SwapnilKumbhar

Reputation: 367

Facebook bot messages not showing blank lines

I have created a chat bot using Microsoft bot framework and deployed it on Azure and linked it with my Facebook page. Everything is working fine but has a minor issue that, One of the messages send by the bot has a combination of 2-3 different lines, I want to show those 3 lines separated by blank lines so I have added escape sequence "\n\n" between the lines.

"Line1\n\nLine2\n\nLine3"

This works fine when I testes it in Azure web chat but Facebook chat window don't display the blank lines, Can any one help me with this?Thanks in Advance.

Currently face Display message like

Line1
Line2
Line3

I want to show it as

Line 1

Line 2

Line 3 

Upvotes: 1

Views: 136

Answers (1)

Kyle Delaney
Kyle Delaney

Reputation: 12264

Your message text is being run through a rather aggressive Markdown parser that's stripping away extra line breaks. You have a few options for how to deal with this.

Option 1

If you set the text as channel data instead of the actual activity text, it won't be run through the Markdown parser:

var text = "Line1\n\nLine2\n\nLine3";
var activity = turnContext.Activity.CreateReply();
activity.ChannelData = new { text };
await turnContext.SendActivityAsync(activity);

Option 2

If you set the text format to plain, the text won't be run through the Markdown parser:

var text = "Line1\n\nLine2\n\nLine3";
var activity = turnContext.Activity.CreateReply(text);
activity.TextFormat = TextFormatTypes.Plain;
await turnContext.SendActivityAsync(activity);

Option 3

If you're using channel data for something else and you don't want to set the text format to plain, you can always use <br/> instead of \n:

var text = "Line1<br/><br/>Line2<br/><br/>Line3";

Upvotes: 3

Related Questions