Expand description
Sendblue API Client
This module provides a client for interacting with the Sendblue API, including methods for sending messages, retrieving messages, and evaluating phone numbers.
§Overview
The Sendblue API allows you to send messages, retrieve message histories, and evaluate phone numbers for their ability to use iMessage. This module encapsulates these functionalities in a user-friendly Rust client.
§Features
- Send Messages: Send single or group messages using the Sendblue API.
- Retrieve Messages: Fetch message histories with filtering and pagination options.
- Evaluate Phone Numbers: Check if a phone number can send/receive iMessages.
- Typing Indicators: Send typing indicators to recipients.
§Installation
Use the cargo add command:
cargo add sendblue
If you need JSON schema support, enable the schemars
feature:
cargo add sendblue --features schemars
§Usage
To use the Sendblue API client, create an instance of SendblueClient
with your API key and secret.
use sendblue::SendblueClient;
let client = SendblueClient::new("your_api_key".into(), "your_api_secret".into());
§Examples
§Sending a Message
use sendblue::SendblueClient;
use sendblue::models::MessageBuilder;
#[tokio::main]
async fn main() {
let client = SendblueClient::new("your_api_key".into(), "your_api_secret".into());
let message = MessageBuilder::new(phonenumber::parse(None, "+10722971673").unwrap())
.content("Hello, world!".into())
.build()
.unwrap();
match client.send(&message).await {
Ok(response) => println!("Message sent: {:?}", response),
Err(e) => eprintln!("Error sending message: {:?}", e),
}
}
§Retrieving Messages
use sendblue::SendblueClient;
use sendblue::models::GetMessagesParamsBuilder;
#[tokio::main]
async fn main() {
let client = SendblueClient::new("your_api_key".into(), "your_api_secret".into());
let params = GetMessagesParamsBuilder::new()
.limit(Some(50))
.offset(Some(0))
.number(Some(phonenumber::parse(None, "+10722971673").unwrap()))
.from_date(Some("2023-06-15 12:00:00".into()))
.build();
match client.get_messages(params).await {
Ok(response) => println!("Messages retrieved: {:?}", response.messages),
Err(e) => eprintln!("Error retrieving messages: {:?}", e),
}
}
§Evaluating a Phone Number
use sendblue::SendblueClient;
use sendblue::models::EvaluateServiceBuilder;
#[tokio::main]
async fn main() {
let client = SendblueClient::new("your_api_key".into(), "your_api_secret".into());
let evaluate_service = EvaluateServiceBuilder::new()
.number(phonenumber::parse(None, "+10722971673").unwrap())
.build();
match client.evaluate_service(&evaluate_service).await {
Ok(response) => println!("Evaluation result: {:?}", response),
Err(e) => eprintln!("Error evaluating number: {:?}", e),
}
}
§Sending a Typing Indicator
use sendblue::SendblueClient;
#[tokio::main]
async fn main() {
let client = SendblueClient::new("your_api_key".into(), "your_api_secret".into());
let number = phonenumber::parse(None, "+10722971673").unwrap();
match client.send_typing_indicator(&number).await {
Ok(response) => println!("Typing indicator sent: {:?}", response),
Err(e) => eprintln!("Error sending typing indicator: {:?}", e),
}
}
Re-exports§
pub use error::SendblueError;
pub use phonenumber;
Modules§
- Error Types
- Models for the Sendblue API
- Prelude for the Sendblue API
- Traits for the Sendblue API
Structs§
- Client for the Sendblue API