Native Android

Native Android

1. Getting Started

1.1 Open ​Configure> Deploy ​section of​​ https://app.elitbuzz.com/

1.2 Click on the ​Website​​ Chatbot​ tab, where you will get to see ​the Widget Script ​ script.

Initialization script will be like following:

<script>EngtChat.init({“bot_key”: “<bot_key>”, “e”:”p”,”welcome_msg”:true,”branding_key”:”<branding_key>” });</script>

Note down ​’bot_key​’ and ​’branding_key’​ from the widget script. You can find the <bot name > in the Configure> Bot Details tab of the portal. 

2. Gradle Configuration

To get a Git project into your build

Step 1: Add the JitPack repository to your build file. Add it in your root build.gradle at the end of repositories,

allprojects {    repositories {      …        maven {            url ‘https://jitpack.io’ 

Step 2: Add the dependency

dependencies {    implementation ‘com.gitlab.elitbuzz.shared-microservices:android-chatbot-base:1.5.3’}

For accessing latest version for ENChatBot please refer https://jitpack.io/private#com.gitlab.elitbuzz.shared-microservices/android-chatbot-base

Note: If your project uses glide library then make sure to use glide version 4.9.0 or above

e.g. implementation ‘com.github.bumptech.glide:glide:4.11.0’

3. Initializing and launching the bot

After importing the dependency, initialize it in your applications from where you want to launch the Bot. Initializing with example settings will look as follows:

import com.en.botsdk.ui.ChatBotConfig

ChatBotConfig.getInstance().init (“<bot_key>“, “<bot_name>“,true,”<branding_key>“, <activity>,”<bot_user_id>“,”<bot_chat_history>“, <show_done>,”<language_alignment>,”<header_title_font>“,”<header_description_font>“,<send_button_drawable>,<send_button_bitmap_drawable>);

ChatBotConfig.getInstance().launchBot(“<​request_code_for_callback>”​ );

where,

  1. bot_key is to be picked up from the Admin portal
  2. bot_name is the name of the Bot that you intend to display to the users
  3. Third Parameter is a boolean determining whether the welcome message is displayed or not
  4. branding_key is set to either default or the branding_key that you would’ve received on White Label setup.
  5. activity is the appContext which will be used for using shared preference
  6. bot_user_id is an unique identifier for the user. While building an app, you can anything unique to identify a user uniquely based on your business usecase.
  7. bot_chat_history is the chat history limit which the user can set to maintain a chat history up to the mentioned limit in the app.
  8. show_done parameter when set to true enables the done button for a callback from the bot to the user app and disables the button when set to false.
  9. language_alignment parameter is to choose the alignment of the text while conversing between the bot and the user (LTR or RTL). Possible values are LanguageAlignment.DEFAULT, LanguageAlignment.RTL.
  10. header_title_font parameter is to set a custom font for Bot Header Title. It should be of type ​TYPEFACE​.
  11. header_description_font parameter is to set a custom font for Bot Header Description. It should be of type ​TYPEFACE​.
  12. send_button_drawable parameter is to set custom drawable to Bot send button. It should be of type ​Integer​
  13. send_button_bitmap_drawable parameter is to set a custom bitmap drawable to Bot send button. It should be of type ​Integer​ (optional)

Creating a Typeface Object​ :

Here are the steps to create a Typeface :

  1. Add font.ttf to assets folderYou need to add the <font.ttf> file in your asset folder.
  2. Create Typeface from Assets : 
Typeface typeface = Typeface.​createFromAsset(​ getAssets(),​“<font.ttf>”​);

where, <font.ttf> refers to the font folder in your asset folder in your app.

In order to launch the bot activity to start the chat with the bot you just need to launch the ChatActivity after the bot initialization.

  • For normal (full screen) window ​:
ChatBogConfig.getInstance().launchBot(“<​request_code_for_callback>”​ );
  • For pop-up windows​ :
  1. You need to create a Blank Activity which would hold the Bot Fragment. Please see the sample code for more information :
startActivityForResult(new Intent(this,<your_custom_activity>.class),“<​request_code_for_callback>”);

where,

your_custom_activity​ : The first parameter refers to the Activity in which you will inflate the Bot Fragment

request_code_for_callback: To be entered by the user for starting bot and getting a callback respectively.

  1. Inside Activity you need to write the following line of code to open bot:

import com.en.botsdk.ui.ChatFragment;

ChatBotConfig.getInstance().init (“<bot_key>“, “<bot_name>“,true,”<branding_key>“, <activity>,”<bot_user_id>“,”<bot_chat_history>“, <show_done>,”<language_alignment>,”<header_title_font>“,”<header_description_font>“,<send_button_drawable>,<send_button_bitmap_drawable>);
getSupportFragmentManager().beginTransaction().add(R.id.frame_container, new ChatFragment()).commit();

where,

frame_container : First parameter refers to ​Parent layout​ Id of your Blank Activity

ChatFragment : Second parameter refers to the ​BotFragment ​which you need to inflate

  1. Add “​botTheme”​ style to your custom made activity.

              Done button callback:

You will receive a callback in your activity’s overridden method “onActivityResult”

It will be like:

@Overrideprotected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {  super.onActivityResult(requestCode, resultCode, data);  if (resultCode == RESULT_OK) {      if (request_code_for_callback == REQUEST_CODE_CALLBACK) {        if (data != null){            ChatResult result = (ChatResult)          data.getSerializableExtra(“RESULT_DATA”);            Toast.makeText(this, result.getExitUrl(), Toast.LENGTH_SHORT).show();        }      }  }}

            where,

                    REQUEST_CODE_CALLBACK is the constant that you pass in the launchBot() function.

The data we receive will have a specific pattern model :

public class ChatResult implements Serializable {  private String exitUrl;  public String getExitUrl() {      return exitUrl;  }  public void setExitUrl(String exitUrl) {      this.exitUrl = exitUrl;  }}