Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >响应格式错误:从对话流web钩子获取响应时出现Webhook错误

响应格式错误:从对话流web钩子获取响应时出现Webhook错误
EN

Stack Overflow用户
提问于 2019-05-13 10:11:45
回答 1查看 520关注 0票数 2

我正在调用AWS Lambda repo,使用AWS CloudAPI在谷歌(AoG)上执行操作。使用谷歌NodeJS客户端上的操作,一切工作正常,除了从AoG模拟器调用时出现的错误,生成“...目前没有响应。请稍后重试”

node.js AWS Lambda代码如下所示:

代码语言:javascript
运行
AI代码解释
复制
const { dialogflow } = require('actions-on-google'),
    AWS = require('aws-sdk');

const app = dialogflow({
    debug: true
});

const iotData = new AWS.IotData({
    endpoint: '***thing_id***.iot.us-east-1.amazonaws.com'
}),
    name = '***thing_name***',

    /** The parameters required to retrieve the state of the endpoint */
    paramsToGetThing = {
        thingName: name
    };

/**
 * Notify the AWS IoT endpoint on command
 * @param {DialogflowConversation} conv DialogflowConversation instance
 * @return {void}
 */
app.intent('Notify IoT Intent', (conv) => {
    console.log('Inside Notify IoT Intent function');

    return new Promise((resolve, reject) => {
        iotData.getThingShadow(paramsToGetThing, function (error, data) {
            if (error) {
                console.log(error, error.stack);
                conv.close('Network error! Please try again after some time.');
                reject(error);
            } else {
                const parsing = JSON.parse(data.payload);
                console.log('Parsing state is ' + parsing.state.reported.connected);
                if (parsing.state.reported.connected) {
                    console.log('Device is in online state and publish the command');
                    publishMessageForCommands(conv.action)
                        .then((response) => {
                            console.log('Inside publish message delay case');
                            setTimeout(function () {
                                console.log('Inside delaycheck after 2 seconds timeout function');
                                conv.ask(response);
                                resolve();
                            }, 2000); // Two seconds delay before speech response
                        })
                        .catch((rejectError) => {
                            conv.close(rejectError);
                            console.log('Inside CustomIntentHandler error block.');
                            reject();
                        });
                } else {
                    console.log('Inside publish message before time out\nDevice is offline state and cannot publish the message to ' + name);
                    conv.close('The device is offline, please check the device and try again');
                    reject();
                }
            }
        });
    });
});

/**
 * Error handler block
 * @param {DialogflowConversation} conv DialogflowConversation instance
 * @return {void}
 */
app.catch((conv, error) => {
    console.error(error);
    conv.ask('I encountered a glitch. Can you say that again?');
});

/**
 * Default fallback intent
 * @param {DialogflowConversation} conv DialogflowConversation instance
 * @return {void}
 */
app.fallback((conv) => {
    conv.ask(`I couldn't understand. Can you say that again?`);
});

exports.handler = app;

当我深入研究这个问题时,发现AWS部分是干净的,如下所示

它在对话流上运行时也通过了,

当我们试图从AoG模拟器中测试它时,问题就出现了。

错误消息如下:

代码语言:javascript
运行
AI代码解释
复制
 {
 insertId: "5a4yrqg2e6598n"  

labels: {
  channel: "preview"   
  querystream: "GOOGLE_USER"   
  source: "JSON_RESPONSE_VALIDATION"   
 }
 logName: "projects/***project_name***/logs/actions.googleapis.com%2Factions"  
 receiveTimestamp: "2019-05-13T09:31:33.504048852Z"  

resource: {

labels: {
   action_id: "actions.intent.TEXT"    
   project_id: "***project_id***"    
   version_id: ""    
  }
  type: "assistant_action"   
 }
 severity: "ERROR"  
 textPayload: "MalformedResponse: Webhook error (206)"  
 timestamp: "2019-05-13T09:31:33.471947959Z"  
 trace: "projects/263334370390/traces/ABwppHEjcsRXQzqvNSSYSnGKh-9pWv5_c03_IihzYMPvo7dvPGT_wfuIsvJKt3-BQKXgofT1_FILM_Z8inBiAQ"  
}

正在发送带有post数据的请求:

代码语言:javascript
运行
AI代码解释
复制
{
    insertId: "1inzh7lg2hdrojj"  

   labels: {
     channel: "preview"   
     querystream: "GOOGLE_USER"   
     source: "AOG_REQUEST_RESPONSE"   
    }
    logName: "projects/***projecct_name***/logs/actions.googleapis.com%2Factions"  
    receiveTimestamp: "2019-05-13T09:31:33.503838806Z"  

   resource: {

   labels: {
      action_id: "actions.intent.TEXT"    
      project_id: "***project_id***"    
      version_id: ""    
     }
     type: "assistant_action"   
    }
    severity: "DEBUG"  
    textPayload: "Sending request with post data: {"user":{"userId":"ABwppHE6s78QlB8ah1DEkuPAxvJvH23BWfHmJOjvn1L7KVUb1DfszUh_aIMyifDw1BfPZsH5Z2T1vmQ63Xu1aw","locale":"en-IN","lastSeen":"2019-05-13T09:23:50Z"},"conversation":{"conversationId":"ABwppHEjcsRXQzqvNSSYSnGKh-9pWv5_c03_IihzYMPvo7dvPGT_wfuIsvJKt3-BQKXgofT1_FILM_Z8inBiAQ","type":"ACTIVE","conversationToken":"[]"},"inputs":[{"intent":"actions.intent.TEXT","rawInputs":[{"inputType":"KEYBOARD","query":"notify"}],"arguments":[{"name":"text","rawText":"notify","textValue":"notify"}]}],"surface":{"capabilities":[{"name":"actions.capability.ACCOUNT_LINKING"},{"name":"actions.capability.SCREEN_OUTPUT"},{"name":"actions.capability.AUDIO_OUTPUT"},{"name":"actions.capability.WEB_BROWSER"},{"name":"actions.capability.MEDIA_RESPONSE_AUDIO"}]},"isInSandbox":true,"availableSurfaces":[{"capabilities":[{"name":"actions.capability.WEB_BROWSER"},{"name":"actions.capability.AUDIO_OUTPUT"},{"name":"actions.capability.SCREEN_OUTPUT"}]}],"requestType":"SIMULATOR"}."  
    timestamp: "2019-05-13T09:31:33.018260116Z"  
    trace: "projects/263334370390/traces/ABwppHEjcsRXQzqvNSSYSnGKh-9pWv5_c03_IihzYMPvo7dvPGT_wfuIsvJKt3-BQKXgofT1_FILM_Z8inBiAQ"  
   }

从具有正文的代理收到的响应:

代码语言:javascript
运行
AI代码解释
复制
 {
 insertId: "1inzh7lg2hdrojk"  

labels: {
  channel: "preview"   
  querystream: "GOOGLE_USER"   
  source: "AOG_REQUEST_RESPONSE"   
 }
 logName: "projects/***project_name***/logs/actions.googleapis.com%2Factions"  
 receiveTimestamp: "2019-05-13T09:31:33.503838806Z"  

resource: {

labels: {
   action_id: "actions.intent.TEXT"    
   project_id: "***project_id***"    
   version_id: ""    
  }
  type: "assistant_action"   
 }
 severity: "DEBUG"  
 textPayload: "Received response from agent with body: HTTP/1.1 200 OK

Server: nginx/1.13.6

Date: Mon, 13 May 2019 09:31:33 GMT

Content-Type: application/json;charset=UTF-8

Content-Length: 4441

X-Cloud-Trace-Context: 3de98e1e9a922989893d5778d6cd1232/12117959397276118516;o=0

Google-Actions-API-Version: 2

X-SHARD: shard-2

Via: 1.1 google

Alt-Svc: clear



{"conversationToken":"[]","expectUserResponse":true,"expectedInputs":[{"inputPrompt":{"richInitialPrompt":{"items":[{"simpleResponse":{"textToSpeech":"Done"}}]}},"possibleIntents":[{"intent":"assistant.intent.action.TEXT"}]}],"responseMetadata":{"status":{"code":14,"message":"Webhook error (206)"},"queryMatchInfo":{"queryMatched":true,"intent":"8d15dee5-2250-41fd-a5c3-a5a1bf8b1014"},"delegatedRequest":{"delegatedRequest":"{\n  \"responseId\": \"a8fe5f58-23a3-4d72-8f1a-7b1897257fc5\",\n  \"queryResult\": {\n    \"queryText\": \"notify\",\n    \"action\": \"input.Notify\",\n    \"parameters\": {\n    },\n    \"allRequiredParamsPresent\": true,\n    \"fulfillmentText\": \"Done\",\n    \"fulfillmentMessages\": [{\n      \"text\": {\n        \"text\": [\"Done\"]\n      }\n    }],\n    \"outputContexts\": [{\n      \"name\": \"projects/aog-sample-6c818/agent/sessions/ABwppHEjcsRXQzqvNSSYSnGKh-9pWv5_c03_IihzYMPvo7dvPGT_wfuIsvJKt3-BQKXgofT1_FILM_Z8inBiAQ/contexts/actions_capability_screen_output\"\n    }, {\n      \"name\": \"projects/aog-sample-6c818/agent/sessions/ABwppHEjcsRXQzqvNSSYSnGKh-9pWv5_c03_IihzYMPvo7dvPGT_wfuIsvJKt3-BQKXgofT1_FILM_Z8inBiAQ/contexts/actions_capability_account_linking\"\n    }, {\n      \"name\": \"projects/aog-sample-6c818/agent/sessions/ABwppHEjcsRXQzqvNSSYSnGKh-9pWv5_c03_IihzYMPvo7dvPGT_wfuIsvJKt3-BQKXgofT1_FILM_Z8inBiAQ/contexts/actions_capability_audio_output\"\n    }, {\n      \"name\": \"projects/aog-sample-6c818/agent/sessions/ABwppHEjcsRXQzqvNSSYSnGKh-9pWv5_c03_IihzYMPvo7dvPGT_wfuIsvJKt3-BQKXgofT1_FILM_Z8inBiAQ/contexts/google_assistant_input_type_keyboard\"\n    }, {\n      \"name\": \"projects/aog-sample-6c818/agent/sessions/ABwppHEjcsRXQzqvNSSYSnGKh-9pWv5_c03_IihzYMPvo7dvPGT_wfuIsvJKt3-BQKXgofT1_FILM_Z8inBiAQ/contexts/actions_capability_web_browser\"\n    }, {\n      \"name\": \"projects/aog-sample-6c818/agent/sessions/ABwppHEjcsRXQzqvNSSYSnGKh-9pWv5_c03_IihzYMPvo7dvPGT_wfuIsvJKt3-BQKXgofT1_FILM_Z8inBiAQ/contexts/actions_capability_media_response_audio\"\n    }],\n    \"intent\": {\n      \"name\": \"projects/aog-sample-6c818/agent/intents/8d15dee5-2250-41fd-a5c3-a5a1bf8b1014\",\n      \"displayName\": \"Notify IoT Intent\"\n    },\n    \"intentDetectionConfidence\": 1.0,\n    \"languageCode\": \"en-in\"\n  },\n  \"originalDetectIntentRequest\": {\n    \"source\": \"google\",\n    \"version\": \"2\",\n    \"payload\": {\n      \"isInSandbox\": true,\n      \"surface\": {\n        \"capabilities\": [{\n          \"name\": \"actions.capability.ACCOUNT_LINKING\"\n        }, {\n          \"name\": \"actions.capability.SCREEN_OUTPUT\"\n        }, {\n          \"name\": \"actions.capability.AUDIO_OUTPUT\"\n        }, {\n          \"name\": \"actions.capability.WEB_BROWSER\"\n        }, {\n          \"name\": \"actions.capability.MEDIA_RESPONSE_AUDIO\"\n        }]\n      },\n      \"requestType\": \"SIMULATOR\",\n      \"inputs\": [{\n        \"rawInputs\": [{\n          \"query\": \"notify\",\n          \"inputType\": \"KEYBOARD\"\n        }],\n        \"arguments\": [{\n          \"rawText\": \"notify\",\n          \"textValue\": \"notify\",\n          \"name\": \"text\"\n        }],\n        \"intent\": \"actions.intent.TEXT\"\n      }],\n      \"user\": {\n        \"lastSeen\": \"2019-05-13T09:23:50Z\",\n        \"locale\": \"en-IN\",\n        \"userId\": \"ABwppHE6s78QlB8ah1DEkuPAxvJvH23BWfHmJOjvn1L7KVUb1DfszUh_aIMyifDw1BfPZsH5Z2T1vmQ63Xu1aw\"\n      },\n      \"conversation\": {\n        \"conversationId\": \"ABwppHEjcsRXQzqvNSSYSnGKh-9pWv5_c03_IihzYMPvo7dvPGT_wfuIsvJKt3-BQKXgofT1_FILM_Z8inBiAQ\",\n        \"type\": \"ACTIVE\",\n        \"conversationToken\": \"[]\"\n      },\n      \"availableSurfaces\": [{\n        \"capabilities\": [{\n          \"name\": \"actions.capability.WEB_BROWSER\"\n        }, {\n          \"name\": \"actions.capability.AUDIO_OUTPUT\"\n        }, {\n          \"name\": \"actions.capability.SCREEN_OUTPUT\"\n        }]\n      }]\n    }\n  },\n  \"session\": \"projects/aog-sample-6c818/agent/sessions/ABwppHEjcsRXQzqvNSSYSnGKh-9pWv5_c03_IihzYMPvo7dvPGT_wfuIsvJKt3-BQKXgofT1_FILM_Z8inBiAQ\"\n}"},"delegatedResponse":{"delegatedResponse":"{\"statusCode\":200,\"body\":\"{\\\"payload\\\":{\\\"google\\\":{\\\"expectUserResponse\\\":true,\\\"richResponse\\\":{\\\"items\\\":[{\\\"simpleResponse\\\":{\\\"textToSpeech\\\":\\\"Notified\\\"}}]}}}}\",\"headers\":{\"content-type\":\"application/json;charset=utf-8\"}}"}}}."  
 timestamp: "2019-05-13T09:31:33.471512803Z"  
 trace: "projects/263334370390/traces/ABwppHEjcsRXQzqvNSSYSnGKh-9pWv5_c03_IihzYMPvo7dvPGT_wfuIsvJKt3-BQKXgofT1_FILM_Z8inBiAQ"  
}

预期的行为是在AoG模拟器中获得响应,但我得到的却是错误。任何帮助都将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-12-04 16:31:41

@Daniel,我在AWS Lambda上运行dialogFlow时也遇到了这个问题。我通过截获actions-on-google响应并将正文作为JSON响应发送来解决了这个问题。下面是我的示例代码。当dialogFlow只需要JSON时,google sdk上的操作似乎想要返回一个200响应。

代码语言:javascript
运行
AI代码解释
复制
'use strict';

/**
- Lambda functions use a callback function that returns "error and response"
- If there is no error you can usually call the callback function with callback(null,response)
- Many NPM packages handle this callback for you so you dont actually see where the response is sent. By wrapping the lambda handler in another callback function I can see the response that google is sending from my lambda function
*/
exports.handler =  (event,context,callback) => {

function googleCallbackInterceptFunction (err, response){
  console.log('Google Callback');
  console.log(response);
  /**  ^^ THis logging response shows me that google is wrapping the response in a {body:response, status:200} object.  Dialogflow just wants the response so we're going to use the next line vv to pull out the response and just send that*/

  response = JSON.parse(response.body);

  console.log('Google Callback');
  console.log(response);

  /** This callback vv is the lambda callback that wraps this entire program.  when this callback is fired the lambda sends a response to dialogflow and then terminates itself.  Normally the actions-on-google sdk would fire this function but if it does send the wrapped response "{body:response, status:200}" dialogflow is not smart enough to find the response within the body. */
  callback(null, response);
}

const {
      dialogflow,
      Image,
    } = require('actions-on-google');

    // Create an app instance
    const app = dialogflow({
      debug: true //THIS IS A CONFIGURATION SETTING BUILT INTO the actions-on-google SDK that WILL LOG THE REQUEST AND RESPONSES (On their own but will not show you that google is also wrapping them in a 200 response object which we dont want)
    });

    /** 3 basic intents that use the app.intent and conv.ask/conv.close functionality of the actions-on-google sdk.  Based on these responses google will send a response that dialogflow can interpret. */
    app.intent('Default Welcome Intent', conv => {
      console.log('Default welcome intent HIT');
      conv.ask('Hi, how is it going?');
      conv.ask(`Here's a picture of a cat`);
      // conv.ask(new Image({
      //   url: 'https://developers.google.com/web/fundamentals/accessibility/semantics-builtin/imgs/160204193356-01-cat-500.jpg',
      //   alt: 'A cat',
      // }))
    });

    // Intent in Dialogflow called `Goodbye`
    app.intent('Goodbye', conv => {
      conv.close('See you later!')
    });

    app.intent('Default Fallback Intent', conv => {
      conv.ask(`I didn't understand. Can you tell me something else?`)
    });

    app(event,context,googleCallbackInterceptFunction);//I am initializing the actions-on-google sdk with MY callback function, not the Lambda's.  This way I can log the result before the lambda responds and is termindated.  MY callback function returns the result to the lambda callback function so the lambda still works as intended.
};
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56110220

复制
相关文章
matlab导入文件夹里所有图片_如何创建快捷方式到指定文件夹
在matlab中,直接imwrite()保存图片,会保存到当前工作目录文件夹或其子文件夹。
全栈程序员站长
2022/09/30
2.1K0
VSCode插件Todo Tree如何忽略某些文件夹?
VsCode 中的插件 TodoTree是一个特别好用的工具,可以高亮显示任何 打上 // TODO 的位置,同时,在VsCode的工具栏可以将这些TODO列出来。但是,有时侯某些文件中的 TODO 不是你添加的,或者你不想看到这些 TODO,比如 node_modules 中的文件,这时候,如何将这些文件忽略呢? 打开VsCode 文件 => 首选项 => 设置 在输入框中搜索TodoTree 找到Todo-tree>Filter:Exclude Globs 点击添加项 在
CherishTheYouth
2020/10/27
1.6K0
VSCode插件Todo Tree如何忽略某些文件夹?
Linux tar 打包排除某些文件夹[通俗易懂]
使用tar命令来进行打包,并使用-exclude这个参数来排除一个文件夹。如果存在多个排除文件夹,就要写多个参数。
全栈程序员站长
2022/09/03
6.9K0
如何通过Samba共享Linux文件夹
Samba(SMB是其缩写) 是一个网络服务器,用于Linux和Windows共享文件之用;Samba 即可以用于Windows和Linux之间的共享文件,也一样用于Linux和Linux之间的共享文件。
静默虚空
2022/05/10
7.8K0
GitHub上如何创建/删除文件夹
在文件名后面加上"/"这个斜杠回车再输入一个文件名,在里面随便写点东西(因为Github不允许空文件夹存在,空文件夹自动删除),提交接即可。
浩Coding
2019/07/03
15.7K0
Windows 技巧篇-点开头的文件夹名创建方法。如何创建点开头的文件夹?
文件夹命名如果前面加个点会提示: 必须键入文件名 解决办法: 很简单!建的时候前后都加一个点,保存后就只有一个点了。 效果图:
小蓝枣
2020/09/23
3K0
Roslyn 如何使用 MSBuild MakeDir 创建文件夹
在 MSBuild 的 Task 内置任务里面,可以使用 MakeDir task 进行创建文件夹,简单的使用方法如下
林德熙
2020/11/19
9700
如何使用SVN创建分支并复制文件夹
Subversion(SVN)是一个版本控制系统,它可以帮助团队有效地管理代码和文件版本。在这篇文章中,我们将学习如何使用SVN创建一个分支并复制文件夹到新的分支中。具体命令如下:
高久峰
2023/08/03
1.2K0
Python创建目录文件夹
Python对文件的操作还算是方便的,只需要包含os模块进来,使用相关函数即可实现目录的创建。
狼啸风云
2020/08/10
4K0
Python创建目录文件夹
Python对文件的操作还算是方便的,只需要包含os模块进来,使用相关函数即可实现目录的创建。
周小董
2019/03/25
3.7K0
Python 创建递归文件夹
# 创建递归文件夹 def createfiles(filepathname): try: os.makedirs(filepathname) except Exception as err: print(str(filepathname) + "已经存在!") filepathname为目录,类型为 "../data/" or "E:/data/"
机器学习和大数据挖掘
2019/07/02
2.2K0
Python 创建HDFS文件夹
直接上代码 #! /usr/bin/python2.7 # -*- coding: utf8 -*- import os import sys reload(sys) sys.setdefaultencoding("utf-8") sys.path.append("../") import datetime from utils import confUtils def hadoop_make_dir(hadoop_path, auth, src_path): cmd = '%s dfs %s
week
2018/08/24
3.1K0
git提交如何忽略某些文件
在使用git对项目进行版本管理的时候,我们总有一些不需要提交到版本库里的文件和文件夹,这个时候我们就需要让git自动忽略掉一下文件。 使用.gitignore忽略文件 为了让git忽略指定的文件和文件
用户1741436
2018/05/16
15.4K0
python创建文件和文件夹
在os.getcwd()后边 加上 [:-4] + ‘xxoo\\’ 就可以在py文件所在路径下创建 xxoo文件夹
全栈程序员站长
2022/07/05
3K0
python创建文件和文件夹
hdfs创建删除文件和文件夹
在 hadoop 中,基于 Linux 命令可以给 hdfs 创建文件和文件夹,或者删除文件和文件夹
机器学习和大数据挖掘
2019/07/02
16.5K1
用MATLAB将多个文件夹内的某些文件汇总到另一个文件夹
本文介绍了如何使用MATLAB将多个文件夹下的特定文件移动到另一个文件夹,以便于进行后续的分析和处理。首先介绍了MATLAB中的movefile函数,该函数可以移动单个或多个文件,并提供了相应的参数设置。然后通过一个具体的例子,演示了如何使用movefile函数进行文件移动操作。该例子中,将13个文件夹下的特定文件移动到另一个文件夹,并总结了操作的状态,包括成功和失败。最后,对movefile函数的使用进行了总结,并讨论了使用该函数时需要注意的问题。
Alan Lee
2018/01/02
3.5K0
用MATLAB将多个文件夹内的某些文件汇总到另一个文件夹
VBA 创建文件夹和判断文件夹是否存在!
Public Function 创建文件夹(ByVal 路径 As String, ByVal 文件夹名称 As String)
办公魔盒
2019/07/22
4.9K0
VBA 创建文件夹和判断文件夹是否存在!
iOS 创建文件夹,删除文件夹,对文件夹重命名的操作
+ (void)createFolder:(NSString )folderName { NSString imageDir = [NSString stringWithFormat:@"%@/Documents/%@", NSHomeDirectory(),folderName]; NSLog(@"HomeDir: %@",imageDir); BOOL isDir = NO; NSFileManager *fileManager = [NSFileManager defa
大师级码师
2021/10/29
2.8K0
WordPress自动在uploads文件夹内创建子文件夹
在开发主题或者插件的时候,经常要创建一个自定义的文件夹,我经常使用的一种方法就是在插件或主题安装的时候,先让程序自动到某个文件夹下先检测这个文件夹是否存在,如果不存在就自动创建一个文件夹。 下面的代码演示了如何在uploads文件夹中自动地创建一个自定义文件夹: function myplugin_activate() { $upload = wp_upload_dir(); $upload_dir = $upload['basedir']; $upload_dir = $upload_dir . '/my
Jeff
2018/01/19
1.7K0
点击加载更多

相似问题

从某些文件夹导入几个txt文件

14

通过调用从文件夹导入

13

从某些子文件夹中导入PowerShell模块

19

如何在通过maven创建zip文件时排除某些文件夹

11

通过Powershell从文件夹导入多个证书

10
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档