Recently, Dialogflow revamped their documentation quite significantly. In the process, there has been a clear move towards favoring the Google Cloud over Heroku. This is understandable, considering Google acquired Dialogflow recently. 😉
In the process though, the Dialogflow developer community is now required to go through a much more challenging initiation to webhooks, and I had this view confirmed by a few private online conversations too. Earlier, the webhook sample had a one-click deploy to the Heroku cloud, and you could get the example up and running in practically no time.
So, I have decided to retrace the old steps, combine it with the online resources that I could find, and tried to somewhat simplify the process for folks trying to get started with webhooks. This is possible because Heroku is much more "prototype" friendly when compared to the Google Cloud, which makes it particularly well suited for hobbyist developers who are just dabbling in Dialogflow to evaluate its capabilities.
So here is the step by step process for deploying a Dialogflow webhook on Heroku.
Sign up for Heroku
As you know, you can sign up for free. Once you sign up, log in to Heroku.
The logged in view looks something like this.
Click to deploy from GitHub while logged in
Go to this URL:
Click on the big "Deploy to Heroku" button.
Complete deployment from inside Heroku
Click on the Deploy button. Once you click it, Heroku will create a new project for you by running some scripts and will complete the deployment and show you a success message like below.
Copy the webhook URL
Click on the View button. You should see an error message. Don't worry about the error message, it is expected.
Copy the URL in the browser bar.
Prepare your Dialogflow agent
If you haven't done so already, create a new agent inside Dialogflow.
Provide Fulfillment info
The fulfillment tab is where you paste your webhook URL.
When pasting, make sure to append the word webhook, and check that the URL looks like below:
Remember to Save your new information using the Save button at the top.
Create the Dialogflow Intent
Create an intent called weather. Declare the userSays phrases as shown.
Important: Make sure the action is set to yahooWeatherForecast as shown below.
Be sure to use webhook fulfillment in the intent
Scroll down to the bottom of the "weather" intent you created, and fill out the Default Response and more importantly, check the Use Webhook for fulfillment.
Also note the Default response: turns out, the Heroku app can go to sleep after 30 minutes of inactivity. In general, your webhook could fail to respond for many different reasons. So make sure you have some kind of "Service unavailable" message when you use webhooks.
Test in your console
When you type the following (as an example):
weather in Boston
you should get the following back. (If you get service unavailable, just type it in one more time).
So with that, you are now ready to start using webhooks in Dialogflow.
Here is a demo video which also covers mostly what I have shown here.
Migrating webhook code to API v2
I have created a mini-course which explains how you can migrate your Python webhook code from v1 to v2 API.
- Using Collect.chat for preNLU bots
- Reader Question: How to get some sample training data for Dialogflow?
- Getting the top 3 (or top N) intents in Dialogflow: An experiment
- Dialogflow Regexp (regular expression) entity
- Using Dialogflow for educational bots
- Chatbot makes $3 million in sales in 1 hour
- Reader Question: Intent based FAQ bots vs knowledge based FAQ bots
- Should you use Dialogflow from scratch?
- 3 ways Airtable can speed up your Dialogflow prototype development
- Automatically generating a rich Dialogflow website chatbot