Skip to main content

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

  1. Importing the SDK
  2. Basic Implementation
  3. Advanced Implementation
  4. Dependencies
  5. Permissions

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:

  1. Add the .aar File to Your Project:

    • Place the .aar file in the libs directory of your project. If the libs directory doesn't exist, create it in the app module directory.
  2. Modify Your build.gradle File:

    • Open the build.gradle file of your app module and add the following:
    repositories {
    flatDir {
    dirs 'libs'
    }
    }

    dependencies {
    implementation(name: 'orichat-debug', ext: 'aar')
    }

  3. 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

  1. Import the OriChatBot Class:

    Before using OriChatBot, ensure you have imported the class:

    import com.oriserve.orichat.OriChatBot;
  2. Check OriChatBot Availability:

    Before initializing, verify that the OriChatBot is available on the device.

        if (OriChatBot.isAvailable()) {
    // OriChatBot is available
    }
  3. Create a New Bot Instance:

    Instantiate the OriChatBot to start using it.

    OriChatBot bot = new OriChatBot();
  4. Set the Bot ID:

    Assign the bot’s unique identifier using the setBotId method.

    bot.setBotId(botID);
  5. Setting botKeys:

    botKeys introduces security over userData and SDK communications. botKeys is an object.

    bot.setBotKeys(botKeys.toString());

  6. 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

  1. 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());

  2. Setting User Data:

    Pass user-specific data to the bot using the setUserData method. userData is of object type.

    bot.setUserData(userData.toString());
  3. 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);
    }
    });
  4. 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" />

 

Â