Reecall
Connecting to an Assistant

WebRTC Channel

Create a WebRTC Channel, request a connection token from your backend, and connect your browser or app to the Assistant with a LiveKit client.

How it works

A WebRTC Channel is the routing configuration that connects browser or app-based clients to your Assistant. The Calls API generates a room-scoped token with Assistant dispatch configuration; LiveKit creates the room when the client connects.

Unlike SIP Channels, WebRTC Channels don't require whitelist configuration since authentication is handled through tokens.

Call flow

For each connection:

  1. Client requests a connection token from the Calls API, providing the Channel ID
  2. Calls API validates the WebRTC Channel and its Assistant, then generates a token for a new room
  3. Client receives the WebSocket URL and access token
  4. Client connects to LiveKit using the provided credentials
  5. Assistant receives the connection and begins the conversation

Creating a WebRTC Channel

Required fields

FieldRequiredDescription
nameYesDisplay name for the Channel
typeYesMust be WEBRTC for WebRTC Channels
assistantIdYesThe Assistant to handle calls on this Channel

Create request

Use a project-scoped API key, or include projectId in the payload with an organization-scoped key. Data API paths below are relative to the server URL in the API reference, which includes /data_next. The Calls API uses /calls/{channelId} separately.

Code
POST /conversational/channels Content-Type: application/json Authorization: Bearer <your-api-token> { "name": "Web Support Widget", "type": "WEBRTC", "description": "Browser-based voice support for website visitors", "assistantId": "f47ac10b-58cc-4372-a567-0e02b2c3d479" }

Response

JSONCode
{ "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "name": "Web Support Widget", "type": "WEBRTC", "description": "Browser-based voice support for website visitors", "assistantId": "f47ac10b-58cc-4372-a567-0e02b2c3d479", "createdAt": "2024-01-15T10:30:00.000Z", "updatedAt": "2024-01-15T10:30:00.000Z" }

Connecting with LiveKit client

Request a token from your backend, then pass the returned wsUrl and token to a LiveKit client. Keep the Reecall API key on your backend.

Step 1: obtain connection token

From your backend, request a token for the WebRTC Channel:

Code
POST /calls/{channelId} Authorization: Bearer <your-api-token>

Response:

JSONCode
{ "wsUrl": "wss://reecall.livekit.cloud", "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." }

Step 2: connect to LiveKit

The examples below show the connection code for JavaScript, Python, and React. Install the matching LiveKit client SDK and use the wsUrl and token returned in Step 1. These are integration fragments, so supply those values in your application.

For JavaScript, call startCall from a user action, such as clicking a Start call button. If the browser blocks playback, offer an Enable audio button that calls room.startAudio(). For React, provide an audio-unlock control such as LiveKit's StartAudio component.

The JavaScript and React examples capture microphone audio. The Python example creates an audio source only. Feed microphone or other PCM frames into it and consume the incoming audio stream in your application.

JavascriptCode
import { Room, RoomEvent, Track } from "livekit-client"; const room = new Room(); room.on(RoomEvent.TrackSubscribed, (track) => { if (track.kind === Track.Kind.Audio) { document.body.appendChild(track.attach()); } }); room.on(RoomEvent.TrackUnsubscribed, (track) => { track.detach().forEach((element) => element.remove()); }); // Call this from a user action, such as a Start call button. async function startCall() { await room.startAudio(); await room.connect(wsUrl, token); await room.localParticipant.setMicrophoneEnabled(true); }
Code
import asyncio from livekit import rtc async def connect_to_assistant(ws_url: str, token: str): room = rtc.Room() @room.on("track_subscribed") def on_track_subscribed(track, publication, participant): if track.kind == rtc.TrackKind.KIND_AUDIO: # Handle audio track from Assistant audio_stream = rtc.AudioStream(track) # Process audio frames as needed @room.on("disconnected") def on_disconnected(): print("Disconnected from room") # Connect to the room await room.connect(ws_url, token) print(f"Connected to room: {room.name}") # Publish an audio source. Your application must feed PCM frames into it # with await source.capture_frame(frame); creating it does not capture a microphone. source = rtc.AudioSource(sample_rate=48000, num_channels=1) track = rtc.LocalAudioTrack.create_audio_track("microphone", source) await room.local_participant.publish_track(track) return room # Usage async def main(): room = await connect_to_assistant(ws_url, token) # Keep connection alive await asyncio.sleep(300) # 5 minutes await room.disconnect() asyncio.run(main())
TypeScriptCode
import "@livekit/components-styles" import { LiveKitRoom, RoomAudioRenderer, } from "@livekit/components-react" function CallRoom({ wsUrl, token }: { wsUrl: string; token: string }) { return ( <LiveKitRoom serverUrl={wsUrl} token={token} connect={true} audio={true} video={false} > {/* Add your call controls here. */} <RoomAudioRenderer /> </LiveKitRoom> ) }

Constraints

  • An Assistant can have one WebRTC Channel and one SIP Channel. Creating a second Channel of the same type for that Assistant returns an error.

  • Browser permissions: In a browser environment, users must grant microphone access for audio capture. Make sure to handle permission denials gracefully in your UI.

  • Token expiry: Connection tokens have a one hour lifetime. If a connection fails, request a new token before retrying.


Last modified on