CayBot-19 : Conversational AI Chatbot– Ideation to Execution
Introduction:
Welcome to another blog. This time I am going to talk about very sensitive topic that almost everyone knows. Covid -19, word itself is self-explanatory. Every-one tracking news in and around the world about the latest on Covid-19. And at the same time there were rumors on the Corona-virus pandemic. It is very important that correct and right information should reach to people like what are correct stats, what are symptoms of this disease , precaution against contracting the virus, helpline numbers, affected cases in the region, government advisories (including travel) etc. As a technology consultant, this is our social responsibility to utilize technology to help our society and community. And there is some interesting stuff I am going to talk now, how we can utilize few readily available tools and help society to convey right information. Read till end, I hope everyone like it.
Ideation:
Let me tell you how it started, I was following news on 20th March 2020 and found that WHO has launched WhatsApp Bot (https://www.businessinsider.com/who-launches-whatsapp-chatbot-coronavirus-information-2020-3) to warn people about coronavirus danger. Really Interesting??
I started exploring how we can integrate Whats-app's with such conversational AI Bots.
Source of Data: The First thing I explored is the source of this data. After few minutes of googling, I figured out here is the source of data for Carona-virus live update https://www.arcgis.com/apps/opsdashboard/index.html#/bda7594740fd40299423467b48e9ecf6 maintained by Arcgis.com
Before I talk further, let me talk little but about GIS- Geographical Information system is a framework for gathering, managing and analyzing data. GIS integrates many types of data. And with these capabilities GIS is capable to reveal deeper insights into data such as pattern, relationship etc.
While exploring Live Geographic Information system Covid-19 I did some reverse engineering to find an REST API to get all this data. After few tricks from network Tab - I was able to get all interesting and required data.
https://services1.arcgis.com/0MSEUqKaxRlEPj5g/arcgis/rest/services/ncov_cases/FeatureServer/1/query?f=json&where=(Confirmed%20%3E%200)%20AND%20(Deaths%3E0)%20AND%20(Country_Region=%27INDIA%27)&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=*&orderByFields=Deaths%20desc,Country_Region%20asc,Province_State%20asc&outSR=102100&resultOffset=0&resultRecordCount=250&cacheHint=true
Now Next Step, how to create messaging service and conversational agents that can pull this data and display in WhatsApp. And Then I called my colleagues (actually Peers) and started India’s famous Chai Pe Charcha and started exploring how we can utilize this data and create something for the society. Thanks to both, they agreed and listened me patiently without any question?? and they are also co-author of this Blog
- Parthibarajan Perumal Sekar????
- Ankita Joshi
We all know WhatsApp is one of mostly used messaging app. Now a day’s people not only use it for personal use but also started using for business and social activities. Question kicking in our mind, how to integrate it and does this integration make sense. Then My HDFC mutual fund bot came into my mind??. I use to play with whats-App bot and ask predefined queries and bot answers me. Now after having tea we have
1. Covid-19 Live Source of Data.
2. WhatsApp – Messaging app
Now we started thinking which bot to use, Microsoft AI Bots I already worked used a years ago. This time we want to explore Google cloud platform and here comes entry of Dialog Flow of Google.
Conversational AI Chat Bot: Dialogflow is popular and easy to use conversational agent building platform from Google. It’s web-based platform that can be accessed from any web browser. This tool has earlier called API.AI and evolved over time, it supports both voice as well as text. It enables us to create creational experience by providing pre-defined tools to understand two kind of tasks:
· Understand and generate natural language utterance.
· Manage the conversation.
Setting up DialogFlow is very easy.
1. Create an account with https://dialogflow.com
2. Create basic agents and save it
3. This will take us to a page with intents listing. There are two intents already:
- Default Fallback Intent.
- Default Welcome Intent.
4. And then we added our intents: Intent is what user or bot wants to convey using button presses. And we need intents because there are many ways to ask the same thing. So, the process of identifying intents is to map the many ways to intent.
5. Add the training phrases are the example phrases for what end-users’ type, this is basically for end user expressions. For each intent we create many training phrases. When an end user expression resembles one of these phrases , Dialog flow matches the intent. For example, lets take Latest stats intent, we have created couple of training phrases as referred in below figure.
6. In the Response tab, add the bot’s response to the user. This is the actual utterance that the bot will send to the user. Let’s add the following utterance in the Text Response field. We also can add more responses so that the agent can randomly pick one to make it less repetitive and boring.
Finally, test it using the simulator on the right side of the page. In the Try it now box, type stats and press Enter.
7. Finally, an interesting feature by Dialogue bot is Fulfillment, I love this feature by default our agent responds to a matched agent with a static response and if we are using one of the integration options. We can provide more dynamic responses by using fulfillment which our case is the responses from ArcGIS API. when we enable fulfillment for an intent, dialogue flow responds to that intent by calling a service that we have defined.
In our case we want to check total number of cases in India/any other country. Our Web-hook hit ArcGIS Rest API and collects the data and respond back with total cases of selected country. Important to note here - Each intent has settings to enable fulfillment and if an intent without fulfillment enabled is matched, dialogue flow uses static response we have defined for the intent.
8 Here is short summary how it works:
- End user types an expression (Carona-virus stats for India)
- Dialog Flow matched the end user expression to an intent and extracts parameters
- Dialog Flow sends a web-hook request message to our web-hook service. This message contains information about the matched intent, action , parameter and finally the response defined for the intent.
- Our service performs actions and reads the Covid-19 lives updates from Live Geographic Information system Covid-19
- Our API Service endpoint sends a web-hook response message to Dialogue flow. This message contains the response expected for end users.
"features": [ { "attributes": { "OBJECTID": 163, "Province_State": null, "Country_Region": "India", "Last_Update": 1584812583000, "Lat": 20.5937, "Long_": 78.9629, "Confirmed": 330, "Recovered": 23, "Deaths": 4, "Active": 303, "Admin2": null, "FIPS": null, "Combined_Key": null } }
]
- Dialogue Flow sends the response to end user.
- Finally end user sees the Covid -19 Live data.
Now we have chat bot in place and here comes the important topic, how to integrate all these components and can we make this integration meaningful. Answer I found is Twilio which really helped us to achieve this.
Messaging Platform: Twilio is a cloud communication PaaS component. It allows us to programmaticaly make and receive phone calls, send and receive test messages, and perform other communication function using its web service APIs. We can integrate any web-hook with in Twilio to receive and send data from any other system.
We went through Twilio tutorials and found, it is very easy to use
- Create an account with Twilio https://www.twilio.com/login
- Go to Programmable SMS section and select WhatsApp channel
- Setup your testing sandbox
- Enter any Mobile Number and Twilio will create a sandbox code
- And we are ready. We can setup one-way messaging, two-way messaging.
- Go to Sandbox configuration and configure endpoint URL (my Case it was dialog flow Bot URL)
Finally let's look at technical architecture of all 3 systems:
Since I explained all systems above, now understanding architecture is simple and self-explanatory, isn’t it ??.
WhatsApp User sends request to Twilio. Twilio is a messaging platform that receives a request and pass it to DialogFlow bot through endpoint configured in Twilio sandbox configuration.
Once Dialogue Bot Agent receives the user’s request, it goes to list of pre-defined intents. As created above. Again, let me rephrase intents are created as a way of telling the agent "here is the list of task that user is requesting to chatbot". After Dialogflow maps the user’s request to one of predefined intents, it sends a response back to user.
Dialogue Flow has agents that receives the request and compare it against the intent and pick related response and finally sent back to Twilio and from Twilio it goes to requested user. Twilio is only a messaging platform. Dialogue flow bot are decision makers and decide the response based on the request passed through various intents.
Dialogue flow has the capability to integrate web-hooks and get data from third party API which in our case is ArcGIS APIs that return the latest Covid-19 updates.
And Finally, we are ready with our WhatsApp Chat bot: Twilio has given us sandbox number for testing. We are exploring and under discussion, if we can release this chatbot as help-desk for people of Cayman Islands. Soon we launch it.
Execution: Here are snapshots of our Chat Bot:
We hope everyone enjoyed this. we can use this integration with any social messenger. We can also use voice along with text messaging. Please share your thoughts, comments as questions??. And finally, we wish everyone’s safety.
See you in next blog. Topic will be “Data Literacy as Serviceâ€.
References we followed:
- https://www.arcgis.com/apps/opsdashboard/index.html#/bda7594740fd40299423467b48e9ec
- https://www.twilio.com/console/sms/getting-started/build
- https://cloud.google.com/dialogflow/docs/fulfillment-overview
- https://cloud.google.com/dialogflow/docs/agents-design
- https://developers.google.com/assistant/actions/dialogflow/project-agent
Co-Author
Disclaimer: The views and work presented in this article are our personal views.