rust-tg-bot-raw 1.0.0-rc.1

Pure Telegram Bot API types and methods for Rust -- a faithful port of python-telegram-bot's core layer
Documentation
use serde::{Deserialize, Serialize};

use super::files::photo_size::PhotoSize;
use super::files::video::Video;
use super::user::User;

// ---------------------------------------------------------------------------
// PaidMediaPreview
// ---------------------------------------------------------------------------

/// Paid media that is not yet available before payment.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct PaidMediaPreview {
    /// Media width as defined by the sender.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub width: Option<i64>,

    /// Media height as defined by the sender.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub height: Option<i64>,

    /// Duration of the media in seconds as defined by the sender.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub duration: Option<i64>,
}

// ---------------------------------------------------------------------------
// PaidMediaPhoto
// ---------------------------------------------------------------------------

/// The paid media is a photo.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct PaidMediaPhoto {
    /// The photo.
    pub photo: Vec<PhotoSize>,
}

// ---------------------------------------------------------------------------
// PaidMediaVideo
// ---------------------------------------------------------------------------

/// The paid media is a video.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct PaidMediaVideo {
    /// The video.
    pub video: Video,
}

// ---------------------------------------------------------------------------
// PaidMedia — polymorphic, tagged on "type"
// ---------------------------------------------------------------------------

/// Paid media added to a message.
///
/// Discriminated by the `"type"` JSON field.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
#[non_exhaustive]
pub enum PaidMedia {
    /// Media not yet available before payment.
    Preview(PaidMediaPreview),

    /// A photo.
    Photo(PaidMediaPhoto),

    /// A video.
    Video(Box<PaidMediaVideo>),
}

// ---------------------------------------------------------------------------
// PaidMediaInfo
// ---------------------------------------------------------------------------

/// Paid media added to a message, together with the required Star count.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct PaidMediaInfo {
    /// Number of Telegram Stars that must be paid to buy access to the media.
    pub star_count: i64,

    /// Information about the paid media.
    pub paid_media: Vec<PaidMedia>,
}

// ---------------------------------------------------------------------------
// PaidMediaPurchased
// ---------------------------------------------------------------------------

/// Information about a paid media purchase.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct PaidMediaPurchased {
    /// User who purchased the media.
    ///
    /// JSON field name is `"from"` (reserved word in Rust).
    #[serde(rename = "from")]
    pub from_user: User,

    /// Bot-specified paid media payload.
    pub paid_media_payload: String,
}