简体   繁体   中英

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

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 ❤ I'm a chatbot. \\n built with ❤

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>

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM