Use the Core SDK for Android

The Core SDK allows you to call all the necessary In-App Messaging APIs directly from your app. With the Core SDK, you’re in full control over the entire user experience—you tell the API when to send a message and the API tells you when a message is received. If you want to use our ready-made user interface and user experience, use the UI SDK instead.

Use the Core SDK with the Kotlin programming language since this SDK was designed to use Kotlin flows. We don't recommend that you access the Core SDK using Java code.

Create a CoreConfiguration object using the config file that you previously downloaded from your org, or you can manually add the values from within this config file.

OPTION 1: Configure Using the Config File

Once you've added the config.json file to your project, you can reference it from the code.

To learn how to download the config file from your org, see Configure a Messaging for In-App Deployment in Salesforce Help. This file contains the Service API URL, the org ID, and the API name for the deployment. For example:

{
  "OrganizationId": "00ZZZ0000000Zzz",
  "DeveloperName": "MyMessagingForInAppDeployment",
  "Url": "https://zzzz.my.api.url.salesforce-scrt.com"
}

OPTION 2: Configure Manually with Config Info

If you don't want to use the config.json file in your project, you can configure the SDK manually using the Service API URL, the org ID, and the API name for the deployment.

Get the CoreClient from the CoreClientFactory using the configuration object.

Start the core instance using the correct scope. To learn more about scopes, see Coroutines and Kotlin flows in the Android documentation.

Create a ConversationClient from the CoreClient object.

In order to get the pre-chat fields before a conversation, call the retrieveRemoteConfiguration method from your CoreClient object. The returned remote configuration object contains a form with an array of fields. Each pre-chat field has the properties necessary for you to build your pre-chat form. After you present the pre-chat form to the user, fill in the userInput field for each pre-chat field object. Then submit the pre-chat fields from the submitPreChatData method on the ConversationClient object.

Send a message with the sendMessage method on the ConversationClient object.

To listen for conversation events, use Kotlin flows to monitor events on the ConversationClient instance. The following conversation events are available for listening:

  • conversation: To observe the current conversation.
  • events: To listen for events specific to this conversation.

To listen to general events, use flows on the CoreClient instance:

  • networkConnectivityState: To determine network state.
  • events: To listen for general events (including events from all conversations).

For example, to listen for typing events in a particular conversation:

The TypingIndicator object has the following payload:

To learn more, see Set Up Messaging Notifications for Android.

For more detail about the Core SDK, see the Android Reference Documentation.