DialogFlow: why does this Webhook Response fail wi

2019-08-25 15:58发布

问题:

Why does this specific webhook response (passed by DialogFlow back to Google Assistant)

    {
      "fulfillmentMessages" : [ {
        "payload" : {
          "google" : {
        "richResponse" : {
          "items" : [ {
            "simpleResponse" : {
              "textToSpeech" : "And are you male or female?"
            }
          } ]
        },
        "expectUserResponse" : true
          }
        },
        "text" : {
          "text" : [ "And are you male or female?" ]
        }
      }, {
        "quickReplies" : {
          "quickReplies" : [ "Male", "Female" ]
        }
      } ],
      "fulfillmentText" : "And are you male or female?",
      "outputContexts" : [ ... ]
    }

Error as:

"MalformedResponse: Failed to parse Dialogflow response into AppResponse because of empty speech response" 

回答1:

In the case of Google Assistant, the responses are not part of fulfillmentMessages but are in a payload object which should be located at the top level of your response.

Note that quickReplies and text are valid for Dialogflow fulfillment messages but not for Google Assistant too. Instead, you should use simpleResponse and suggestions fields and put them in the response.

So, for example here is a response for Google Assistant which is made of suggestion chips and a simple response:

{
  payload: {
    google: {
      richResponse: {
        items: [{
          simpleResponse: {
            textToSpeech: "Are you male or female"
          }
        }],
        suggestions: [
          { title: 'Male' },
          { title: 'Female' }
        ]
      }
    }
  },
  outputContexts: [...]
}

For Dialogflow fulfillment messages (in the Dialogflow console for example), it would have been something like that:

{
  fulfillmentMessages: [
    { text: { text: ['Are you male or female'] } },
    { quickReplies: { quickReplies: ['Male', 'Female'] } } 
  ],
  outputContexts: [...]
}

Hope that helps.