📘 Overview
This guide walks you through setting up Asterisk (v16 or higher) for modern telephony development using the Asterisk REST Interface (ARI) with Node.js, PJSIP for SIP/WebRTC clients, and optional AMI (Asterisk Manager Interface) for monitoring.
By the end, you’ll have:
- A working Asterisk system with ARI and AMI enabled
- Support for both SIP and WebRTC endpoints
- A functional dialplan routing calls into your Node.js app
- A simple Node.js example using
node-ari-client
⚙️ 1. Prerequisites
Before you start, ensure you have:
- Asterisk installed (
apt install asteriskor source build) - Node.js (v16+)
- At least one SIP softphone (e.g., Zoiper, Linphone)
- Optional: a browser WebRTC client (SIP.js, SIPML5)
- Proper firewall/NAT configuration for SIP, RTP, and WebSocket ports
🌐 2. Configure HTTP for ARI & WebRTC
File: /etc/asterisk/http.conf
[general]
enabled = yes
bindaddr = 0.0.0.0
bindport = 8088
; TLS (HTTPS/WSS) for WebRTC
tlsenable = yes
tlsbindaddr = 0.0.0.0:8089
tlscertfile = /etc/asterisk/keys/asterisk.crt
tlsprivatekey = /etc/asterisk/keys/asterisk.key
Notes:
- Create self-signed certs for testing:
cd /etc/asterisk/keys
ast_tls_cert -C yourdomain.com -O "Asterisk" -d /etc/asterisk/keys
Port 8089 (TLS) is used for secure WebSocket (wss://) signaling in WebRTC.
🔑 3. Enable ARI (REST Interface)
File: /etc/asterisk/ari.conf
[general]
enabled = yes
pretty = yes
allowed_origins = http://localhost:3000, https://myapp.example.com
[ariuser]
type = user
read_only = no
password = strongpassword
Notes:
allowed_originsdefines which web apps can connect (CORS).- Credentials here are used by your Node.js app.
📡 4. Enable AMI (Manager Interface)
File: /etc/asterisk/manager.conf
[general]
enabled = yes
webenabled = yes
port = 5038
bindaddr = 127.0.0.1 ; restrict to localhost for security
[amiuser]
secret = amisecret
read = system,call,log,verbose,command,agent,user
write = system,call,log,verbose,command,agent,user
Notes:
- AMI is optional, mainly used for monitoring and legacy automation.
- Limit AMI access to localhost or secure network only.
5. Configure SIP & WebRTC Endpoints (PJSIP)
File: /etc/asterisk/pjsip.conf
[global]
type = global
user_agent = MyAsteriskPBX/20.0
; TRANSPORTS
[transport-udp]
type = transport
protocol = udp
bind = 0.0.0.0:5060
[transport-wss]
type = transport
protocol = wss
bind = 0.0.0.0:8089
; === WebRTC Client (1000) ===
[1000_auth]
type = auth
auth_type = userpass
username = 1000
password = 1000pass
[1000_aor]
type = aor
max_contacts = 1
[1000_endpoint]
type = endpoint
transport = transport-wss
context = webrtc-context
disallow = all
allow = opus,ulaw,alaw
ice_support = yes
rtcp_mux = yes
rtp_symmetric = yes
media_use_received_transport = yes
dtls_auto_generate_cert = yes
dtls_setup = actpass
aors = 1000_aor
auth = 1000_auth
direct_media = no
; === SIP Phones (2000 & 2001) ===
[2000_auth]
type = auth
auth_type = userpass
username = 2000
password = 2000pass
[2000_aor]
type = aor
max_contacts = 2
[2000_endpoint]
type = endpoint
transport = transport-udp
context = internal
disallow = all
allow = ulaw,alaw
aors = 2000_aor
auth = 2000_auth
direct_media = no
[2001_auth]
type = auth
auth_type = userpass
username = 2001
password = 2001pass
[2001_aor]
type = aor
max_contacts = 2
[2001_endpoint]
type = endpoint
transport = transport-udp
context = internal
disallow = all
allow = ulaw,alaw
aors = 2001_aor
auth = 2001_auth
direct_media = no
Notes:
transport-wssallows WebRTC clients overwss://.- Codecs
opus,ulaw, andalawensure broad compatibility. - Each endpoint maps to a specific
contextin your dialplan
6. Dialplan Configuration
File: /etc/asterisk/extensions.conf
[internal]
exten => 2000,1,NoOp(2000 Calling 2001)
same => n,Dial(PJSIP/2001,20)
same => n,Hangup()
exten => 2001,1,NoOp(2001 Calling 2000)
same => n,Dial(PJSIP/2000,20)
same => n,Hangup()
; Route call into ARI app
exten => 4000,1,NoOp(SIP phone enters ARI)
same => n,Answer()
same => n,Stasis(my_app)
same => n,Hangup()
[webrtc-context]
exten => 3000,1,NoOp(WebRTC call into ARI)
same => n,Stasis(my_app)
same => n,Hangup()
Explanation:SIP phones can call each other on 2000 and 2001.Dialing 4000 or 3000 routes the call into the ARI app my_app.💻 7. Node.js ARI Application ExampleFile: app.js
'use strict';
const ari = require('ari-client');
const url = 'http://localhost:8088';
const user = 'ariuser';
const pass = 'strongpassword';
ari.connect(url, user, pass, clientLoaded);
function clientLoaded(err, client) {
if (err) throw err;
client.on('StasisStart', (event, channel) => {
console.log(`Channel ${channel.name} entered Stasis`);
channel.answer()
.then(() => channel.play({ media: 'sound:demo-congrats' }))
.then(() => channel.hangup())
.catch(console.error);
});
client.start('my_app');
}
Run the app
npm init -y
npm install ari-client
node app.js
Test:
- From your SIP/WebRTC client, dial
3000or4000. - The Node.js app answers, plays “demo-congrats”, then hangs up.
🔐 8. Security Tips
- Use strong passwords for ARI/AMI/PJSIP.
- Restrict network access (use
127.0.0.1where possible). - Enable TLS for WebRTC/WSS.
- Use firewalls or iptables to restrict ports.
- For production, use Nginx as a reverse proxy for ARI/WebRTC signaling.
🚀 9. Verify Setup
Run the following in Asterisk CLI:
| Component | Purpose | Config File |
|---|---|---|
| HTTP / WebSocket | REST + WebRTC Transport | /etc/asterisk/http.conf |
| ARI | Node.js REST Control | /etc/asterisk/ari.conf |
| AMI | Legacy Manager Interface | /etc/asterisk/manager.conf |
| PJSIP | SIP & WebRTC Endpoints | /etc/asterisk/pjsip.conf |
| Dialplan | Call Logic & Routing | /etc/asterisk/extensions.conf |
| Node.js App | Call Control via ARI | app.js |





