A runnable Vite + React chat widget demonstrating @salesforce/chat-sdk-core,
@salesforce/chat-sdk-react, and @salesforce/chat-sdk-adapter-redux wired together in
one app — a floating "bubble launcher" that opens a chat window backed by a real (or mocked)
Enhanced Chat v2.0 (MIAW) conversation, with its state genuinely flowing through a Redux store
(visible in Redux DevTools), not just the SDK's own headless hooks.
From the repo root:
# Terminal 1 — start the mock server (defaults to http://localhost:3001)
yarn workspace @salesforce/chat-sdk-example-react-client run mock-server
# Terminal 2 — run the dev server; with no env vars set, it points at the mock server above
yarn workspace @salesforce/chat-sdk-example-react-client run devOpen the printed local URL, click the floating chat bubble in the bottom-right corner — the
bot sends a welcome message, streamed word by word by default — and type a message. The bot
replies with a lorem ipsum-style message (also streamed) a moment later, unless your message
starts with "stop", "goodbye", "end chat", or "end conversation", which ends the conversation
instead. Start the mock server with --no-streaming to disable word-by-word streaming.
Set these Vite env vars (e.g. in examples/react-client/.env.local) before running dev/build:
| Env var | Maps to | Default |
|---|---|---|
VITE_SCRT_URL |
scrtUrl — SCRT2 host, e.g. xyz.my.salesforce-scrt.com |
http://localhost:3001 |
VITE_ORG_ID |
orgId — 15/18-char Salesforce org ID |
00Dxx0000000001 (mock-server placeholder) |
VITE_ES_DEVELOPER_NAME |
esDeveloperName — Embedded Service deployment API name (must have deploymentType: "Custom Client") |
ExampleReactClientDeployment |
This uses createDevAuthAdapter({ mode: 'unauthenticated', ... }), which calls Salesforce's
unauthenticated/guest access-token endpoint directly from the browser — fine for prototyping
against a real org, but see that adapter's doc comment: it's dev-only, never production.
configureChatStore()builds a standalone Redux store; the returned adapter is passed intoChatClient({ stateAdapter: adapter })and wired up by hand viaclient.addEventListener({ predicate: () => true }, (event) => adapter.handleDomainEvent(event))— seesrc/chatSetup.ts— since that wiring is not automatic for a customstateAdapter.- The message list and typing indicator use the headless render-prop components from
@salesforce/chat-sdk-react(MessageList,TypingIndicator), which read through the client's activeStateAdapter(the Redux adapter, transparently). The composer intentionally does not use<Composer>— see the doc comment onChatWidget.tsxfor why (its auto-derivedconversationIdstaysnulluntil the first inbound message, too late for this demo's first outbound send) — and instead wires a plain<input>touseSendMessage()with an explicitly-generated conversation ID. - The connection-status pill in the header instead reads
useSelector(selectConnectionStatus)directly off thereact-reduxstore — bypassing the SDK's own hooks — to prove the Redux adapter really is dispatching into the store a host app could otherwise read directly. See the comment onChatWidget.tsxfor the full rationale behind this split.
yarn workspace @salesforce/chat-sdk-example-react-client run dev— start the Vite dev server.yarn workspace @salesforce/chat-sdk-example-react-client run build— type-check and build for production.yarn workspace @salesforce/chat-sdk-example-react-client run preview— preview the production build.yarn workspace @salesforce/chat-sdk-example-react-client run typecheck— type-check with no build step.yarn workspace @salesforce/chat-sdk-example-react-client run mock-server— convenience alias for starting the mock server from this package.
Set VITE_PRIMARY_SECONDARY_DEMO=true (e.g. in .env.local, or inline: VITE_PRIMARY_SECONDARY_DEMO=true yarn workspace @salesforce/chat-sdk-example-react-client run dev) to show a small product catalog above the chat. Off by default.
The host page is the primary: it authenticates, owns the connection and renders the main chat. The product catalog is a separate page (catalog.html) embedded in a single iframe, standing in for the customer's site. That page is the secondary: one SecondaryClient (linked with adapter-primary-link) with no token and no connection of its own, driving a mini chat on every product card. Start the main chat first; each card's "Chat about …" button stays disabled until it has a conversation. Activating a card turns it into a small chat that sends and receives through the primary. Only one card is active at a time (the catalog page tracks this itself), and a card's mini chat shows only what happens after activation and is discarded when another card takes over or it is closed. The main chat keeps the full transcript.
This is the shape of "an out-of-the-box chat plus custom page experiences" without a full client per experience. See src/primaryDemo.ts (primary side) and src/catalog.tsx and src/ProductCatalog.tsx (secondary side).