Skip to main content
Asterisk integrates with Rapida using two transport methods. Choose based on your Asterisk version and network topology.

Transport Comparison

AudioSocketWebSocket
Asterisk version16+20+
Moduleres_audiosocketchan_websocket
ProtocolRaw TCP port 4573WSS (standard HTTPS port)
FirewallTCP 4573 must be open outboundStandard HTTPS only
Audio codecSLIN 16-bit 8kHzμ-law 8kHz
LatencyLowestSlightly higher
TLSNoYes (native WSS)
Best forLAN / private networkCloud / NAT traversal

AudioSocket

1

Configure env vars

# docker/assistant-api/.assistant.env
PUBLIC_ASSISTANT_HOST=your-hostname.com
AUDIOSOCKET__HOST=0.0.0.0
AUDIOSOCKET__PORT=4573
assistant-api binds a TCP AudioSocket server on AUDIOSOCKET__PORT at startup.
2

Verify the module is loaded

asterisk -rx "module show like audiosocket"
# Expected: res_audiosocket.so
If not loaded, add to /etc/asterisk/modules.conf:
[modules]
load = res_audiosocket.so
3

Configure the dialplan

# /etc/asterisk/extensions.conf

[globals]
RAPIDA_API_KEY = rpd-xxx-your-api-key
RAPIDA_HOST    = {PUBLIC_ASSISTANT_HOST}   ; HTTP/webhook host (HTTPS)
RAPIDA_AS_HOST = {PUBLIC_ASSISTANT_HOST}   ; AudioSocket TCP host
RAPIDA_PORT    = 4573
ASSISTANT_ID   = 123456789

[rapida-inbound]
exten => _X.,1,Answer()
 same => n,Set(CHANNEL(audioreadformat)=slin)
 same => n,Set(CHANNEL(audiowriteformat)=slin)
 ; Phase 1 — register the call and get a contextId
 same => n,Set(CTX=${CURL(https://${RAPIDA_HOST}/v1/talk/asterisk/call/${ASSISTANT_ID}?from=${CALLERID(num)}&x-api-key=${RAPIDA_API_KEY})})
 same => n,GotoIf($["${CTX}" = ""]?error)
 ; Phase 2 — open AudioSocket TCP using contextId as UUID
 same => n,AudioSocket(${CTX},${RAPIDA_AS_HOST}:${RAPIDA_PORT})
 same => n,Hangup()
 same => n(error),Playback(an-error-has-occurred)
 same => n,Hangup()
CHANNEL(audioreadformat)=slin and CHANNEL(audiowriteformat)=slin are required. AudioSocket expects SLIN (signed linear PCM) — without this Asterisk will not convert the audio format.
4

Reload and test

asterisk -rx "dialplan reload"

# Verify connectivity
nc -zv {RAPIDA_AS_HOST} 4573    # AudioSocket TCP
curl -I https://{RAPIDA_HOST}   # HTTPS webhook

Outbound via ARI (AudioSocket)

For outbound calls, Rapida uses Asterisk’s ARI to originate the channel. The RAPIDA_CONTEXT_ID channel variable is injected by Rapida ARI automatically:
; /etc/asterisk/extensions.conf
[rapida-outbound]
exten => s,1,Set(CHANNEL(audioreadformat)=slin)
 same => n,Set(CHANNEL(audiowriteformat)=slin)
 ; RAPIDA_CONTEXT_ID is set by Rapida ARI when originating the call
 same => n,AudioSocket(${RAPIDA_CONTEXT_ID},${RAPIDA_AS_HOST}:${RAPIDA_PORT})
 same => n,Hangup()
ARI vault credential keys (store in Rapida vault, provider type Asterisk):
KeyRequiredDescription
ari_urlYesARI base URL, e.g. http://asterisk.local:8088
ari_userYesARI username
ari_passwordYesARI password
endpoint_technologyNoChannel technology — default PJSIP
trunkNoSIP trunk name — builds PJSIP/trunk/number

WebSocket

1

Configure env vars

# docker/assistant-api/.assistant.env
PUBLIC_ASSISTANT_HOST=your-hostname.com
# No AudioSocket port needed — WebSocket uses standard HTTPS
2

Verify the module is loaded

asterisk -rx "module show like chan_websocket"
# Expected: chan_websocket.so — requires Asterisk 20+
If not loaded, add to /etc/asterisk/modules.conf:
[modules]
load = chan_websocket.so
3

Configure the dialplan

# /etc/asterisk/extensions.conf

[globals]
RAPIDA_API_KEY = rpd-xxx-your-api-key
RAPIDA_HOST    = {PUBLIC_ASSISTANT_HOST}
ASSISTANT_ID   = 123456789

[rapida-inbound-ws]
exten => _X.,1,Answer()
 ; Phase 1 — register the call and get a contextId
 same => n,Set(CTX=${CURL(https://${RAPIDA_HOST}/v1/talk/asterisk/call/${ASSISTANT_ID}?from=${CALLERID(num)}&x-api-key=${RAPIDA_API_KEY})})
 same => n,GotoIf($["${CTX}" = ""]?error)
 ; Phase 2 — open WSS connection with contextId in the URL path
 same => n,WebSocket(wss://${RAPIDA_HOST}/v1/talk/asterisk/ctx/${CTX})
 same => n,Hangup()
 same => n(error),Playback(an-error-has-occurred)
 same => n,Hangup()
4

Reload and test

asterisk -rx "dialplan reload"
curl -I https://{RAPIDA_HOST}

Outbound via ARI (WebSocket)

; /etc/asterisk/extensions.conf
[rapida-outbound-ws]
exten => s,1,NoOp(Outbound WebSocket call)
 ; RAPIDA_CONTEXT_ID is set by Rapida ARI
 same => n,WebSocket(wss://${RAPIDA_HOST}/v1/talk/asterisk/ctx/${RAPIDA_CONTEXT_ID})
 same => n,Hangup()
Same ARI vault credentials apply — see the AudioSocket section.

Production URLs

For Rapida SaaS:
VariableValue
RAPIDA_HOST (HTTP/WebSocket)websocket-01.in.rapida.ai
RAPIDA_AS_HOST (AudioSocket TCP)socket-01.in.rapida.ai
RAPIDA_PORT4573