4
votes

I am using firebase function for the webhook fulfillment in Dialogflow. I am getting webhook successful as a fulfillment status but it is not working. I am using version 1. When I test it on Google Assistant simulator, it says "App is not responding".

firebase function

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"
                 }
              ]
           }
        }
      }
   )
});`

When I copy paste the response from {google... to the end in the custom payload manually via GUI, It works. While for webhook, it is not working.

RAW API RESPONSE

 {
  "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"
}

FULFILLMENT REQUEST

{
  "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"
}

FULFILLMENT RESPONSE

{
  "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"
        }
      ]
    }
  }
}

FULFILLMENT STATUS

Webhook execution successful

enter image description here

Firebase Logs enter image description here

Google Assistant Simulator Logs enter image description here

1

1 Answers

1
votes

You're not using the correct JSON in the response. By putting it in the GUI in the "custom payload" section, it is creating a larger JSON response for you. The google object needs to be under the data object for Dialogflow v1 or payload for Dialogflow v2. (And if you haven't switched to v2 - you should do so immediately, since v1 will be switched off in about a month.)

So what you're returning should look more like

{
  "payload": {
    "google": {
      ...
    }
  }
}