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.
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’
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,
Creating a Typeface Object :
Here are the steps to create a Typeface :
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.
ChatBogConfig.getInstance().launchBot(“<request_code_for_callback>” ); |
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.
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
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; }} |