📞 FreePBX & Asterisk PBX Configuration Guide¶
This guide details the configuration of Asterisk PBX (18 / 20 / 21 / 22) and FreePBX for seamless integration with py-phone-caller.
Tip
Looking for Complete Native /etc/asterisk/*.conf Examples (No FreePBX GUI)?
See Asterisk PBX Configuration & Examples (Native Linux) for complete, copy-pasteable configurations (http.conf, ari_py_phone_caller.conf, pjsip_py_phone_caller.conf with SIP trunks & local softphone extension 1000, extensions_py_phone_caller.conf with DTMF 4 acknowledgment callbacks, modules.conf, SELinux rules, and matching settings.toml / .secrets.toml).
Automated Native Asterisk 22 Provisioning (Ansible):
If you are deploying Asterisk directly on Linux (Debian 13 via AllStarLink, Ubuntu 26.04 LTS official packages, or Rocky Linux 10 / AlmaLinux 10 via Tucny 22.9.0-1.el10), use the automated asterisk_py_phone_caller Ansible role documented in deploy/docs/02-ansible-deployment.md.
Ready-to-Use Local SIP Extension 1000 (Optional): Set asterisk_sip_exten_1000_enabled: true in your Ansible inventory to automatically provision a ready-to-register local PJSIP extension (1000) with a cryptographically random password logged during execution (and preserved idempotently across reruns). It uses max_contacts=1 and qualify_frequency=0 for reliable mobile/VPN/air-gapped softphone registration (e.g., Linphone) and supports both ARI voice calls and RFC 3428 SIP MESSAGE text alerts from caller_sms.
📑 Table of Contents¶
- Architectural Role of Asterisk & FreePBX
- Prerequisites & Network Ports
- Configuring Outbound SIP / PJSIP Trunks (Visual)
- Creating SIP / PJSIP Extensions for Testing
- Creating the Custom Extension & Stasis Dialplan
- Configuring Asterisk REST Interface (ARI) & WebSockets
- RTP, Codecs & NAT Network Settings
- Testing & Connectivity Verification
1. Architectural Role of Asterisk & FreePBX¶
py-phone-caller uses the Asterisk REST Interface (ARI) to dynamically originate outbound phone calls, control audio playback, deliver optional RFC 3428 SIP MESSAGE notifications (caller_sms asterisk_sip carrier), and capture real-time dual-tone multi-frequency (DTMF) keypad responses from on-call personnel.
+-----------------------+ +---------------------------+
| asterisk_caller |---(1. HTTP ARI POST)--->| Asterisk PBX / FreePBX |
| (Outbound Controller) | | (ARI Port 8088 / SIP 5060)|
+-----------------------+ +---------------------------+
|
+-----------------------+ (2. Places Outbound Call)
| asterisk_ws_monitor |<--(3. WS Stasis Events)-+ |
| (Audio/Playback Loop) | v
+-----------------------+ +---------------------------+
| PSTN / SIP Trunk / Mobile |
+---------------------------+
2. Prerequisites & Network Ports¶
Ensure the following network communication is allowed between the py-phone-caller host/containers and the Asterisk PBX:
| Port / Protocol | Direction | Purpose | Default Value |
|---|---|---|---|
| 8088 / TCP | App ➔ PBX | Asterisk HTTP ARI & WebSocket Events (/ari/events) |
8088 (or 8089 for TLS) |
| 5060 / UDP, TCP | PBX ➔ Gateway | SIP Trunk Signaling (PJSIP or chan_sip) | 5060 |
| 10000–20000 / UDP | Bidirectional | RTP Audio Media Streams | 10000:20000 |
3. Configuring Outbound SIP / PJSIP Trunks (Visual)¶
To route emergency calls out to landlines or mobile phones, configure a SIP or PJSIP trunk in the FreePBX GUI:
Step 3.1: Navigate to Trunks¶
- In the FreePBX top navigation menu, click Connectivity.
- Select Trunks.

Step 3.2: Add a New Trunk¶
- Click the + Add Trunk button.
- Select + Add SIP (chan_pjsip) Trunk (or chan_sip for legacy gateways).

Step 3.3: Configure General Trunk Settings¶
- Set the Trunk Name (e.g.
sip-provider). - Set the Outbound CallerID to your organization's valid emergency caller ID.

Step 3.4: Configure SIP Credentials & Server Details¶
- Switch to the pjsip Settings (or sip Settings) tab.
- Enter your VoIP provider's SIP Server / Outbound Proxy, Username, and Secret / Password.
- Set Context to
from-trunkand Authentication toOutbound.

Step 3.5: Apply Config¶
Click Submit and then click the red Apply Config button at the top right of the FreePBX header.

4. Creating SIP / PJSIP Extensions for Testing¶
For lab environments and softphone verification (e.g. Linphone, Zoiper, MicroSIP):
Step 4.1: Navigate to Extensions¶
Click Applications ➔ Extensions ➔ + Add Extension ➔ + Add New PJSIP Extension.

Step 4.2: Configure Extension Credentials¶
- Set User Extension (e.g.
2001). - Set Display Name (e.g.
On-Call Test Phone). - Set Secret (PJSIP password).

Click Submit and Apply Config.
5. Creating the Custom Extension & Stasis Dialplan¶
Asterisk needs a dialplan context that routes answered calls into the Stasis application managed by asterisk_ws_monitor.
Step 5.1: Configure extensions_custom.conf¶
Log into your Asterisk/FreePBX server via SSH and edit /etc/asterisk/extensions_custom.conf (replacing <PY_PHONE_CALLER_HOST> with the IP or hostname of your py-phone-caller caller_register service):
[py-phone-caller-custom]
exten => s,1,NoOp(Starting py-phone-caller Stasis Application)
same => n,Answer()
same => n,Playback(greeting-message)
same => n,Stasis(py-phone-caller)
same => n,Set(RES=${CURL(http://<PY_PHONE_CALLER_HOST>:8083/heard?asterisk_chan=${CHANNEL(uniqueid)})})
same => n,Playback(press-4-for-acknowledgement)
same => n,Playback(beep)
same => n,Read(get,"silence/1",,,,2)
same => n,GotoIf($["${get}" = "4"]?ack:done)
same => n(ack),Set(RES=${CURL(http://<PY_PHONE_CALLER_HOST>:8083/ack?asterisk_chan=${CHANNEL(uniqueid)})})
same => n(done),Playback(vm-goodbye)
same => n,Hangup()
Reload Asterisk dialplan:
Step 5.2: Register Custom Extension in FreePBX (Optional GUI Binding)¶
- Go to Applications ➔ Custom Extensions.
- Click + Add Custom Extension.
- Set Custom Extension to
999and Target topy-phone-caller-custom,s,1.

6. Configuring Asterisk REST Interface (ARI) & WebSockets¶
Enable the HTTP server and create dedicated credentials for py-phone-caller:
Step 6.1: Configure /etc/asterisk/http.conf¶
Ensure Asterisk's built-in HTTP server is active:
Step 6.2: Configure /etc/asterisk/ari.conf¶
Configure the ARI user matching your settings.toml or environment variables:
[general]
enabled = yes
pretty = yes
allowed_origins = *
[py-phone-caller]
type = user
read_only = no
password = <PASSWORD>
password_format = plain
Step 6.3: GUI Alternative via FreePBX Asterisk REST Interface Users¶
- Go to Admin ➔ Asterisk REST Interface Users.
- Add user
py-phone-caller, set Read Only toNo, and configure your password.

Reload Asterisk ARI modules:
7. RTP, Codecs & NAT Network Settings¶
For clean audio playback without one-way audio issues:
- Audio Codec: Ensure
alawandulaw(G.711) are enabled in your SIP trunk and extensions.generate_audiogenerates 8000 Hz 16-bit PCM WAV audio matching G.711 native sampling. - NAT Settings (
/etc/asterisk/pjsip.confor SIP Settings GUI):- If Asterisk is behind NAT, configure
external_media_addressandexternal_signaling_address. - Set
local_net=192.168.0.0/16(or your local subnet CIDR).
- If Asterisk is behind NAT, configure
8. Testing & Connectivity Verification¶
From the py-phone-caller host, verify ARI connectivity with curl:
# 1. Test HTTP ARI API
curl -v -u py-phone-caller:<PASSWORD> \
http://<asterisk-ip>:8088/ari/asterisk/info
# Expected output: HTTP 200 OK with Asterisk version information JSON
# 2. Test Stasis WebSocket Connection
uv run python -c "
import asyncio, websockets
async def test():
uri = 'ws://py-phone-caller:<PASSWORD>@<asterisk-ip>:8088/ari/events?app=py-phone-caller'
async with websockets.connect(uri) as ws:
print('Connected successfully to Asterisk Stasis WebSocket!')
asyncio.run(test())
"
Once verified, configure asterisk_host, asterisk_user, and asterisk_pass in src/config/settings.toml or your deployment .env file!