asterisk-rs-ari
Async Rust client for the Asterisk REST Interface (ARI). Build Stasis applications with full call control over REST + WebSocket.
Quick Start
use ;
use AriConfigBuilder;
use AriEvent;
use ChannelHandle;
async
Transport Modes
ARI supports two transport modes, selected at config time.
HTTP (default) — standard REST + WebSocket for events. Works with all supported Asterisk versions.
WebSocket — REST calls are tunnelled over the same WebSocket connection as events. Requires Asterisk 22+ with the unified WebSocket ARI transport enabled.
use ;
let config = new
.host
.username
.password
.transport
.build?;
Race-Free Resource Creation
Subscribing to a channel's events after originating it creates a window where
early events (including StasisStart) can be missed. PendingChannel eliminates
that race by registering the event subscription before issuing the REST call.
use OriginateParams;
let pending = client.channel;
let params = new.app;
let = pending.originate.await?;
// events are buffered from creation — StasisStart is guaranteed captured
while let Some = events.recv.await
The same pattern applies to bridges (client.bridge()) and playbacks
(client.playback()).
Resource Handles
Handles wrap a resource ID and a cloned client reference, exposing typed methods without requiring you to construct REST paths manually.
ChannelHandle
answer(),hangup(reason)play(media_uri),record(name, format, ...)mute(direction),unmute(direction)hold(),unhold()send_dtmf(digit, ...)get_variable(name),set_variable(name, value)
BridgeHandle
add_channel(channel_id),remove_channel(channel_id)play(media_uri)start_moh(class),stop_moh()destroy()
PlaybackHandle
pause(),unpause(),restart(),stop()
RecordingHandle
stop(),pause(),unpause(),mute(),unmute(),get()
Outbound WebSocket Server
For Asterisk 22+ deployments, ARI can connect outbound to your application
instead of the reverse. AriServer listens for those incoming Asterisk
connections.
use AriServer;
let = builder
.bind
.allow_external_bind
.build.await?;
server.run.await?;
Media Channel
MediaChannel provides raw audio exchange through chan_websocket's JSON control
protocol. Asterisk defaults chan_websocket to plaintext, so create the external
media channel with ExternalMediaParams::websocket_json; it selects
encapsulation=none, transport=websocket, and transport_data=f(json).
use MediaChannel;
use ExternalMediaParams;
let params = websocket_json;
let channel = external_media.await?;
let media = connect.await?;
media.answer.await?;
while let Some = media.recv_audio.await?
Cleartext http:///ws:// is accepted by default only for loopback hosts.
Remote cleartext requires the explicit allow_insecure_remote(true) opt-in.
For private PKI, pass the PEM CA bundle with AriConfigBuilder::private_ca_pem;
the same parsed roots are applied to HTTPS, event WSS, and unified WSS. Use
MediaConnectionOptions::private_ca_pem for a media WSS connection.
Capabilities
- REST/WebSocket clients for the modeled ARI surface, with Asterisk 22 as the live-proven boundary
- Typed events with metadata (application, timestamp, asterisk_id) on every event
- Filtered subscriptions -- receive only events you care about
- Race-free resource creation with PendingChannel, PendingBridge, PendingPlayback
- Resource handles for channels, bridges, playbacks, recordings
- Dual transport modes: HTTP and unified WebSocket (Asterisk 22+)
- Outbound WebSocket server for Asterisk 22+ outbound connections
- Media channel for raw audio exchange via chan_websocket
- System management -- modules, logging, config, global variables
- URL-safe query encoding for user-provided values
- HTTP connect and request timeouts
- Automatic WebSocket reconnection
#[non_exhaustive]enums -- new variants won't break your code
Documentation
Part of asterisk-rs. MSRV 1.86. MIT/Apache-2.0.