1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
use super::InputFile;
use crate::model::{MessageEntity, ParseMode};
use serde::{Deserialize, Serialize};

/// This object represents the content of a media message to be sent

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[serde(tag = "type")]
pub enum InputMedia {
    #[serde(rename = "photo")]
    Photo(InputMediaPhoto),
    #[serde(rename = "video")]
    Video(InputMediaVideo),
    #[serde(rename = "animation")]
    Animation(InputMediaAnimation),
    #[serde(rename = "audio")]
    Audio(InputMediaAudio),
    #[serde(rename = "document")]
    Document(InputMediaDocument),
}

/// Represents a photo to be sent.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct InputMediaPhoto {
    /// File to send. Pass a file_id to send a file that exists on the Telegram

    /// servers (recommended), pass an HTTP URL for Telegram to get a file

    /// from the Internet

    pub media: InputFile,
    /// Caption of the photo to be sent, 0-1024 characters after entities

    /// parsing

    #[serde(skip_serializing_if = "Option::is_none")]
    pub caption: Option<String>,
    /// Send Markdown or HTML, if you want Telegram apps to show bold, italic,

    /// fixed-width text or inline URLs in the media caption

    #[serde(skip_serializing_if = "Option::is_none")]
    pub parse_mode: Option<ParseMode>,
    /// List of special entities that appear in the caption, which can be

    /// specified instead of parse_mode

    #[serde(skip_serializing_if = "Option::is_none")]
    pub caption_entities: Option<Vec<MessageEntity>>,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct InputMediaVideo {
    /// File to send. Pass a file_id to send a file that exists on the Telegram

    /// servers (recommended), pass an HTTP URL for Telegram to get a file

    /// from the Internet

    pub media: InputFile,
    /// Caption of the video to be sent, 0-1024 characters after entities

    /// parsing

    #[serde(skip_serializing_if = "Option::is_none")]
    pub caption: Option<String>,
    /// Send Markdown or HTML, if you want Telegram apps to show bold, italic,

    /// fixed-width text or inline URLs in the media caption

    #[serde(skip_serializing_if = "Option::is_none")]
    pub parse_mode: Option<ParseMode>,
    /// List of special entities that appear in the caption, which can be

    /// specified instead of parse_mode

    #[serde(skip_serializing_if = "Option::is_none")]
    pub caption_entities: Option<Vec<MessageEntity>>,
    /// Duration of the video in seconds

    #[serde(skip_serializing_if = "Option::is_none")]
    pub duration: Option<i64>,
    /// Video width

    #[serde(skip_serializing_if = "Option::is_none")]
    pub width: Option<i64>,
    /// Video height

    #[serde(skip_serializing_if = "Option::is_none")]
    pub height: Option<i64>,
    /// If the uploaded video is suitable for streaming

    pub supports_streaming: bool,
}

/// Represents an animation file (GIF or H.264/MPEG-4 AVC video without sound)

/// to be sent.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct InputMediaAnimation {
    /// File to send. Pass a file_id to send a file that exists on the Telegram

    /// servers (recommended), pass an HTTP URL for Telegram to get a file

    /// from the Internet

    pub media: InputFile,
    /// Caption of the animation to be sent, 0-1024 characters after entities

    /// parsing

    #[serde(skip_serializing_if = "Option::is_none")]
    pub caption: Option<String>,
    /// Send Markdown or HTML, if you want Telegram apps to show bold, italic,

    /// fixed-width text or inline URLs in the media caption

    #[serde(skip_serializing_if = "Option::is_none")]
    pub parse_mode: Option<ParseMode>,
    /// List of special entities that appear in the caption, which can be

    /// specified instead of parse_mode

    #[serde(skip_serializing_if = "Option::is_none")]
    pub caption_entities: Option<Vec<MessageEntity>>,
    /// Duration of the animation in seconds

    #[serde(skip_serializing_if = "Option::is_none")]
    pub duration: Option<i64>,
    /// Animation width

    #[serde(skip_serializing_if = "Option::is_none")]
    pub width: Option<i64>,
    /// Animation height

    #[serde(skip_serializing_if = "Option::is_none")]
    pub height: Option<i64>,
}

/// Represents an audio file to be treated as music to be sent.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct InputMediaAudio {
    /// File to send. Pass a file_id to send a file that exists on the Telegram

    /// servers (recommended), pass an HTTP URL for Telegram to get a file

    /// from the Internet

    pub media: InputFile,
    /// Caption of the audio file to be sent, 0-1024 characters after entities

    /// parsing

    #[serde(skip_serializing_if = "Option::is_none")]
    pub caption: Option<String>,
    /// Send Markdown or HTML, if you want Telegram apps to show bold, italic,

    /// fixed-width text or inline URLs in the media caption

    #[serde(skip_serializing_if = "Option::is_none")]
    pub parse_mode: Option<ParseMode>,
    /// List of special entities that appear in the caption, which can be

    /// specified instead of parse_mode

    #[serde(skip_serializing_if = "Option::is_none")]
    pub caption_entities: Option<Vec<MessageEntity>>,
    /// Duration of the audio in seconds

    #[serde(skip_serializing_if = "Option::is_none")]
    pub duration: Option<i64>,
    /// Performer of the audio

    #[serde(skip_serializing_if = "Option::is_none")]
    pub performer: Option<String>,
    /// Title of the audio

    #[serde(skip_serializing_if = "Option::is_none")]
    pub title: Option<String>,
}

/// Represents a general file to be sent.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct InputMediaDocument {
    /// File to send. Pass a file_id to send a file that exists on the Telegram

    /// servers (recommended), pass an HTTP URL for Telegram to get a file

    /// from the Internet

    pub media: InputFile,
    /// Caption of the document to be sent, 0-1024 characters after entities

    /// parsing

    #[serde(skip_serializing_if = "Option::is_none")]
    pub caption: Option<String>,
    /// Send Markdown or HTML, if you want Telegram apps to show bold, italic,

    /// fixed-width text or inline URLs in the media caption

    #[serde(skip_serializing_if = "Option::is_none")]
    pub parse_mode: Option<ParseMode>,
    /// List of special entities that appear in the caption, which can be

    /// specified instead of parse_mode

    #[serde(skip_serializing_if = "Option::is_none")]
    pub caption_entities: Option<Vec<MessageEntity>>,
    /// Disables automatic server-side content type detection for files uploaded

    /// using multipart/form-data. Always true, if the document is sent as

    /// part of an album.

    pub disable_content_type_detection: bool,
}

impl InputMedia {
    pub fn get_media(&self) -> &InputFile {
        match self {
            InputMedia::Photo(m) => &m.media,
            InputMedia::Video(m) => &m.media,
            InputMedia::Audio(m) => &m.media,
            InputMedia::Animation(m) => &m.media,
            InputMedia::Document(m) => &m.media,
        }
    }
}