| Crates.io | asterisk-ari |
| lib.rs | asterisk-ari |
| version | 0.3.0 |
| created_at | 2025-03-08 09:24:08.369005+00 |
| updated_at | 2025-03-10 19:01:12.557224+00 |
| description | Asterisk ARI client |
| homepage | |
| repository | https://github.com/jBernavaPrah/asterisk-ari-rs |
| max_upload_size | |
| id | 1584248 |
| size | 252,352 |
A simple yet powerful library for managing the Asterisk ARI (Asterisk REST Interface). This library implements all Asterisk REST APIs and WebSocket events documented in the ARI API Documentation.
To use this library, add the following line to your Cargo.toml file:
[dependencies]
asterisk-ari = "x.y.z" # Replace x.y.z with the latest version
Here's a basic example of how to use the library:
First spin the Asterisk server with ARI & HTTP enabled, or use the dockerized example. See examples/asterisk for more details.)
use asterisk_ari::apis::channels;
use asterisk_ari::AriClient;
use asterisk_ari::Config;
use asterisk_ari::Result;
use tracing::info;
#[tokio::main]
async fn main() -> Result<()> {
tracing_subscriber::fmt()
.with_max_level(tracing::Level::DEBUG)
.init();
let config = Config::new("http://localhost:8088", "asterisk", "asterisk");
let mut client = AriClient::with_config(config);
client.on_stasis_start(|client, event| async move {
println!("Handling StasisStart event: {:?}", event);
client
.channels()
.answer(&event.data.channel.id)
.await
.unwrap();
client
.channels()
.play(channels::params::PlayRequest::new(
&event.data.channel.id,
"sound:tt-monkeys",
))
.await
.unwrap();
});
info!("Applications: {:?}", client.applications().list().await?);
info!("Ping: {:?}", client.asterisk().ping().await?);
info!("Info: {:?}", client.asterisk().info().await?);
let _client = client.clone();
tokio::spawn(async move {
_client.start("my-application".to_string()).await.unwrap();
});
tokio::time::sleep(std::time::Duration::from_secs(30)).await;
info!("Stopping client");
client.stop();
info!("Await client to stop");
tokio::time::sleep(std::time::Duration::from_secs(4)).await;
Ok(())
}
For detailed usage and API documentation, visit the docs.
Ensure that your Asterisk instance is configured to enable ARI.
Update your ari.conf file with the appropriate settings, example:
[general]
enabled = yes
pretty = yes ; not mandatory.
[asterisk]
type = user
read_only = no
password = asterisk
Contributions are welcome! If you'd like to contribute to this project, please follow these steps:
git checkout -b my-feature-branch.git commit -m 'Add some feature'.git push origin my-feature-branch.Before submitting, ensure your code follows the project’s coding standards and passes all tests.
To run the tests, use:
cargo test
Ensure your code adheres to the Rust style guide by running:
cargo fmt -- --check && cargo clippy --all-targets --all-features -- -D warnings
If you encounter any issues, please create a new issue. Feedback and feature requests are always appreciated!
This project is licensed under either of the following licenses, at your option:
For more information, see the LICENSE-APACHE and LICENSE-MIT files.
Special thanks to the Asterisk community for creating such a powerful telephony platform.