Making Chatbot a best companion for your Android app

Asmita Wakchaure
4 min readMay 30, 2020

--

It is correctly said, “any sufficiently advanced technology is indistinguishable from magic”. With the advancement in technology, currently the life around us is not less than something which seemed just like magic centuries ago. Invention of Chatbot enabled proactive human interaction hence discarding the constraint of serving limited number of clients at same time by humans.

Moreover, an add on to this is introduction of Dialog flow which is an conversational user interface powered by Google’s machine learning. Chatbot by Dialog being user-friendly and intuitive, implementing a customized Chatbot in your application gives a whole new dimension for your users to interact with your product.

Dialogflow have made it possible to easily integrate customized Chatbot in our application making our app more interactive and user-friendly. With few simple steps mention in this article Chatbot can be easily implemented in your Android application hence making your application more fulfilling, reliable and interactive.

Initially, we need to setup the initial configuration on Dialog flow console by creating a fresh account for your project. For understanding purpose, I have created a Google I/O Event Planner Chatbot which shall further provided all the details to the user regarding the event.

Client Access token setup

To begin with the configuration, we need to start with enabling the service account and hence generating the Client Access token which we shall further use for integrating Android Client library. As shown in the image above enable the Service account and note down the Client Access token.

Before starting the implementation we need to understand few basic terms of Dialogflow such as an Agent. Nomenclature for a Chatbot in Dialogflow is an Agent. The more we train our agent the more it becomes intelligent enough using the information we provided while training. Once we have created an agent you can see the Dashboard on Dialogflow console as shown above which is further bifurcated into different components like Intents. Intent being an major aspect for our agent since the basic business idea of our app would be cut down into different intents. For now our basic business idea is Event which further got cut down into Intents as Event Agenda, Event Time, Event Venue.

Firstly, create an Intent as per your business requirement. Insert the training phrases which are most likely queries your end user might ask to the bot regarding that portion of your application.

Query based bot response

As you see in the image below where we have added a bot response based on our query under Event Venue Intent. Once we add all the Intents, training phrases and Text responses we can immediately test if our bot works according to the training phrases and responses added in those specific Intents.

Now, when we have added the Intents, we can Try it out the functioning of our agent in the given right section of Dialogflow console. As you see in the image above when a query is generated regarding Event venue the agent have responded with the text response we have provided in for Event venue intent.

Once the basic configuration setup have been done we can proceed with the code setup need in Android Studio. Initially, you need to sync your project with api libraries as shown in the image below

api dependencies

After the adding the api dependency files and syncing the project we need to add the Client access token which we have noted from Dialogflow console.

Client Access Token

All the communication here with the bot are handled in asynchronous manner. For this we have used Async task where all the request from the user is send to the bot and the each of the request and response have been captured and presented accordingly.

Asynchronously handling the response

Once the code setup is completed you can similarly retest the functionality of bot in your application and expected behavior of the bot is similar to the one which we tested on the console.

Final app output

As per shown in the image above you can create similar chat window UI and manage the user query and bot response accordingly. In this way we can easily integrate chatbot using Dialog flow in our Android app hence making our app more effective and interactive.

--

--