Skip to main content
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;
}
PropertyTypeDescriptionRequired
endpointUrlstringURL to fetch SIP configuration from the Cognigy backendYes
userIdstringOptional user identifier for the sessionNo
captureAudiobooleanWhen set to true, the SDK emits the captureAudio event with the remote MediaStream during a call. Defaults to falseNo
pcConfigRTCConfigurationCustom WebRTC peer connection configuration. Use this to specify STUN/TURN servers or other RTCPeerConnection settingsNo

WebRTCClient

The main client interface returned by createWebRTCClient(). Provides all call control, state query, and event handling methods.
MethodReference
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;
}
PropertyTypeDescription
idstringUnique identifier for the call session
statusSessionStatusCurrent session status: 'init', 'ringing', 'answered', 'failed', or 'ended'
direction'incoming' | 'outgoing'Whether the call was initiated locally or received from a remote party
startTimeDateTimestamp when the session was created
answerTimeDate | undefinedTimestamp when the call was answered, or undefined if not yet answered
durationnumberCall duration in seconds since the call was answered
mutedbooleanWhether the local microphone is muted
localHoldbooleanWhether the call is on hold locally
remoteHoldbooleanWhether 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;
}
PropertyTypeDescription
originator'local' | 'remote' | nullWho initiated the call end — the local user, the remote party, or null if unknown
causestring | nullThe reason the call ended, for example, Terminated, Canceled, Rejected
descriptionstring | null | undefinedAdditional 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';
}
PropertyTypeDescription
originatorstringIndicates 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:
EventCallback 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);