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 ❤