So... what can you do when there is a quarantine and you have to spend all day at home and all of the sudden you now have extra time after work? You learn to build chatbots to talk to your Google Mini!
It's been a while since I had time to work on a personal project, but when I had to decide between reading sensationalist news and spending my evenings on Netflix, I thought that maybe...this was the perfect time to finally get to learn a little bit about DialogFlow and Google Actions...
I got a Google Mini for 35 Euro over a year ago and I have to say this has been one of the best gadgets I have got over years of buying random stuff. I would be exaggerating if I say I have become dependent on it but I would definitely miss it if I did not have it. I use my Google Mini on a daily basis for getting the news, the weather forecast, starting my favourite podcasts, controlling Netflix with my voice, playings games, hearing random jokes and facts and more often that I'd like...to find my phone.
Being someone who until recently used public transport almost on a daily basis and often have to spend over 15 minutes waiting for the next bus, I thought it would be very nice if my Google Mini could let me know my bus is coming while I am getting ready or by simply asking her a question ...yes, is a she ;) This is where Google DialogFlow and the Google Assistant come into play!
Dialogflow is a service by Google under their AI and Machine learning umbrella designed to provide conversational interfaces for a variety of applications and devices ranging from mobile phones and websites to IoT gadgets such as the Google Home. The beauty of DialogFlow is that allows people without any knowledge of machine learning to build modern and human-like interfaces, that are capable to understand human language and transform the information into input that can be given to any application that exposes a web service. DialogFlow applications can be invoked as Google Actions from the Google assistant either by human interaction or by including them as part of a Routine.
DialogFlow allows you to configure "Intents" which map what the user says to a specific action and response, the responses can be static text responses specified by you or invocations (Fulfillments) to a web service, which will then do something with the information given and provide a response back. Understanding these basic concepts and going back to my "when is my bus coming" use case I realized I needed the following:
- A dialogflow application, consisting of the "Intent" of knowing when a bus is
coming to a particular bus stop.
- The source of this information, for this purpose, since I could not find a
documented API, I would need to do the dirty job of scraping the Transport For
Ireland site (rtpi.ie)
- A web service that would do the scraping and would interface with my Dialogflow
application. This web service will be called by my Fulfillment.
- Any device than can run the Google Assistant...
Here is what my architecture ended up looking like:
The configuration above along with a bit of Python code (Dublin On Time Service) allow me to call my application directly from my phone and from my Google Mini (see below).
In the example above I configured a routine in my google assistant to call my "Dublin On Time" app with the parameter of my local bus stop, this was as simple as configuring "When is my bus coming 7294", I mapped this command to the routine "When is my bus coming", but I can also start the agent by saying "Hey Google, can I talk to Dublin on Time?" which would lead to the app asking me which bus stop I am interested in. As you can see, with DialogFlow is now easy to build human-friendly applications that can be initiated from any device, at any time.