| Crates.io | comms_sdk |
| lib.rs | comms_sdk |
| version | 1.0.1 |
| created_at | 2025-12-17 12:46:16.327254+00 |
| updated_at | 2025-12-19 21:58:48.716876+00 |
| description | Pahappa Comms platform Rust SDK |
| homepage | https://pahappa.com |
| repository | https://www.github.com/pahappa-ltd/CommsSDK |
| max_upload_size | |
| id | 1990108 |
| size | 62,217 |
A Rust implementation of the CommsSDK for sending SMS and managing communications, following the same patterns as the Python and Ruby reference implementations.
Version: 1.0.1
Add this to your Cargo.toml:
[dependencies]
comms_sdk = "1.0.1"
Or, run:
cargo add comms_sdk
use comms_sdk::v1::{CommsSDK, MessagePriority};
fn main() {
// Authenticate with username and API key
let mut sdk = CommsSDK::authenticate("your_username", "your_api_key");
// Send SMS to a single number
let result = sdk.send_sms(vec!["256712345678"], "Hello from Rust!");
match result {
Ok(success) => println!("SMS sent: {}", success),
Err(e) => eprintln!("Error sending SMS: {:?}", e),
}
// Send SMS to multiple numbers with custom sender ID and priority
let mut sdk = sdk.with_sender_id("MyApp");
let result = sdk.send_sms_full(
vec!["256712345678", "256787654321"],
"Hello to all!",
"SenderID",
MessagePriority::High,
);
match result {
Ok(success) => println!("Bulk SMS sent: {}", success),
Err(e) => eprintln!("Error sending bulk SMS: {:?}", e),
}
// Get account balance
match sdk.get_balance() {
Ok(balance) => println!("Balance: {}", balance),
Err(e) => eprintln!("Error getting balance: {:?}", e),
}
}
// Use sandbox environment for testing
CommsSDK::use_sandbox();
// Use live server (default)
CommsSDK::use_live_server();
// Set custom sender ID
let mut sdk = sdk.with_sender_id("MyCustomSender");
CommsSDK::authenticate(user_name: &str, api_key: &str) -> CommsSDK
CommsSDK::use_sandbox()
CommsSDK::use_live_server()
with_sender_id(&self, sender_id: &str) -> CommsSDK
send_sms(&mut self, numbers: Vec<S>, message: T) -> Result<bool, Error>
send_sms_full(&mut self, numbers: Vec<S>, message: T, sender_id: &str, priority: MessagePriority) -> Result<bool, Error>
query_send_sms(&mut self, numbers: Vec<S>, message: T) -> Result<ApiResponse, Error>
query_send_sms_full(&mut self, numbers: Vec<S>, message: T, sender_id: &str, priority: MessagePriority) -> Result<ApiResponse, Error>
get_balance(&mut self) -> Result<f64, Error>
query_balance(&mut self) -> Result<ApiResponse, Error>
is_authenticated(&self) -> bool
MessagePriority::Highest - Priority "0"MessagePriority::High - Priority "1"MessagePriority::Medium - Priority "2"MessagePriority::Low - Priority "3"MessagePriority::Lowest - Priority "4"status - Response status (ApiResponseCode::OK or ApiResponseCode::Failed)message - Response messagecost - Message costcurrency - Currency codemessage_follow_up_code - Unique tracking codebalance - Account balanceAll methods that perform network or validation operations return Result<T, anyhow::Error>. Handle errors using standard Rust error handling patterns:
match sdk.send_sms(vec!["256712345678"], "Hello!") {
Ok(success) => println!("SMS sent: {}", success),
Err(e) => eprintln!("Error: {}", e),
}
Bug reports and pull requests are welcome on GitHub.
This crate is available as open source under the terms of the MIT License.