Arafat Husayn
Arafat Husayn

Reputation: 69

Add new line (\n) in Text Response from API.ai

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;
  // ...
})

Upvotes: 2

Views: 8750

Answers (4)

manoz kirati
manoz kirati

Reputation: 16

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

Upvotes: 0

Ketan
Ketan

Reputation: 113

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);

Upvotes: 0

Arafat Husayn
Arafat Husayn

Reputation: 69

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 ❤

Upvotes: 2

Dinesh undefined
Dinesh undefined

Reputation: 5546

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>

Upvotes: 1

Related Questions