asterisk-rs-agi 0.2.0

Async Rust FastAGI server for Asterisk Gateway Interface
Documentation

asterisk-rs-agi

crates.io docs.rs license

Async Rust FastAGI server for Asterisk Gateway Interface.

AGI allows external programs to control Asterisk dialplan execution over a TCP connection (FastAGI, port 4573). This crate provides a typed, async server built on Tokio that dispatches incoming AGI sessions to a user-defined handler.

Features:

  • AgiHandler trait using async fn in trait (RPITIT)
  • 47 typed AGI commands (answer, stream_file, get_data, hangup, etc.)
  • AgiChannel for sending commands and reading responses within a session
  • AgiRequest with parsed agi_* environment variables
  • Configurable concurrency via max_connections

Install

cargo add asterisk-rs-agi

Usage

use asterisk_rs_agi::{AgiChannel, AgiHandler, AgiRequest, AgiServer};

struct MyHandler;

impl AgiHandler for MyHandler {
    async fn handle(
        &self,
        request: AgiRequest,
        mut channel: AgiChannel,
    ) -> asterisk_rs_agi::error::Result<()> {
        channel.answer().await?;
        channel.stream_file("hello-world", "#").await?;
        channel.hangup(None).await?;
        Ok(())
    }
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let server = AgiServer::builder()
        .bind("0.0.0.0:4573")
        .handler(MyHandler)
        .build()
        .await?;

    server.run().await?;
    Ok(())
}

See examples/agi_server.rs for a more complete example.

Part of asterisk-rs

This crate is part of the asterisk-rs workspace.

MSRV

The minimum supported Rust version is 1.83.

License

Licensed under either of Apache License, Version 2.0 or MIT License at your option.