1. Home
  2. SDKs
  3. Verloop-Client App Integration Android SDK
  • User Guide
  • Developer Docs
Frequently visited sections What is verloop?, FAQ Overview?

Verloop-Client App Integration Android SDK

 GitHub – verloop/android-sdk

Release Candidate 

v1.1.0-rc.1

Migration from an older version

build.gradle inside root directory 

add

apply plugin: ‘kotlin-android’

update gradle version to 4.2.0 or above

classpath ‘com.android.tools.build:gradle:4.2.0’

update google-services version to 4.3.10 or above

classpath ‘com.google.gms:google-services:4.3.10’

build.gradle inside app directory

update compile and target SDK version to 31

compileSdkVersion 31

targetSdkVersion 31

Update firebase messaging dependency

From 

implementation ‘com.google.firebase:firebase-messaging:***’

To

implementation ‘com.google.firebase:firebase-messaging-ktx:23.0.0’

implementation platform(‘com.google.firebase:firebase-bom:29.0.3’)

implementation ‘com.google.firebase:firebase-analytics-ktx’

In your code:

In order to get FCM token, replace 

FirebaseInstanceId.getInstance()

with

FirebaseMessaging.getInstance()

How to install

Add JitPack to your project’s gradle file :

 allprojects {
 repositories {
       ...
       maven { url 'https://jitpack.io' }
     }
 } 

Then add the Verloop’s dependency in your app’s gradle file

 dependencies {
           implementation 'com.github.verloop:android-sdk:1.1.0-rc.1'
 } 

Usage

In your MainActivity (or any of the activities), you need to initialize an object of Verloop class. It accepts a VerloopConfig object as an argument for initializing.

 var verloopConfig = VerloopConfig.Builder()
 .clientId("CLIENT_ID")
 .userId("USER_ID")
 .fcmToken("FCMTOKEN_FOR_DEVICE")
 .recipeId("RECIPE_ID")
 .userName("USER_NAME")
 .userEmail("USER_EMAIL")
 .userPhone("USER_PHONE")
 .department("DEPARTMENT")
 .isStaging(true)
 .fields(customFields)
 .build() 

Params to VerloopConfig

clientId: Required, throws VerloopException if null

useId: Optional, if you don’t have a user ID, simply leave the field and our SDK will take care of it.

fcmToken: Optional, deeded if you want to receive Notifications.

recipeId: Optional, default recipe will run during the conversation unless we do a manual recipe override 

userName: Optional, User property

userPhone: Optional, User property

userPhone: Optional, User property

Department: Optional

isStaging: Optional, for testing env

fields: Optional, custom variables

Custom variables

You can send custom details of a customer with a conversation scope or a global scope.

Custom fields set on the conversation scope will have context associated with only that particular conversation. Once the conversation is over, you can set different values for a new conversation for the same customer. Use the following code to set the value:

verloopConfig.putCustomField("Test Field", "Test Value");

OR

verloopConfig.putCustomField("Test Field", "Test Value", VerloopConfig.Scope.ROOM);

Global scope variables are associated with customers and not with conversation. Something like name, email etc. do not change on different conversations of the same user. To set the value for global scope variables:

verloopConfig.putCustomField("Test Field", "Test Value", VerloopConfig.Scope.USER);

Once config is ready, create Verloop object using the config and start chat

var verloop = Verloop(this, verloopConfig) // `this` here refers to an activity context.
verloop.showChat();

Notifications

Notifications will work only if you have added FCM token at the time of creation of the verloop config object.

Now, to let Verloop handle Notifications, simply add this line in your FirebaseMessagingService class

 @Override
 public void onMessageReceived(RemoteMessage remoteMessage) {
     int icon = R.drawable.notification_image; // set a drawable to use as icon for notifications
     VerloopNotification.showNotification(this, icon, remoteMessage.getData()); // This will be auto-ignored if notification is not from Verloop.
     // Do anything else with your message.
 }
 

Notifications will not be shown in the system tray if chat activity is visible.

Handle Notification click

In your Launcher activity override onNewIntent as given below.

 override fun onNewIntent(intent: Intent?) {
     super.onNewIntent(intent)
     if (intent != null && intent.extras != null) {
         val verloopData = intent.extras?.get("verloop")
         if (verloopData != null) {
             val obj = JSONObject(verloopData.toString())
             if (obj.has("client_id")) clientId = obj.getString("client_id")
             if (obj.has("userId")) userId = obj.getString("userId")
         }
         if (clientId === null) clientId = intent.extras?.get("clientId") as String?
         if (userId === null) userId = intent.extras?.get("userId") as String?
         if (clientId != null) {
             verloop?.showChat()
         }
     }
 }
 

In case you have multiple objects of Verloop class, use the one associated with clientId and userId received with intent data. If required create a new Verloop object with the same configuration

Button click listener

At the time of having the conversation, bot shows a button for faster replies. Button click listeners can be added using:

 verloopConfig.setButtonClickListener(object: LiveChatButtonClickListener {
     override fun buttonClicked(title: String?, type: String?, payload: String?) {
         // Add the app logic for button click
     }
 }) 

URL click listener

If the user clicks on any URL provided by the bot or by the agent, then you can listen to the URL and take the action in the app. Actions can be like re-routing based on the product link etc. URL click listeners can be added using:

 verloopConfig2?.setUrlClickListener(object : LiveChatUrlClickListener {
 override fun urlClicked(url: String?) {
     // Add the app logic for url click
 }
 }, true) 

You can override the default behaviour of URL click by setting the second parameter ‘overrideUrlClick’ to true. By default, it opens the URL in the browser. By adding a ‘urlClickListener’ and setting ‘overrideUrlClick’ true you can override this behaviour to get a callback and handle it yourself.

User session management

When the user logs out of your app, make sure to call

verloop.logout()
Updated on December 27, 2022

Was this article helpful?

Related Articles

Schedule a demo

Get Started with Verloop.io