Android Chatbot SDK
Overview
The OriChatBot SDK allows you to integrate chatbots into your Android applications. This guide will walk you through the process of importing the SDK and implementing both basic and advanced features.
Table of Contents
Importing the SDK
To use the OriChatBot in your Android project, you need to import the .aar file into your project.
Download OriChatBot SDK from here.
Steps to Import the .aar File:
Add the
.aarFile to Your Project:- Place the
.aarfile in thelibsdirectory of your project. If thelibsdirectory doesn't exist, create it in theappmodule directory.
- Place the
Modify Your
build.gradleFile:- Open the
build.gradlefile of yourappmodule and add the following:
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
implementation(name: 'orichat-debug', ext: 'aar')
}- Open the
Sync Your Project:
- Sync your project with Gradle files to ensure that the SDK is properly imported.
Â
Â
Basic Implementation
Once the SDK is imported, the basic bot can be presented with few lines as below
Import the OriChatBot Class:
Before using OriChatBot, ensure you have imported the class:
import com.oriserve.orichat.OriChatBot;Check OriChatBot Availability:
Before initializing, verify that the OriChatBot is available on the device.
if (OriChatBot.isAvailable()) {
// OriChatBot is available
}Create a New Bot Instance:
Instantiate the OriChatBot to start using it.
OriChatBot bot = new OriChatBot();Set the Bot ID:
Assign the bot’s unique identifier using the setBotId method.
bot.setBotId(botID);Setting botKeys:
botKeysintroduces security overuserDataand SDK communications.botKeysis an object.bot.setBotKeys(botKeys.toString());Launch the Bot:
Finally, launch the bot to start interacting with chatbot.
bot.launchBot();
Complete Integration for Basic Implimentation, for example onCreate method of the Activity:
import com.oriserve.orichat.OriChatBot;
//... other imports
@Override
protected void onCreate(Bundle savedInstanceState) {
if (OriChatBot.isAvailable()) {
OriChatBot bot = new OriChatBot();
bot.setBotId("botId");
bot.setBotKeys(botKeys.toString());
bot.launchBot();
}
}
Â
Â
Advanced Implementation
Set App Details:
Provide details about your application that the bot may require. For example : OS version, or device specific details. appDetails is of type Object.
bot.setAppDetails(appDetails.toString());Setting User Data:
Pass user-specific data to the bot using the setUserData method. userData is of object type.
bot.setUserData(userData.toString());Add Event Listener:
Attach an event listener to handle bot events. This is used to pass event based data to parent app. The data will be received within onEventReceived() method.
bot.addEventListener(new OriChatBot.EventListener() {
@Override
public void onEventReceived(JSONObject data) {
System.out.println("Event Received :-------------------> " + data);
}
});Launch the Bot:
Finally, launch the bot to start interacting with users with complete integration.
import com.oriserve.orichat.OriChatBot;
if (OriChatBot.isAvailable()) {
OriChatBot bot = new OriChatBot();
bot.setUserData(userData.toString());
bot.setBotId(botID);
bot.setAppDetails(appDetails.toString());
bot.setBotKeys(botKeys.toString());
bot.addEventListener(new OriChatBot.EventListener() {
@Override
public void onEventReceived(JSONObject data) {
System.out.println("Event Received :-------------------> " + data);
}
});
bot.launchBot();
}
Â
Dependencies
Following dependencies are used in this chatbot SDK.
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
Â
Permissions
We are declaring and asking for following permissions in our manifest file.
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
Â
Â