Asista Chatbot SDK for Android
Last updated on: May 17th, 2019
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:
1. Adding bot properties as string resources:
Add values (BotUrl & BotId) as string values in the application’s string resource file (strings.xml).
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.
2. 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);
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.
Name | Type | Comment |
---|---|---|
activity | Activity | Context of the calling Activity class. |
The default chat UI looks like this:
Default Chat UI
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 |
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 |
To fetch previous chats
BotService.getInstance().getPreviousChats(callback);
Name | Type | Comment |
---|---|---|
callback | Callback<List |
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 |
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 |
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 |