Rust
Rust
WaTrend Send WhatsApp Text
See more WaTrend Examples
Send a WhatsApp text.Chilkat Rust Downloads
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = chilkat::Http::new();
// Use your actual access token instead of 555555555555555555555555555555
let req = chilkat::HttpRequest::new();
req.add_param("number", "84933313xxx");
req.add_param("type", "text");
req.add_param("message", "This is a test message");
req.add_param("instance_id", "609ACF283XXXX");
req.add_param("access_token", "555555555555555555555555555555");
// Note: The WaTrend online documentation indicate a POST should be used.
// However, it seems you might actually need to send a GET request.
// It is unclear.
// If a GET is neeed, you would just send to the URL w/ query params like this:
let sb_url = chilkat::StringBuilder::new();
let _ = sb_url.append("https://app.watrend.com/api/send.php?");
let _ = sb_url.append(&req.get_url_encoded_params().unwrap_or_default());
let response_body_str = http.quick_get_str(&sb_url.get_as_string().unwrap_or_default()).unwrap_or_default();
// The responseBodyStr contains the JSON response from the server..
req.set_http_verb("POST");
req.set_content_type("application/x-www-form-urlencoded");
let resp = chilkat::HttpResponse::new();
if http.http_req("https://app.watrend.com/api/send.php", &req, &resp).is_err() {
println!("{}", http.last_error_text());
return;
}
let sb_response_body = chilkat::StringBuilder::new();
let _ = resp.get_body_sb(&sb_response_body);
let resp_status_code = resp.status_code();
println!("Response Status Code = {}", resp_status_code);
if resp_status_code >= 400 {
println!("Response Header:");
println!("{}", resp.header());
println!("Failed.");
return;
}
println!("{}", resp.body_str());
// Both success and failed responses use 200 status code.
// A success response contains this JSON in the response body:
// {"status":"success", ... }
// A failed response will contain something like this:
// {"status":"error","message":"License Invalidated"}
let j_resp = chilkat::JsonObject::new();
let _ = j_resp.load_sb(&sb_response_body);
let status = j_resp.string_of("status").unwrap_or_default();
println!("status: {}", status);