# Twilio Elastic SIP

> Connect a Twilio Elastic SIP Trunk to Edesy as a bring-your-own carrier - IP-authenticated gateway, E.164 with a leading plus, and the origination and termination settings on the Twilio side.

Source: https://edesy.in/docs/sip-trunking/byoc/twilio-elastic-sip

To use a Twilio Elastic SIP Trunk with Edesy, register it as an IP-authenticated carrier whose gateway is your trunk's Twilio termination host, with numbers sent in E.164 with a leading `+`. On the Twilio side, allow Edesy's IP for termination and add an origination URI pointing to Edesy, so calls flow both ways.

## Values

| Setting | Value |
|---|---|
| Auth to Twilio | IP access control list (no registration) |
| Gateway | `<your-trunk>.pstn.twilio.com`, port `5060`, UDP |
| Number format | E.164 with `+` (`e164_leading_plus: true`) |
| Edesy SIP address for Twilio origination | Given to you during onboarding, port `5070` |

## 1. Register the carrier on Edesy

```bash
curl -X POST https://voice-api.edesy.in/v1/trunk-portal/trunks \
  -H "Authorization: Bearer sk_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Twilio",
    "e164_leading_plus": true,
    "host": "your-trunk.pstn.twilio.com",
    "port": 5060,
    "protocol": "udp",
    "numbers": ["+1XXXXXXXXXX"]
  }'
```

## 2. Configure the Twilio trunk

In the Twilio console, open your Elastic SIP Trunk:

1. **Termination** (Edesy to Twilio): note the termination SIP URI (this is your gateway host) and add Edesy's signalling IP to an **IP Access Control List** on the trunk.
2. **Origination** (Twilio to Edesy): add an origination URI of `sip:<edesy-sip-address>:5070`, using the address from onboarding.
3. **Numbers**: attach the numbers you listed in step 1 to the trunk.

## 3. Test

- Outbound: `POST /v1/calls` with `from` set to one of your Twilio numbers.
- Inbound: dial the Twilio number. The call should arrive at Edesy and run the application linked to the number.

## FAQ

### Why IP auth instead of credentials?

Twilio Elastic SIP termination supports IP access control lists, which avoids per-call passwords. Twilio also supports credential lists; if you use one, set `requires_register` and the register fields instead.

### My outbound calls get 403 from Twilio.

Edesy's IP is not in the trunk's IP Access Control List, or the caller ID is not a number on your Twilio account.

### Inbound calls never reach Edesy.

Check the origination URI, including port `5070`, and that the number is attached to the trunk.

See [Bring Your Own Carrier](https://edesy.in/docs/sip-trunking/byoc) for how routing works.
