This page documents all TypeScript types and interfaces exported by the Cognigy Click To Call SDK.
WebRTCClientConfig
The configuration object passed to createWebRTCClient().
interface WebRTCClientConfig {
endpointUrl: string;
userId?: string;
captureAudio?: boolean;
pcConfig?: RTCConfiguration;
}
| Property | Type | Description | Required |
|---|
endpointUrl | string | URL to fetch SIP configuration from the Cognigy backend | Yes |
userId | string | Optional user identifier for the session | No |
captureAudio | boolean | When set to true, the SDK emits the captureAudio event with the remote MediaStream during a call. Defaults to false | No |
pcConfig | RTCConfiguration | Custom WebRTC peer connection configuration. Use this to specify STUN/TURN servers or other RTCPeerConnection settings | No |
WebRTCClient
The main client interface returned by createWebRTCClient(). Provides all call control, state query, and event handling methods.
| Method | Reference |
|---|
connect() | connect |
disconnect() | disconnect |
connectAndCall() | connectAndCall |
startCall() | startCall |
endCall() | endCall |
mute() | mute |
unmute() | unmute |
sendInfo() | sendInfo |
isConnected() | isConnected |
getCurrentSession() | getCurrentSession |
on() | on |
off() | off |
destroy() | destroy |
CallSession
Represents an active call session.
interface CallSession {
id: string;
status: SessionStatus;
direction: 'incoming' | 'outgoing';
startTime: Date;
answerTime?: Date;
duration: number;
muted: boolean;
localHold: boolean;
remoteHold: boolean;
}
| Property | Type | Description |
|---|
id | string | Unique identifier for the call session |
status | SessionStatus | Current session status: 'init', 'ringing', 'answered', 'failed', or 'ended' |
direction | 'incoming' | 'outgoing' | Whether the call was initiated locally or received from a remote party |
startTime | Date | Timestamp when the session was created |
answerTime | Date | undefined | Timestamp when the call was answered, or undefined if not yet answered |
duration | number | Call duration in seconds since the call was answered |
muted | boolean | Whether the local microphone is muted |
localHold | boolean | Whether the call is on hold locally |
remoteHold | boolean | Whether the call is on hold by the remote party |
SessionStatus
type SessionStatus = 'init' | 'ringing' | 'answered' | 'failed' | 'ended';
CallEndInfo
Contains information about why a call ended.
interface CallEndInfo {
originator: 'local' | 'remote' | null;
cause: string | null;
description?: string | null;
}
| Property | Type | Description |
|---|
originator | 'local' | 'remote' | null | Who initiated the call end — the local user, the remote party, or null if unknown |
cause | string | null | The reason the call ended, for example, Terminated, Canceled, Rejected |
description | string | null | undefined | Additional description, such as a SIP status code or SIP Reason header value |
Transcription Data
The transcription event emits the value of the _transcription property from incoming SIP INFO messages. The structure depends on your Cognigy Voice Gateway configuration, but typically has the following shape:
interface TranscriptionData {
messages: { text: string }[];
originator: 'user' | 'bot';
}
| Property | Type | Description |
|---|
originator | string | Indicates the source of the transcription, for example, 'user' or 'bot' |
messages | { text: string }[] | Array of message objects, each containing a text field |
This is not a formally defined SDK interface. The transcription data is passed through as-is from the SIP INFO message body. The actual structure depends on your Voice Gateway configuration.
WebRTCClientEvents
Type map of all event names to their callback signatures. Use this for type-safe event handling.
The following events are emitted by the client:
| Event | Callback Signature |
|---|
connecting | () => void |
connected | () => void |
disconnected | () => void |
registered | () => void |
unregistered | () => void |
ringing | (session: CallSession) => void |
answered | (session: CallSession) => void |
ended | (session: CallSession, endInfo: CallEndInfo) => void |
failed | (session: CallSession, endInfo: CallEndInfo) => void |
muted | (session: CallSession) => void |
unmuted | (session: CallSession) => void |
audioEnded | () => void |
infoSent | (text: string, data: Record<string, any>) => void |
infoReceived | (data: { originator: string, info: { body: string } }) => void |
transcription | (transcription: { originator: string; messages: { text: string }[] }) => void |
error | (error: Error) => void |
captureAudio | (stream: MediaStream) => void |
import type { WebRTCClientEvents } from '@cognigy/click-to-call-sdk';
const handleAnswered: WebRTCClientEvents['answered'] = (session) => {
console.log('Call answered:', session.id);
};
client.on('answered', handleAnswered);
For all available events, see the Event Reference.
TypeScript Usage
The SDK is written in TypeScript and ships comprehensive type definitions. All interfaces and types can be imported directly:
import type {
WebRTCClient,
CallSession,
CallEndInfo,
WebRTCClientEvents
} from '@cognigy/click-to-call-sdk';
Type-Safe Event Handling
Use the WebRTCClientEvents type map for fully typed event callbacks:
const handleAnswered: WebRTCClientEvents['answered'] = (session) => {
console.log('Call answered:', session.id);
};
client.on('answered', handleAnswered);
Type-Safe Info Messages
When sending structured data via sendInfo(), you can define your data shape:
interface MyInfoData {
action: string;
payload: { key: string; value: number };
}
const data: MyInfoData = {
action: 'update',
payload: { key: 'score', value: 42 }
};
await client.sendInfo('custom-action', data);