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.

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 fun connect(): Cancellable

Attempts to connect the chat session using existing configuration, the attempt will be made on background thread. Successful connection will be announced to the ChatStateListener.onConnected which was supplied in ChatBuilder. If there is an issue during/after reconnection the ChatStateListener.onUnexpectedDisconnect will be called, it is responsibility of application to perform a repeated reconnection attempt, if it is desirable. Reconnect attempts should be performed only if the device is connected to the internet. If the repeated reconnection attempts are made, they should be called with exponential backoff, in order to prevent backend overload.

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 fun reconnect(): Cancellable

Attempts to restart the chat session using existing configuration, the attempt will be made on background thread. Successful connection will be announced to the ChatStateListener.onConnected which was supplied in ChatBuilder. If there is an issue during/after reconnection the ChatStateListener.onUnexpectedDisconnect will be called, it is responsibility of application to perform a repeated reconnection attempt, if it is desirable. Reconnect attempts should be performed only if the device is connected to the internet. If the repeated reconnection attempts are made, they should be called with exponential backoff, in order to prevent backend overload.

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 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 Threads.