我正在尝试使用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"
}
屏幕截图形式的错误:
答案 0 :(得分:2)
我假设您正在使用Java构建JSON响应。该请求从AoG发送到Dialogflow,后者调用您的Webhook。在这种情况下,Dialogflow如https://developers.google.com/actions/build/json/dialogflow-webhook-json
中所述将原始AoG请求包装到“ originalDetectIntentRequest”中由于您正在解析JSON请求并在Webhook中构建响应,因此您应参考上述URL以获取原始JSON协议。
希望这会有所帮助。