2

While using a Node.js module (apiai), I tried to add new lines (\n) in API.ai text response given a query result but it doesn't seem to work when I save the response in a variable from the callback like this:

request.on('response', function (response) {
  var textResponse = response.result.fulfillment.speech;
  // ...
})
Arafat Husayn
  • 69
  • 2
  • 13

4 Answers4

2

Finally I solved it like this:

var textResponse = response.result.fulfillment.speech;
textResponse = textResponse.replace(/\\n/g, '\n');

The input was like: I'm a chatbot. \n built with ❤

Arafat Husayn
  • 69
  • 2
  • 13
1

use Break-line <\br> instead of \n

For example:

<div>This is with break line<br>this is after break line</div>
<div>This is with break line \n this is after new line</div>
Dinesh undefined
  • 5,490
  • 2
  • 19
  • 40
0

I was using the agent.add() method in the dialogflow inline editor and wanted a newline between some text. so I used " \n"( Two spaces followed by \n), and it gave the output as required on my dialogflow messenger integration.

eg.

agent.add(firstName + " " + lastName + " \n" + phoneno);

Ketan
  • 13
  • 1
  • 3
0

When entering a response, press Shift + Enter to input a newline or just Enter to input another text response.

The following limitations apply:

Max of 300 text entries per text response