Sample code for 30+ languages & platforms
Rust Requires Chilkat v11.0.0+

Check message delivery status with Twilio

See more Twilio Examples

Fetch an outbound SMS or MMS using the Message SID returned by a live send. A queued message is waiting to be sent. A sent message has been accepted by the upstream carrier. Delivered means Twilio received delivery confirmation. Some routes provide no final delivery receipt.

Read the current status once per lookup. For failed or undelivered messages, display the available delivery error code and text for troubleshooting. A missing message or an HTTP authentication error is a separate result from a delivery failure.

Twilio documentation

Chilkat Rust Downloads

Rust
let mut success = false;

// Assumes Chilkat is unlocked. See Global Unlock Sample.
// Load an API key for the Twilio account from private application configuration.
let http = chilkat::Http::new();
http.set_require_ssl_cert_verify(true);
http.set_basic_auth(true);
http.set_login("YOUR_API_KEY_SID");
http.set_password("YOUR_API_KEY_SECRET");

let url = chilkat::StringBuilder::new();
let _ = url.append("https://api.twilio.com/2010-04-01/Accounts/");
let _ = url.append("YOUR_ACCOUNT_SID");
let _ = url.append("/Messages");
let _ = url.append("/");
let _ = url.append("YOUR_MESSAGE_SID");
let _ = url.append(".json");
let resp = chilkat::HttpResponse::new();
let reply = chilkat::JsonObject::new();

success = http.http_no_body("GET", &url.get_as_string().unwrap_or_default(), &resp).is_ok();
if resp.status_code() == 0 {
    println!("No HTTP response from Twilio.");
    return;
}

let parsed = reply.load(&resp.body_str()).is_ok();
if (!success) || (resp.status_code() != 200) {
    println!("Twilio returned HTTP {}", resp.status_code());
    if (parsed) && (reply.json_type_of("code") == 2) {
        println!("Twilio error: {}  {}", reply.int_of("code"), reply.string_of("message").unwrap_or_default());
    }

    return;
}

if !parsed {
    println!("Expected a JSON response from Twilio.");
    return;
}

if reply.json_type_of("status") != 1 {
    println!("Message status missing from response.");
    return;
}

println!("Delivery status: {}", reply.string_of("status").unwrap_or_default());
if (reply.string_of_equals("status", "failed", true)) || (reply.string_of_equals("status", "undelivered", true)) {
    if reply.json_type_of("error_code") == 2 {
        println!("Delivery error code: {}", reply.int_of("error_code"));
    }

    if reply.json_type_of("error_message") == 1 {
        println!("{}", reply.string_of("error_message").unwrap_or_default());
    }

}