telers/types/
input_media_animation.rs

1use super::{InputFile, MessageEntity};
2
3use serde::Serialize;
4use serde_with::skip_serializing_none;
5
6/// Represents an animation file (GIF or H.264/MPEG-4 AVC video without sound) to be sent.
7/// # Documentation
8/// <https://core.telegram.org/bots/api#inputmediaanimation>
9#[skip_serializing_none]
10#[derive(Debug, Clone, Hash, PartialEq, Serialize)]
11pub struct InputMediaAnimation<'a> {
12    /// 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).
13    pub media: InputFile<'a>,
14    /// 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).
15    pub thumbnail: Option<InputFile<'a>>,
16    /// Caption of the video to be sent, 0-1024 characters after entities parsing
17    pub caption: Option<String>,
18    /// Caption of the animation to be sent, 0-1024 characters after entities parsing"""
19    pub parse_mode: Option<String>,
20    /// Mode for parsing entities in the animation caption. See [`formatting options`](https://core.telegram.org/bots/api#formatting-options) for more details.
21    pub caption_entities: Option<Vec<MessageEntity>>,
22    /// Pass `true`, if the caption must be shown above the message media
23    pub show_caption_above_media: Option<bool>,
24    /// Video width
25    pub width: Option<i64>,
26    /// Animation height
27    pub height: Option<i64>,
28    /// Animation duration in seconds
29    pub duration: Option<i64>,
30    /// Pass `true` if the animation needs to be covered with a spoiler animation
31    pub has_spoiler: Option<bool>,
32}
33
34impl<'a> InputMediaAnimation<'a> {
35    #[must_use]
36    pub fn new(media: impl Into<InputFile<'a>>) -> Self {
37        Self {
38            media: media.into(),
39            thumbnail: None,
40            caption: None,
41            parse_mode: None,
42            caption_entities: None,
43            show_caption_above_media: None,
44            width: None,
45            height: None,
46            duration: None,
47            has_spoiler: None,
48        }
49    }
50
51    #[must_use]
52    pub fn media(self, val: impl Into<InputFile<'a>>) -> Self {
53        Self {
54            media: val.into(),
55            ..self
56        }
57    }
58
59    #[must_use]
60    pub fn thumbnail(self, val: impl Into<InputFile<'a>>) -> Self {
61        Self {
62            thumbnail: Some(val.into()),
63            ..self
64        }
65    }
66
67    #[must_use]
68    pub fn caption(self, val: impl Into<String>) -> Self {
69        Self {
70            caption: Some(val.into()),
71            ..self
72        }
73    }
74
75    #[must_use]
76    pub fn parse_mode(self, val: impl Into<String>) -> Self {
77        Self {
78            parse_mode: Some(val.into()),
79            ..self
80        }
81    }
82
83    #[must_use]
84    pub fn caption_entity(self, val: MessageEntity) -> Self {
85        Self {
86            caption_entities: Some(
87                self.caption_entities
88                    .unwrap_or_default()
89                    .into_iter()
90                    .chain(Some(val))
91                    .collect(),
92            ),
93            ..self
94        }
95    }
96
97    #[must_use]
98    pub fn caption_entities(self, val: impl IntoIterator<Item = MessageEntity>) -> Self {
99        Self {
100            caption_entities: Some(
101                self.caption_entities
102                    .unwrap_or_default()
103                    .into_iter()
104                    .chain(val)
105                    .collect(),
106            ),
107            ..self
108        }
109    }
110
111    #[must_use]
112    pub fn show_caption_above_media(self, val: bool) -> Self {
113        Self {
114            show_caption_above_media: Some(val),
115            ..self
116        }
117    }
118
119    #[must_use]
120    pub fn width(self, val: i64) -> Self {
121        Self {
122            width: Some(val),
123            ..self
124        }
125    }
126
127    #[must_use]
128    pub fn height(self, val: i64) -> Self {
129        Self {
130            height: Some(val),
131            ..self
132        }
133    }
134
135    #[must_use]
136    pub fn duration(self, val: i64) -> Self {
137        Self {
138            duration: Some(val),
139            ..self
140        }
141    }
142
143    #[must_use]
144    pub fn has_spoiler(self, val: bool) -> Self {
145        Self {
146            has_spoiler: Some(val),
147            ..self
148        }
149    }
150}
151
152impl<'a> InputMediaAnimation<'a> {
153    #[must_use]
154    pub fn thumbnail_option(self, val: Option<impl Into<InputFile<'a>>>) -> Self {
155        Self {
156            thumbnail: val.map(Into::into),
157            ..self
158        }
159    }
160
161    #[must_use]
162    pub fn caption_option(self, val: Option<impl Into<String>>) -> Self {
163        Self {
164            caption: val.map(Into::into),
165            ..self
166        }
167    }
168
169    #[must_use]
170    pub fn parse_mode_option(self, val: Option<impl Into<String>>) -> Self {
171        Self {
172            parse_mode: val.map(Into::into),
173            ..self
174        }
175    }
176
177    #[must_use]
178    pub fn caption_entities_option(
179        self,
180        val: Option<impl IntoIterator<Item = MessageEntity>>,
181    ) -> Self {
182        Self {
183            caption_entities: val.map(|val| {
184                self.caption_entities
185                    .unwrap_or_default()
186                    .into_iter()
187                    .chain(val)
188                    .collect()
189            }),
190            ..self
191        }
192    }
193
194    #[must_use]
195    pub fn show_caption_above_media_option(self, val: Option<bool>) -> Self {
196        Self {
197            show_caption_above_media: val,
198            ..self
199        }
200    }
201
202    #[must_use]
203    pub fn width_option(self, val: Option<i64>) -> Self {
204        Self { width: val, ..self }
205    }
206
207    #[must_use]
208    pub fn height_option(self, val: Option<i64>) -> Self {
209        Self {
210            height: val,
211            ..self
212        }
213    }
214
215    #[must_use]
216    pub fn duration_option(self, val: Option<i64>) -> Self {
217        Self {
218            duration: val,
219            ..self
220        }
221    }
222
223    #[must_use]
224    pub fn has_spoiler_option(self, val: Option<bool>) -> Self {
225        Self {
226            has_spoiler: val,
227            ..self
228        }
229    }
230}