How can I integrate the Google Actions responses i

2019-03-01 02:50发布

问题:

I am trying to figure out how I can embed Google Actions responses, such as the cards carousel, in a webhook response for DialogFlow.

On https://developers.google.com/actions/dialogflow/webhook, I found the following information:

The response format of the Dialogflow webhook contains the standard Dialogflow webhook response contents and a data.google object that closely resembles a standard conversation webhook response with the following general differences.

So I tried extending the webhook response with a data.google structure as following:

{
   "fulfillmentText":"Please select any card you like.",
   "data":{
      "google":{
         ...
      }
   }
}

When testing in the console, I get the following error:

Webhook call failed. Error: Failed to parse webhook JSON response: Cannot find field: data in message google.cloud.dialogflow.v2beta1.WebhookResponse.

Looking to the definition of WebhookResponse, it looks like there is indeed no data field.

I am going around in circles. My question is basically: how can I enrich Dialogflow webhook responses with Google Actions responses?

回答1:

The documentation for Actions on Google still refers to the Dialogflow V1 protocol documentation and the node.js library from Google only supports the V1 protocol. Since it sounds like you're trying to use Dialogflow V2 Beta, you need to change how you've formatted the JSON.

Instead of using the data.google data structure, as in V1, V2Beta uses the payload.google field (that is, a payload object that has a google object in it). (See https://dialogflow.com/docs/fulfillment#requirements under the "Response" section and click on the V2 tab.)

The payload.google field would be set to the same thing the contents of the data.google field was set to.