Kustomer Chat SDKs

The Kustomer Chat SDK is available for Android, iOS, and web

Migrate from Chat 1.0

Learn how to migrate to the Kustomer Chat 2.0 Android SDK from Chat 1.0.

This guide explains the key changes your team needs to make to migrate to the Kustomer Chat 2.0 (and later) Android SDKs from earlier SDK versions.

We've listed the Android SDK API calls you'll need to update for the migration below. Each entry provides brief descriptions and examples of the changes.

Initialize and open chat

To learn more, see Installation and Open the Chat UI.

From Chat 1.0

// Initialize the Kustomer Android SDK with an API key, and start a user session.
Kustomer.init(this, K_KUSTOMER_API_KEY);

// Present new or recent chat conversation if there is any.
Kustomer.showSupport(ACTIVITY);

To Chat 2.0

// Init will throw AssertionException if the API Key used is invalid or has more than the required permissions
Kustomer.init(application = this, apiKey = apiKey) {
                    //Callback block
            Log.i(TAG,"Kustomer is initialized ${it.dataOrNull}")
        }

Kustomer.getInstance().open()

Override chat settings within the SDK

To learn more, see Initialize Chat Android SDK with options
.

From Chat 1.0

KUSChatAttributes chatAttributes = new KUSChatAttributes();

    // Initial message to start a new conversation
    // if not specified then it will show either the most recent session or new window to start a new conversation
    chatAttributes.put(Kustomer.KUS_MESSAGE,"MESSAGE");

    // Custom schedule id, if not specified then SDK will use the schedule id specified on the admin panel
    // This can be access by an admin panel via Administration > Business Schedules
    chatAttributes.put(Kustomer.KUS_SCHEDULE_ID,"SCHEDULE_ID");

    // Custom form id, if not specified then SDK will use the conversational assistant form specified on the admin panel
    // This can be access be an admin panel via Channels > Chat > Conversational Assistant
    chatAttributes.put(Kustomer.KUS_FORM_ID,"FORM_ID");

    // Attach custom attributes to the user's next new conversation
    // These key-value pairs must be enabled on the Conversation Klass via the admin portal.
    // This can be done by an admin via Settings > Platform Settings > Klasses > Conversation
    JSONObject customObject = new JSONObject();
    customObject.put("customAttributeStr", "value");

    chatAttributes.put(Kustomer.KUS_CUSTOM_ATTRIBUTES, customObject);

    // Option to provide latest emoji support to older devices
    // if not specified then SDK will provide support by default.
    // You can choose to disable it by providing false as the value
    chatAttributes.put(Kustomer.KUS_EMOJI_COMPACT_SUPPORTED,true|false);

// Present new chat conversation with chatAttributes a.k.a Key-Pair value options -
Kustomer.showSupport(ACTIVITY,chatAttributes);


/*
 Show/Hide the "New Conversation" button in closed chat. By default, "Start New Conversation" button will appear in closed chat listing. You can update the settings by this method.
*/
Kustomer.hideNewConversationButtonInClosedChat(true);

To Chat 2.0

val options = KustomerOptions.Builder()  
            .setChatAssistantId("CUSTOM_ASSISTANT_ID")
            .setBusinessScheduleId("CUSTOM_BUSINESS_SCHEDULE")
            .setKnowledgeBaseId("CUSTOM_KB_ID")
            .setUserLocale(Locale)
            .hideNewConversationButtonInClosedChat(true | false)
            .setLogLevel(KusLogOptions.KusLogOptionErrors)
                    
  
//Pass KustomerOptions in `init`
Kustomer.init(application = this, apiKey = apiKey, options = options.build()) {
            Log.i(TAG,"Kustomer is initialized ${it.dataOrNull}")
        }
  • Use Override Business Schedule id to set the schedule id after Kustomer.init().

  • To start a new conversation with an initial message use the following:

Kustomer.getInstance().openNewConversation(message: "Custom Message"){}

Identify a customer

To learn more, see Authentication.

From Chat 1.0

// Securely identify a customer. Requires a valid JSON Web Token.
Kustomer.identify("SECURE_ID_HASH", new KUSIdentifyListener() {
  @Override
  public void onComplete(final boolean success) {
      // Note: This will be called on background thread
  }
});

To Chat 2.0

// This is a suspend function
suspend Kustomer.getInstance().logIn(jwt) : KusResult<KusIdentifiedCustomer>

// or

Kustomer.getInstance().logIn(jwt){
            when (it) {
                is KusResult.Success -> it.data
                is KusResult.Error -> it.exception.localizedMessage
            }
        }

Log out a customer

To learn more, see Log out.

From Chat 1.0

// Resets the user session, clearing the user's access to any existing chats from the device.
Kustomer.resetTracking();

To Chat 2.0

Kustomer.getInstance().logOut()

Describe a customer

To learn more, see Describe Customer.

From Chat 1.0

/*
 Attach custom attributes to the user

 NOTE:
 Attached key-value pairs via the `custom` property must be enabled on the Customer Klass via the admin portal.
 This can be done by an admin via Settings > Platform Settings > Klasses > Customer
*/

KUSCustomerDescription customerDescription = new KUSCustomerDescription();
customerDescription.setEmail("[email protected]");

JSONObject customObject = new JSONObject();
customObject.put("customAttributeStr", "value");
// ...

customerDescription.setCustom(customObject);
Kustomer.describeCustomer(customerDescription);

To Chat 2.0

val attributes = KusCustomerDescribeAttributes(
  
  emails = listOf(KusEmail(value)),
  socials = listOf(KusSocial(value, KusSocialType.twitter))
  custom = mutableMapOf(key to value)
  
)

val result = Kustomer.getInstance().describeCustomer(attributes)
  
  when (result) {
    is KusResult.Success -> //Success
    is KusResult.Error -> //Error
  }

Describe a conversation

To learn more, see Describe Conversation.

From Chat 1.0

/*
 Attach custom attributes to the user's most recent conversation (or the first one they create)

 NOTE:
 These key-value pairs must be enabled on the Conversation Klass via the admin portal.
 This can be done by an admin via Settings > Platform Settings > Klasses > Conversation
*/

JSONObject conversationObject = new JSONObject();
conversationObject.put("customAttributeStr", "value");
// ...

Kustomer.describeConversation(conversationObject);

To Chat 2.0

val result = Kustomer.getInstance()
                .describeConversation(conversationId, 
                                      mapOf(customKey to customValue))

  when (result) {
    is KusResult.Success -> //Success
      is KusResult.Error -> //Error
  }

📘

Deprecated: Kustomer.describeNextConversation(conversationObject)

We have removed Kustomer.describeNextConversation(conversationObject) from the API. Instead, We recommend that you describe conversations in the callback block for one of the following:

  • Kustomer.getInstance().openNewConversation{}
  • Kustomer.getInstance().openConversationWithId(conversationId){}

To learn more, see Open new conversation.

Count unread and open conversations

To learn more, see Observe unread count & Observe active conversation ids.

From Chat 1.0

/*
 Return the current count of un-read messages. It might not be immediately available.
*/
Kustomer.getUnreadMessageCount();

/*
 Return the total number of open conversations.
*/
Kustomer.getOpenConversationsCount();

To Chat 2.0

val unreadCount = liveData {
        emitSource(Kustomer.getInstance().observeUnreadCount())
}

val activeConversationIds = liveData {
        emitSource(Kustomer.getInstance().observeActiveConversationIds())
}

Is chat available?

To learn more, see Is Chat available?.

From Chat 1.0

/*
Check the "turned on/off" status of your chat along with within Business Hours and outside of Holidays settings asynchronously. For example if chat is turned off or outside of business hours, you may want to disable the button or deflect customers to contact an email)
*/
Kustomer.isChatAvailable(new KUSChatAvailableListener(){
    @Override
    public void onSuccess(boolean enabled){
        // Note: This will be called on background thread
        
        // This is called when API call is successful.
        // enabled true represents chat is enabled in settings and within business hours and outside of holidays

    }
    
    @Override
    public void onFailure(){
        // Note: This will be called on background thread
        
        // This is called when API call fails.
    }
});

To Chat 2.0

Kustomer.getInstance().isChatAvailable {
            val response = it.successOr(KusChatAvailability.KUS_OFFLINE)
            when(response){
                KusChatAvailability.KUS_ONLINE -> //Chat is available
                KusChatAvailability.KUS_OFFLINE -> //Chat is unavailable. outside of business hours, or a holiday
                KusChatAvailability.KUS_HIDDEN -> //Chat is unavailable. outside of business hours, or a holiday
                KusChatAvailability.KUS_DISABLED -> //Chat is disabled
            }
        }

Updated 7 months ago



Migrate from Chat 1.0


Learn how to migrate to the Kustomer Chat 2.0 Android SDK from Chat 1.0.

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.