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 = OriginateParams ;
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
.build.await?;
server.run.await?;
Media Channel
MediaChannel provides raw audio exchange via chan_websocket. Use it to
stream audio directly to/from an Asterisk channel without a separate media
server.
use MediaChannel;
let media = connect.await?;
media.answer.await?;
while let Some = media.recv_audio.await?
Capabilities
- REST client and WebSocket listener covering the full Asterisk 23 ARI surface
- 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.83. MIT/Apache-2.0.