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

Clickatell One API: Send WhatsApp reply buttons

See more Clickatell Examples

Send an appointment question with Confirm and Reschedule buttons within 24 hours of the customer’s last WhatsApp message. This standalone example ends when Clickatell returns the send result. The response gives the outbound message ID. A customer’s eventual selection is a separate inbound event.

Clickatell API reference

Chilkat Rust Downloads

Rust
// Assumes Chilkat is unlocked. See Global Unlock Sample.
let http = chilkat::Http::new();
http.set_require_ssl_cert_verify(true);
// Load the key for this One API integration from your application configuration.
http.set_request_header("Authorization", "ONE_API_KEY");
http.set_request_header("Accept", "application/json");

let body = chilkat::JsonObject::new();
let _ = body.update_string("messages[0].channel", "whatsapp");
let _ = body.update_string("messages[0].to", "PHONE_NUMBER");
let _ = body.update_string("messages[0].button.body", "Can you attend your appointment tomorrow at 10:00?");
// The visible titles can be translated. Each button has a distinct application ID.
let _ = body.update_string("messages[0].button.items[0].type", "reply");
let _ = body.update_string("messages[0].button.items[0].title", "Confirm");
let _ = body.update_string("messages[0].button.items[0].postbackData", "appt-1042-confirm");
let _ = body.update_string("messages[0].button.items[1].type", "reply");
let _ = body.update_string("messages[0].button.items[1].title", "Reschedule");
let _ = body.update_string("messages[0].button.items[1].postbackData", "appt-1042-reschedule");

let resp = chilkat::HttpResponse::new();
let sent = http.http_json("POST", "https://platform.clickatell.com/v1/message", &body, "application/json", &resp).is_ok();
if resp.status_code() == 0 {
    println!("No HTTP response. Check the message report before resending.");
    return;
}

let reply = chilkat::JsonObject::new();
let parsed = reply.load(&resp.body_str()).is_ok();
if (!sent) || (resp.status_code() != 202) {
    println!("Send returned HTTP {}", resp.status_code());
    if reply.has_member("error.description") {
        println!("{}", reply.string_of("error.description").unwrap_or_default());
    }

    return;
}

if reply.has_member("error.code") {
    if !reply.is_null_of("error.code") {
        println!("Submission error {}  {}", reply.string_of("error.code").unwrap_or_default(), reply.string_of("error.description").unwrap_or_default());
        return;
    }

}

// HTTP acceptance and the recipient result are separate checks.
if (!parsed) || (reply.json_type_of("messages[0].accepted") != 5) {
    println!("Missing recipient result. Check the message report.");
    return;
}

if !reply.bool_of("messages[0].accepted") {
    println!("Message rejected: {}  {}", reply.string_of("messages[0].error.code").unwrap_or_default(), reply.string_of("messages[0].error.description").unwrap_or_default());
    return;
}

if reply.json_type_of("messages[0].apiMessageId") != 1 {
    println!("Accepted without a message ID. Check the message report.");
    return;
}

println!("Accepted. Message ID: {}", reply.string_of("messages[0].apiMessageId").unwrap_or_default());