infobip_whatsapp_sdk/lib.rs
1//! # Infobip WhatsApp SDK
2//!
3//! A type-safe Rust client for the [Infobip WhatsApp API](https://www.infobip.com/docs/api/channels/whatsapp).
4//!
5//! This SDK provides full coverage of the Infobip WhatsApp Business API, including
6//! sending messages (text, media, templates, interactive), managing templates and flows,
7//! handling webhooks, and more.
8//!
9//! ## Quick Start
10//!
11//! ```rust,no_run
12//! use infobip_whatsapp_sdk::{Auth, ClientConfig, WhatsAppClient};
13//! use infobip_whatsapp_sdk::models::messages::text::TextMessage;
14//!
15//! #[tokio::main]
16//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
17//! // Create a client with API key authentication
18//! let config = ClientConfig::new(
19//! "https://your-base-url.api.infobip.com",
20//! Auth::ApiKey("your-api-key".into()),
21//! )?;
22//! let client = WhatsAppClient::new(config);
23//!
24//! // Send a text message
25//! let msg = TextMessage::new("441134960000", "441134960001", "Hello from Rust!");
26//! let response = client.messages().send_text(&msg).await?;
27//!
28//! println!("Message ID: {:?}", response.message_id);
29//! Ok(())
30//! }
31//! ```
32//!
33//! ## Authentication
34//!
35//! The SDK supports all four Infobip authentication methods:
36//!
37//! ```rust
38//! use infobip_whatsapp_sdk::Auth;
39//!
40//! // API Key (most common)
41//! let auth = Auth::ApiKey("your-api-key".into());
42//!
43//! // Basic auth
44//! let auth = Auth::Basic {
45//! username: "user".into(),
46//! password: "pass".into(),
47//! };
48//!
49//! // OAuth2 Bearer token
50//! let auth = Auth::Bearer("oauth-token".into());
51//!
52//! // IBSSO token
53//! let auth = Auth::IbSso("sso-token".into());
54//! ```
55//!
56//! ## Error Handling
57//!
58//! Every API call returns [`Result<T, InfobipError>`]. The error type provides
59//! rich inspection for logging, monitoring (Sentry, Datadog), and retry logic:
60//!
61//! ```rust,no_run
62//! # use infobip_whatsapp_sdk::{Auth, ClientConfig, WhatsAppClient};
63//! # use infobip_whatsapp_sdk::models::messages::text::TextMessage;
64//! # async fn example() {
65//! # let config = ClientConfig::new("https://example.com", Auth::ApiKey("k".into())).unwrap();
66//! # let client = WhatsAppClient::new(config);
67//! # let msg = TextMessage::new("s", "r", "t");
68//! match client.messages().send_text(&msg).await {
69//! Ok(info) => println!("Sent: {:?}", info.message_id),
70//! Err(e) => {
71//! // Quick classification
72//! if e.is_retryable() {
73//! // 429 rate-limited, 5xx server error, or network timeout
74//! println!("Retryable error, will try again");
75//! }
76//!
77//! // Drill into API-specific error details
78//! if let Some(api_err) = e.api_error() {
79//! println!("HTTP {}", api_err.status());
80//! println!("Code: {:?}", api_err.error_code());
81//! println!("Message: {:?}", api_err.message());
82//!
83//! if api_err.is_rate_limited() {
84//! // Back off and retry
85//! }
86//! }
87//! }
88//! }
89//! # }
90//! ```
91//!
92//! ## API Domains
93//!
94//! Access each API domain through the client:
95//!
96//! | Accessor | API Domain | Description |
97//! |---|---|---|
98//! | [`client.messages()`](WhatsAppClient::messages) | Messages | Send text, media, template, contact, location messages |
99//! | [`client.interactive()`](WhatsAppClient::interactive) | Interactive | Buttons, lists, products, flows, carousels |
100//! | [`client.templates()`](WhatsAppClient::templates) | Templates | Create, read, update, delete message templates |
101//! | [`client.flows()`](WhatsAppClient::flows) | Flows | Manage WhatsApp Flows |
102//! | [`client.events()`](WhatsAppClient::events) | Events | Send typing indicators |
103//! | [`client.inbound()`](WhatsAppClient::inbound) | Inbound | Download media, mark messages as read |
104//! | [`client.payments()`](WhatsAppClient::payments) | Payments | Check payment transaction status |
105//! | [`client.sender()`](WhatsAppClient::sender) | Sender | Quality ratings, business info, public keys |
106//! | [`client.identity()`](WhatsAppClient::identity) | Identity | Manage end-user identity verification |
107//! | [`client.conversions()`](WhatsAppClient::conversions) | Conversions | Track ad conversion events |
108//! | [`client.media()`](WhatsAppClient::media) | Media | Delete uploaded media |
109//! | [`client.registration()`](WhatsAppClient::registration) | Registration | Register and verify sender numbers |
110//!
111//! ## Webhook Models
112//!
113//! The [`models::webhooks`] module provides types for deserializing webhook payloads
114//! that Infobip sends to your server (delivery reports, seen reports, etc.):
115//!
116//! ```rust,no_run
117//! use infobip_whatsapp_sdk::models::webhooks::DeliveryResults;
118//!
119//! // In your webhook handler:
120//! fn handle_delivery_report(body: &str) {
121//! let report: DeliveryResults = serde_json::from_str(body).unwrap();
122//! for result in report.results.unwrap_or_default() {
123//! println!("Message {} status: {:?}",
124//! result.message_id.unwrap_or_default(),
125//! result.status.map(|s| s.group_name));
126//! }
127//! }
128//! ```
129
130pub mod auth;
131pub mod client;
132pub mod config;
133pub mod error;
134
135pub mod models;
136pub mod api;
137
138pub use auth::Auth;
139pub use client::WhatsAppClient;
140pub use config::ClientConfig;
141pub use error::{InfobipError, ApiError, ApiErrorKind};