尝试在 Dialogflow 上使用 webhook 动态给出响应时出现 Webhook 响应错误(206)

getting Webhook response error (206) when trying to give response Dynamically using webhook On Dialogflow

我正尝试在 java 中使用 DialogFlow api 执行 google 操作。 我正在使用 Webhook 请求对 DialogFlow 中所示操作的响应 下图。

当尝试此代码时,它工作正常并给出正确的响应,因为 dialogflow 具有预定义的操作工具。

代码:

@PostMapping("/webhook")
public ResponseEntity payload(RequestBody FulfillmentResponse fulfillmentResponse) {
   log.info(fulfillmentResponse.getQueryResult().getQueryText());
   return ResponseEntity.ok(HttpStatus.OK);
}

但是当我动态给出响应时。它给我一个错误。

代码:

@PostMapping("/webhook")
public ResponseEntity payload(RequestBody FulfillmentResponse fulfillmentResponse) {
    log.info(fulfillmentResponse.getQueryResult().getQueryText());
    return ResponseEntity.ok("{\n" + 
            "  \"data\": {\n" + 
            "    \"google\": {\n" + 
            "      \"expectUserResponse\": true,\n" + 
            "      \"richResponse\": {\n" + 
            "        \"items\": [\n" + 
            "          {\n" + 
            "            \"simpleResponse\": {\n" + 
            "              \"textToSpeech\": \"Choose a item\"\n" + 
            "            }\n" + 
            "          }\n" + 
            "        ]\n" + 
            "      },\n" + 
            "      \"systemIntent\": {\n" + 
            "        \"intent\": \"assistant.intent.action.TEXT\",\n" + 
            "        \"data\": {\n" + 
            "          \"@type\": \"type.googleapis.com/google.actions.v2.OptionValueSpec\",\n" + 
            "          \"listSelect\": {\n" + 
            "            \"title\": \"Hello\",\n" + 
            "            \"items\": [\n" + 
            "              {\n" + 
            "                \"optionInfo\": {\n" + 
            "                  \"key\": \"first title\"\n" + 
            "                },\n" + 
            "                \"description\": \"first description\",\n" + 
            "                \"image\": {\n" + 
            "                  \"url\": \"https://developers.google.com/actions/images/badges/XPM_BADGING_GoogleAssistant_VER.png\",\n" + 
            "                  \"accessibilityText\": \"first alt\"\n" + 
            "                },\n" + 
            "                \"title\": \"first title\"\n" + 
            "              },\n" + 
            "              {\n" + 
            "                \"optionInfo\": {\n" + 
            "                  \"key\": \"second\"\n" + 
            "                },\n" + 
            "                \"description\": \"second description\",\n" + 
            "                \"image\": {\n" + 
            "                  \"url\": \"https://lh3.googleusercontent.com/Nu3a6F80WfixUqf_ec_vgXy_c0-0r4VLJRXjVFF_X_CIilEu8B9fT35qyTEj_PEsKw\",\n" + 
            "                  \"accessibilityText\": \"second alt\"\n" + 
            "                },\n" + 
            "                \"title\": \"second title\"\n" + 
            "              }\n" + 
            "            ]\n" + 
            "          }\n" + 
            "        }\n" + 
            "      }\n" + 
            "    }\n" + 
            "  }\n" + 
            "}");
}

错误:

2018-11-02 16:14:43.906 IST Error in fulfillment status received from app endpoint. See ResponseMetadata in the response. Status code: 14. Error message: Webhook error (206)
 { 
   insertId: "6nwj8wf153t5q"  
   labels: {
            channel:  "preview"   
            querystream:  "GOOGLE_USER"   
            source:  "AOG_REQUEST_RESPONSE"   
           }
   logName: "projects/elysiot-217606/logs/actions.googleapis.com%2Factions"  
   receiveTimestamp:  "2018-11-02T10:44:43.940057016Z"  
   resource: {
             labels: {
                     action_id:  "actions.intent.TEXT"    
                     project_id:  "elysiot-217606"    
                     version_id:  ""    
                     }
             type:  "assistant_action"   
             }
   severity:  "ERROR"  
   textPayload:  "Error in fulfillment status received from app endpoint. See ResponseMetadata in the response. Status code: 14. Error message: Webhook error (206)"  
   timestamp:  "2018-11-02T10:44:43.906927701Z"  
   trace:  "projects/847724381623/traces/ABwppHFGjhCqYgY_YpSxJp5p9-s6NpvBRVzWdzGRhfypm0eZcqzYjDqjCVsdpxVXofc4xpOFLs4eAtWf9Ek"  
  }

截图形式同样错误:

我假设您正在使用 Java 构建 JSON 响应。请求从 AoG 发送到 Dialogflow,后者调用您的 webhook。在这种情况下,Dialogflow 将原始 AoG 请求包装成 "originalDetectIntentRequest",如 https://developers.google.com/actions/build/json/dialogflow-webhook-json

中所述

由于您正在解析 JSON 请求并在您的 webhook 中构建响应,因此您应该参考上面的 URL 了解原始 JSON 协议。

希望对您有所帮助。