响应格式错误:由于语音响应为空,无法将Dialogflow响应解析为AppResponse

时间:2019-04-15 12:10:40

标签: dialogflow actions-on-google

我正在使用firebase函数实现Dialogflow中的webhook。我已经成功地将Webhook用作fulfillment status,但是它无法正常工作。我正在使用版本1。当我在Google Assistant模拟器上对其进行测试时,它显示“应用程序无响应”。

firebase功能

const functions = require('firebase-functions');

exports.webhook = functions.https.onRequest((request, response) => {
    response.send({
        "google":{
           "richResponse":{
              "items":[
                 {
                    "simpleResponse":{
                       "textToSpeech":"Hey! Good to see you."
                    }
                 },
                 {
                    "mediaResponse":{
                       "mediaType":"AUDIO",
                       "mediaObjects":[
                          {
                             "name":"Exercises",
                             "description":"ex",
                             "largeImage":{
                                "url":"http://res.freestockphotos.biz/pictures/17/17903-balloons-pv.jpg",
                                "accessibilityText":"..."
                             },
                             "contentUrl":"https://theislam360.me:8080/hbd.mp3"
                          }
                       ]
                    }
                 }
              ],
              "suggestions":[
                 {
                    "title":"chips"
                 }
              ]
           }
        }
      }
   )
});`

当我通过GUI手动将响应从{google...粘贴到自定义有效负载的末尾时,它可以工作。对于Webhook,它不起作用。

RAW API响应

 {
  "id": "eaf627ed-26b5-4965-b0b0-bc77144e144b",
  "timestamp": "2019-04-15T11:54:18.948Z",
  "lang": "en",
  "result": {
    "source": "agent",
    "resolvedQuery": "play hbd",
    "action": "",
    "actionIncomplete": false,
    "parameters": {
      "any": "hbd"
    },
    "contexts": [],
    "metadata": {
      "isFallbackIntent": "false",
      "webhookResponseTime": 34,
      "intentName": "play",
      "intentId": "e60071cd-ce31-4ef9-ae9b-cc370c3362b3",
      "webhookUsed": "true",
      "webhookForSlotFillingUsed": "false"
    },
    "fulfillment": {
      "messages": []
    },
    "score": 1
  },
  "status": {
    "code": 200,
    "errorType": "success"
  },
  "sessionId": "e91bd62f-766b-b19d-d37b-2917ac20caa6"
}

满足要求

{
  "id": "eaf627ed-26b5-4965-b0b0-bc77144e144b",
  "timestamp": "2019-04-15T11:54:18.948Z",
  "lang": "en",
  "result": {
    "source": "agent",
    "resolvedQuery": "play hbd",
    "speech": "",
    "action": "",
    "actionIncomplete": false,
    "parameters": {
      "any": "hbd"
    },
    "contexts": [],
    "metadata": {
      "intentId": "e60071cd-ce31-4ef9-ae9b-cc370c3362b3",
      "webhookUsed": "true",
      "webhookForSlotFillingUsed": "false",
      "isFallbackIntent": "false",
      "intentName": "play"
    },
    "fulfillment": {
      "speech": "",
      "messages": []
    },
    "score": 1
  },
  "status": {
    "code": 200,
    "errorType": "success"
  },
  "sessionId": "e91bd62f-766b-b19d-d37b-2917ac20caa6"
}

履行响应

{
  "google": {
    "richResponse": {
      "items": [
        {
          "simpleResponse": {
            "textToSpeech": "Hey! Good to see you."
          }
        },
        {
          "mediaResponse": {
            "mediaType": "AUDIO",
            "mediaObjects": [
              {
                "name": "Exercises",
                "description": "ex",
                "largeImage": {
                  "url": "http://res.freestockphotos.biz/pictures/17/17903-balloons-pv.jpg",
                  "accessibilityText": "..."
                },
                "contentUrl": "https://theislam360.me:8080/hbd.mp3"
              }
            ]
          }
        }
      ],
      "suggestions": [
        {
          "title": "chips"
        }
      ]
    }
  }
}

实现状态

Webhook execution successful

enter image description here

Firebase日志 enter image description here

Google Assistant模拟器日志 enter image description here

1 个答案:

答案 0 :(得分:0)

您没有在响应中使用正确的JSON。通过将其放在“自定义有效负载”部分的GUI中,它将为您创建一个更大的JSON响应。对于Dialogflow v1,google对象必须位于data对象下;对于Dialogflow v2,payload必须位于{ "payload": { "google": { ... } } } 下。 (而且,如果您尚未切换到v2,则应立即这样做,因为v1将在大约一个月后关闭。)

所以您返回的内容应该更像

"aggs": { 
    "atendimentos": {
      "terms": {
        "field": "_parent",
        "size" : 0
      }
    }
  }