[英]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:在使用 Node.js 模块 (
apiai
) 时,我尝试在给定查询结果的 API.ai 文本响应中添加新行 ( \\n
),但当我将响应保存在回调变量中时,它似乎不起作用像这样:
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 ❤
I'm a chatbot. \\n built with ❤
use Break-line <\\br>
instead of \\n
使用 Break-line
<\\br>
而不是\\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.我在 dialogflow 内联编辑器中使用 agent.add() 方法,并希望在某些文本之间有一个换行符。 so I used
" \\n"
( Two spaces followed by \\n
), and it gave the output as required on my dialogflow messenger integration.所以我使用了
" \\n"
(两个空格后跟\\n
),它根据我的 dialogflow messenger 集成的要求给出了输出。
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.输入响应时,按 Shift + Enter 输入换行符或仅 Enter 输入另一个文本响应。
The following limitations apply:以下限制适用:
Max of 300 text entries per text response每个文本响应最多 300 个文本条目
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.