CoreClient

interface CoreClient

The entry point for the Messaging for In-App SDK.

A CoreClient instance manages conversations, handles real-time messaging events, authentication, and push notification registration. Use this client to create and manage conversations, observe messaging events, and coordinate with the backend service.

Obtain an instance using CoreClientFactory:

val configuration = CoreConfiguration(
serviceAPI = URL("https://myorg.my.salesforce-scrt.com"),
organizationId = "00D000000000001",
developerName = "My_Messaging_Deployment"
)
val coreClient = CoreClient.Factory.create(context, configuration)

To begin receiving real-time events, call start with a CoroutineScope. The host app is responsible for maintaining this scope — when the scope is cancelled, the connection closes. When the client is started, push notifications are suppressed in favor of real-time delivery. Call stop to resume push notification delivery.

A typical setup registers providers and manages the connection via Compose lifecycle:

val coreClient = CoreClient.Factory.create(context, configuration).apply {
registerHiddenPreChatValuesProvider { fields ->
fields.onEach { it.userInput = resolveValue(it.name) }
}
if (configuration.isUserVerificationRequired) {
registerUserVerificationProvider { reason ->
UserVerificationToken.externalToken(fetchJwt())
}
}
}

// In a Composable, tie the event stream to the lifecycle
LifecycleResumeEffect(Unit) {
coreClient.start(lifecycleScope)
onPauseOrDispose { coreClient.stop() }
}

See also

Types

Link copied to clipboard
object Companion : Core

Companion object providing static SDK operations and the Factory for creating instances.

Properties

Link copied to clipboard

Gets the Configuration that this instance is configured with.

Link copied to clipboard
abstract val events: SharedFlow<CoreEvent>

A SharedFlow of CoreEvents emitted by the SDK.

Link copied to clipboard
abstract val networkConnectivityStatusFlow: Flow<NetworkConnectivityStatus>

Observes the current network connectivity status.

Link copied to clipboard
abstract val realtimeConnectionState: Flow<ServerSentEvent.Connection>

Observes the state of the real-time connection to the messaging service.

Link copied to clipboard

The endpoint URL path for Salesforce authentication requests, derived from the current Configuration.

Functions

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

Closes a conversation, ending the messaging session permanently.

Link copied to clipboard
abstract fun conversationClient(conversationId: UUID = UUID.randomUUID()): ConversationClient

Returns a ConversationClient for interacting with a specific conversation.

Link copied to clipboard
abstract suspend fun conversations(limit: Int, sortedByActivityDescending: Boolean = true, olderThanConversation: Conversation? = null): Result<List<Conversation>>

Retrieves conversations from the local cache sorted by latest activity.

abstract suspend fun conversations(limit: Int, olderThanConversation: Conversation? = null, conversationId: UUID? = null, forceRefresh: Boolean = false): Result<List<Conversation>>

Retrieves conversations available to the local participant.

Link copied to clipboard
abstract fun conversationsFlow(limit: Int, sortedByActivityDescending: Boolean = true, olderThanConversation: Conversation? = null): Flow<Result<List<Conversation>>>

Retrieves conversations from the local cache sorted by latest activity as a Flow.

abstract fun conversationsFlow(limit: Int, olderThanConversation: Conversation? = null, conversationId: UUID? = null, forceRefresh: Boolean = false): Flow<Result<List<Conversation>>>

Retrieves conversations available to the local participant as a Flow.

Link copied to clipboard
abstract fun conversationsPaged(pageSize: Int): Flow<Result<PagingData<Conversation>>>

Retrieves conversations available to the local participant with pagination support.

abstract fun conversationsPaged(pageSize: Int, sortedByActivityDescending: Boolean = true): Flow<Result<PagingData<Conversation>>>

Retrieves conversations from the local cache sorted by latest activity with pagination support.

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

Creates a new conversation with the messaging service.

Link copied to clipboard
abstract suspend fun deleteConversation(conversationId: UUID): Int

Deletes a conversation and its entries from the local database.

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

Deregisters this device from receiving push notifications for this deployment.

Link copied to clipboard
abstract fun destroy()

Destroys this CoreClient instance and releases all associated resources.

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

Sends a read acknowledgement for a ConversationEntry.

Link copied to clipboard

Returns a MultimediaClient for managing voice and video sessions.

Link copied to clipboard
abstract suspend fun registerDevice(context: Context, deviceToken: String): Result<Unit>

Registers this device for push notifications using the provided FCM device token.

Link copied to clipboard

Registers a provider for supplying hidden pre-chat field values.

Link copied to clipboard

Registers a provider for supplying templated URL values for an auto-response messaging component.

Link copied to clipboard

Registers a provider for verifying an already authenticated user.

Link copied to clipboard

Retrieves the BusinessHoursInfo for the current deployment.

Link copied to clipboard

Retrieves the RemoteConfiguration from the messaging service.

Link copied to clipboard
abstract suspend fun revokeToken(deregisterDevice: Boolean): Result<Unit>

Revokes the current authorization token, preventing further operations until a new token is granted.

Link copied to clipboard
abstract fun start(scope: CoroutineScope)

Starts listening to remote events via a real-time connection.

Link copied to clipboard
abstract fun stop()

Stops listening to remote events and closes the real-time connection.