2017-07-02 47 views
1

在使用Node.js模块(apiai)时,我试图在给API查询结果的API.ai文本响应中添加新行(\n),但它没有“吨似乎工作当我保存从回调这样在变量中响应:在API中添加新行( n)API.ai

request.on('response', function (response) { 
    var textResponse = response.result.fulfillment.speech; 
    // ... 
}) 
+0

你怎么试过吗?在添加\ n之后你需要做什么? –

+0

它从字面上给了我'\ n'。我尝试将它直接发送到Facebook Messenger。它显示如下:'示例文本\ n示例文本',但它应该在那里有一个新的行。 –

+0

我回答检查我的答案。 –

回答

2

最后我解决了它这样的:

var textResponse = response.result.fulfillment.speech; 
textResponse = textResponse.replace(/\\n/g, '\n'); 

输入是这样的:I'm a chatbot. \n built with ❤

+0

最后,这种方法只有工作。 @Dinesh –

+0

很酷。这意味着逃避\为您工作 –

0

使用断开线的<\br>代替\n

例如:

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

+0

我试过了。它也不工作。截图:http://i.imgur.com/UU4HGQD.png –

+0

OK尝试\ u000A代替

+0

或使用 试试这个 –