Integrate with Android app


To integrate floatbot sdk in android app first download floatbot aar file from here

Sdk has only 1 fragment which can be placed in any activity

Your Activity must implement OnFloatbotInteractionListener interface and override its method onChatWindowClosed


public class SampleActivity extends AppCompatActivity implements FloatbotFragment.OnFloatbotInteractionListener{ 
.... 

  //Called when user click on closebutton from chatwindow 

  @Override 

  public void onChatWindowClosed() { 

    finish(); 

  } 

} 

To initialize SDK, we need to pass below parameters in fragment


 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); 
flb =  new FloatbotFragment(this); 
Bundle bundle = new Bundle(); 
bundle.putString("bot_id","BOT-ID"); 
bundle.putString("key","BOT-TOKEN");

To get your key and bot_id, Login to https://floatbot.ai/console

Note: Please change URL accordingly, if your setup is on-premises or on private cloud, Example: https://domain/console

Once you are logged in, please click on Bot API Keys under Developers Section Select Bot ID and Secret Key against your Bot Name and Key Name Android security token

To hide header from chat window, simply pass showHeader value as false. By default, value will be true

bundle.putBoolean("showHeader",false);

To show list of sessions to user. You can call showSessions() method of fragment class

flb.showSessions();

To use login architecture in your app., Create a Json string and pass encrypted data in bundle Encryption method - 'AES CBC 256'

bundle.putString("data",AES-CBC-256 Encrypted Json String);

You can set attributes by encrypting them in Json string (data bundle) Or to set attributes directly from SDK

FloatbotAttributes attributes = new FloatbotAttributes(); 
try { 

    attributes.addAttributes("name","user-name"); 

    bundle.putString("attributes",attributes.value()); 

} catch (Exception e) { 

}

To register for push notification, you need to pass gcm/fcm token in bundle as below

bundle.putString("push_token","GCM/FCM TOKEN");

You can also update fcm/gcm token later by calling below function

FloatbotUtils.updatePushToken("GCM/FCM TOKEN"); 

For push notification, you will need to handle json string in onMessageReceived

@Override
public void onMessageReceived(RemoteMessage message) {
  Log.e("fcm-message",message.getData().toString());
  //Create notification	
}

You can also set your own loading screen/no connection (layout), which will be shown when chatbot is loading or when there is no internet access

FloatbotUtils.setLoadingView(this,R.layout.connecting);
FloatbotUtils.setNoInternetConnectionView(this,R.layout.nointernet);

If you have enabled mic in chatbot. You need to handle Microphone permission in activity before loading fragment

NOTE: Currently as of now attachment item is not supported in android floatbot sdk

To Delete user/Clear/Logout from Floatbot app

FloatbotUtils.clearUserData(this);

From Sdk version 2.2 You can handle callback URL in android app Just implement onCallback() method from OnFloatbotInteractionListener interface in your main activity

@Override 

    public void onCallback(Uri uri) { 

        Log.e("callback",uri.toString()); 

        //finish(); 

    }

From SDK version 2.3, you can pass one more parameter in bundle It will create new session every time when value is set to true (Default value is false)

bundle.putBoolean("create_new_session",true);

From SDK version 3.2, you can set/change chatbot domain in SDK It is used to point to that domain [use these settings for on-premises or private cloud setup or public cloud with different region] (Default value is https://floatbot.ai)

bundle.putString("domain","https://floatbot.ai");

Please refer to the video below to get know how to get BOT ID and Token.

NOTE: If you encounter any issues, please feel free to contact us at connect@floatbot.ai