Skip to content

deadcode-walker/asterisk-rs

asterisk-rs

crates.io docs.rs CI MSRV License

Async Rust client for Asterisk PBX. Originate calls, handle events, control channels, bridges, queues, and recordings across all three Asterisk interfaces.

  • AMI -- monitor and control Asterisk over TCP. Typed events, actions, automatic reconnection, MD5 auth.
  • AGI -- run dialplan logic from your Rust service. FastAGI server with typed async commands.
  • ARI -- full call control via REST + WebSocket. Resource handles, typed events with metadata.

Example

use asterisk_rs::ami::{AmiClient, AmiEvent};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = AmiClient::builder()
        .host("10.0.0.1")
        .credentials("admin", "secret")
        .build()
        .await?;

    // subscribe to hangup events only
    let mut hangups = client.subscribe_filtered(|e| {
        e.event_name() == "Hangup"
    });

    while let Some(event) = hangups.recv().await {
        if let AmiEvent::Hangup { channel, cause, cause_txt, .. } = event {
            println!("{channel} hung up: {cause} ({cause_txt})");
        }
    }

    Ok(())
}

Install

[dependencies]
asterisk-rs = "0.2"

Or pick individual protocols:

[dependencies]
asterisk-rs-ami = "0.2"   # AMI only
asterisk-rs-agi = "0.1"   # AGI only
asterisk-rs-ari = "0.2"   # ARI only

Capabilities

  • Typed actions, events, and commands for the full Asterisk 23 protocol surface
  • Filtered event subscriptions -- receive only what you need
  • Event-collecting actions -- send_collecting() gathers multi-event responses (Status, QueueStatus, etc.)
  • Automatic reconnection with exponential backoff, jitter, and re-authentication
  • Resource handles for ARI (ChannelHandle, BridgeHandle, PlaybackHandle, RecordingHandle)
  • Domain types for hangup causes, channel states, device states, dial statuses, and more
  • ARI event metadata (application, timestamp, asterisk_id) on every event
  • AMI command output capture for Response: Follows
  • URL-safe query encoding, HTTP timeouts, WebSocket lifecycle management
  • #[non_exhaustive] enums -- new variants won't break your code
  • Structured logging via tracing

Protocols

Protocol Default Port Transport Use Case
AMI 5038 TCP Monitoring, call control, system management
AGI 4573 TCP Dialplan logic, IVR, call routing
ARI 8088 HTTP + WS Stasis applications, full media control

Documentation

MSRV

1.83 -- required for async fn in traits (RPITIT).

License

Licensed under either of

at your option.

About

Async Rust client for Asterisk AMI, AGI, and ARI

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors