Integrate the Client Widget into Your Custom Application

Instead of using the Agentforce Commerce Client, add the client widget to your custom React application by passing the CopilotWidgetProps configuration object to the widget’s React component.

The React component provides the settings it needs, such as connection details, contextual information, supported capabilities, and presentation options. This approach lets you embed the commerce experience in your own application while tailoring the integration to your client’s architecture and user experience. For guidance, look at the out-of-the-box implementation for your storefront.

Customize these parts of the copilotWidgetProps object:

  • Client connection properties
  • Widget appearance and behavior
  • Widget component configuration

Example of the configuration structure for the widget.

1const copilotWidgetProps = {
2  messagingConfig: {
3    scrt2Url: "https://your-org.my.salesforce-scrt.com",
4    orgId: "00Dxx0000000000",
5    esDeveloperName: "Your_Messaging_Channel",
6    capabilitiesVersion: "63",
7  },
8  autoScroll: true,
9  componentConfig: {
10    type: "dialog",
11    isOpen: true,
12  },
13};

Client Connection Properties 

The messagingConfig property controls the widget’s backend SCRT2 messaging connection and behavior. It’s a required property.

The table lists all the settings. Required settings are noted.

SettingTypeRequiredDescription
scrt2UrlstringYesSCRT2 messaging endpoint URL
orgIdstringYesThe 18-character ID of the Salesforce org that hosts your Agentforce agent. This isn’t your B2C Commerce instance or realm ID.
esDeveloperNamestringYesEmbedded Service Deployment messaging channel developer name.
routingAttributesRecord <string, string>NoPre-chat routing attributes passed to the messaging channel.
capabilitiesVersionstringNoCapabilities version for the SCRT2 token request. Set to 63 or higher to receive action progress-indicator messages.
enableDownloadTranscriptbooleanNoShows a transcript-download control. Requires the org’s messaging channel to allow transcript download. Defaults to true.
enableEscalationToAgentbooleanNoShows an escalate-to-agent control. Requires the Agentforce agent to be configured with an escalation path. Otherwise, the button is a no-op. Defaults to false.
showProductCaptionsbooleanNoShows captions on product cards.
progressStepsLimitnumberNoMaximum number of actions shown in the chat window as the agent processes a shopper’s prompt. When the list goes past the limit, only the most recent actions are shown.
onProductResult(detail: ProductResultDetail) => voidNoThe widget calls this setting after the agent returns a result from a product search or a product-details lookup. For example, it highlights the returned products on the page.

When the widget calls onProductResult, it passes a ProductResultDetail object.

FieldTypeDescription
agentSessionIdstringID of the Agentforce session with the agent results.
kind`“search""detail”`
productIdsstring[]The product IDs the agent returns.

Widget Appearance and Behavior 

These configuration properties provide you greater flexibility to customize the widget’s appearance and behavior.

The table lists the widget’s available configuration properties and their expected values.

SettingTypeDescription
disclaimerTextstringPlain-text disclaimer shown in the widget.
disclaimerMarkdownstringMarkdown disclaimer, as an alternative to disclaimerText.
headerConfigheaderConfigCustomizes the header of the dialog or modal component with your own header text and logo. See Customize the Agentforce Commerce Client.
searchConfigsearchConfigSets your own placeholder text and button label on the widget’s search bar. See Customize the Agentforce Commerce Client.
openLinksInNewTabbooleanOpens links from the widget in a new tab.
showProductDescriptionbooleanShows product descriptions in product displays.
autoScrollbooleanAuto-scrolls to the latest message. Defaults to true.
messageAlignment`“start""end”`
conversationHistory{ sinceHours?: number; limit?: number }Limits how much of a prior conversation the widget loads. The value sinceHours defaults to 24.
promptsConfigPromptsExtensionConfigConfigures the prompts extension. See Customize the Agentforce Commerce Client.
isDevelopmentbooleanEnables development logging.

Widget Component Configuration 

The componentConfig object controls how the widget component presents itself, for example as inline chat, a floating dialog, or a modal. It also controls the widget’s open or minimized state.

The table lists the available settings.

SettingTypeDescription
type`“chat""dialog"
isOpenbooleanDetermines whether the widget chat window starts open.
isMinimizedbooleanDetermines whether the widget is minimized when it initially starts.
enableMinimizebooleanAllows the shopper to minimize the widget.
options.dialogPositionDialogPositionPlaces the dialog anchor position, such as "bottom-right".
options.dialogFullHeightbooleanChat window is full height.
options.dialogWidthstringChat window’s width.
options.isModalFullscreenbooleanMakes the chat window fullscreen.

Open and Close the Widget Programmatically 

After the CDN script injects the widget into your storefront page, you can use window.CimulateMessaging.eventHandlers.components to control it programmatically.

The most common use is a storefront-owned launcher. For example, you can create a custom storefront button, such as Ask AI in search suggestions, and open the widget when a shopper selects the button.

Example

1<div id="messaging-widget"></div>
2
3<!-- Storefront-owned launcher: style and position this button yourself. -->
4<button type="button" onclick="openShopperAgent()">Ask AI</button>
5
6<script>
7  function openShopperAgent() {
8    // Pass true to force open, false to force close, or omit to toggle.
9    window.CimulateMessaging?.eventHandlers.components.toggleWidgetOpen(true);
10  }
11</script>

These control methods are available on eventHandlers.components:

SettingDescription
toggleWidgetOpen(isOpen?)Opens or closes the widget. Pass true to force open, false to force close, or omit the argument to toggle. Opening also restores the widget if it’s minimized.
toggleWidgetMinimized(isMinimized?)Minimizes or restores the widget. Pass a boolean to force a state, or omit the argument to toggle. Minimizing also closes the widget.
setWidgetType(type)Switches the presentation form. Specify "chat", "dialog", or "modal".
setWidgetDialogPosition(position)Sets the dialog anchor position, such as "bottom-right".
toggleModalFullscreen(isFullscreen)Switches the modal’s fullscreen state on or off.

An override’s api.sendMessage can send a message from within a rendered slot.

Manage Client Chat Sessions Programmatically 

You can manage sessions using event handlers.

These control methods are available on eventHandlers.session:

SettingDescription
resetConversationEnds the current conversation and starts a new one
endConversationEnds the current conversation. The client doesn’t automatically create a new one.
sendMessageSubmits a user prompt to the agent, similar to a user input on the widget’s search bar. Component overrides can use api.sendMessage to send a message.

Related resources