chan_websocket) — enabling real-time bidirectional audio streaming for AI-powered voice conversations.
Both transports follow the same two-phase flow: an HTTP webhook registers the call, then a media connection (TCP or WebSocket) carries the audio. Choose the transport that fits your Asterisk version and network topology.
Transport Comparison
Architecture Overview
Both transports share the same backend pipeline. The only difference is the Streamer layer that bridges the media connection to the AI pipeline.Two-Phase Call Setup
Every Asterisk call (inbound or outbound, AudioSocket or WebSocket) follows this pattern:- Phase 1 — Webhook: An HTTP request registers the call and gets a
contextId - Phase 2 — Media: A transport connection (TCP or WebSocket) streams audio using that
contextId
Prerequisites
Asterisk Server
Asterisk 16+ (AudioSocket) or 20+ (WebSocket) with the required module loaded
Rapida Account
Active Rapida account with an API key (
rpd-xxx)Voice Assistant
A configured Rapida voice assistant with phone deployment enabled
Network Access
TCP 4573 (AudioSocket) or HTTPS 443 (WebSocket) to Rapida
For outbound calls, you also need Asterisk ARI enabled with credentials stored in a Rapida vault credential.
Quick Start — Inbound Calls
Choose your transport and follow the matching setup:Inbound Call Flow — Detailed
Sequence Diagram
What Happens at Each Step
Outbound Call Flow — Detailed
Outbound calls are initiated via the Rapida SDK (gRPCCreatePhoneCall RPC) or REST API. Rapida uses Asterisk’s ARI (Asterisk REST Interface) to originate the call.
Prerequisites for Outbound
1
Enable ARI on Asterisk
2
Create Vault Credential in Rapida
In the Rapida dashboard, go to Credentials → Create Credential and select Asterisk. Provide:
3
Configure Outbound Dialplan
ARI can originate calls in two modes. Choose one:
- Stasis App Mode (Recommended)
- Dialplan Mode
ARI originates the channel directly into a Stasis application — no dialplan needed for the outbound leg. The channel is handled programmatically.Rapida sends:
POST /ari/channels?endpoint=PJSIP/+15551234567&app=rapida4
Assign Credential to Phone Deployment
In the assistant’s Phone Deployment, select the Asterisk vault credential and configure:
Outbound Sequence Diagram
SDK Code Examples (Outbound)
- Python
- Node.js
- Go
- cURL
AudioSocket Protocol Reference
Frame Format
Each frame has a 3-byte header followed by a variable-length payload:Frame Types
Audio Format
Rapida handles all resampling and codec conversion transparently.
Status Callbacks
Rapida sends status updates to Asterisk via ARI events. You can also configure a webhook on the assistant to receive call lifecycle events.Event Callback URL
Event Types
Credential Configuration
Vault Credential Fields
When creating an Asterisk credential in the Rapida vault, provide:Phone Deployment Options
These options are configured on the assistant’s phone deployment:Full Configuration Examples
Example 1: Inbound Only (AudioSocket)
Simplest setup — no ARI needed, no vault credential required for inbound-only.- Asterisk Config
- Network Requirements
Example 2: Inbound Only (WebSocket)
No firewall port needed beyond HTTPS — ideal for cloud-hosted Asterisk.Example 3: Inbound + Outbound (Full Setup)
Complete setup with ARI for outbound calls and AudioSocket for media.- extensions.conf
- ari.conf
- http.conf
- Rapida Vault Credential
- Deployment Options
- Network Requirements
Example 4: WebSocket-Only (Inbound + Outbound)
Zero custom ports — everything runs over HTTPS.- extensions.conf
- Rapida Deployment Options
Call Lifecycle
State Machine
Captured Metrics
Each call automatically records:Troubleshooting
Connection Refused (AudioSocket)
Connection Refused (AudioSocket)
Symptoms:
AudioSocket() returns immediately, no audioChecklist:- Verify Rapida host is reachable:
nc -zv socket-01.in.rapida.ai 4573 - Check firewall allows TCP 4573 outbound
- Ensure
res_audiosocket.sois loaded - Verify the contextId (token) is non-empty in the dialplan
WebSocket Connection Failed
WebSocket Connection Failed
Symptoms:
WebSocket() fails, no audioChecklist:- Verify WSS URL is correct:
wss://websocket-01.in.rapida.ai/v1/talk/asterisk/ctx/{contextId}?x-api-key={your-api-key} - Ensure
chan_websocket.sois loaded - Check TLS certificate trust on the Asterisk server
- Verify Asterisk version is 20+ for
chan_websocket
Call Context Not Found
Call Context Not Found
Symptoms: Transport connects but immediately drops with “call context not found”Checklist:
- Context ID expires after 5 minutes — ensure fast connection after webhook
- Each contextId is single-use (atomically deleted on first connection)
- Don’t reuse contextIds across calls
- Verify the webhook returned a valid contextId (not an error message)
No Audio / One-Way Audio (AudioSocket)
No Audio / One-Way Audio (AudioSocket)
Symptoms: AI speaks but doesn’t hear, or vice versaChecklist:
- Set
CHANNEL(audioreadformat)=slinandCHANNEL(audiowriteformat)=slin - Verify
res_audiosocketmodule is loaded - Check Asterisk timing:
asterisk -rx "timing test"
Choppy Audio / Delays
Choppy Audio / Delays
Symptoms: Audio artifacts, long pausesChecklist:
- Check network latency to Rapida:
ping websocket-01.in.rapida.ai(target < 100ms) - Verify no packet loss on the path
- For WebSocket: ensure no proxy is buffering WebSocket frames
- Reduce network hops if possible
ARI Outbound Call Fails
ARI Outbound Call Fails
Symptoms: SDK call returns error, no ring on customer phoneChecklist:
- Verify ARI is enabled:
asterisk -rx "http show status" - Check ARI credentials in vault:
ari_url,ari_user,ari_password - Verify endpoint format:
PJSIP/trunk/numberorPJSIP/number - Check ARI URL is reachable from Rapida: must not be behind NAT without port forwarding
- Review Asterisk CLI:
asterisk -rvvvfor ARI request logs
RAPIDA_CONTEXT_ID Empty in Outbound Dialplan
RAPIDA_CONTEXT_ID Empty in Outbound Dialplan
Symptoms: Outbound call connects but AudioSocket/WebSocket has no contextChecklist:
- Verify ARI channel variables are configured:
{"variables": {"RAPIDA_CONTEXT_ID": "..."}} - Check the dialplan references
${RAPIDA_CONTEXT_ID}(exact case) - Verify deployment options include
contextandextension
Debug Commands
High Availability
Multi-Node Deployment
Dialplan with failover (AudioSocket):API Reference
Inbound Webhook
Response: Plain text
contextId (UUID)
WebSocket Media Endpoint
Status Callback
type field.
Related Resources
Voice Deployment Options
Overview of all voice deployment channels
Create an Assistant
Build your voice AI assistant
Webhooks
Configure event notifications
API Reference
Call API documentation