ConversationClient

Client for interacting with a specific conversation.

A ConversationClient is scoped to a single conversation identified by conversationId. It provides methods for sending messages, observing conversation state, managing the session lifecycle, and handling structured content interactions.

Obtain an instance from CoreClient.conversationClient:

val conversationId = UUID.randomUUID()
val conversationClient = coreClient.conversationClient(conversationId)

Conversation ID Management

The conversationId must be a randomly generated UUID. Never use customer IDs, user IDs, business identifiers, or any other deterministic value as the conversation ID. Using non-random IDs causes authentication failures (HTTP 403) when the app is reinstalled or tokens expire, because the server associates the ID with the previous access token.

The recommended approach is to check for existing conversations first, and only generate a new UUID if none exist:

See also

Samples

val result = coreClient.conversations(limit = 10, forceRefresh = true)
val conversationId = if (result is Result.Success) {
    result.data.firstOrNull()?.identifier ?: UUID.randomUUID()
} else {
    UUID.randomUUID()
}
val conversationClient = coreClient.conversationClient(conversationId)
scope.launch {
    conversationClient.events.collect { event ->
        when (event) {
            is ConversationEvent.Entry -> { /* Display the new entry in the chat feed */ }
            is ConversationEvent.ProgressIndicator -> { /* Show typing indicator */ }
            is ConversationEvent.QueuePosition -> { /* Update queue position UI */ }
            else -> {}
        }
    }
}

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
abstract val conversation: Flow<Result<Conversation>>

An observable stream of the current Conversation state.

Link copied to clipboard
abstract val conversationId: UUID

The unique identifier of the conversation this client operates on.

Link copied to clipboard

A stream of real-time ConversationEvents for this conversation.

Functions

Link copied to clipboard
abstract suspend fun changeModality(modality: Modality): Result<Unit>

Changes the modality of the conversation between Modality.Messaging and Modality.Voice.

Link copied to clipboard
abstract suspend fun closeConversation(): Result<Unit>

Permanently closes the conversation.

Link copied to clipboard
abstract suspend fun conversationEntries(limit: Int = 100, timestamp: Long? = null, direction: QueryDirection = QueryDirection.Descending, forceRefresh: Boolean = false): Result<List<ConversationEntry>>

Gets the ConversationEntrys scoped to this conversation.

Link copied to clipboard
abstract fun conversationEntriesFlow(limit: Int = 100, timestamp: Long? = null, direction: QueryDirection = QueryDirection.Descending, forceRefresh: Boolean = false): Flow<Result<List<ConversationEntry>>>

Gets the ConversationEntry objects related to this conversation.

Link copied to clipboard
abstract fun conversationEntriesPaged(pageSize: Int = DEFAULT_PAGE_SIZE): Flow<Result<PagingData<ConversationEntry>>>

Returns a paginated stream of ConversationEntry objects for this conversation.

Link copied to clipboard
abstract suspend fun conversationEntry(entryId: String): ConversationEntry?

Gets a single ConversationEntry given its unique entry ID.

Link copied to clipboard
abstract fun conversationEntryFlow(entryId: String): Flow<ConversationEntry?>

Gets a Flow of a single ConversationEntry given its unique entry ID.

Link copied to clipboard
abstract suspend fun createConversation(remoteConfiguration: RemoteConfiguration? = null, modality: Modality = Modality.Messaging): Result<Conversation>

Explicitly creates a conversation on the server without sending a message.

Link copied to clipboard
abstract suspend fun currentConversation(): Conversation?

Gets the current Conversation for the ConversationClient.

Link copied to clipboard
abstract suspend fun endSession(): Result<Unit>

Ends the current messaging session without closing the conversation.

Link copied to clipboard
abstract suspend fun markAsRead(conversationEntry: ConversationEntry): Result<ConversationEntry>

Marks a ConversationEntry as read by the local participant.

Link copied to clipboard
abstract suspend fun retrieveTranscript(): Result<InputStream>

Retrieves a transcript of the entire conversation as a downloadable stream.

Link copied to clipboard
abstract suspend fun retryEntry(conversationEntry: ConversationEntry): Result<ConversationEntry>

Retries sending a previously failed conversation entry.

abstract suspend fun retryEntry(conversationEntry: ConversationEntry, remoteConfiguration: RemoteConfiguration): Result<ConversationEntry>

Retries sending a previously failed conversation entry with a remote configuration.

Link copied to clipboard
abstract suspend fun sendCancel(entry: ConversationEntry): Result<ConversationEntry>

Sends a cancel action for an in-progress structured content interaction.

Link copied to clipboard
abstract suspend fun sendFile(file: File, message: String? = null): Result<ConversationEntry>

Sends a file attachment in this conversation, with an optional text message.

Link copied to clipboard

Sends a completed form back to the agent.

Link copied to clipboard
abstract suspend fun sendMessage(message: String): Result<ConversationEntry>

Sends a text message in this conversation.

Link copied to clipboard
abstract suspend fun sendReply(reply: OptionItem): Result<ConversationEntry>

Sends a reply to a structured content message (e.g., quick replies or displayable options).

Link copied to clipboard
abstract suspend fun sendTypingEvent(): Result<Unit>

Sends a typing indicator to notify the agent that the user is composing a message.

Link copied to clipboard

Sets context data to be attached to the next outbound message.

Link copied to clipboard
abstract suspend fun submitRemoteConfiguration(remoteConfiguration: RemoteConfiguration, createConversationOnSubmit: Boolean = true, modality: Modality = Modality.Messaging): Result<Conversation>

Submits a remote configuration with pre-chat fields and routing data.