#twilio #async #hyper #api-bindings #twiml

twilio-async

An async and ergonomic wrapper around Twilio API & TwiML

7 releases (4 breaking)

0.5.0 Sep 16, 2021
0.4.1 Mar 22, 2020
0.3.0 Mar 22, 2020
0.2.0 Feb 2, 2019
0.1.1-beta Jun 30, 2018

#1803 in Web programming

Download history 393/week @ 2023-11-18 1017/week @ 2023-11-25 966/week @ 2023-12-02 924/week @ 2023-12-09 579/week @ 2023-12-16 27/week @ 2023-12-23 429/week @ 2023-12-30 934/week @ 2024-01-06 498/week @ 2024-01-13 655/week @ 2024-01-20 918/week @ 2024-01-27 799/week @ 2024-02-03 623/week @ 2024-02-10 384/week @ 2024-02-17 949/week @ 2024-02-24 1170/week @ 2024-03-02

3,228 downloads per month

MIT license

55KB
1.5K SLoC

twilio-async

Example Usage

An async and ergonomic wrapper around Twilio API & TwiML.

All types can run run() or a similar function. They return a value that implements Deserialize.

The examples/ dir has up to date working example code.

Messages:


#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let twilio = Twilio::new(account_sid, token)?;
    // sending a message
    twilio.send_msg("from", "to", "Hello World").run().await?;
    // sending a body-less message with media
    twilio
        .send_msg("from", "to", "body")
        .media("http://i0.kym-cdn.com/photos/images/newsfeed/000/377/946/0b9.jpg")
        .run().await?;
    // get details about a message
    twilio.msg("messagesid").run().await?;
    // redact a message
    twilio.msg("messagesid").redact().await?;
    // get a msg media url
    twilio.msg("messagesid").media().await?;
    // delete a msg
    twilio.msg("messagesid").delete().await?;
    // get all messages
    twilio.msgs().run().await?;
    // get all messages between some time
    twilio.msgs().between("start date", "end date").run().await?;
    // get all messages on a specific date
    twilio.msgs().on("date").run().await?;
}

Calls:

let twilio = Twilio::new(env::var("TWILIO_SID")?, env::var("TWILIO_TOKEN")?)?;
let (status, resp) = twilio
    .call("from", "to", "http://demo.twilio.com/docs/voice.xml")
    .run().await?;

Twiml:

use twilio_async::twiml::Response;

let resp = Response::new()
    .say("Hello World") // builder pattern also supports say(Say::new("Hello World").lang("de")...)
    .play("https://api.twilio.com/Cowbell.mp3")
    .build();
let s = "<Response><Say voice=\"man\" language=\"en\" loop=\"1\">Hello World</Say><Play loop=\"1\">https://api.twilio.com/Cowbell.mp3</Play></Response>";
assert_eq!(resp.unwrap(), s.to_string());

Contributing

There is untested code for conferences/recordings.

The TwiML work is complete and has some test coverage.

PRs and suggestions are welcome.

Dependencies

~8–22MB
~318K SLoC