Quick Setup: Chat in the Service Chat SDK
Before starting, make sure that you’ve already:
- Set up your console to work with Chat. See Org Setup for Chat in Lightning Experience with a Guided Flow.
- Installed the SDK. See Install the Service SDK for Android.
To set up Chat with the default UI, create a configuration object that points to your org and then start a chat session. If you prefer to build your own user interface, see Build Your Own UI with the Chat Core API.
-
Specify your Chat org settings.
In Java:
public static final String ORG_ID = "YOUR_ORG_ID"; public static final String DEPLOYMENT_ID = "YOUR_DEPLOYMENT_ID"; public static final String BUTTON_ID = "YOUR_BUTTON_ID"; public static final String LIVE_AGENT_POD = "YOUR_LAC_ORG_URL"; // e.g. "d.la.salesforce.com"
In Kotlin:
val ORG_ID = "YOUR_ORG_ID" val DEPLOYMENT_ID = "YOUR_DEPLOYMENT_ID" val BUTTON_ID = "YOUR_BUTTON_ID" val LIVE_AGENT_POD = "YOUR_LAC_ORG_URL" // e.g. "d.la.salesforce.com"
-
Create a ChatConfiguration object using your org settings.
In Java:
// Create a core configuration instance ChatConfiguration chatConfiguration = new ChatConfiguration.Builder(ORG_ID, BUTTON_ID, DEPLOYMENT_ID, LIVE_AGENT_POD) .build();
In Kotlin:
// Create a core configuration instance val chatConfiguration = ChatConfiguration.Builder(ORG_ID, BUTTON_ID, DEPLOYMENT_ID, LIVE_AGENT_POD) .build()
-
Configure and launch a chat session using ChatUI, ChatUIConfiguration, and ChatUIClient.
In Java:
// Create a UI configuration instance from a core config object // and start session! ChatUI.configure(ChatUIConfiguration.create(chatConfiguration)) .createClient(getApplicationContext()) .onResult(new Async.ResultHandler<ChatUIClient>() { @Override public void handleResult (Async<?> operation, ChatUIClient chatUIClient) { chatUIClient.startChatSession(MainActivity.this); } });
In Kotlin:
// Create a UI configuration instance from a core config object // and start session! ChatUI.configure(ChatUIConfiguration.create(chatConfiguration)) .createClient(applicationContext) .onResult { _, chatUIClient -> chatUIClient.startChatSession(this@MainActivity) }
When calling startChatSession, pass the context for the Activity that you want to show the chat UI on top of. The chat session starts minimized and the user can tap the thumbnail to go full screen. If you want the session to start in full-screen mode, call defaultToMinimized(false) on the builder.
By default, the user's queue position is shown while the user waits for an agent. You can change this information from a position number to an estimated wait time using the queueStyle build method and specifying QueueStyle.EstimatedWaitTime. When using the estimated wait time, you can set the minimum (minimumWaitTime) and maximum (maximumWaitTime) wait time values. If the wait time exceeds the maximum value, a generic message appears, which you can customize (using the customizable chat strings). To understand the algorithm used for the estimated wait time, see the estimated wait time documentation in the Chat REST API Developer Guide. To hide queue information entirely, use a queue style of None.
Sample alternate configuration in Java:
ChatUIConfiguration uiConfig = new ChatUIConfiguration.Builder() .chatConfiguration(chatConfiguration) .queueStyle(QueueStyle.EstimatedWaitTime) // Use estimated wait time .defaultToMinimized(false) // Start in full-screen mode .build();
Sample alternate configuration in Kotlin:
val uiConfig = ChatUIConfiguration.Builder() .chatConfiguration(chatConfiguration) .queueStyle(QueueStyle.EstimatedWaitTime) // Use estimated wait time .defaultToMinimized(false) // Start in full-screen mode .build()
-
(Optional) Customize the interface.
You can customize the colors, strings, and other aspects of the interface. You can also localize the strings into other languages.
-
(Optional) Add listeners for state changes or events.
You can add listeners for state changes and events during a chat session and respond accordingly. For instance, when the client ends a session, you can display a dialog to the user. See Listen for State Changes and Events.
When a session launches, it appears minimized.
The user can tap the session to make it full screen and begin a conversation with an agent.