Asista Chatbot SDK for Android

Last updated on: May 17th, 2019

About

This SDK is designed to make it as simple as possible to integrate asista chat-bot into your app. Adding the bot to your app will enable your users to interact with your service or your product. The chat-bot can be integrated along with knowledge base and FAQ support to provide more detailed and relevant answers.

The SDK comes packed with a default UI which can be used to load previous conversations and post new messages. Or you can use your own UI and integrate the SDK’s service request functions to make the server API calls.

Getting Started

Importing the SDK in a gradle based project

Add the following Bintray maven repository url to your project’s (root) build.gradle file.

allprojects {
    repositories {
        ....
        maven { url 'https://dl.bintray.com/asista/asista-sdk-android' }
    }
}

Add the following dependencies to your module’s (app)  build.gradle file.

dependencies {
      /* make sure to add this dependency if using the default UI provided in the SDK */
      implementation 'com.android.support:design:27.1.1'
      implementation 'com.squareup.retrofit2:retrofit:2.4.0
      implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
      implementation 'com.squareup.okhttp3:logging-interceptor:3.8.0'
      //dependency for asista-bot
      implementation 'com.asista:asista-bot:1.0.0'
}

Configure a Bot in asista

To begin using the Chatbot SDK, you need to register for a chat bot on the Asista Web portal and get credentials for your app. Someone with administrator access to Asista must do this. You will get an chatbotUrl and chatBotId after the successful registration of the Bot.

To configure a bot, login to asista and in your asista web portal navigate to Settings >Integration> Chat Bot.

Initialize the SDK

The SDK needs to be initialized with two values to function.

  • BotUrl– url of the chat-bot obtained during asista-bot registration.
  • BotId– Id of the chat-bot obtained during asista-bot registration. 

The SDK can be initialized in two ways:

Adding bot properties as string resources

Add values (BotUrl & BotId) as string values in the application’s string resource file (strings.xml).

NOTE: If your project does not have a strings.xml file under project(app) > res > values folder, create a Values resource file and name it ‘strings.xml’, and add the following values.

strings.xml

<resources>
  <string name=”BOT_URL”>{bot_url}</string>
  <string name=”BOT_ID”>{bot_id}</string>
</resources>

NOTE: Make sure to use the same string names

After adding the string resources, from your Application/Activity call AsistaBot.init(Context)(under asista-bot > bot package) to initialze the SDK.

AsistaBot.init(MainActivity.this);        
Initializing using BotProperties (under asista-bot >bot > model package) instance

From your Application/Activity populate an instance of BotProperties with values(BotUrl & BotId).

BotProperties properties = new BotProperties();
properties.setBotUrl(BOT_URL);
properties.setBotId(BOT_ID);

From your application/activity call the AsistaBot.init(BotProperties) method (under asista-bot > bot package)  by passing the populated BotProperties(under asista-bot > bot > model package)instanceas parameter to initialize the SDK.

AsistaBot.init(properties); 

NOTE: Anyone of  the two AsistaBot.init() method needs to be called before using anyother function of the sdk.

Using the SDK

Using the default UI provided in the SDK.

The default UI provided within the SDK will list the previous conversations if any present. And also allows to post new queries to the Bot server.

From your Application/Activity call  AsistaBot.showChatBotUi(Activity) to show the default chat bot UI.

AsistaBot.showChatBotUi(activity); 
Name Type Comment
activity Activity Context of the calling Activity class.


The default chat UI looks like this:

Using the Service request functions from the SDK to make API calls

These Service requests can be used to make server API calls, such as fetching the chat bot configurations, to fetch previous conversations, or to post a new message.

These Service request calls can be made using the BotService class.

To fetch chat bot configuration:
BotService.getInstance().getBotConfig(callback);
Name Type Comment
callback Callback<BotConfig> The callback invoked when the request is either successful or has failed. If the fetch is successful then BotConfiguration will be returned to the onSuccess(Result<BotConfig> result) of the callback, and result.data will return the BotCofig object. If the fetch fails an exception will be returned to the onFailed() of the callback
To fetch previous chats:
BotService.getInstance().getPreviousChats(callback);
Name Type Comment
callback Callback<List<Chat>> The callback invoked when the request is either successful or has failed. If the fetch is successful then list of previous chats(i.e., List<Chat>) will be returned to the onSuccess(Result<List<Chat>> result) of the callback, and result.data will return the chats list. If the fetch fails an exception will be returned to the onFailed() of the callback
To post a message:
BotService.getInstance().postMessage(message, callback); 
Name Type Comment
message String Message(query) to be posted to the bot server.
callback Callback<MessageResponse> The callback invoked when the post is either successful or has failed. If the post is successful then the bot’s response(i.e., MessageResponse)  will be returned to the onSuccess(Result<MessageResponse> result) of the callback, and result.data will return a MessageResponse object which will consist of  the bot’s response. If the fetch fails an exception will be returned to the onFailed() of the callback