admin管理员组文章数量:1404620
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;
// ...
})
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;
// ...
})
Share
Improve this question
asked Jul 2, 2017 at 5:43
Arafat HusaynArafat Husayn
692 silver badges13 bronze badges
7
- how you tried? after adding \n what you have to do with that? – Dinesh undefined Commented Jul 2, 2017 at 5:48
-
It gave me the
\n
literally. I tried by sending it to Facebook Messenger directly. It shows like this:sample text \n sample text
but it should take a new line there. – Arafat Husayn Commented Jul 2, 2017 at 5:52 - i answered check my answer. – Dinesh undefined Commented Jul 2, 2017 at 5:56
- try \u000A instead <\br> – Dinesh undefined Commented Jul 2, 2017 at 6:11
- No luck with that too. – Arafat Husayn Commented Jul 2, 2017 at 6:19
4 Answers
Reset to default 2Finally 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 ❤
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
本文标签: javascriptAdd new line (n) in Text Response from APIaiStack Overflow
版权声明:本文标题:javascript - Add new line (n) in Text Response from API.ai - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744838928a2627803.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论