Asterisk ARI Integration
Connect Talkr AI to your Asterisk PBX using the Asterisk REST Interface (ARI)
Overview
Asterisk ARI (Asterisk REST Interface) allows you to connect Talkr AI voice agents to your existing Asterisk PBX. ARI provides a WebSocket-based event model for controlling calls via Stasis applications, giving Talkr full control over call flow and audio streaming.
This guide focuses on the Talkr-specific configuration. For general Asterisk installation and administration, refer to the official Asterisk documentation.
Prerequisites
Before setting up the ARI integration, ensure you have:
- A running Asterisk instance with
chan_websocketandres_websocket_clientmodules available. Known-working setups: (a) Asterisk 22+, (b) Asterisk 20 LTS with these modules included - ARI module enabled in Asterisk
chan_websocket(WebSocket channel driver) andres_websocket_client(loadswebsocket_client.conf) enabled in your Asterisk build. Verify withasterisk -rx "module show like chan_websocket"andasterisk -rx "module show like res_websocket_client"— both should report Running.- Network connectivity between your Talkr instance and Asterisk
- Talkr AI instance running and accessible
If you compiled Asterisk from source, ensure both chan_websocket and res_websocket_client are included during the build. These modules are required for external media streaming between Asterisk and Talkr. Refer to the Asterisk build system documentation for details on enabling modules.
Asterisk Configuration
The following Asterisk configuration files need to be set up to work with Talkr. These are minimal examples focused on the Talkr integration -- refer to the Asterisk documentation for full configuration details.
Enable ARI (ari.conf)
Create an ARI user that Talkr will use to authenticate:
[general]
enabled = yes
[talkr]
type = user
read_only = no
password = your_secure_passwordThe username (section name, e.g., talkr) and password here must match the Stasis App Name and App Password you configure in Talkr.
Enable the HTTP Server (http.conf)
ARI requires the Asterisk HTTP server to be enabled:
[general]
enabled = yes
bindaddr = 0.0.0.0
bindport = 8088Configure the Stasis Dialplan (extensions.conf)
Route incoming calls to your Stasis application so Talkr can handle them:
[from-external]
exten => _X.,1,NoOp(Incoming call to ${EXTEN})
same => n,Stasis(talkr)
same => n,Hangup()Replace talkr with the app name you configured in ari.conf and in Talkr.
Configure External Media Streaming (websocket_client.conf)
Talkr uses Asterisk's external media streaming to send and receive audio over WebSocket. Configure a WebSocket client connection that points to your Talkr instance:
[talkr]
type = websocket_client
uri = wss://talkr.intelstacks.com/api/v1/telephony/ws/ari
protocols = media
tls_enabled = yes
ca_list_file = /etc/ssl/certs/ca-certificates.crttls_enabled = yes is required even though the URI scheme is wss:// — without it Asterisk will not negotiate TLS and the connection will fail. The ARI credentials (Stasis App Name and App Password) must match what you configure in the Talkr dashboard under Telephony Settings.
The section name (e.g., talkr) is the WebSocket Client Name you'll enter in the Talkr telephony configuration. This name tells Asterisk which WebSocket connection to use for external media streaming during calls.
Configure the uri as a base URL only, without a query string. During each call, Talkr asks Asterisk to create an externalMedia channel and Asterisk appends workflow_id, organization_id, and workflow_run_id through the v() transport data for that call. Opening /api/v1/telephony/ws/ari directly in a browser or with wscat can return HTTP 403 because those routing parameters are missing; that is expected and does not indicate a websocket_client.conf misconfiguration.
Talkr's external media channel uses G.711 μ-law (ulaw). Make sure any PJSIP endpoint or SIP trunk that places or receives calls through Talkr allows ulaw (e.g. allow=ulaw in the endpoint config).
Refer to the Asterisk WebSocket documentation for additional websocket_client.conf options and TLS configuration.
Apply the configuration changes
After editing any of the files above, reload the affected Asterisk modules from the Asterisk CLI (asterisk -rvvv):
ari reload # picks up ari.conf changes
dialplan reload # picks up extensions.conf changes
module reload res_websocket_client.so # picks up websocket_client.conf changesChanges to http.conf require a full Asterisk reload (core reload) or a service restart.
Configuration in Talkr
Step 1: Navigate to Telephony Settings
- Navigate to /telephony-configurations and click Add configuration
- Select Asterisk ARI as your provider
Step 2: Enter Your ARI Credentials
Configure the following fields:
| Field | Description | Example |
|---|---|---|
| ARI Endpoint URL | HTTP base URL of your Asterisk ARI server | http://asterisk.example.com:8088 |
| Stasis App Name | The ARI username configured in ari.conf | talkr |
| App Password | The ARI password configured in ari.conf | your_secure_password |
| WebSocket Client Name | The connection name from websocket_client.conf | talkr |
| From Extensions | Optional SIP extensions or trunk numbers for outbound calls | PJSIP/6001 or 6001 |
Step 3: Save and Add Extensions
- Click Save Configuration
- Open the configuration you just created and add each SIP extension that should be reachable as a phone number (e.g.
8000). For inbound, you'll assign a workflow to each extension separately — see Inbound Calling below. - Create a test workflow and initiate a test call to verify the connection.
Inbound Calling
Unlike other telephony providers that use HTTP webhooks for inbound calls, ARI delivers inbound calls as StasisStart events on the ARI WebSocket. Talkr automatically detects these events and activates the workflow assigned to the called extension.
How It Works
- An external call arrives at Asterisk and the dialplan routes it to
Stasis(talkr) - Asterisk fires a StasisStart event over the ARI WebSocket with the channel in
Ringstate and the dialed extension in the dialplan context - Talkr looks up the called extension in your telephony configuration's phone numbers, finds the assigned workflow, validates quota, and creates a workflow run
- The call is answered, bridged to an external media channel, and your voice agent workflow begins
Workflow assignment is per extension, so different extensions on the same Asterisk can route to different agents.
Setting Up Inbound Calls
Step 1: Configure the Asterisk dialplan
Ensure your dialplan routes the extensions you care about into the Stasis application. Either route a specific extension:
[from-external]
exten => 8000,1,NoOp(Incoming call to 8000)
same => n,Stasis(talkr)
same => n,Hangup()…or use a pattern that catches every extension you'll register in Talkr:
[from-external]
exten => _X.,1,NoOp(Incoming call to ${EXTEN})
same => n,Stasis(talkr)
same => n,Hangup()Replace talkr with the app name you configured in ari.conf and in Talkr.
Step 2: Add the extension as a phone number in Talkr
-
Go to /telephony-configurations and open your Asterisk ARI configuration
-
In the Phone numbers section, add a phone number whose address is the SIP extension (e.g.
8000) -
Set its Inbound workflow to the agent that should answer
-
Save
Adding the extension in Talkr doesn't change Asterisk's dialplan — that's what Step 1 is for. The Talkr entry tells the StasisStart handler which workflow to run when a call to that extension reaches the Stasis app.
Repeat Step 2 for each extension that should reach a voice agent.
Step 3: Test an inbound call
Place a call to one of the extensions you configured. You should see the assigned workflow activate and the voice agent respond.
Inbound Call Context
When an inbound call activates a workflow, the following context is available to your workflow:
| Field | Description |
|---|---|
caller_number | The caller's phone number or extension |
called_number | The dialed number or extension |
direction | Always inbound |
call_id | The Asterisk channel ID |
provider | Always ari |
Troubleshooting
Best Practices
- Keep your Asterisk instance on the same network or a low-latency connection to Talkr for optimal audio quality
- Use strong passwords for ARI authentication
- Restrict ARI access to known IP addresses using firewall rules
- Monitor Asterisk logs alongside Talkr logs when debugging call issues
- Keep Asterisk updated to the latest stable version for security and compatibility
Further Reading
- Asterisk Documentation -- official reference for all Asterisk configuration
- ARI Documentation -- detailed ARI configuration and API reference