tgbot/types/inline_mode/result/mpeg4_gif/
mod.rs1use serde::{Deserialize, Serialize};
2
3use super::raw::{
4 RawInlineQueryResult,
5 RawInlineQueryResultData,
6 RawInlineQueryResultDataError::{self, MissingField},
7 RawInlineQueryResultType,
8};
9use crate::types::{InlineKeyboardMarkup, InputMessageContent, Integer, ParseMode, TextEntities, TextEntity};
10
11#[cfg(test)]
12mod tests;
13
14#[serde_with::skip_serializing_none]
20#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
21pub struct InlineQueryResultMpeg4Gif {
22 id: String,
23 mpeg4_url: String,
24 thumbnail_url: String,
25 caption: Option<String>,
26 caption_entities: Option<TextEntities>,
27 input_message_content: Option<InputMessageContent>,
28 mpeg4_duration: Option<Integer>,
29 mpeg4_height: Option<Integer>,
30 mpeg4_width: Option<Integer>,
31 parse_mode: Option<ParseMode>,
32 reply_markup: Option<InlineKeyboardMarkup>,
33 show_caption_above_media: Option<bool>,
34 thumbnail_mime_type: Option<String>,
35 title: Option<String>,
36}
37
38impl InlineQueryResultMpeg4Gif {
39 pub fn new<A, B, C>(id: A, mpeg4_url: B, thumbnail_url: C) -> Self
47 where
48 A: Into<String>,
49 B: Into<String>,
50 C: Into<String>,
51 {
52 Self {
53 id: id.into(),
54 mpeg4_url: mpeg4_url.into(),
55 thumbnail_url: thumbnail_url.into(),
56 caption: None,
57 caption_entities: None,
58 input_message_content: None,
59 mpeg4_duration: None,
60 mpeg4_height: None,
61 mpeg4_width: None,
62 parse_mode: None,
63 reply_markup: None,
64 show_caption_above_media: None,
65 thumbnail_mime_type: None,
66 title: None,
67 }
68 }
69
70 pub fn with_caption<T>(mut self, value: T) -> Self
76 where
77 T: Into<String>,
78 {
79 self.caption = Some(value.into());
80 self
81 }
82
83 pub fn with_caption_entities<T>(mut self, value: T) -> Self
91 where
92 T: IntoIterator<Item = TextEntity>,
93 {
94 self.caption_entities = Some(value.into_iter().collect());
95 self.parse_mode = None;
96 self
97 }
98
99 pub fn with_caption_parse_mode(mut self, value: ParseMode) -> Self {
107 self.parse_mode = Some(value);
108 self.caption_entities = None;
109 self
110 }
111
112 pub fn with_input_message_content<T>(mut self, value: T) -> Self
118 where
119 T: Into<InputMessageContent>,
120 {
121 self.input_message_content = Some(value.into());
122 self
123 }
124
125 pub fn with_mpeg4_duration(mut self, value: Integer) -> Self {
131 self.mpeg4_duration = Some(value);
132 self
133 }
134
135 pub fn with_mpeg4_height(mut self, value: Integer) -> Self {
141 self.mpeg4_height = Some(value);
142 self
143 }
144
145 pub fn with_mpeg4_width(mut self, value: Integer) -> Self {
151 self.mpeg4_width = Some(value);
152 self
153 }
154
155 pub fn with_reply_markup<T>(mut self, value: T) -> Self
161 where
162 T: Into<InlineKeyboardMarkup>,
163 {
164 self.reply_markup = Some(value.into());
165 self
166 }
167
168 pub fn with_show_caption_above_media(mut self, value: bool) -> Self {
174 self.show_caption_above_media = Some(value);
175 self
176 }
177
178 pub fn with_thumbnail_mime_type<T>(mut self, value: T) -> Self
186 where
187 T: Into<String>,
188 {
189 self.thumbnail_mime_type = Some(value.into());
190 self
191 }
192
193 pub fn with_title<T>(mut self, value: T) -> Self
199 where
200 T: Into<String>,
201 {
202 self.title = Some(value.into());
203 self
204 }
205}
206
207#[serde_with::skip_serializing_none]
215#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
216pub struct InlineQueryResultCachedMpeg4Gif {
217 id: String,
218 mpeg4_file_id: String,
219 caption: Option<String>,
220 caption_entities: Option<TextEntities>,
221 input_message_content: Option<InputMessageContent>,
222 parse_mode: Option<ParseMode>,
223 reply_markup: Option<InlineKeyboardMarkup>,
224 show_caption_above_media: Option<bool>,
225 title: Option<String>,
226}
227
228impl InlineQueryResultCachedMpeg4Gif {
229 pub fn new<A, B>(id: A, mpeg4_file_id: B) -> Self
236 where
237 A: Into<String>,
238 B: Into<String>,
239 {
240 Self {
241 id: id.into(),
242 mpeg4_file_id: mpeg4_file_id.into(),
243 caption: None,
244 caption_entities: None,
245 input_message_content: None,
246 parse_mode: None,
247 reply_markup: None,
248 show_caption_above_media: None,
249 title: None,
250 }
251 }
252
253 pub fn with_caption<T>(mut self, caption: T) -> Self
259 where
260 T: Into<String>,
261 {
262 self.caption = Some(caption.into());
263 self
264 }
265
266 pub fn with_caption_entities<T>(mut self, value: T) -> Self
274 where
275 T: IntoIterator<Item = TextEntity>,
276 {
277 self.caption_entities = Some(value.into_iter().collect());
278 self.parse_mode = None;
279 self
280 }
281
282 pub fn with_caption_parse_mode(mut self, value: ParseMode) -> Self {
290 self.parse_mode = Some(value);
291 self.caption_entities = None;
292 self
293 }
294
295 pub fn with_input_message_content<T>(mut self, input_message_content: T) -> Self
301 where
302 T: Into<InputMessageContent>,
303 {
304 self.input_message_content = Some(input_message_content.into());
305 self
306 }
307
308 pub fn with_reply_markup<T>(mut self, value: T) -> Self
314 where
315 T: Into<InlineKeyboardMarkup>,
316 {
317 self.reply_markup = Some(value.into());
318 self
319 }
320
321 pub fn with_show_caption_above_media(mut self, value: bool) -> Self {
327 self.show_caption_above_media = Some(value);
328 self
329 }
330
331 pub fn with_title<T>(mut self, title: T) -> Self
337 where
338 T: Into<String>,
339 {
340 self.title = Some(title.into());
341 self
342 }
343}
344
345impl TryFrom<RawInlineQueryResult> for InlineQueryResultMpeg4Gif {
346 type Error = RawInlineQueryResultDataError;
347
348 fn try_from(value: RawInlineQueryResult) -> Result<Self, Self::Error> {
349 Ok(Self {
350 id: value.id,
351 input_message_content: value.data.input_message_content,
352 caption: value.data.caption,
353 caption_entities: value.data.caption_entities,
354 mpeg4_url: value.data.mpeg4_url.ok_or(MissingField("mpeg4_url"))?,
355 mpeg4_width: value.data.mpeg4_width,
356 mpeg4_height: value.data.mpeg4_height,
357 mpeg4_duration: value.data.mpeg4_duration,
358 parse_mode: value.data.parse_mode,
359 reply_markup: value.data.reply_markup,
360 show_caption_above_media: value.data.show_caption_above_media,
361 thumbnail_mime_type: value.data.thumbnail_mime_type,
362 thumbnail_url: value.data.thumbnail_url.ok_or(MissingField("thumbnail_url"))?,
363 title: value.data.title,
364 })
365 }
366}
367
368impl From<InlineQueryResultMpeg4Gif> for RawInlineQueryResult {
369 fn from(value: InlineQueryResultMpeg4Gif) -> Self {
370 Self {
371 data: RawInlineQueryResultData {
372 caption: value.caption,
373 caption_entities: value.caption_entities,
374 input_message_content: value.input_message_content,
375 mpeg4_duration: value.mpeg4_duration,
376 mpeg4_height: value.mpeg4_height,
377 mpeg4_width: value.mpeg4_width,
378 mpeg4_url: Some(value.mpeg4_url),
379 parse_mode: value.parse_mode,
380 reply_markup: value.reply_markup,
381 show_caption_above_media: value.show_caption_above_media,
382 thumbnail_url: Some(value.thumbnail_url),
383 thumbnail_mime_type: value.thumbnail_mime_type,
384 title: value.title,
385 ..Default::default()
386 },
387 id: value.id,
388 result_type: RawInlineQueryResultType::Mpeg4Gif,
389 }
390 }
391}
392
393impl TryFrom<RawInlineQueryResult> for InlineQueryResultCachedMpeg4Gif {
394 type Error = RawInlineQueryResultDataError;
395
396 fn try_from(value: RawInlineQueryResult) -> Result<Self, Self::Error> {
397 Ok(Self {
398 id: value.id,
399 caption: value.data.caption,
400 caption_entities: value.data.caption_entities,
401 input_message_content: value.data.input_message_content,
402 mpeg4_file_id: value.data.mpeg4_file_id.ok_or(MissingField("mpeg4_file_id"))?,
403 parse_mode: value.data.parse_mode,
404 show_caption_above_media: value.data.show_caption_above_media,
405 reply_markup: value.data.reply_markup,
406 title: value.data.title,
407 })
408 }
409}
410
411impl From<InlineQueryResultCachedMpeg4Gif> for RawInlineQueryResult {
412 fn from(value: InlineQueryResultCachedMpeg4Gif) -> Self {
413 Self {
414 data: RawInlineQueryResultData {
415 caption: value.caption,
416 caption_entities: value.caption_entities,
417 input_message_content: value.input_message_content,
418 mpeg4_file_id: Some(value.mpeg4_file_id),
419 parse_mode: value.parse_mode,
420 reply_markup: value.reply_markup,
421 show_caption_above_media: value.show_caption_above_media,
422 title: value.title,
423 ..Default::default()
424 },
425 id: value.id,
426 result_type: RawInlineQueryResultType::CachedMpeg4Gif,
427 }
428 }
429}