0

I built a bot using Dialogflow and connected it to a local webhook (now accessing it through ngrok). I am able to receive the response from Dialogflow but I am unable to replay to it. I followed the JSON structure as shown here - Test response from webhook. But I am getting the following error in Dialogflow.

Webhook call failed. Error: Failed to parse webhook JSON response: Cannot find field: messages in message google.cloud.dialogflow.v2.Intent.Message.

Following is the reply that I sent to Dialogflow -

{
   "messages":[
      {
         "speech":"Text response",
         "type":0
      }
   ]
}

Please tell me what should be the exact format of the reply that I should send to Dialogflow.

Sunil
  • 429
  • 1
  • 9
  • 25

5 Answers5

3

From v1 to v2, the response object almost change completely. For just simple text, you can use like:

{
  "fulfillmentText": "Text response",
  "fulfillmentMessages": [
    {
      "text": {
        "text": ["Text response"]
      }
    }
  ],
  "source": "<Text response>"
}
Abhay
  • 6,410
  • 4
  • 26
  • 34
3

I faced same issue,resolved using below json on dialogflow :

enter image description here

I made a simple node program which accepts a post response and returns json of the format accepted by Dialogflow.You may send your request in any way you like. check on Fulfillment status tab :

enter image description here

Shashank Bodkhe
  • 941
  • 10
  • 15
  • Thanks; I'm using C# and to fix "IDE1006 Naming rule violation:" I had changed fulfillmentText to FulfillmentText. After seeing your screenshot realized what was going on. – Sri Feb 26 '19 at 22:14
1

The field messageswas renamed/refactored to fulfillmentMessages - "can not find" means that it is not a property in the definition. This is some comparable result accepted by v2:

{
   "fulfillmentText": "response text",
   "fulfillmentMessages": [{"simpleResponses": {"simpleResponses": [   {
      "textToSpeech": "response text",
      "displayText": "response text"
   }]}}]
}
Yahoo Serious
  • 3,728
  • 1
  • 33
  • 37
0

Messages alone is not sufficient. Refer to Dialogflow V2 webhook fulfillment documentation for complete list of parameters expected and format of JSON.

Are you sure you are using V2 of the DialogFlow APIs?

Vinay P
  • 617
  • 3
  • 13
  • Vinay P Thanks for responding. I am not using their SDK. I am receiving the POST request from Dialogflow in a flask app and parsing it. I am then sending a custom reply from flask app. I Used the link that you gave but still not working. Can you tell me how to use this - https://dialogflow.com/docs/reference/api-v2/rest/v2beta1/WebhookResponse – Sunil May 17 '18 at 12:50
  • This another [link](https://dialogflow.com/docs/fulfillment#response) says that all the values are optional. – Sunil May 17 '18 at 12:53
  • @sunil I have done similar implementation using V1, it is not sufficient to send only the fields you have considered. And again the messages error would I guess appear only in V1, because V2 doesnt seem to have that field(I can be wrong with V2 as I havent worked on that). And I have not migrated to V2 as it is still not production ready. – Vinay P May 18 '18 at 05:24
  • Thank you @Vinay for sticking with me. I changed the agent from V2 to V1 and I changed the reply from webhook accordingly. But the question still remains - What is the exact format of reply from webhook that V2 can understand? – Sunil May 18 '18 at 06:45
  • I would not suggest anything in V2 as I haven't moved to that yet. In V1 _displaytext_ is one field could be needed. – Vinay P May 18 '18 at 06:58
  • Cool, I will take a look at it. But the question still remains unanswered. – Sunil May 18 '18 at 08:18
0

Use the Webhook Playground to Get the appropriate response for either the Dialogflow API or the Actions SDK which is depricated but still works. There is also the yet newer and different API for the Google Actions Builder/SDK framework as per :

DiaglowFlow JSON Response:

{
  "payload": {
    "google": {
      "expectUserResponse": true,
      "richResponse": {
        "items": [
          {
            "simpleResponse": {
              "textToSpeech": "Webhook worked.",
              "displayText": "Webhook worked."
            }
          }
        ]
      }
    }
  }
}

Actions SDK Response:

{
  "expectUserResponse": true,
  "expectedInputs": [
    {
      "inputPrompt": {
        "richInitialPrompt": {
          "items": [
            {
              "simpleResponse": {
                "textToSpeech": "Webhook worked.",
                "displayText": "Webhook worked."
              }
            }
          ]
        }
      },
      "possibleIntents": [
        {
          "intent": "actions.intent.TEXT"
        }
      ]
    }
  ]
}

Action Builder/SDK. Note that the session id needs to be returned.

{
  "session": {
    "id": "example_session_id",
    "params": {}
  },
  "prompt": {
    "override": false,
    "firstSimple": {
      "speech": "Hello World.",
      "text": ""
    }
  },
  "scene": {
    "name": "SceneName",
    "slots": {},
    "next": {
      "name": "actions.scene.END_CONVERSATION"
    }
  }
}
FastGTR
  • 343
  • 4
  • 4