Google 助手的执行响应带有转义字符“\”
Google Assistant's fulfillment response comes with escape character "\"
我创建了一个简单的 webhook 来使用 Actions on Google Client Library 实现 Google 操作意图。此 webhook 使用此代码托管在 AWS Lambda 函数上:
'use strict';
// Import the Dialogflow module from the Actions on Google client library.
const {dialogflow} = require('actions-on-google');
// Instantiate the Dialogflow client.
const app = dialogflow({debug: true});
// Handle the Dialogflow intent named 'favorite color'.
// The intent collects a parameter named 'color'.
app.intent('favorite color', (conv, {color}) => {
const luckyNumber = color.length;
// Respond with the user's lucky number and end the conversation.
conv.close('Your lucky number is ' + luckyNumber);
});
// Set the DialogflowApp object to handle the HTTPS POST request.
exports.fulfillment = app;
我的问题是响应以这种形式返回给助手:
{
"statusCode": 200,
"body": "{\"payload\":{\"google\":{\"expectUserResponse\":false,\"richResponse\":{\"items\":[{\"simpleResponse\":{\"textToSpeech\":\"Your lucky number is 3\"}}]}}},\"fulfillmentText\":\"Your lucky number is 3\"}",
"headers": {
"content-type": "application/json;charset=utf-8"
}
}
如您所见,正文中插入了导致执行失败的转义字母。
我尝试了以下方法:
JSON.stringify(conv.close('Your lucky number is ' + luckyNumber));
JSON.parse(conv.close('Your lucky number is ' + luckyNumber));
JSON.parse(conv.close('Your lucky number is ' + luckyNumber).body);
没有任何变化,因为我认为我需要到达负载部分。
事实证明 AWS API 网关中有一个复选框选项名为:使用 Lambda 代理集成.
选择它时 returns JSON 原样 来自我的代码,没有额外的格式。
我创建了一个简单的 webhook 来使用 Actions on Google Client Library 实现 Google 操作意图。此 webhook 使用此代码托管在 AWS Lambda 函数上:
'use strict';
// Import the Dialogflow module from the Actions on Google client library.
const {dialogflow} = require('actions-on-google');
// Instantiate the Dialogflow client.
const app = dialogflow({debug: true});
// Handle the Dialogflow intent named 'favorite color'.
// The intent collects a parameter named 'color'.
app.intent('favorite color', (conv, {color}) => {
const luckyNumber = color.length;
// Respond with the user's lucky number and end the conversation.
conv.close('Your lucky number is ' + luckyNumber);
});
// Set the DialogflowApp object to handle the HTTPS POST request.
exports.fulfillment = app;
我的问题是响应以这种形式返回给助手:
{
"statusCode": 200,
"body": "{\"payload\":{\"google\":{\"expectUserResponse\":false,\"richResponse\":{\"items\":[{\"simpleResponse\":{\"textToSpeech\":\"Your lucky number is 3\"}}]}}},\"fulfillmentText\":\"Your lucky number is 3\"}",
"headers": {
"content-type": "application/json;charset=utf-8"
}
}
如您所见,正文中插入了导致执行失败的转义字母。
我尝试了以下方法:
JSON.stringify(conv.close('Your lucky number is ' + luckyNumber));
JSON.parse(conv.close('Your lucky number is ' + luckyNumber));
JSON.parse(conv.close('Your lucky number is ' + luckyNumber).body);
没有任何变化,因为我认为我需要到达负载部分。
事实证明 AWS API 网关中有一个复选框选项名为:使用 Lambda 代理集成.
选择它时 returns JSON 原样 来自我的代码,没有额外的格式。