Skip to main content

telers/types/
input_media_animation.rs

1use serde::{Deserialize, Serialize};
2/// Represents an animation file (GIF or H.264/MPEG-4 AVC video without sound) to be sent.
3/// # Documentation
4/// <https://core.telegram.org/bots/api#inputmediaanimation>
5#[derive(Clone, Debug, Serialize, Deserialize)]
6pub struct InputMediaAnimation {
7    /// 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, or pass `attach://<file_attach_name>` to upload a new one using multipart/form-data under <`file_attach_name`> name. More information on Sending Files: <https://core.telegram.org/bots/api#sending-files>
8    pub media: crate::types::InputFile,
9    /// Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass `attach://<file_attach_name>` if the thumbnail was uploaded using multipart/form-data under <`file_attach_name`>. More information on Sending Files: <https://core.telegram.org/bots/api#sending-files>
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub thumbnail: Option<crate::types::InputFile>,
12    /// Caption of the animation to be sent, 0-1024 characters after entities parsing
13    #[serde(skip_serializing_if = "Option::is_none")]
14    pub caption: Option<Box<str>>,
15    /// Mode for parsing entities in the animation caption. See formatting options for more details.
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub parse_mode: Option<Box<str>>,
18    /// List of special entities that appear in the caption, which can be specified instead of `parse_mode`
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub caption_entities: Option<Box<[crate::types::MessageEntity]>>,
21    /// Pass `true`, if the caption must be shown above the message media
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub show_caption_above_media: Option<bool>,
24    /// Animation width
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub width: Option<i64>,
27    /// Animation height
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub height: Option<i64>,
30    /// Animation duration in seconds
31    #[serde(skip_serializing_if = "Option::is_none")]
32    pub duration: Option<i64>,
33    /// Pass `true` if the animation needs to be covered with a spoiler animation
34    #[serde(skip_serializing_if = "Option::is_none")]
35    pub has_spoiler: Option<bool>,
36}
37impl InputMediaAnimation {
38    /// Creates a new `InputMediaAnimation`.
39    ///
40    /// # Arguments
41    /// * `media` - 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, or pass `attach://<file_attach_name>` to upload a new one using multipart/form-data under <`file_attach_name`> name. More information on Sending Files: <https://core.telegram.org/bots/api#sending-files>
42    ///
43    /// # Notes
44    /// Use builder methods to set optional fields.
45    #[must_use]
46    pub fn new<T0: Into<crate::types::InputFile>>(media: T0) -> Self {
47        Self {
48            media: media.into(),
49            thumbnail: None,
50            caption: None,
51            parse_mode: None,
52            caption_entities: None,
53            show_caption_above_media: None,
54            width: None,
55            height: None,
56            duration: None,
57            has_spoiler: None,
58        }
59    }
60
61    /// 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, or pass `attach://<file_attach_name>` to upload a new one using multipart/form-data under <`file_attach_name`> name. More information on Sending Files: <https://core.telegram.org/bots/api#sending-files>
62    #[must_use]
63    pub fn media<T: Into<crate::types::InputFile>>(self, val: T) -> Self {
64        let mut this = self;
65        this.media = val.into();
66        this
67    }
68
69    /// Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass `attach://<file_attach_name>` if the thumbnail was uploaded using multipart/form-data under <`file_attach_name`>. More information on Sending Files: <https://core.telegram.org/bots/api#sending-files>
70    #[must_use]
71    pub fn thumbnail<T: Into<crate::types::InputFile>>(self, val: T) -> Self {
72        let mut this = self;
73        this.thumbnail = Some(val.into());
74        this
75    }
76
77    /// Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass `attach://<file_attach_name>` if the thumbnail was uploaded using multipart/form-data under <`file_attach_name`>. More information on Sending Files: <https://core.telegram.org/bots/api#sending-files>
78    #[must_use]
79    pub fn thumbnail_option<T: Into<crate::types::InputFile>>(self, val: Option<T>) -> Self {
80        let mut this = self;
81        this.thumbnail = val.map(Into::into);
82        this
83    }
84
85    /// Caption of the animation to be sent, 0-1024 characters after entities parsing
86    #[must_use]
87    pub fn caption<T: Into<Box<str>>>(self, val: T) -> Self {
88        let mut this = self;
89        this.caption = Some(val.into());
90        this
91    }
92
93    /// Caption of the animation to be sent, 0-1024 characters after entities parsing
94    #[must_use]
95    pub fn caption_option<T: Into<Box<str>>>(self, val: Option<T>) -> Self {
96        let mut this = self;
97        this.caption = val.map(Into::into);
98        this
99    }
100
101    /// Mode for parsing entities in the animation caption. See formatting options for more details.
102    #[must_use]
103    pub fn parse_mode<T: Into<Box<str>>>(self, val: T) -> Self {
104        let mut this = self;
105        this.parse_mode = Some(val.into());
106        this
107    }
108
109    /// Mode for parsing entities in the animation caption. See formatting options for more details.
110    #[must_use]
111    pub fn parse_mode_option<T: Into<Box<str>>>(self, val: Option<T>) -> Self {
112        let mut this = self;
113        this.parse_mode = val.map(Into::into);
114        this
115    }
116
117    /// List of special entities that appear in the caption, which can be specified instead of `parse_mode`
118    ///
119    /// # Notes
120    /// Adds multiple elements.
121    #[must_use]
122    pub fn caption_entities<T: Into<Box<[crate::types::MessageEntity]>>>(self, val: T) -> Self {
123        let mut this = self;
124        this.caption_entities = Some(
125            this.caption_entities
126                .unwrap_or_default()
127                .into_vec()
128                .into_iter()
129                .chain(val.into())
130                .collect(),
131        );
132        this
133    }
134
135    /// List of special entities that appear in the caption, which can be specified instead of `parse_mode`
136    ///
137    /// # Notes
138    /// Adds a single element.
139    #[must_use]
140    pub fn caption_entity<T: Into<crate::types::MessageEntity>>(self, val: T) -> Self {
141        let mut this = self;
142        this.caption_entities = Some(
143            this.caption_entities
144                .unwrap_or_default()
145                .into_vec()
146                .into_iter()
147                .chain(Some(val.into()))
148                .collect(),
149        );
150        this
151    }
152
153    /// List of special entities that appear in the caption, which can be specified instead of `parse_mode`
154    ///
155    /// # Notes
156    /// Adds a single element.
157    #[must_use]
158    pub fn caption_entities_option<T: Into<Box<[crate::types::MessageEntity]>>>(
159        self,
160        val: Option<T>,
161    ) -> Self {
162        let mut this = self;
163        this.caption_entities = val.map(Into::into);
164        this
165    }
166
167    /// Pass `true`, if the caption must be shown above the message media
168    #[must_use]
169    pub fn show_caption_above_media<T: Into<bool>>(self, val: T) -> Self {
170        let mut this = self;
171        this.show_caption_above_media = Some(val.into());
172        this
173    }
174
175    /// Pass `true`, if the caption must be shown above the message media
176    #[must_use]
177    pub fn show_caption_above_media_option<T: Into<bool>>(self, val: Option<T>) -> Self {
178        let mut this = self;
179        this.show_caption_above_media = val.map(Into::into);
180        this
181    }
182
183    /// Animation width
184    #[must_use]
185    pub fn width<T: Into<i64>>(self, val: T) -> Self {
186        let mut this = self;
187        this.width = Some(val.into());
188        this
189    }
190
191    /// Animation width
192    #[must_use]
193    pub fn width_option<T: Into<i64>>(self, val: Option<T>) -> Self {
194        let mut this = self;
195        this.width = val.map(Into::into);
196        this
197    }
198
199    /// Animation height
200    #[must_use]
201    pub fn height<T: Into<i64>>(self, val: T) -> Self {
202        let mut this = self;
203        this.height = Some(val.into());
204        this
205    }
206
207    /// Animation height
208    #[must_use]
209    pub fn height_option<T: Into<i64>>(self, val: Option<T>) -> Self {
210        let mut this = self;
211        this.height = val.map(Into::into);
212        this
213    }
214
215    /// Animation duration in seconds
216    #[must_use]
217    pub fn duration<T: Into<i64>>(self, val: T) -> Self {
218        let mut this = self;
219        this.duration = Some(val.into());
220        this
221    }
222
223    /// Animation duration in seconds
224    #[must_use]
225    pub fn duration_option<T: Into<i64>>(self, val: Option<T>) -> Self {
226        let mut this = self;
227        this.duration = val.map(Into::into);
228        this
229    }
230
231    /// Pass `true` if the animation needs to be covered with a spoiler animation
232    #[must_use]
233    pub fn has_spoiler<T: Into<bool>>(self, val: T) -> Self {
234        let mut this = self;
235        this.has_spoiler = Some(val.into());
236        this
237    }
238
239    /// Pass `true` if the animation needs to be covered with a spoiler animation
240    #[must_use]
241    pub fn has_spoiler_option<T: Into<bool>>(self, val: Option<T>) -> Self {
242        let mut this = self;
243        this.has_spoiler = val.map(Into::into);
244        this
245    }
246}