infobip-sms-sdk 0.1.0

Async Rust SDK for the Infobip SMS API: send messages, manage scheduled bulks, query delivery reports and logs, fetch inbound SMS, and parse webhook payloads.
Documentation
//! Payload shapes for the webhooks Infobip POSTs to your callback URLs.
//!
//! Wire the URL into your account settings or per-message via
//! [`crate::models::send::MessageDeliveryReporting::url`] /
//! [`crate::models::send::UrlOptions::tracking_url`], then deserialize
//! the request body in your handler:
//!
//! ```
//! # use infobip_sms::models::webhooks::DeliveryReportPayload;
//! let body = r#"{"results":[]}"#;
//! let parsed: DeliveryReportPayload = serde_json::from_str(body).unwrap();
//! # let _ = parsed;
//! ```
//!
//! # Webhook types
//!
//! | Webhook | Body type |
//! |---|---|
//! | Inbound SMS forwarding | [`InboundSmsPayload`] |
//! | Outbound delivery reports (v3) | [`DeliveryReportPayload`] |
//! | URL click-tracking | [`UrlTrackingWebhook`] |
//!
//! `InboundSmsPayload` and `DeliveryReportPayload` are aliases for the
//! types you already get from the polling endpoints, so handler code
//! and polling code can share the same parsing logic.

use serde::{Deserialize, Serialize};

use crate::models::inbox::InboundSmsResponse;
use crate::models::reports::DeliveryReports;

/// Body of the webhook fired for the v3 outbound message delivery
/// reports.
///
/// Same shape as the response of
/// [`Client::get_delivery_reports`](crate::Client::get_delivery_reports).
pub type DeliveryReportPayload = DeliveryReports;

/// Body of the webhook fired when forwarding inbound SMS in real time.
///
/// Same shape as the response of
/// [`Client::get_inbound_messages`](crate::Client::get_inbound_messages).
pub type InboundSmsPayload = InboundSmsResponse;

/// Body of the webhook fired for SMS click-tracking notifications.
///
/// One of these is POSTed each time a recipient clicks a tracked URL
/// inside a message you sent with [`UrlOptions::track_clicks`][1] set.
///
/// [1]: crate::models::send::UrlOptions::track_clicks
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct UrlTrackingWebhook {
    /// Type of user action. Currently only `"CLICKED"` is documented.
    pub notification_type: Option<String>,
    /// Recipient address that did the action.
    pub recipient: Option<String>,
    /// The URL the recipient clicked.
    pub url: Option<String>,
    /// Epoch milliseconds when the click was recorded.
    pub send_date_time: Option<i64>,
    /// Per-recipient message ID this click is tied to.
    pub message_id: Option<String>,
    /// Bulk ID this click is tied to.
    pub bulk_id: Option<String>,
    /// `callbackData` set on the original send, echoed back.
    pub callback_data: Option<String>,
    /// Device / OS metadata about the action originator.
    pub recipient_info: Option<RecipientInfo>,
    /// Geolocation metadata about the action originator.
    pub geo_location_info: Option<GeoLocationInfo>,
    /// Application ID that owned the message.
    pub application_id: Option<String>,
    /// Entity ID that owned the message.
    pub entity_id: Option<String>,
}

/// Device / OS metadata about a click.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RecipientInfo {
    /// Type of device (e.g. `"MOBILE"`).
    pub device_type: Option<String>,
    /// OS name (e.g. `"Android"`, `"iOS"`).
    pub os: Option<String>,
    /// Device name reported by the user-agent.
    pub device_name: Option<String>,
}

/// Geolocation metadata about a click.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GeoLocationInfo {
    /// Country where the click was recorded.
    pub country_name: Option<String>,
    /// City where the click was recorded.
    pub city: Option<String>,
}