-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01_basic_usage.rs
More file actions
37 lines (32 loc) · 1.19 KB
/
01_basic_usage.rs
File metadata and controls
37 lines (32 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use kwtsms::KwtSms;
fn main() {
// Create client from environment variables / .env file
let sms = KwtSms::from_env(None).expect("Failed to create client");
// Verify credentials and check balance
let verify = sms.verify();
if verify.ok {
println!("Credentials OK!");
println!("Balance: {:?}", verify.balance);
println!("Purchased: {:?}", verify.purchased);
} else {
eprintln!("Verification failed: {:?}", verify.error);
return;
}
// Send a single SMS
let result = sms
.send_one("96598765432", "Hello from the kwtsms Rust client!", None)
.expect("Send failed");
println!(
"Send result: {}",
serde_json::to_string_pretty(&result).unwrap()
);
// Check the msg-id and balance-after from the response
if let Some(msg_id) = result.get("msg-id").and_then(|v| v.as_str()) {
println!("Message ID: {}", msg_id);
// Save this msg-id for status checks and delivery reports
}
if let Some(balance) = result.get("balance-after").and_then(|v| v.as_f64()) {
println!("Balance after send: {}", balance);
// Save to your database: no need to call balance() again
}
}