> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cognigy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Types

This page documents all TypeScript types and interfaces exported by the Cognigy Click To Call SDK.

## WebRTCClientConfig

The configuration object passed to [`createWebRTCClient()`](/click-to-call/sdk/api-reference/create-click-to-call-client).

```typescript theme={null}
interface WebRTCClientConfig {
  endpointUrl: string;
  userId?: string;
  captureAudio?: boolean;
  pcConfig?: RTCConfiguration;
}
```

| Property       | Type               | Description                                                                                                                                                                      | Required |
| -------------- | ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
| `endpointUrl`  | `string`           | URL to fetch SIP configuration from the Cognigy Voice Gateway Endpoint.                                                                                                          | Yes      |
| `userId`       | `string`           | Optional user identifier for the session.                                                                                                                                        | No       |
| `captureAudio` | `boolean`          | When set to `true`, the SDK emits the [`captureAudio`](/click-to-call/sdk/event-reference/capture-audio) 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()`](/click-to-call/sdk/api-reference/create-click-to-call-client). Provides all call control, state query, and event handling methods.

| Method                | Reference                                                                 |
| --------------------- | ------------------------------------------------------------------------- |
| `connect()`           | [connect](/click-to-call/sdk/api-reference/connect)                       |
| `disconnect()`        | [disconnect](/click-to-call/sdk/api-reference/disconnect)                 |
| `connectAndCall()`    | [connectAndCall](/click-to-call/sdk/api-reference/connect-and-call)       |
| `startCall()`         | [startCall](/click-to-call/sdk/api-reference/start-call)                  |
| `endCall()`           | [endCall](/click-to-call/sdk/api-reference/end-call)                      |
| `mute()`              | [mute](/click-to-call/sdk/api-reference/mute)                             |
| `unmute()`            | [unmute](/click-to-call/sdk/api-reference/unmute)                         |
| `sendInfo()`          | [sendInfo](/click-to-call/sdk/api-reference/send-info)                    |
| `isConnected()`       | [isConnected](/click-to-call/sdk/api-reference/is-connected)              |
| `getCurrentSession()` | [getCurrentSession](/click-to-call/sdk/api-reference/get-current-session) |
| `on()`                | [on](/click-to-call/sdk/api-reference/on)                                 |
| `off()`               | [off](/click-to-call/sdk/api-reference/off)                               |
| `destroy()`           | [destroy](/click-to-call/sdk/api-reference/destroy)                       |

## CallSession

Represents an active call session.

```typescript theme={null}
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

```typescript theme={null}
type SessionStatus = 'init' | 'ringing' | 'answered' | 'failed' | 'ended';
```

## CallEndInfo

Contains information about why a call ended.

```typescript theme={null}
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`](/click-to-call/sdk/event-reference/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:

```typescript theme={null}
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.                    |

<Note>
  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.
</Note>

## 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`                                                 |

```typescript theme={null}
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](/click-to-call/sdk/event-reference/overview).

## TypeScript Usage

The SDK is written in TypeScript and ships comprehensive type definitions. All interfaces and types can be imported directly:

```typescript theme={null}
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:

```typescript theme={null}
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()`](/click-to-call/sdk/api-reference/send-info), you can define your data shape:

```typescript theme={null}
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);
```
