Build your own UI
Learn how to build your own mobile Chat UI with the Kustomer Core SDK.
To build your own UI for Kustomer Chat and the Knowledge Base, you can use the Kustomer Core SDK. The Core SDK gives you access to all the data, events, and methods available for our built-in UI.
The Kustomer Core SDK exposes APIs in the form of provider interfaces that allow you to create your own chat widget UI and send information into Kustomer APIs.
This guide shows you how to use the Kustomer Core SDK to build your own mobile chat UI.
Prerequisites
Before you get started, you'll need the following:
-
A valid API key with just the
org.tracking
role. See Requirements -
Chat SDK installation. To learn more, see Installation.
Install with Gradle
Add the following dependency to your app.gradle
:
dependencies {
implementation 'com.kustomer.chat:core:<<Android_SDK_Version>>'
...
}
Overview
To build your own UI with the Kustomer Core SDK, you will need to do the following:
-
Initialize
KustomerCore
from your Application class (either with or without options to override SDK settings). -
Implement KusChatListener to receive chat events.
-
Register listeners and perform actions with Provider classes that allow your chat UI to interact with Kustomer Services.
We've provided more information, code examples, and links to resources for each step below.
Step 1: Initialize KustomerCore
First, initialize [KustomerCore
]https://kustomer.github.io/customer-android-kotlin/com.kustomer.core/-kustomer-core/) from your Application class.
You can initialize KustomerCore
with or without options.
Always initialize with an Application class
You must always have an Application class to initialize Kustomer Chat properly. Create an Application class before you call
Kustomer.init()
.
Option 1: Initialize with options
Create KustomerCoreOptions object
To override any settings within the SDK, create a KustomerCoreOptions object with KustomerCoreOptions.Builder.
val kustomerCoreOptions = KustomerCoreOptions.Builder()
.setBusinessScheduleId("<business_schedule_id>") //override business schedule
.setLogLevel(KusLogLevel.All) //set log options
.build()
Initialize with KustomerCoreOptions
To initialize with options, include your Kustomer API Key and KustomerCoreOptions as a parameter for KustomerCore.init
in your onCreate
method in your Application class.
KustomerCore.init(
application,
"API_KEY", // read it from gradle properties
kustomerCoreOptions //Optional parameter
)
Option 2: Initialize without options
To initialize without options, include your Kustomer API key as a parameter for KustomerCore.init
in your onCreate
method in your Application class.
KustomerCore.init(
application,
"API_KEY", // read it from gradle properties
)
Step 2. Implement KusChatListener
After you initialize KustomerCore, implement KusChatListener to receive chat events.
KusChatListener
receives chat events that contain a KusConversation.id parameter for the relevant chat event.
To show events for a single active session only, store the chat event
KusConversation.id in your application memory. You can then use the KusConversation.id parameter for the event to either show or ignore event updates for users.
KusChatListener supports the following events:
KusChatListener
documenationSee the full documentation for
KusChatListener
for more information and code examples for supported chat events.
Event | Description |
---|---|
KusChatListener.onChatMessageReceived | Detects when a customer or an agent receives a chat message |
KusChatListener.onAgentIsTyping | Detects when the agent starts and stops typing. |
KusChatListener.onUnreadCountChange | Detects when the unread count changes for a conversation. |
KusChatListener.onAgentJoined | Detects information for an agent when the agent joins the chat and responds to a conversation for the first time. |
KusChatListener.onPreviewChanged | Detects when conversation preview text changes after the customer or agents receives a new message. |
KusChatListener.onConversationEnded | Detects when a conversation ends. |
Step 3. Register listeners and perform actions with Kustomer Core Providers
Initialize the KustomerCore class with a valid API key
Make sure you have initialized the KustomerCore class with a valid API key.
For the final step, you will register listeners and perform actions with Kustomer Core Provider classes.
Provider classes enable your custom chat UI to interact with Kustomer Services.
API Provider class documentation
Refer to our API Provider documentation for further implementation reference.
Provider responses
All API provider classes return a response wrapped as KusResult.
APIs with suspend
modifier
APIs with heavy processing or network operations are marked with the suspend
modifier. You can call these APIs asynchronously from Kotlin coroutines.
A future version of the Kustomer Core SDK will include KusCallback response support for these suspend
functions.
Kustomer API Providers
We've provided a list of Kustomer API Provider classes below:
- Register a KusChatListener to receive chat updates
- Create new conversation
- Send chat messages and attachments
- Mark conversations as read
- End conversation
- Get unread count across all conversations
- Call identify to login a user
- Fetch chat settings and business schedules
- Register and unregister device tokens with Kustomer to receive push notifications
- Fetch article categories and articles
- Search for articles with any term
Additional Kustomer Core Android SDK resources
Packages
Package Name | Summary |
---|---|
com.kustomer.core | . |
com.kustomer.core.exception | This package contains all Custom Exceptions for Kustomer |
com.kustomer.core.listeners | This package contains all listener classes for Kustomer |
com.kustomer.core.models | This package contains all Common model classes for Kustomer |
com.kustomer.core.models.chat | This package contains all Chat model classes for Kustomer |
com.kustomer.core.models.kb | This package contains all Knowledge base model classes for Kustomer |
com.kustomer.core.providers | This package contains all Provider classes for Kustomer |
com.kustomer.core.utils.helpers | |
com.kustomer.core.utils.log |
Index
Updated 3 months ago