customer-android-kotlin

//core/com.kustomer.core.providers/KusChatProvider

KusChatProvider

[androidJvm]
interface KusChatProvider

This provider class is used to interact with all chat related functionality.

Obtain an instance of KusChatProvider like below:

Note: Before you begin, make sure you have initialized KustomerCore class with a valid API key

val chatProvider = KustomerCore.getInstance().kusChatProvider()

Once you have an instance of the provider, you can call methods on it and handle the KusResult object.

APIs with network or heavy data processing operations are currently marked with suspend modifier, and can be called from Kotlin Coroutines. If not using Kotlin Coroutines, then we are going to add KusCallback response support in the future

Below is an example of how to make API calls and handle its response

Samples

[androidJvm]
ExampleChatViewModel

Functions

Name Summary
addChatListener [androidJvm]
abstract fun addChatListener(listener: KusChatListener)
Register a KusChatListener to the Core SDK to receive chat events across all open conversations
changeActiveAssistant [androidJvm]
abstract suspend fun changeActiveAssistant(activeAssistant: KusActiveAssistant): KusResult<KusAssistant>?
Overrides the KusAssistant in the SDK with the specified assistant ID or no assistant.
createConversation [androidJvm]
abstract suspend fun createConversation(title: String? = null, messages: List<String>?, attachments: List<KusUploadAttachment>?, messageAction: KusMessageAction? = null, lastDeflectionData: KusKbLastDeflectionData? = null, attributes: Map<String, Any>? = null, initialAgentMessages: List<String>? = null): KusResult<Pair<KusConversation, List<KusChatMessage>>>
Creates a new conversation. Adds messages to the created conversation if passed in the parameter. Currently this API only supports adding text messages for a newly created conversation. Use KusChatProvider.sendMessageWithAttachments to send more messages and/or attachments in the conversation.
describeConversation [androidJvm]
abstract suspend fun describeConversation(conversationId: String, customAttributes: Map<String, Any>): KusResult<Boolean>
Describe a conversation with Custom attributes This should be used to provide context to any conversation
describeCustomer [androidJvm]
abstract suspend fun describeCustomer(describeAttributes: KusCustomerDescribeAttributes): KusResult<Boolean>
This should be used to describe any relevant attributes for the current user This should not be confused with logIn call
endConversation [androidJvm]
abstract suspend fun endConversation(conversationId: String): KusResult<KusConversation>
Ends the conversation for the given id
fetchChatMessages [androidJvm]
abstract suspend fun fetchChatMessages(conversationId: String, page: Int, pageSize: Int, startTimeToken: Long? = null): KusResult<List<Any>>
Returns list of KusChatMessage&KusSatisfaction object if present for a conversation
fetchConversation [androidJvm]
abstract suspend fun fetchConversation(conversationId: String): KusResult<KusConversation>
Fetches the KusConversation object for the given id. Returns KusResult.Error if the conversation is not found with that id
fetchConversations [androidJvm]
abstract suspend fun fetchConversations(page: Int, pageSize: Int): KusResult<List<KusConversation>>
Returns previous list of conversations for the current user. If Hide Chat History is enabled in Synchronous Chat Settings, then only open conversations will be sent in response. If Hide Chat History is disabled, then all the previous open and closed conversations will be sent in response.
getChatMessagesBeforeTimestamp [androidJvm]
abstract suspend fun getChatMessagesBeforeTimestamp(conversationId: String, timeStamp: Long?, pageSize: Int): KusResult<List<Any>>
Returns paginated list of KusChatMessage&KusSatisfaction before a given messageID
getChatSettings [androidJvm]
abstract suspend fun getChatSettings(): KusResult<KusChatSetting>
Returns chat settings Default brand id is used if no value is overridden in the Core SDK KustomerCoreOptions.brandId
getConversation [androidJvm]
abstract suspend fun getConversation(conversationId: String): KusResult<KusConversation>
Returns the KusConversation object for the given id Returns KusResult.Error if the conversation is not found with that id
getHistoricChatMessages [androidJvm]
abstract suspend fun getHistoricChatMessages(conversationId: String, page: Int, pageSize: Int): KusResult<List<Any>>
Returns paginated list of KusChatMessage if present for a conversation
getInitialMessages [androidJvm]
abstract suspend fun getInitialMessages(): KusResult<List<KusChatMessage>>
Returns the initial messages for the chat assistant declared in via KustomerCoreOptions.chatAssistantId Returns an empty list if no initial messages present for the assistant
getTimeTokenMap [androidJvm]
abstract suspend fun getTimeTokenMap(channelNames: MutableList<String>): Map<String, Long>?
Gets a map of last-updated time tokens for a given channel name. TimeToken is represented as a 17-digit precision unix time (UTC)
init [androidJvm]
abstract suspend fun init(): KusResult<Boolean>
isChatAvailable [androidJvm]
abstract suspend fun isChatAvailable(): KusResult<KusChatAvailability>
Returns the current Chat availability status. This should be used to show online/offline business status on UI. If the availability status is KusChatAvailability.KUS_DISABLED, chat functionality will not work and events wont be received in listeners. Default brand id is used if no value is overridden in the Core SDK KustomerCoreOptions.brandId
logIn [androidJvm]
abstract suspend fun logIn(jwtToken: String): KusResult<KusIdentifiedCustomer>
Returns KusIdentifiedCustomer as success response Generate a JWT Token on your backend server which should be passed in this function’s parameter For more information, Refer this link
logOut [androidJvm]
abstract fun logOut()
Clears all in memory cache. This will not close any active conversations for the user. To fetch the current user’s chat data again, call KusChatProvider.logIn to login the user
markRead [androidJvm]
abstract suspend fun markRead(conversationId: String, messageIds: List<String>)
Marks a conversation as read for current timestamp. Any message received for this conversation after this will be treated as unread, until marked read again This function should be called, whenever the user closes the chat view for a conversation
observeActiveConversationIds [androidJvm]
abstract fun observeActiveConversationIds(): LiveData<Set<String>>
Returns LiveData object with Set of active/open conversation ids
observeUnreadCount [androidJvm]
abstract fun observeUnreadCount(): LiveData<Int>
Returns LiveData object with unread count. If Hide Chat History is enabled in Synchronous Chat Settings, then only unread count across open conversations will be sent in response.
overrideAssistant [androidJvm]
abstract suspend fun overrideAssistant(assistantId: String): KusResult<KusAssistant>
Overrides the KusAssistant in the SDK with the specified assistant Id.
overrideBrand [androidJvm]
abstract suspend fun overrideBrand(brandId: String): KusResult<KusChatSetting>
Overrides the KusChatSetting.brandId in the SDK with the specified brand Id.
overrideBusinessSchedule [androidJvm]
abstract suspend fun overrideBusinessSchedule(scheduleId: String): KusResult<KusSchedule>
Overrides the KusSchedule with in the SDK with the specified schedule Id.
removeAllListeners [androidJvm]
abstract fun removeAllListeners()
Removes all registered listeners from the Core SDK This can be used, if there are multiple listeners attached
removeChatListener [androidJvm]
abstract fun removeChatListener(listener: KusChatListener)
Unregister a KusChatListener from the Core SDK
sendArticlesClicked [androidJvm]
abstract suspend fun sendArticlesClicked(conversationId: String, articleDeflection: KusKbLastDeflectionData?): KusResult<Boolean>
Sends data about KB deflection articles that are clicked
sendMessageWithAttachments [androidJvm]
abstract suspend fun sendMessageWithAttachments(body: String?, messageAction: KusMessageAction?, attachments: List<KusUploadAttachment>?, conversationId: String, isFirstMessage: Boolean = false, lastDeflectionData: KusKbLastDeflectionData? = null, initialAgentMessages: List<String>? = null): KusResult<KusChatMessage>
Sends message along with attachment to a conversation. Total attachment size allowed with a single message is 9MB. Maximum allowed size per attachment is 5MB.
sendPresenceActivity [androidJvm]
abstract fun sendPresenceActivity(presence: KusPresenceEvent)
Sets a user’s presence to show agents when a user is online or offline.
sendTypingStatus [androidJvm]
abstract suspend fun sendTypingStatus(conversationId: String, typingStatus: KusTypingStatus): KusResult<Boolean>
Sends typing indicator status to conversation for current customer
submitSatisfactionForm [androidJvm]
abstract suspend fun submitSatisfactionForm(conversationSatisfactionId: String, response: KusSatisfactionNetworkPostBody, conversationId: String): KusResult<KusSatisfaction>
Adds/Updates the satisfaction response on a conversation. This will override any previously added satisfaction response for the same conversation
subscribeToTypingStatus [androidJvm]
abstract suspend fun subscribeToTypingStatus(sharedChannel: String): KusResult<Boolean>
Subscribe for real-time agent typing events for a given conversation. The subscription should happen when a user navigates to the conversation in UI
unsubscribeFromTypingStatus [androidJvm]
abstract suspend fun unsubscribeFromTypingStatus(sharedChannel: String): KusResult<Boolean>
Unsubscribe for real-time agent typing events for a given conversation. The unsubscribe should happen whenever a user navigates away from that conversation UI