2017-07-02 52 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

或使用 試試這個 –