paint-brush
Build Android Chatbot with Dialogflow (API.ai)by@devashish_m
12,637 reads
12,637 reads

Build Android Chatbot with Dialogflow (API.ai)

by Devashish Datt MamgainNovember 27th, 2018
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

In this article, we will be sharing steps to integrate <a href="https://dialogflow.com/" target="_blank">dialogflow</a> chatbot into your <a href="https://hackernoon.com/tagged/android" target="_blank">Android</a> app. All you need to build a sample <a href="https://hackernoon.com/tagged/chatbot" target="_blank">chatbot</a> for an android app is <a href="https://dialogflow.com/" target="_blank">Dialogflow</a> and <a href="https://www.kommunicate.io/" target="_blank">Kommunicate.</a>

Company Mentioned

Mention Thumbnail
featured image - Build Android Chatbot with Dialogflow (API.ai)
Devashish Datt Mamgain HackerNoon profile picture

In this article, we will be sharing steps to integrate dialogflow chatbot into your Android app. All you need to build a sample chatbot for an android app is Dialogflow and Kommunicate.

Below is an example of Kommunicate Support Bot developed in android using Dialogflow. We actually use this bot on our website. If you wish to see the bot live in action, head here.

The actionable rich messaging powered bot can reply based on whether users are on chat for general queries, technical queries or scheduling a demo.

You can use your existing dialogflow bot or checkout bot samples to build a qualifying bot of your own. Download the Kommunicate Support Bot from here and import into your Dialogflow account.

Step 1: Setup an account in Kommunicate

This is fairly simple. You can get a free account in Kommunicate. Signup and navigate to the Bot section. Click on Settings in Dialogflow block.

Upload your Dialogflow provided client keys. In case you are using Dialogflow V1, you can copy paste your client and dev tokens. Though, we recommend using Dialogflow V2 for the latest capabilities.

Step 2: Install Dialogflow integrated Android Chatbot SDK into your app

Add Android SDK to your app

Installing Kommunicate in your Android app is easy and fast. Kommunicate SDK comes with pre-configured dialogflow integration.


InstallationAdd the following in your app build.gradle dependency:

implementation 'io.kommunicate:kommunicate:1.6.3'


**Initialize SDK**After the Gradle sync has finished with kommunicate dependency, you can initialize the SDK by calling the below method:

Kommunicate.init(context, Your-APP-Key);


You can get the Application Key by signing up on Kommunicate Dashboard.For full documentation, refer here.

Sample Android app with Dialogflow Chatbot

Here is a sample android app which has dialogflow chatbot integrated. Download and run it in android studio.

Step 3: Launch Android chat app with Dialogflow integrated chatbot


Now, you can send payload to dialogflow through chat screen and get text response from Dialogflow Agent.Kommunicate provides a ready to use Chat UI so only launching the chat screen is required in this step.

Here are the instructions for launching the chat with Dialogflow bot:


List<String> agentList = new ArrayList();agentList.add("[email protected]"); //add your agentID


List<String> botList = new ArrayList();botList.add("bot1"); //enter your integrated bot Ids





Kommunicate.launchSingleChat(context, "Support", Kommunicate.getVisitor(), false, true, agentList, botList, new KmCallback(){@Overridepublic void onSuccess(Object message) {Log.d(context, "ChatLaunch", "Success : " + message);}





@Overridepublic void onFailure(Object error) {Log.d(context, "ChatLaunch", "Failure : " + error);}});

That’s all! Run the Android app and chat with the Dialogflow bot. You can easily integrate Dialogflow in Android apps in a few simple steps. In case you need more information, you can check out the Kommunicate documentation.

Dialogflow Android SDK


Dialogflow provides Android Client SDK that makes it easy to integrate speech recognition with API.AI natural language processing API on Android devices. If you are looking to develop your own chat implementation and directly integrate dialogflow into your android app without kommunicate SDK, then integrate with the following SDK.Github — Dialogflow Android Client SDK

Read more about dialogflow and bot integration here:

  1. Integrate Dialogflow (Api.ai) Bot into Website
  2. Beginner’s Guide to Creating Chatbots Using Dialogflow

This article is originally published here.