If you are building complex integrations for Dialogflow, odds are you need to build custom Dialogflow middleware.
Custom Dialogflow middleware
Let us first understand what I mean by custom Dialogflow middleware.
What is custom Dialogflow middleware?
Here is an example of what I mean. The 1-click web demo integration of Dialogflow doesn’t support a lot of stuff. So you can build your own custom Dialogflow middleware to get around this. This is what the middleware does in this particular use case:
- take the user’s message
- relay the message to Dialogflow using the REST API
- get the response from Dialogflow’s REST API
- process the response to provide the appropriate result
Here is a little flow diagram explaining this:
As an example, you can write Markdown directly into the Text response field of Dialogflow. Your middleware will contain a markdown parser which will convert the Markdown into HTML (thus helping your website chatbot support things like clickable hyperlinks).
Benefits of custom Dialogflow middleware
A while back, I wrote an article about creating your own Chatbase alternative. In hindsight, the article was a little unfocussed and scattered, although some readers sent me feedback which told me they understood what I was trying to say.
I wrote another article a bit more recently where I point out why you almost always need to write a custom integration. Many of my clients who have built complex chatbots using Dialogflow have needed to build them.
In those articles, I mention the benefit of creating such custom integrations.
You need to understand the REST API to create middleware
If you wish to create Dialogflow middleware, you need to develop a good understanding of Dialogflow’s REST API.
Other reasons why you need to master Dialogflow’s REST API
Learning about and mastering Dialogflow’s REST API will be very useful for you in many situations, and I think it is going to only become more important moving forward.
Custom website chatbot
This is a specific example of custom Dialogflow middleware. If you wish to create a rich website chatbot, you need to get a good understanding of how Dialogflow’s REST API works.
Long running webhooks
Similarly, suppose you wish to move your webhook out of Dialogflow because it takes too much time to execute, again you need a good understanding of the REST API.
Build your own conversation analytics
If you would like to build out your own Chatbase alternative so you can monitor and analyze the conversations in ways that Chatbase doesn’t yet allow, it is useful to build a custom integration and save all the request-response pairs as part of the relay process.
Automated conversation testing
There isn’t yet a tool to do automated conversation testing in Dialogflow, although I am seriously considering building one. (Would you be interested? Leave a comment below).
You can create your own tool using the REST API.
Automated Dialogflow training
This is quite a complex task, but in theory you can do this by using the REST API and coming up with your own annotation syntax for the training phrases.
Automated Bot Generators
If you follow the general principles I talk about in this website, it is actually possible to automatically generate certain kinds of simple chatbots by first specifying them in a spreadsheet file. The REST API will be a part of this automation process.
Training phrase analytics and reverse engineering intent mapping
You can even study your agent in great detail and reverse engineer the intent mapping process for your Dialogflow agent by using a tool such as NLTK, and dissecting the intent mapping which is already happening in your agent. Again, the REST API will be required for this.
You can also use the REST API to build out a little mini-CMS for your Dialogflow agent. For example, you can save the JSON corresponding to common Facebook quick replies (e.g. Yes/ No/ Maybe choice for a question), and use the REST API to automatically populate these standard responses into a set of selected intents.
This website contains affiliate links. See the disclosure page for more details.
"The magic key I needed as a non-programmer" The custom payload generator was the magic key I needed (as a non-programmer) to build a good demo with rich responses in DialogFlow Messenger. I've only used it for 30 minutes and am thrilled. I've spent hours trying to figure out some of the intricacies of DialogFlow on my own. Over and over, I kept coming back to Aravind's tutorials available on-line. I trust the other functionalities I learn to use in the app will save me additional time and heartburn. - Kathleen R Cofounder, gathrHealth