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 |
require_challenge(true) |
false | reject plaintext login fallback; recommended at every non-TLS boundary |
use AmiClient;
use ReconnectPolicy;
use Duration;
async
TLS boundary
Version 0.8 connects to AMI over plain TCP and does not claim native TLS. For
non-loopback deployments, terminate TLS in a separately managed, versioned TCP
proxy (for example a pinned stunnel or HAProxy deployment), authenticate and
authorize access at that boundary, and connect this client only to the proxy's
loopback/private listener. Set require_challenge(true) as defense in depth.
Proxy certificate verification, upgrades, and availability remain deployment
responsibilities; the library never disables certificate verification because
it does not own that TLS session.
Capabilities
- Typed actions and events for the modeled AMI surface; exact support is defined by rustdoc and the repository's Asterisk 22 protocol/live evidence
- 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, with explicitly configurable plaintext fallback
- 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.86. MIT/Apache-2.0.