Asterisk ARI Integration
Fone AI supports direct integration with Asterisk via ARI (Asterisk REST Interface), using the official streaming middleware to route audio from your Asterisk server to the AI system over WebSocket.
Requirements​
- Asterisk version 16.6 or above
- ARI enabled and configured
- Active internet connection
- Linux environment with sufficient compute resources
- Middleware app downloaded from the Asterisk ARI page
- WS_URL – Websocket Streaming URL from the Asterisk ARI page
How It Works​
- The streaming middleware is a standalone executable that runs alongside your Asterisk server.
- It acts as a bridge between Asterisk (via ARI) and the Fone AI server to stream real-time audio.
- You'll configure:
- Asterisk ARI credentials
- HTTP binding port
- AI WebSocket endpoint
Once configured, the middleware connects to the ARI WebSocket and starts streaming audio from ongoing calls.
Step 1: Configure ari.conf
​
[general]
enabled = yes
[ARI_USERNAME] ; <-- Replace with ARI Username
type = user
read_only = no
password = ARI_PASSWORD ; <-- Replace with ARI Password
password_format = plain
Step 2: Configure http.conf
​
[general]
enabled = yes
bindaddr = 0.0.0.0
bindport = HTTP_BIND_PORT ; <-- Replace with an available HTTP port (e.g., 8088)
Step 3: Configure the Middleware (config.json
)​
After downloading and unzipping the middleware zip, you’ll find:
- The executable binary
- A sample
config.json
file
Edit the config.json
as below:
{
"ari": {
"url": "http://127.0.0.1:HTTP_BIND_PORT", // <-- Replace with an available HTTP port (e.g., 8088)
"username": "ARI_USERNAME", // <-- Replace with ARI Username
"password": "ARI_PASSWORD", // <-- Replace with ARI Password
"appName": "APP_NAME" // <-- Replace with App name (e.g., foneai)
},
"rtpServer": {
"port": "7777",
"format": "slin16",
"host": "127.0.0.1",
"swap16": true,
"socketType": "udp4"
},
"asterisk": {
"packetTimestampIncrement": 160,
"rtpPayloadType": 11
},
"ai": {
"serverUrl": "WS_URL" // <-- Replace with Websocket URL
},
"log": {
"logLevel": "info"
}
}
🔧 Replace placeholders like
HTTP_BIND_PORT
,ARI_USERNAME
,ARI_PASSWORD
,WS_URL
, andAPP_NAME
with your actual values.
Step 4: Configure the Dialplan (extensions.conf
)​
exten => _X.,1,NoOp()
same => n,Set(campaign=${EXTEN})
same => n,Set(apiKey=API_KEY) ; <-- Replace with your API key from the console
;same => n,Set(custom={"key1": "value1"}) ; Optional: pass custom JSON payload
same => n,Answer()
same => n,Stasis(APP_NAME) ; <-- Replace with the appName in config.json
; --- Extra Post-ARI Logic for transfer variables ---
same => n,NoOp(SessionId after ARI: ${sessionId})
same => n,Set(transferContextSafe=${IF($["${transferContext}" != ""]?${transferContext}:'default')})
same => n,NoOp(Transfer Context after ARI: ${transferContextSafe})
same => n,NoOp(Transfer Extension after ARI: ${transferExtension})
; --- Perform the transfer ---
; same => n,GotoIf($["${transferContextSafe}" != ""]?${transferContextSafe},${transferExtension},1)
; same => n,NoOp(Transferring to default context with extension ${transferExtension})
; same => n,Goto(default,${transferExtension},1)
; --- Hangup the call ---
; Remember: do not hang up if transferring
; same => n,Hangup()
🔧 The sessionId can be used to query the session log and transcript of the particular session using the official API. transferContext and transferExtension come from the directory records given in the console.
Step 5: Run the Middleware​
Once everything is configured and Asterisk is reloaded:
./asterisk-ari-client ./config.json
If successful, the app will log:
Successfully connected to the ARI websocket
The streaming middleware needs to run continuously alongside Asterisk. You can run it in the background using different methods:
-
Quick method with & ./asterisk-ari-client ./config.json &
-
Better method with nohup
nohup ./asterisk-ari-client ./config.json > middleware.log 2>&1 &
- Using screen (recommended for interactive sessions)
screen -S ai-middleware
./asterisk-ari-client ./config.json
Detach with Ctrl+A, D and reattach anytime with: screen -r ai-middleware
Result​
You can now route calls directly to Fone AI from any Asterisk extension by dialing into a context that invokes the Stasis(APP_NAME)
application. The audio will be streamed in real time to the Fone AI platform for processing.
✅ You can now use this setup to trigger AI-based bot conversations without SIP.