---
title: Native Android
slug: native-android
docTags: 
createdAt: 2022-05-11T08:40:11.000Z
---

## <font color="#ae1536">1. Getting Started</font>

1.1 Open ​Configure> Deploy ​section of​​ https\://app.engati.ai/

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. 

## <font color="#ae1536">2. Gradle Configuration</font>

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.engati.gitlab.engati.shared-microservices\:android-chatbot-base:1.5.8’} |
| -------------------------------------------------------------------------------------------------------------- |

For accessing latest version for ENChatBot please refer[ https://jitpack.io/private#com.gitlab.engati.shared-microservices/android-chatbot-base](https://jitpack.io/private#com.gitlab.engati.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’

## <font color="#ae1536">3. Initializing and launching the bot</font>

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)

### Optional: If you want to pass attributes from the application to chatbot

If you want to pass attributes pertinent to user from the application, use the below launch bot code instead of the one mentioned above

:::BlockQuote
val userAttr: ArrayList\<UserAttrs> = ArrayList\<UserAttrs>()
&#x20;           userAttr.add(UserAttrs("attr1", "value 1"))
&#x20;           userAttr.add(UserAttrs("attr2", "value 2"))
&#x20;           ChatBotConfig.getInstance().setDataAttributes(userAttr)
ChatBotConfig.getInstance().launchBot()
:::

and create one UserAttrs data class

:::BlockQuote
data class UserAttrs(val name: String, val value: String)
:::

In the above replace the following under 'UserAttrs'

- "attr1" - Name of the attribute that will be created,&#x20;
- "value 1" - Value of the same attribute

In a similar manner, multiple attributes can be created and the used in the chatbot flow for automation and personalization in [paths](https://help.engati.ai/conversation-flow-paths)

## <font color="#ae1536">4. Additional Customizations</font>

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;  }}  |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

 

### Sample Demo App

Please find below link for demo app for chat sdk:

https\://branding-resources.s3.ap-south-1.amazonaws.com/default/android-sdk-app/EngatiFreshTest.zip

