Chat

interface Chat : AutoCloseable

Current chat instance. Client is not limited to a single instance of any given chat. They can create (or rather build) as many instances as they like. They are though advised that creating CONFLICTING (or identical) instances with the same configuration may lead to unexpected consequences.

After creating an instance via build, the customer is automatically authorized if the authorization is enabled and the customer was not previously authorized, otherwise reconnects the customer. The created chat instance also starts listening for the authorization and updates customer details after customer authorization. The time it takes to reach the device is undefined.

Moreover, it starts listening to events that modify welcome messages. Therefore, a welcome message is only available after we receive the given event and requires no actions from the client side. The time it takes to reach the device is undefined.

Properties

Link copied to clipboard
open val chatMode: ChatMode

Current mode of the chat.

Link copied to clipboard

Current options of the channel as received from the backend. It will remain unchanged while this Chat instance exists.

Link copied to clipboard
abstract val environment: Environment

Current environment provided by the SocketFactoryConfiguration. It will remain unchanged for the duration while this object exists.

Link copied to clipboard

Current collection of global customer CustomFields set in SDK. Instance provided by the method won't be updated if the CustomFields collection is updated in the Chat, it should be considered as a snapshot of current state. Values can be updated from backend, after ChatThreadsHandler.refresh call.

Link copied to clipboard
abstract val isChatAvailable: Boolean

Last known channel availability.

Link copied to clipboard
abstract val stateFlow: SharedFlow<ChatStateEvent>

Flow of chat state events. Observe this to receive notifications about connection state changes, readiness, and runtime exceptions.

Functions

Link copied to clipboard
abstract fun actions(): ChatActionHandler

Returns new instance of an action handler for this Chat.

Link copied to clipboard
abstract override fun close()

Closes the connection to the chat backend and removes all listeners, even those the client forgot to unregister.

Link copied to clipboard
abstract suspend fun closeSuspending()

Coroutine-native equivalent of close -- suspends until the same cleanup (storage/cookie persistence, socket teardown) completes, without blocking the calling thread. Prefer this over close whenever a coroutine context is available.

Link copied to clipboard
abstract suspend fun connect()

Attempts to connect the chat session.

Link copied to clipboard

Creates new instance to modify global custom fields.

Link copied to clipboard
abstract fun events(): ChatEventHandler

Creates new instance to interact with this instance.

Link copied to clipboard
abstract suspend fun getChannelAvailability(): Boolean

Determine if a chat is available.

Link copied to clipboard
abstract fun setDeviceToken(token: String?)

Sets device token (notification push token) to this instance and transmits it to the server. It's not guaranteed that the token is delivered to the server though. Therefore, clients are strongly advised to call this method every time they receive new tokens and reconnect to this instance.

Link copied to clipboard
abstract fun setUserName(firstName: String, lastName: String)

Attempts to change username if the channel configuration allows setting of the username. All subsequent events sent from chat will have new value filled out.

Link copied to clipboard
abstract suspend fun signOut()

Signs out the user, clears all stored values and closes the connection. Client doesn't need to call close explicitly.

Link copied to clipboard
abstract fun threads(): ChatThreadsHandler

Creates new instance to observe and interact with ChatThread.