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

twilio-async

Twilio API & TwiML 的异步且易用的包装器

7 个版本 (4 个重大更新)

0.5.0 2021 年 9 月 16 日
0.4.1 2020 年 3 月 22 日
0.3.0 2020 年 3 月 22 日
0.2.0 2019 年 2 月 2 日
0.1.1-beta2018 年 6 月 30 日

#2 in #twilio

Download history 1102/week @ 2024-04-23 858/week @ 2024-04-30 1004/week @ 2024-05-07 669/week @ 2024-05-14 797/week @ 2024-05-21 811/week @ 2024-05-28 847/week @ 2024-06-04 728/week @ 2024-06-11 656/week @ 2024-06-18 460/week @ 2024-06-25 716/week @ 2024-07-02 771/week @ 2024-07-09 781/week @ 2024-07-16 926/week @ 2024-07-23 670/week @ 2024-07-30 814/week @ 2024-08-06

每月 3,336 次下载

MIT 许可证

55KB
1.5K SLoC

twilio-async

示例用法

Twilio API & TwiML 的异步且易用的包装器。

所有类型都可以运行 run() 或类似的函数。它们返回一个实现了 Deserialize 的值。

examples/ 目录包含最新的工作示例代码。

消息


#[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?;
}

通话

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());

贡献

有关会议/录音的代码未经过测试。

TwiML 的工作已完成,并有一些测试覆盖率。

欢迎 PR 和建议。

依赖项

~8–19MB
~294K SLoC