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.
- Full implementation of Asterisk REST APIs.
- WebSocket support for handling ARI events.
- Designed for simplicity and ease of use.
- Suitable for building custom telephony applications and integrations.
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:
- Fork the repository.
- Create a new branch:
git checkout -b my-feature-branch
. - Make your changes and commit them:
git commit -m 'Add some feature'
. - Push to the branch:
git push origin my-feature-branch
. - Submit a pull request.
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
- Add more tests.
- Add more examples and documentation.
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.