谷歌助手的实现响应带有转义字符。 [英] Google Assistant's fulfillment response comes with escape character ""
本文介绍了谷歌助手的实现响应带有转义字符。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Actions on Google Client Library创建了一个简单的WebHook来实现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 Gateway中有一个名为:使用Lambda代理集成的复选框选项。
选中后,它将按原样返回代码中的JSON,而不会设置额外的格式。
这篇关于谷歌助手的实现响应带有转义字符。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文