KitChat
Class that represents basic functions of the mobile channel, such as connecting to Voximplant Kit, sending, and receiving messages. It also notifies an application if any changes to the connection state occur, delivers customer data, and informs if there is an active conversation.
Constructors
KitChat
fun KitChat(accountRegion: String
, channelUuid: String
, token: String
, clientId: String
):
Parameters
accountRegion:
String
Account region for a mobile channel.
channelUuid:
String
Mobile channel UUID.
token:
String
Mobile channel token.
clientId:
String
Customer unique identifier.
Props
MAX_FILE_ATTACHMENTS
val MAX_FILE_ATTACHMENTS: Int
Maximum number of attachments that can be sent in a message.
Returns
type:
Int
MAX_FILE_SIZE
val MAX_FILE_SIZE: Long
Maximum file attachment size in bytes that can be sent in a message.
Returns
type:
Long
MAX_TEXT_LENGTH
val MAX_TEXT_LENGTH: Int
Maximum text length in characters that can be sent in a message.
Returns
type:
Int
SUPPORTED_DOCUMENT_MIME_TYPES
val SUPPORTED_DOCUMENT_MIME_TYPES: List<String>
List of supported document MIME types.
Returns
type:
List<String>
SUPPORTED_FILE_MIME_TYPES
val SUPPORTED_FILE_MIME_TYPES: List<String>
List of supported file MIME types - unified list of SUPPORTED_IMAGE_MIME_TYPES and SUPPORTED_DOCUMENT_MIME_TYPES.
Returns
type:
List<String>
SUPPORTED_IMAGE_MIME_TYPES
val SUPPORTED_IMAGE_MIME_TYPES: List<String>
List of supported image MIME types.
Returns
type:
List<String>
clientData
val clientData: StateFlow<ClientData?>
Flow of ClientData that emits new instances of the ClientData once the customer information is updated.
The customer information can be updated as a result of:
- KitChat.setClientData API call.
- connection state changes to ConnectionState.Connected.
Returns
type:
StateFlow<ClientData?>
connectionState
val connectionState: Flow<ConnectionState>
Flow of ConnectionState that emits new instances of ConnectionState once the state of the connection to Voximplant Kit is changed.
The connection state can be changed as a result of:
- KitChat.openConnection API call.
- KitChat.closeConnection API call.
- internet connection loss on a device.
- network change on a device.
- Android OS drops the connection due to battery restriction while the application is in the background.
Returns
type:
Flow<ConnectionState>
hasActiveConversation
val hasActiveConversation: StateFlow<Boolean>
Flow of the Boolean that represents the current status of the conversation.
The conversation is not active if it is closed by an agent, timeout, or other channel settings.
Returns
type:
StateFlow<Boolean>
Methods
closeConnection
fun closeConnection(): Unit
Closes a previously opened connection to Voximplant Kit.
Returns
type:
Unit
getMessages
fun getMessages(messageUuid: String?
, size: Int
, direction: ): Result<GetMessagesResult>
Requests previous or next messages from a message UUID.
If the message UUID parameter is null, the request is performed from the last message in the conversation even if the last message has not been received by the customer.
The maximum number of messages to be requested is 20. Requesting more than 20 messages causes IllegalArgumentException.
If the connectionState is not ConnectionState.Connected, KitConnectionRequiredException is returned as the Result.failure.
Returns a Result with the result of the operation. If the request is successfully completed, provides a GetMessagesResult instance with additional data, such as a list of messages and a boolean indicator whether there are more messages in the requested direction.
If the operation fails, provides an exception with details:
- KitConnectionRequiredException if the connection to Voximplant Kit is not established or has been closed while processing the operation.
- KitTimeoutException if the operation has not completed in time.
- KitInternalException if something went wrong.
Parameters
messageUuid:
String?
OptionalMessage UUID from which the history is requested.
size:
Int
Number of messages. The default value is 10.
direction:
Request direction. The default value is MessageHistoryDirection.Ascending.
Returns
type:
Result<GetMessagesResult>
openConnection
fun openConnection(): Boolean
Opens a connection to Voximplant Kit.
The API makes KitChat.connectionState to emit new instances of ConnectionState representing the connection state changes.
If the connection to Voximplant Kit is successful, the following data can be updated:
If the current state is not ConnectionState.Disconnected, returns false.
Returns the Boolean that represents whether the connection is successfully established.
Returns
type:
Boolean
registerPushToken
fun registerPushToken(token: String
): Result<Unit>
Registers a token to receive push notifications for new inbound messages on the current device.
To receive push notifications, it is also required to upload a Firebase certificate.
Returns a Result with the result of the operation. If the operation fails, provides an exception with details:
- IllegalArgumentException if the token is an empty string.
- KitConnectionRequiredException if the connection to Voximplant Kit is not established or has been closed while processing the operation.
- KitTimeoutException if the operation has not completed in time.
- KitInternalException if something went wrong.
Parameters
token:
String
FCM registration token to register.
Returns
type:
Result<Unit>
sendMessage
fun sendMessage(message: ): Result<Message>
Sends a message.
The message may be:
- a text message
- a text message with attachments (up to KitChat.MAX_FILE_ATTACHMENTS)
- attachments only message (up to KitChat.MAX_FILE_ATTACHMENTS)
If the connectionState is not ConnectionState.Connected, KitConnectionRequiredException is returned as the Result.failure.
Returns a Result with the result of the operation. If the message is sent successfully, provides a Message instance with additional data, such as the message UUID and attachments' URLs.
If the operation fails, provides an exception with details:
- KitConnectionRequiredException if the connection to Voximplant Kit is not established or has been closed while sending the message.
- KitTimeoutException if the SDK has not received a confirmation in time that the message is sent.
- KitFileUploadException if the message contains attachments that failed to upload.
- KitInternalException if something went wrong.
Parameters
message:
Message to be sent
Returns
type:
Result<Message>
setClientData
fun setClientData(client: ): Result<Unit>
Sets customer information to the agent's workspace.
Returns a Result with the result of the operation.
If the operation fails, provides an exception with details:
- IllegalArgumentException if all ClientData fields are null or empty.
- KitConnectionRequiredException if the connection to Voximplant Kit is not established or has been closed while processing the operation.
- KitTimeoutException if the operation has not completed in time.
- KitInternalException if something went wrong.
Parameters
client:
Customer information.
Returns
type:
Result<Unit>
unregisterPushToken
fun unregisterPushToken(token: String
): Result<Unit>
Unregisters a token to stop receiving push notifications on the current device.
Returns a Result with the result of the operation.
If the operation fails, provides an exception with details:
- IllegalArgumentException if the token is an empty string.
- KitConnectionRequiredException if the connection to Voximplant Kit is not established or has been closed while processing the operation.
- KitTimeoutException if the operation has not completed in time.
- KitInternalException if something went wrong.
Parameters
token:
String
FCM registration token to unregister.
Returns
type:
Result<Unit>