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

# Vobiz and SIP Trunks

> What SIP trunks are, why Vobiz is used, and how LiveKit SIP is configured.

## What Is SIP?

SIP means Session Initiation Protocol. It is a standard protocol used by phone systems to start, manage, and end voice calls over the internet.

In this application, SIP is the bridge between:

* The normal telephone network where leads receive calls
* LiveKit rooms where the AI voice agent listens and speaks

Without SIP, the AI agent can talk inside a browser/WebRTC session, but it cannot call a normal mobile phone number.

## What Is A SIP Trunk?

A SIP trunk is a configured connection between a telephony provider and an application. Think of it as the phone line for internet-based calling.

This app uses two trunk concepts:

| Trunk type     | Use                                                |
| -------------- | -------------------------------------------------- |
| Inbound trunk  | Receives calls from the phone network into LiveKit |
| Outbound trunk | Places calls from LiveKit to real phone numbers    |

The main production path uses the outbound trunk.

## Why Vobiz Is Used

Vobiz is the SIP/telephony provider in this project. It supplies:

* SIP domain or address
* SIP username
* SIP password
* Caller phone number
* PSTN connectivity for dialing Indian mobile numbers

LiveKit does not directly own the phone number in this setup. LiveKit asks the configured SIP trunk to place the call, and Vobiz completes the call over the phone network.

## How The Call Travels

```text theme={null}
scheduler.py
  -> LiveKit SIP API
  -> LiveKit outbound SIP trunk
  -> Vobiz SIP endpoint
  -> mobile phone network
  -> lead answers phone
  -> audio returns to LiveKit room
  -> AI agent speaks/listens
```

## Environment Variables

```env theme={null}
VOBIZ_PHONE_NUMBER=+918071XXXXXX
VOBIZ_SIP_DOMAIN=your-trunk-id.sip.vobiz.ai
VOBIZ_SIP_USERNAME=your_vobiz_username
VOBIZ_SIP_PASSWORD=your_vobiz_password
LIVEKIT_SIP_TRUNK_ID=ST_xxxxxxxxxxxx
```

## Creating SIP Config

Run:

```powershell theme={null}
python sip_setup.py create
```

This creates:

* A LiveKit inbound trunk named `Ignitech Vobiz Inbound`
* A LiveKit dispatch rule named `Ignitech Lead Dispatch`
* A LiveKit outbound trunk named `Ignitech Vobiz Outbound`

The dispatch rule routes inbound SIP calls into rooms using:

```text theme={null}
room_prefix="ignitech-lead-"
```

## Listing SIP Config

```powershell theme={null}
python sip_setup.py list
```

Use the outbound trunk ID as:

```env theme={null}
LIVEKIT_SIP_TRUNK_ID=ST_xxxxxxxxxxxx
```

## Manual Test Call

```powershell theme={null}
python sip_setup.py call +91XXXXXXXXXX
```

With a real lead ID:

```powershell theme={null}
python sip_setup.py call +91XXXXXXXXXX 123
```

This creates:

```text theme={null}
room: ignitech-lead-123
participant: sip-lead-123
```

## Deleting SIP Config

```powershell theme={null}
python sip_setup.py delete
```

This deletes dispatch rules first, then inbound trunks, then outbound trunks.

## Important Notes

* `LIVEKIT_SIP_TRUNK_ID` must be an outbound trunk ID.
* Phone numbers must normalize to E.164, such as `+91XXXXXXXXXX`.
* `participant_identity` uses hyphens: `sip-lead-123`.
* `VOBIZ_PHONE_NUMBER` is used as caller ID when configured.
* `krisp_enabled=True` is set for noise reduction.
* `play_ringtone=True` is enabled so ringing behavior feels natural.
