Use the PostMessage API to integrate Corti Assistant via iframe or WebView
The PostMessage API enables secure cross-origin communication between your application and the embedded Corti Assistant. This method is recommended for iframe or WebView integrations.
This method is recommended for iFrame/WebView integration. Note, a web
component is coming soon that will make this integration easier to use.
The PostMessage API uses the browser’s postMessage mechanism to enable secure communication between your application and the embedded Corti Assistant, even when they’re served from different origins. This makes it ideal for embedding Corti Assistant in iframes or WebViews.
The Embedded Assistant API only supports user-based authentication. You
must authenticate as an end user, not as an application. Client credentials
and other machine-to-machine authentication methods are not supported.
Before you can use the PostMessage API, you need to authenticate your users using OAuth2. The recommended flow is Authorization Code Flow with PKCE for secure, user-facing integrations.For detailed information on OAuth2 flows and authentication, see our OAuth Authentication Guide.Key points:
Use Authorization Code Flow with PKCE for embedded integrations
Obtain access_token, refresh_token, and id_token for your users
These examples omit * intentionally. In an iframe allow attribute, each
feature defaults to the iframe src origin, which is the safer default for
Corti Assistant embeds. Use feature * only if you explicitly want to grant
that permission to any origin the iframe might later navigate to.
If you omit allow="microphone" on the iframe, the embedded Assistant cannot
access the user’s microphone even if the site itself has microphone
permission.
If you support virtual mode, include display-capture so the embedded
Assistant can request browser-managed capture of remote audio streams.
<!-- Load the embedded Corti iframe --><iframe id="corti-iframe" src="https://assistant.eu.corti.app/embedded" width="100%" height="600px" allow="microphone; display-capture; clipboard-write"></iframe><script>const iframe = document.getElementById('corti-iframe');let isReady = false;// Listen for the ready eventwindow.addEventListener('message', async (event) => { if (event.data?.type === 'CORTI_EMBEDDED_EVENT' && event.data.event === 'embedded.ready') { isReady = true; console.log('Corti embedded app is ready'); // Authenticate the user (requires OAuth2 tokens) await authenticateUser(); }});async function authenticateUser() { // Send authentication request with OAuth2 tokens iframe.contentWindow.postMessage({ type: 'CORTI_EMBEDDED', version: 'v1', action: 'auth', requestId: 'auth-1', payload: { access_token: 'your-access-token', // From OAuth2 flow refresh_token: 'your-refresh-token', // From OAuth2 flow id_token: "your-id-token", // From OAuth2 flow token_type: "Bearer", } }, '*');}</script>
Corti Assistant dispatches events to notify your application of state changes and important updates. When using the PostMessage API, these events are wrapped in the CORTI_EMBEDDED_EVENT message type.
The embedded Assistant also dispatches legacy
events using camelCase names (e.g.,
recordingStarted, documentGenerated). These are deprecated and will be
removed in a future version.