Skip to main content

Crate infobip_whatsapp_sdk

Crate infobip_whatsapp_sdk 

Source
Expand description

§Infobip WhatsApp SDK

A type-safe Rust client for the Infobip WhatsApp API.

This SDK provides full coverage of the Infobip WhatsApp Business API, including sending messages (text, media, templates, interactive), managing templates and flows, handling webhooks, and more.

§Quick Start

use infobip_whatsapp_sdk::{Auth, ClientConfig, WhatsAppClient};
use infobip_whatsapp_sdk::models::messages::text::TextMessage;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create a client with API key authentication
    let config = ClientConfig::new(
        "https://your-base-url.api.infobip.com",
        Auth::ApiKey("your-api-key".into()),
    )?;
    let client = WhatsAppClient::new(config);

    // Send a text message
    let msg = TextMessage::new("441134960000", "441134960001", "Hello from Rust!");
    let response = client.messages().send_text(&msg).await?;

    println!("Message ID: {:?}", response.message_id);
    Ok(())
}

§Authentication

The SDK supports all four Infobip authentication methods:

use infobip_whatsapp_sdk::Auth;

// API Key (most common)
let auth = Auth::ApiKey("your-api-key".into());

// Basic auth
let auth = Auth::Basic {
    username: "user".into(),
    password: "pass".into(),
};

// OAuth2 Bearer token
let auth = Auth::Bearer("oauth-token".into());

// IBSSO token
let auth = Auth::IbSso("sso-token".into());

§Error Handling

Every API call returns Result<T, InfobipError>. The error type provides rich inspection for logging, monitoring (Sentry, Datadog), and retry logic:

match client.messages().send_text(&msg).await {
    Ok(info) => println!("Sent: {:?}", info.message_id),
    Err(e) => {
        // Quick classification
        if e.is_retryable() {
            // 429 rate-limited, 5xx server error, or network timeout
            println!("Retryable error, will try again");
        }

        // Drill into API-specific error details
        if let Some(api_err) = e.api_error() {
            println!("HTTP {}", api_err.status());
            println!("Code: {:?}", api_err.error_code());
            println!("Message: {:?}", api_err.message());

            if api_err.is_rate_limited() {
                // Back off and retry
            }
        }
    }
}

§API Domains

Access each API domain through the client:

AccessorAPI DomainDescription
client.messages()MessagesSend text, media, template, contact, location messages
client.interactive()InteractiveButtons, lists, products, flows, carousels
client.templates()TemplatesCreate, read, update, delete message templates
client.flows()FlowsManage WhatsApp Flows
client.events()EventsSend typing indicators
client.inbound()InboundDownload media, mark messages as read
client.payments()PaymentsCheck payment transaction status
client.sender()SenderQuality ratings, business info, public keys
client.identity()IdentityManage end-user identity verification
client.conversions()ConversionsTrack ad conversion events
client.media()MediaDelete uploaded media
client.registration()RegistrationRegister and verify sender numbers

§Webhook Models

The models::webhooks module provides types for deserializing webhook payloads that Infobip sends to your server (delivery reports, seen reports, etc.):

use infobip_whatsapp_sdk::models::webhooks::DeliveryResults;

// In your webhook handler:
fn handle_delivery_report(body: &str) {
    let report: DeliveryResults = serde_json::from_str(body).unwrap();
    for result in report.results.unwrap_or_default() {
        println!("Message {} status: {:?}",
            result.message_id.unwrap_or_default(),
            result.status.map(|s| s.group_name));
    }
}

Re-exports§

pub use auth::Auth;
pub use client::WhatsAppClient;
pub use config::ClientConfig;
pub use error::InfobipError;
pub use error::ApiError;
pub use error::ApiErrorKind;

Modules§

api
WhatsApp Business API modules.
auth
Authentication methods for the Infobip API.
client
The main HTTP client for the Infobip WhatsApp API.
config
Client configuration.
error
Error types for the Infobip SDK.
models
WhatsApp Business API data models.