简体   繁体   English

Google Assistant的履行响应带有转义符“ \\”

[英]Google Assistant's fulfillment response comes with escape character “\”

I created a simple webhook to fulfill a Google Action intent using Actions on Google Client Library . 我创建了一个简单的webhook,以使用Google Client Library上的Actions实现Google Action意图。 This webhook is hosted on an AWS Lambda function with this code: 该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;

My issue is the that the response comes back to the assistant in this form: 我的问题是响应以这种形式返回给助手:

{
  "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"
  }
}

As you can see, the body comes with the escape letter inserted which causes the fulfillment to fail. 如您所见,主体附带插入了转义字母,这会导致实现失败。

I tried the following: 我尝试了以下方法:

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

Nothing changed as I think I need to reach the payload part. 什么都没有改变,因为我认为我需要到达有效载荷部分。

Turns out there's an checkbox option in AWS API Gateway called: Use Lambda Proxy Integration . 原来,AWS API Gateway中有一个复选框选项: Use Lambda Proxy Integration

When selected it returns the JSON as is from my code without extra formatting. 选中后,它将按原样从我的代码返回JSON 而无需进行额外的格式化。

使用Lambda代理集成

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法将Google Assistant的Buffer响应解析为String - Unable to parse Google Assistant's Buffer response into String Google Assistant 的 web 抓取响应出错 - Error in web scraping response for Google Assistant Dialogflow 履行获取未显示响应 - Dialogflow fulfillment fetch not showing response Dialogflow + 外部 API + Google Cloud Functions *无 * Firebase:如何返回履行响应? - Dialogflow + external API + Google Cloud Functions *without* Firebase: how to return fulfillment response? 如何在 Dialogflow 实现中创建卡片响应? - How to create Card response in Dialogflow fulfillment? Alexa 的 Google 助理技能 - Google Assistant Skill for Alexa 如何从谷歌助手的用户那里获取文本,并从sqlite数据库中回复一些内容 - how to get a text from an user of google assistant, and response something from a sqlite db 错误:未设置响应。 Cloud Functions for Actions on Google Assistant - Error: No response has been set. Cloud Functions for Actions on Google Assistant 如何为 Actions on Google 使用异步履行 - How to use async fulfillment for Actions on Google 通过 Dialogflow 实现在 Google Actions 上设置上下文 - Set context on Google Actions through Dialogflow fulfillment
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM