teloxide_core/types/
inline_query_result_mpeg4_gif.rs

1use serde::{Deserialize, Serialize};
2
3use crate::types::{InlineKeyboardMarkup, InputMessageContent, MessageEntity, ParseMode, Seconds};
4
5/// Represents a link to a video animation (H.264/MPEG-4 AVC video without
6/// sound).
7///
8/// By default, this animated MPEG-4 file will be sent by the user with optional
9/// caption. Alternatively, you can use `input_message_content` to send
10/// a message with the specified content instead of the animation.
11///
12/// [The official docs](https://core.telegram.org/bots/api#inlinequeryresultmpeg4gif).
13#[serde_with::skip_serializing_none]
14#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
15pub struct InlineQueryResultMpeg4Gif {
16    /// Unique identifier for this result, 1-64 bytes.
17    pub id: String,
18
19    // FIXME: rename everything so that it doesn't have `mpeg4_` (and similarly for other
20    // `InlineQueryResult*`)
21    /// A valid URL for the MP4 file. File size must not exceed 1MB.
22    pub mpeg4_url: reqwest::Url,
23
24    /// Video width.
25    pub mpeg4_width: Option<u32>,
26
27    /// Video height.
28    pub mpeg4_height: Option<u32>,
29
30    /// Video duration.
31    pub mpeg4_duration: Option<Seconds>,
32
33    /// URL of the static (JPEG or GIF) or animated (MPEG4) thumbnail for the
34    /// result
35    pub thumbnail_url: reqwest::Url,
36
37    // FIXME: maybe make dedicated enum for the mime type?
38    /// MIME type of the thumbnail, must be one of “image/jpeg”, “image/gif”, or
39    /// “video/mp4”. Defaults to “image/jpeg”
40    pub thumbnail_mime_type: Option<String>,
41
42    /// Title for the result.
43    pub title: Option<String>,
44
45    /// Caption of the MPEG-4 file to be sent, 0-1024 characters.
46    pub caption: Option<String>,
47
48    /// Send [Markdown] or [HTML], if you want Telegram apps to show [bold,
49    /// italic, fixed-width text or inline URLs] in the media caption.
50    ///
51    /// [Markdown]: https://core.telegram.org/bots/api#markdown-style
52    /// [HTML]: https://core.telegram.org/bots/api#html-style
53    /// [bold, italic, fixed-width text or inline URLs]: https://core.telegram.org/bots/api#formatting-options
54    pub parse_mode: Option<ParseMode>,
55
56    /// List of special entities that appear in the caption, which can be
57    /// specified instead of `parse_mode`.
58    pub caption_entities: Option<Vec<MessageEntity>>,
59
60    /// Pass `true`, if the caption must be shown above the message media.
61    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
62    pub show_caption_above_media: bool,
63
64    /// [Inline keyboard] attached to the message.
65    ///
66    /// [Inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
67    pub reply_markup: Option<InlineKeyboardMarkup>,
68
69    /// Content of the message to be sent instead of the video animation.
70    pub input_message_content: Option<InputMessageContent>,
71}
72
73impl InlineQueryResultMpeg4Gif {
74    pub fn new<S>(id: S, mpeg4_url: reqwest::Url, thumbnail_url: reqwest::Url) -> Self
75    where
76        S: Into<String>,
77    {
78        Self {
79            id: id.into(),
80            mpeg4_url,
81            thumbnail_url,
82            thumbnail_mime_type: None,
83            mpeg4_width: None,
84            mpeg4_height: None,
85            mpeg4_duration: None,
86            title: None,
87            caption: None,
88            parse_mode: None,
89            caption_entities: None,
90            show_caption_above_media: false,
91            reply_markup: None,
92            input_message_content: None,
93        }
94    }
95
96    pub fn id<S>(mut self, val: S) -> Self
97    where
98        S: Into<String>,
99    {
100        self.id = val.into();
101        self
102    }
103
104    #[must_use]
105    pub fn mpeg4_url(mut self, val: reqwest::Url) -> Self {
106        self.mpeg4_url = val;
107        self
108    }
109
110    #[must_use]
111    pub fn mpeg4_width(mut self, val: u32) -> Self {
112        self.mpeg4_width = Some(val);
113        self
114    }
115
116    #[must_use]
117    pub fn mpeg4_height(mut self, val: u32) -> Self {
118        self.mpeg4_height = Some(val);
119        self
120    }
121
122    #[must_use]
123    pub fn mpeg4_duration(mut self, val: Seconds) -> Self {
124        self.mpeg4_duration = Some(val);
125        self
126    }
127
128    #[must_use]
129    pub fn thumbnail_url(mut self, val: reqwest::Url) -> Self {
130        self.thumbnail_url = val;
131        self
132    }
133
134    pub fn title<S>(mut self, val: S) -> Self
135    where
136        S: Into<String>,
137    {
138        self.title = Some(val.into());
139        self
140    }
141
142    pub fn caption<S>(mut self, val: S) -> Self
143    where
144        S: Into<String>,
145    {
146        self.caption = Some(val.into());
147        self
148    }
149
150    #[must_use]
151    pub fn parse_mode(mut self, val: ParseMode) -> Self {
152        self.parse_mode = Some(val);
153        self
154    }
155
156    pub fn caption_entities<C>(mut self, val: C) -> Self
157    where
158        C: IntoIterator<Item = MessageEntity>,
159    {
160        self.caption_entities = Some(val.into_iter().collect());
161        self
162    }
163
164    pub fn show_caption_above_media(mut self, val: bool) -> Self {
165        self.show_caption_above_media = val;
166        self
167    }
168
169    #[must_use]
170    pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
171        self.reply_markup = Some(val);
172        self
173    }
174
175    #[must_use]
176    pub fn input_message_content(mut self, val: InputMessageContent) -> Self {
177        self.input_message_content = Some(val);
178        self
179    }
180}