If you are using Dialogflow's REST API, these tips can help speed up your development.
Use the Postman app
If you hadn't used it already, Postman calls itself "the complete toolchain of API developers".
For our case, Postman allows you to take the various API calls you see in the Dialogflow documentation and test these requests.
For example, here is a request I created as I was working on the Chatfuel integration tutorial.
But here is the best part. Once you confirm that the request is constructed properly, you can simply use the Code link at the top right and get auto-generated code for the request you just made.
And the Postman app supports many programming languages:
Understand what a Dialogflow session is
When you send a request to the /query endpoint, you need to specify the sessionID.
While I haven't seen a good definition of a session (as it relates to Dialogflow) in the documentation, you can think of HTTP sessions as a reasonable starting point.
But there are a few things you need to know about the Dialogflow sessions. I wrote about this on Dialogflow's old forum:
- I don’t think there is a good, published documentation of best practices
- The sessionID duration depends on the channel (web, FB, Slack etc)
- The Facebook integration seems to change the sessionID somewhat unpredictably midway through a conversation. I don’t know if this is still an issue. See here: SessionId consistency
Understand how contexts work inside a session
Now this is really important.
If your app takes the responsibility of managing the sessionID (as it should), you don't have to worry about managing the context for the conversation. Said another way, as long as you are making sure that you are sending the correct sessionID in each /query request, Dialogflow will automatically do the context management for that particular session.
This point may seem somewhat obvious. But I am not so sure.
Here is a good example of what not to do and how people sometimes get confused:
If you didn't know, there is a chatbot building framework called Chatfuel. And someone wrote a piece of code which integrates Chatfuel and Dialogflow. It was the only solution which was available when I went looking for some sample code, so I need to give this person their due.
However, the solution was created by a Chatfuel expert who doesn't fully understand how contexts work inside Dialogflow's API-managed sessions. By API managed, I mean that the session starts as a result of sending API requests to Dialogflow and further session actions - a technical way of saying that the conversation goes on 🙂 - are performed by sending more API requests.
As a result the solution which is currently doing the rounds cannot work for intents which set and use contexts (the NLP portion will work though).
You can use Dialogflow's REST API and build some powerful stuff.
For example, the SupportBot you see on my site uses the REST API to provide a custom website chat interface which is more feature rich than Dialogflow's own web demo integration.
I have created a little tool which can help people choose a good value for the ML Threshold by using the REST API.
There is plenty of stuff you can build on top of Dialogflow once you learn its REST API. It is important that you learn these concepts (especially 2 and 3) so you can make the most of your REST API integrations.
REST API v2 Course
Nov 2018 update: You might also be interested in my course on REST API v2.
- Dialogflow vs RASA NLU
- Dialogflow vs Lex vs LUIS vs Watson vs Chatfuel
- Machine Learning vs non-Machine Learning algorithm
- BotFlo update
- Learn Dialogflow basics for free (till May 31)
- 10+ practical projects to learn spaCy in depth
- An Epidemiology Glossary for Programmers
- All my mini-courses are free this week
- Reader Question: What if a specific system entity isn’t available in all languages in a multi-lingual bot?
- How much can Machine Learning ACTUALLY help with answering free-form questions?