响应格式错误:从dialogflow Web挂钩获取响应时出现Webhook错误

时间:2019-05-13 10:11:45

标签: node.js aws-lambda actions-on-google dialogflow-fulfillment

我正在使用AWS CloudAPI调用AWS Lambda存储库,以实现Google(AoG)上的操作。使用Google-Actions NodeJS客户端,一切正常,除了从AoG模拟器调用时出现错误时,错误消息是“ ...目前无响应。请稍后重试”。

node.js AWS Lambda代码如下,

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部分是干净的,AWS CloudWatch Logs 它在dialogflow上运行时也通过了测试,Dialogflow Response

当我们尝试通过AoG模拟器进行测试时,就会出现问题,Actions on Google simulator

错误消息如下,

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

带有帖子数据的发送请求:

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

从具有主体的代理收到的响应:

 {
 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模拟器中获得响应,但我收到了错误消息。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

@Daniel, 在AWS Lambda上运行dialogFlow时,我也遇到这个问题。我通过拦截谷歌上的动作响应并仅将正文作为JSON响应发送来解决了该问题。下面是我的示例代码。当dialogFlow只需要JSON时,似乎Google动作sdk希望返回200响应。

Cluster 0 2
Cluster 1 2
Cluster 2 1
Cluster 3 1