Native Android
1.1 Open Configure> Deploy section of https://app.engati.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.
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
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’
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,
- bot_key is to be picked up from the Admin portal
- bot_name is the name of the Bot that you intend to display to the users
- Third Parameter is a boolean determining whether the welcome message is displayed or not
- branding_key is set to either default or the branding_key that you would’ve received on White Label setup.
- activity is the appContext which will be used for using shared preference
- 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.
- 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.
- 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.
- 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.
- header_title_font parameter is to set a custom font for Bot Header Title. It should be of type TYPEFACE.
- header_description_font parameter is to set a custom font for Bot Header Description. It should be of type TYPEFACE.
- send_button_drawable parameter is to set custom drawable to Bot send button. It should be of type Integer
- send_button_bitmap_drawable parameter is to set a custom bitmap drawable to Bot send button. It should be of type Integer (optional)
If you want to pass attributes pertinent to user from the application, use the below launch bot code instead of the one mentioned above
and create one UserAttrs data class
In the above replace the following under 'UserAttrs'
- "attr1" - Name of the attribute that will be created,
- "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
Creating a Typeface Object :
Here are the steps to create a Typeface :
- Add font.ttf to assets folderYou need to add the <font.ttf> file in your asset folder.
- 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 :
- 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.
- 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
- 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; }} |
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