Skip to content

jBernavaPrah/asterisk-ari-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Asterisk ARI Client

CI License License: MIT Version Docs

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.

Features

  • 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.

Installation

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

Usage

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.

Configuration

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

Contributing

Contributions are welcome! If you'd like to contribute to this project, please follow these steps:

  1. Fork the repository.
  2. Create a new branch: git checkout -b my-feature-branch.
  3. Make your changes and commit them: git commit -m 'Add some feature'.
  4. Push to the branch: git push origin my-feature-branch.
  5. Submit a pull request.

Before submitting, ensure your code follows the project’s coding standards and passes all tests.

Development

Running Tests

To run the tests, use:

cargo test

Linting

Ensure your code adheres to the Rust style guide by running:

cargo fmt -- --check && cargo clippy --all-targets --all-features -- -D warnings

Roadmap

  • Add more tests.
  • Add more examples and documentation.

Issues and Feedback

If you encounter any issues, please create a new issue. Feedback and feature requests are always appreciated!

License

This project is licensed under either of the following licenses, at your option:

For more information, see the LICENSE-APACHE and LICENSE-MIT files.

Acknowledgments

Special thanks to the Asterisk community for creating such a powerful telephony platform.

About

No description, website, or topics provided.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages