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
//! Models for `POST /sms/1/preview` — previewing how a message would
//! look on the wire.
//!
//! Use this to figure out:
//! - How many SMS parts a body of text would split into.
//! - How many characters you have left in the last part.
//! - What the body looks like after transliteration / language
//!   conversion.
//!
//! No SMS is sent.
//!
//! # Example
//!
//! ```no_run
//! # use infobip_sms::Client;
//! use infobip_sms::models::preview::PreviewRequest;
//!
//! # async fn run(client: Client) -> Result<(), infobip_sms::Error> {
//! let preview = client
//!     .preview_message(&PreviewRequest {
//!         text: "Some Cyrillic: Привет!".into(),
//!         transliteration: Some("CYRILLIC".into()),
//!         ..Default::default()
//!     })
//!     .await?;
//!
//! for p in &preview.previews {
//!     println!("{} parts, {} chars left", p.message_count.unwrap_or(0), p.characters_remaining.unwrap_or(0));
//! }
//! # Ok(()) }
//! ```

use serde::{Deserialize, Serialize};

/// Request body for
/// [`Client::preview_message`](crate::Client::preview_message).
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PreviewRequest {
    /// The message body to evaluate.
    pub text: String,
    /// Language hint. One of `"TR"`, `"ES"`, `"PT"`, `"AUTODETECT"`.
    /// Stored as `String` because the API also accepts other values
    /// not exposed via `LanguageCode`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub language_code: Option<String>,
    /// Transliteration code, e.g. `"TURKISH"`, `"GREEK"`, `"CYRILLIC"`,
    /// `"ALL"`. See the API docs for the full list.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub transliteration: Option<String>,
}

/// Response body from
/// [`Client::preview_message`](crate::Client::preview_message).
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PreviewResponse {
    /// Echo of the original `text` field.
    pub original_text: Option<String>,
    /// One [`Preview`] per evaluated configuration. The API may
    /// return multiple — for example, an unprocessed preview plus one
    /// per requested transliteration / language.
    #[serde(default)]
    pub previews: Vec<Preview>,
}

/// One previewed configuration.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Preview {
    /// What the body looks like after applying [`Self::configuration`].
    pub text_preview: Option<String>,
    /// SMS parts the body would split into.
    pub message_count: Option<i32>,
    /// Characters left in the last SMS part before triggering another
    /// concatenated part.
    pub characters_remaining: Option<i32>,
    /// Configuration that produced this preview.
    pub configuration: Option<LanguageConfiguration>,
}

/// Language / transliteration configuration applied to a [`Preview`].
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct LanguageConfiguration {
    /// Language settings used.
    pub language: Option<Language>,
    /// Transliteration code applied, if any.
    pub transliteration: Option<String>,
}

/// Language metadata in a [`LanguageConfiguration`].
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Language {
    /// Language code (`"TR"`, `"ES"`, `"PT"`, `"AUTODETECT"`).
    pub language_code: Option<String>,
}