Minimal React example showing how to integrate the Corti Embedded Assistant.
- Authenticates with Corti using ROPC flow via backend
- Creates an interaction with encounter details
- Navigates to the session view
- Handles events and errors from the embedded component
- Customisation
- Advanced event handling
- Production error handling patterns
- State management
- Install dependencies:
npm install-
Configure environment (copy
.env.exampleto.envwith your credentials) -
Start both servers:
npm run devOpens on http://localhost:5173 with backend at http://localhost:3000.
- server.ts - Express HTTP server with CORS for Vite dev server:
- Config endpoint (
/api/config) - ReturnsbaseUrlconstructed fromCORTI_ENVIRONMENT - Authentication endpoint (
/api/auth) - Implements ROPC flow using@corti/sdkto exchange user credentials for OAuth tokens - Runs on port 3000, separate from Vite dev server
- Config endpoint (
-
src/App.tsx - Root component coordinating data fetching:
- Suspense boundary - Uses React 19's
use()hook for async config and auth loading - Data coordination - Fetches config and auth in parallel via Suspense
- Error handling - Displays authentication errors
- Suspense boundary - Uses React 19's
-
src/components/EmbeddedAssistant.tsx - Main integration component:
- Component setup - Uses
CortiEmbeddedReactcomponent with ref - API access - Gets API via
useCortiEmbeddedApi()hook - Authentication - Calls
api.auth()inonReadyhandler - Interaction creation - Creates encounter and navigates to session
- Event handling - Handles
onReady,onEvent, andonErrorcallbacks
- Component setup - Uses
-
src/lib/auth.ts - Backend communication helpers:
- Config fetching - Fetches baseUrl from
/api/configendpoint - Token fetching - Fetches credentials from
/api/authendpoint - Caching - Implements promise cache to prevent duplicate requests
- Config fetching - Fetches baseUrl from
.env- Corti credentials and environment configuration:CORTI_ENVIRONMENT,CORTI_TENANT_NAME,CORTI_CLIENT_ID- Target environment and OAuth clientCORTI_USER_EMAIL,CORTI_USER_PASSWORD- End-user credentials for ROPC authentication
// Get API access via hook
const api = useCortiEmbeddedApi(cortiRef);
// In onReady callback:
await api.auth(credentials);
const interaction = await api.createInteraction({ encounter: {...} });
await api.navigate(`/session/${interaction.id}`);