freeswitch-esl

Crates.iofreeswitch-esl
lib.rsfreeswitch-esl
version0.1.0
sourcesrc
created_at2022-01-30 07:20:07.249938
updated_at2023-09-05 15:31:23.670538
descriptionFreeSwitch ESL implementation for Rust
homepage
repositoryhttps://github.com/KaranGauswami/freeswitch-esl.git
max_upload_size
id523931
size59,617
Karan Gauswami (KaranGauswami)

documentation

README

freeswitch-esl (WIP)

workflow Crates.io Documentation

FreeSwitch ESL implementation for Rust

Examples

Inbound Example

use freeswitch_esl::{Esl, EslError};

#[tokio::main]
async fn main() -> Result<(), EslError> {
    let addr = "localhost:8021"; // Freeswitch host
    let password = "ClueCon";
    let inbound = Esl::inbound(addr, password).await?;

    let reloadxml = inbound.api("reloadxml").await?;
    println!("reloadxml response : {:?}", reloadxml);

    let reloadxml = inbound.bgapi("reloadxml").await?;
    println!("reloadxml response : {:?}", reloadxml);

    Ok(())
}

Outbound Example

use freeswitch_esl::{Esl, EslConnection, EslError};

async fn process_call(conn: EslConnection) -> Result<(), EslError> {
    conn.answer().await?;
    conn.playback("ivr/ivr-welcome.wav").await?;
    let digit = conn
        .play_and_get_digits(
            1,
            1,
            3,
            3000,
            "#",
            "conference/conf-pin.wav",
            "conference/conf-bad-pin.wav",
        )
        .await?;
    println!("got digit {}", digit);
    conn.playback("ivr/ivr-you_entered.wav").await?;
    conn.playback(&format!("digits/{}.wav", digit)).await?;
    conn.hangup("NORMAL_CLEARING").await?;
    Ok(())
}

#[tokio::main]
async fn main() -> Result<(), EslError> {
    env_logger::init();
    let addr = "0.0.0.0:8085"; // Listening address
    let listener = Esl::outbound(addr).await?;

    loop {
        let (socket, _) = listener.accept().await?;
        tokio::spawn(async move { process_call(socket).await });
    }
}

TODO

  • support for event listener
Commit count: 96

cargo fmt