Build a Core SDK App 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.

This article applies to the following implementations:

UI SDKCore SDK

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.

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"
}

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.

This example creates a random UUID for the conversation ID. However, if you want this conversation to persist even after the app is restarted, be sure to use the same conversation ID. Also, if you want to see this same conversation across multiple devices, in addition to using the same conversation ID, turn on user verification, which is described in the Enhance the Experience section.

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 submitRemoteConfiguration method on the ConversationClient object.

IMPORTANT: The submitPreChatData method is deprecated in SDK version 1.4. If you want to use new features in version 1.4 and later, submit pre-chat fields using the submitRemoteConfiguration method.

To learn about hidden pre-chat fields, see Hidden Pre-Chat for Android.

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

You can listen for conversation activity with the ConversationClient object and by using Android's Paging library. To learn about paged data, see Load and display paged data in the Android documentation.

For example, to listen for conversation entries, use the conversationEntriesPaged method.

Use your PagingDataAdapter class to listen to the latest events.

Your ViewHolder class can extract information from the conversation entry.

When you receive conversation entries from various flows, they’re delivered as ConversationEntry objects. In addition to the payload, you can inspect the entryType (for example, Message) when deciding how to process the message. The payload is an instance of the EntryPayload class and it contains, in addition to the payload itself, a content field that describes the message format.

To see how this can be implemented, check out the Core SDK example in GitHub.

To listen for transient events that come from the network, such as typing indicator feedback and network connectivity info, use Kotlin flows on ConversationClient and CoreClient.

To monitor conversation events on the ConversationClient instance, use the following properties:

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

To monitor general events on the CoreClient instance, use the following properties:

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

For example, to listen for typing events in a particular conversation, filter on the events property.

The TypingIndicator object has the following payload:

When you receive events, you can extract information from the contents and pass it to the UI.

To see how this can be implemented, check out the Core SDK example in GitHub.

You can enhance your users' experience by adding push notifications, passing information to Salesforce about a verified user, sending hidden pre-chat fields, adjusting chat button visibility based on business hours, and more.

For enhanced features, see Enhance the Experience for Android.

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

For an example app, see the Core SDK example in GitHub.