Webhook Examples for Online Store Support Agent


This example shows one of many ways to design your agent so that it can respond depending on parameter values using the API.AI Webhook integration.

We suggest that you read the article about creating Online Store Support agent first.


Let’s imagine that our Online Store Support agent should provide information about shipping prices for different regions. Here’s our pricing table:

Region Shipping Price
Europe 100
North America 200
South America 300
Asia 400
Africa 500

It wouldn’t be convenient to store this information in your agent – you’d have to create 5 different intents to provide 5 different responses.

Instead, you can store the data in your own database and let your agent access it through a web service via an API.AI Webhook integration.

Create Entity for Shipping Zones

We’ll create an entity “shipping-zone” in order to extract parameter values corresponding to world regions.

Modify “shipping.cost” Intent

We add some examples with shipping zones to the existing “shipping.cost” intent. The “shipping-zone” parameter should automatically appear in the parameter table. Check the ‘Required’ checkbox and add a prompt to choose from 5 shipping zones.

If a user asks a general question about shipment like “Is shipping expensive?”, the agent will request more information, namely, to choose one of the 5 shipping regions in order to answer the user’s specific question.

For more information about required parameters, see the documentation on Slot Filling.

Create a Web Service

Let’s create a web service using a microframework for Python called Flask.

The web service should meet all the requirements described here.

For illustration purposes, our web service example will be very simple. Instead of creating a real database, we’ll simulate one with a Python dictionary that maps the shipping zones to the shipping costs.

cost = {'Europe':100, 'North America':200, 'South America':300, 'Asia':400, 'Africa':500}

How to design the database is entirely up to you. For example, instead of these world regions, you could use country names as a criteria for providing the shipping price information.

Deploy the Web Service

To deploy our web service, we’ll use Heroku. You can use any other service or your own server.

If you want to try it with your agent on Heroku, sign into your Heroku account and click the 'Deploy to Heroku' button here: https://github.com/svet4/shipping-costs-sample.

On the Heroku page that will open, create a name for your app and click 'Deploy for Free'.

Enable Webhook in API.AI

Go to ‘Fulfillment’ from the left side menu in your agent, enable the Webhook integration, insert the link https://[App Name].herokuapp.com/webhook to the URL field, and click ‘Save’.

Go to the “shipping.cost” intent, check ‘Use webhook’ in the ‘Fulfillment’ section, and save the intent.

You can leave a generic response in the ‘Response’ section. It’ll be given if the web service is unavailable or returns errors.

Test Your Agent

Now we can test our agent. Here’s how it can look if you test it via the agent demo page: