kiran
kiran

Reputation: 444

How to read webhook response in Dialogflow CX

I have created a simple Agent in Dialogflow CX. When the user enters a city name then it should list pin codes that belong to the entered city. In order to get the pin codes, I have performed a webhook POST request. The webhook URL returns the required pin code in JSON format but I don't know how I should display it in the chat.

Can I get some tutorial links? OR What changes I need to add in the Agent inorder to read the JSON response.

Upvotes: 2

Views: 3087

Answers (1)

fcagnola
fcagnola

Reputation: 670

Don't know if this will actually solve your problem, but I recently had a similar doubt to yours and this cleared it up for me.

From Google's Documentation for CX Webhooks, the response message for a webhook call is structured with a fulfillment_response field: this contains what the bot will say to the user if the webhook call is successful.

So, to answer your question what should happen is this:

  1. The user enters a city name, e.g. Atlanta
  2. The bot extracts the city name with a parameter and stores it, for example, as the $intent.params.city_name
  3. The bot also has "Enable Webhook for this page" enabled, and thus makes a Webhook request in JSON with a field called IntentInfo which contains a parameters field
  4. You call your API o do your computation or whatever in your script
  5. You build a WebhookResponse compliant with their format which contains a fulfillment_response field with a list of all ZIP codes for Atlanta in a format like such: "Here we are, these are $intent.params.city_name's ZIP codes: [your computed zipcodes]". For reference, there is an API package for most programming languages which can help you with that.
  6. The bot will receive the JSON and directly respond to the user with what is inside the fulfillment_response field

Hope this solved your doubts!

Upvotes: 2

Related Questions