DialogFlow: why does this Webhook Response fail with 'empty speech response'

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-25 01:48:49

问题


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.



来源:https://stackoverflow.com/questions/56158748/dialogflow-why-does-this-webhook-response-fail-with-empty-speech-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!