asterisk-rs-ami
Async Rust client for the Asterisk Manager Interface (AMI). Monitor calls, originate channels, manage queues, and react to real-time events over TCP.
Quick Start
use ;
use StatusAction;
async
Call Tracker
call_tracker() correlates DialBegin, DialEnd, Hangup, and bridge events
into a single CompletedCall record per channel pair. The record includes
start/end timestamps, duration, hangup cause, and the ordered event list.
use AmiClient;
use Duration;
async
Builder Options
| Option | Default | Description |
|---|---|---|
host(h) |
"127.0.0.1" |
AMI host |
port(p) |
5038 |
AMI TCP port |
credentials(u, p) |
required | AMI login |
timeout(d) |
30 s | per-action response timeout |
ping_interval(d) |
disabled | keep-alive Ping cadence; set to detect dead connections |
reconnect(policy) |
exponential backoff | ReconnectPolicy::exponential(min, max) or ::none() |
event_capacity(n) |
1024 | broadcast channel depth; drop events when full if subscribers are slow |
use AmiClient;
use ReconnectPolicy;
use Duration;
async
Capabilities
- Typed events and actions covering the full Asterisk 23 AMI surface
- Filtered subscriptions -- receive only events you care about
- Event-collecting actions --
send_collecting()gathers multi-event responses - Call tracking with
CallTracker-- correlates events intoCompletedCallrecords - MD5 challenge-response and plaintext authentication
- Automatic reconnection with re-authentication on every reconnect
- Command output capture for
Response: Followsresponses - Channel variable extraction --
ChanVariable(name)headers parsed into a dedicated map - Keep-alive pings with configurable interval -- detects dead connections without sending traffic
- Connection state monitoring via
client.connection_state() - Domain types for hangup causes, channel states, device states, and more
#[non_exhaustive]enums -- new variants won't break your code- Configurable timeouts, backoff, ping interval, and event buffer size
Documentation
Part of asterisk-rs. MSRV 1.83. MIT/Apache-2.0.