Manage Conversations in React Native
Learn how to launch, manage, and enrich Agentforce conversations in your React Native application.
There are two methods for opening the conversation UI:
Opens the conversation UI. If an existing conversation is available, it's preserved and the user can continue where they left off.
This is the recommended method for most use cases. It avoids discarding conversation history and provides a smoother user experience.
Closes any existing conversation and starts fresh. The previous conversation is terminated and a new one is created.
Use this when you explicitly want to discard the previous conversation, for example, when the user switches accounts, resolves an issue, or navigates to a different context.
Both methods require:
- The SDK must be configured via
configure(). If not, the native module rejects withNOT_CONFIGURED. - On Android, a current Activity must be available. If not, the promise rejects with
ERROR: Activity not available.
Terminate the current conversation and dismiss the conversation UI:
The user can also close the conversation by:
- iOS: Tapping the close button in the chat view's top bar
- Android: Tapping the back arrow in the toolbar
Understanding how conversations are managed helps you build better user experiences.
Calling launchConversation() multiple times reuses the same conversation object. This means:
- The user sees their previous messages when re-opening the chat.
- The agent retains context from the ongoing session.
- Additional context set earlier is still active.
Conversations are cleared when:
closeConversation()is calledstartNewConversation()is calledresetSettings()is called (clears everything)- Switching modes (for example, calling
configure()withtype: 'employee'after previously configuringtype: 'service') setEmployeeAgentId()is called with a different agent ID (iOS only)
Additional context provides contextual information to the Agentforce agent during a conversation. This helps the agent deliver more personalized and relevant responses.
setAdditionalContext() must be called after launchConversation() or startNewConversation(). The context is set on the active conversation object, which doesn't exist until a conversation is launched.
| Type | Description | Example Value |
|---|---|---|
Text | String value | 'Jane Smith' |
Number | Numeric value | 15234.56 |
Boolean | True/false | true |
Date | ISO date string | '2024-01-15' |
DateTime | ISO datetime string | '2026-03-11T10:30:00.000Z' |
Json | JSON data (object or string) | { language: 'en' } |
List | Array value | ['ORD-001', 'ORD-002'] |
Money | Monetary value | 50000 |
Object | Key-value map | { street: '123 Main St', city: 'SF' } |
Ref | Reference value | '003xx0000001234AAA' |
Variable | Generic variable | 'sess_abc123' |
The bridge validates context variables before sending them to the native SDK:
- Type names are case-sensitive. Use
'Text'not'text','Boolean'not'boolean'. Invalid types cause an error. - Each variable must have a non-empty
nameandtype. Missing fields cause anINVALID_CONTEXTerror. - Validation errors are thrown synchronously before the native call, so you can catch them immediately.
- The
descriptionfield is only supported on Android. On iOS, it's silently ignored.
This example demonstrates all 11 context variable types:
The description field is only supported on Android. On iOS, it's ignored.
Hidden prechat fields let you pass values to the Service Agent prechat form without displaying them to the user. Common use cases include pre-populating a ContactId, AccountId, or session token.
:::warning Android Limitation On Android, hidden prechat fields are stored but not sent to the native SDK during session initialization. This feature is fully functional on iOS only. If hidden prechat fields are critical to your use case, use iOS or wait for a future bridge update. :::
Hidden prechat fields only apply to Service Agent conversations. They have no effect for Employee Agent conversations.
Register hidden prechat fields before calling launchConversation():
This example shows the full flow of configuring, registering hidden fields, and launching:
The conversation UI is presented differently on each platform.
The conversation UI is presented as a full-screen modal:
- Dismissal triggers
onContainerClose, which callsdismiss(animated: true). - The SDK's built-in top bar is shown.
- The chat view is a SwiftUI view created by the SDK.
The conversation UI is launched as a separate Activity:
- The user closes the conversation by tapping the back arrow.
- It displays a Material 3 Scaffold with a Salesforce-blue top app bar.
AgentforceConversationActivityis aComponentActivitythat uses Jetpack Compose.
| Aspect | iOS | Android |
|---|---|---|
| Presentation | Full-screen modal | New Activity |
| Top bar | SDK-provided | Custom Material 3 TopAppBar |
| Close mechanism | onContainerClose callback | Back arrow / system back |
| Transition | Cover vertical animation | Standard activity transition |