# FreePBX, Asterisk, Issabel

## How Voice Logica connects

The PBX **registers a SIP trunk to Voice Logica** ([way 1](https://docs.voicelogica.ai/phone-systems/#the-four-ways-voice-logica-connects)). Voice Logica creates the trunk and gives you a server, a username and a password; the PBX sends a REGISTER out, so no port forwarding is needed.

- Calls routed to this trunk are answered by the AI agent.
- The agent transfers callers back over the same trunk; they land in the trunk's context (`from-pstn`) and the inbound route rings the extension.

## 1. Create the connection in Voice Logica

**Telephony - Trunks - Connect your PBX**, pick **FreePBX / Asterisk** and the agent. Keep the dialog open until it says **Connected**.

## 2. Add the trunk

<Tabs syncKey="asterisk">
<TabItem label="FreePBX 16 / 17">

1. **Connectivity → Trunks → Add SIP (chan_pjsip) Trunk**. **Trunk Name** `voicelogica`.
2. **pjsip Settings → General**: **Username** and **Auth username** = the username, **Secret** = the password, **Authentication** = Outbound, **Registration** = Send, **SIP Server** = the server, **SIP Server Port** = 5060, **Transport** = 0.0.0.0-udp, **Context** = `from-pstn`.
3. **pjsip Settings → Advanced**: **From Domain** = the server, **DTMF Mode** = RFC 4733, **Qualify Frequency** 60.
4. **Codecs**: alaw first, then ulaw.
5. **Submit** and **Apply Config**.

</TabItem>
<TabItem label="Issabel / Elastix">

1. **PBX → PBX Configuration → Trunks → Add SIP Trunk**.
2. **PEER Details**:

   ```
   host=<server>
   username=<username>
   fromuser=<username>
   secret=<password>
   fromdomain=<server>
   type=peer
   insecure=port,invite
   dtmfmode=rfc2833
   disallow=all
   allow=alaw&ulaw
   qualify=yes
   context=from-pstn
   ```

3. **Register String**: `<username>:<password>@<server>/<username>`
4. Submit and apply.

</TabItem>
<TabItem label="Plain Asterisk (pjsip.conf)">

```ini
[voicelogica]
type=registration
outbound_auth=voicelogica-auth
server_uri=sip:<server>:5060
client_uri=sip:<username>@<server>
contact_user=<username>

[voicelogica-auth]
type=auth
auth_type=userpass
username=<username>
password=<password>

[voicelogica]
type=aor
contact=sip:<server>:5060

[voicelogica]
type=endpoint
context=from-voicelogica
disallow=all
allow=alaw,ulaw
dtmf_mode=rfc4733
outbound_auth=voicelogica-auth
aors=voicelogica
from_domain=<server>

[voicelogica]
type=identify
endpoint=voicelogica
match=<server>
```

</TabItem>
</Tabs>

## 3. Send calls to the agent

- **A short code:** **Connectivity → Outbound Routes**, a dial pattern (for example `9|.` or a dedicated code) using the Voice Logica trunk.
- **A number, an IVR option, a ring group or queue failover, after-hours calls:** send it to a **Misc Destination** that dials over this trunk.

## 4. Let the agent transfer back to extensions

**Connectivity → Inbound Routes** for calls from this trunk, with the extension as destination (or a route whose DID matches the extension numbers). Then, in Voice Logica, add the extensions as transfer destinations: an **External** destination with the extension number (for example `201`), or a **User** with that extension. Use **Warm** transfer.

## 5. Check it works

- The dialog says **Connected**. On the PBX, `asterisk -rx "pjsip show registrations"` shows **Registered**.
- Dial the route from an extension: the call appears in **Calls**.
- Ask the agent for a colleague: the extension rings.

## Good to know

- **Behind NAT:** set **External Address** and **Local Networks** in **Settings → Asterisk SIP Settings** (Issabel: **PBX → Tools → Asterisk SIP Settings**).
- Turn off **SIP ALG** on the office router.
