Skip to main content

telexide_fork/model/
message_contents.rs

1use super::{utils::unix_date_formatting, User};
2use crate::model::MessageEntity;
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5
6/// This object represents an audio file to be treated as music by the Telegram
7/// clients.
8#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
9pub struct Audio {
10    /// Identifier for this file, which can be used to download or reuse the
11    /// file
12    pub file_id: String,
13    /// Unique identifier for this file, which is supposed to be the same over
14    /// time and for different bots. Can't be used to download or reuse the
15    /// file.
16    pub file_unique_id: String,
17    /// Duration of the audio in seconds as defined by sender
18    pub duration: usize,
19    /// Performer of the audio as defined by sender or by audio tags
20    pub performer: Option<String>,
21    /// Title of the audio as defined by sender or by audio tags
22    pub title: Option<String>,
23    /// Original filename as defined by sender
24    pub file_name: Option<String>,
25    /// MIME type of the file as defined by sender
26    pub mime_type: Option<String>,
27    /// File size
28    pub file_size: Option<usize>,
29    /// Thumbnail of the album cover to which the music file belongs
30    pub thumb: Option<PhotoSize>,
31}
32
33/// This object represents a general file (as opposed to [photos][PhotoSize],
34/// [voice messages][Voice] and [audio files][Audio]).
35#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
36pub struct Document {
37    /// Identifier for this file, which can be used to download or reuse the
38    /// file
39    pub file_id: String,
40    /// Unique identifier for this file, which is supposed to be the same over
41    /// time and for different bots. Can't be used to download or reuse the
42    /// file.
43    pub file_unique_id: String,
44    /// Document thumbnail as defined by sender
45    pub thumb: Option<PhotoSize>,
46    /// Original filename as defined by sender
47    pub file_name: Option<String>,
48    /// MIME type of the file as defined by sender
49    pub mime_type: Option<String>,
50    /// File size
51    pub file_size: Option<usize>,
52}
53
54/// This object represents an animation file (GIF or H.264/MPEG-4 AVC video
55/// without sound).
56#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
57pub struct Animation {
58    /// Identifier for this file, which can be used to download or reuse the
59    /// file
60    pub file_id: String,
61    /// Unique identifier for this file, which is supposed to be the same over
62    /// time and for different bots. Can't be used to download or reuse the
63    /// file.
64    pub file_unique_id: String,
65    /// Video width as defined by sender
66    pub width: usize,
67    /// Video height as defined by sender
68    pub height: usize,
69    /// Duration of the video in seconds as defined by sender
70    pub duration: usize,
71    /// Animation thumbnail as defined by sender
72    pub thumb: Option<PhotoSize>,
73    /// MIME type of the file as defined by sender
74    pub mime_type: Option<String>,
75    /// File size
76    pub file_size: Option<usize>,
77    /// Original animation filename as defined by sender
78    pub file_name: Option<String>,
79}
80
81/// This object represents one size of a photo or a file / sticker thumbnail
82#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
83pub struct PhotoSize {
84    /// Identifier for this file, which can be used to download or reuse the
85    /// file
86    pub file_id: String,
87    /// Unique identifier for this file, which is supposed to be the same over
88    /// time and for different bots. Can't be used to download or reuse the
89    /// file.
90    pub file_unique_id: String,
91    /// Photo width
92    pub width: usize,
93    /// Photo height
94    pub height: usize,
95    /// File size
96    pub file_size: Option<usize>,
97}
98
99/// This object represents a video file
100#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
101pub struct Video {
102    /// Identifier for this file, which can be used to download or reuse the
103    /// file
104    pub file_id: String,
105    /// Unique identifier for this file, which is supposed to be the same over
106    /// time and for different bots. Can't be used to download or reuse the
107    /// file.
108    pub file_unique_id: String,
109    /// Video width as defined by sender
110    pub width: usize,
111    /// Video height as defined by sender
112    pub height: usize,
113    /// Duration of the video in seconds as defined by sender
114    pub duration: usize,
115    /// Video thumbnail
116    pub thumb: Option<PhotoSize>,
117    /// Original filename as defined by sender
118    pub file_name: Option<String>,
119    /// Mime type of a file as defined by sender
120    pub mime_type: Option<String>,
121    /// File size
122    pub file_size: Option<usize>,
123}
124
125/// This object represents a voice note
126#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
127pub struct Voice {
128    /// Identifier for this file, which can be used to download or reuse the
129    /// file
130    pub file_id: String,
131    /// Unique identifier for this file, which is supposed to be the same over
132    /// time and for different bots. Can't be used to download or reuse the
133    /// file.
134    pub file_unique_id: String,
135    /// Duration of the audio in seconds as defined by sender
136    pub duration: usize,
137    /// MIME type of the file as defined by sender
138    pub mime_type: Option<String>,
139    /// File size
140    pub file_size: Option<usize>,
141}
142
143/// This object represents a [video message](https://telegram.org/blog/video-messages-and-telescope)
144#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
145pub struct VideoNote {
146    /// Identifier for this file, which can be used to download or reuse the
147    /// file
148    pub file_id: String,
149    /// Unique identifier for this file, which is supposed to be the same over
150    /// time and for different bots. Can't be used to download or reuse the
151    /// file.
152    pub file_unique_id: String,
153    /// Video width and height (diameter of the video message) as defined by
154    /// sender
155    pub length: usize,
156    /// Duration of the video in seconds as defined by sender
157    pub duration: usize,
158    /// Video thumbnail
159    pub thumb: Option<PhotoSize>,
160    /// File size
161    pub file_size: Option<usize>,
162}
163
164/// This object represents a phone contact.
165#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
166pub struct Contact {
167    /// Contact's phone number
168    pub phone_number: String,
169    /// Contact's first name
170    pub first_name: String,
171    /// Contact's last name
172    pub last_name: Option<String>,
173    /// Contact's user identifier in Telegram
174    pub user_id: Option<i64>,
175    /// Additional data about the contact in the form of a [vCard]
176    ///
177    /// [vCard]: https://en.wikipedia.org/wiki/VCard
178    pub vcard: Option<String>,
179}
180
181/// This object represents a point on the map.
182#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
183pub struct Location {
184    /// Longitude as defined by sender
185    pub longitude: f64,
186    /// Latitude as defined by sender
187    pub latitude: f64,
188    /// The radius of uncertainty for the location, measured in meters; 0-1500.
189    pub horizontal_accuracy: Option<f64>,
190    /// Time relative to the message sending date, during which the location can
191    /// be updated, in seconds. For active live locations only.
192    pub live_period: Option<i64>,
193    /// The direction in which user is moving, in degrees; 1-360. For active
194    /// live locations only.
195    pub heading: Option<i64>,
196    /// Maximum distance for proximity alerts about approaching another chat
197    /// member, in meters. For sent live locations only.
198    pub proximity_alert_radius: Option<i64>,
199}
200
201/// This object represents a venue.
202#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
203pub struct Venue {
204    /// Venue location
205    pub location: Location,
206    /// Name of the venue
207    pub title: String,
208    /// Address of the venue
209    pub address: String,
210    /// Foursquare identifier of the venue
211    pub foursquare_id: Option<String>,
212    /// Foursquare type of the venue.
213    /// (For example, “arts_entertainment/default”,
214    /// “arts_entertainment/aquarium” or “food/icecream”.)
215    pub foursquare_type: Option<String>,
216    /// Google Places identifier of the venue
217    pub google_place_id: Option<String>,
218    /// Google Places type of the venue. (See [supported types].)
219    ///
220    /// [supported types]: https://developers.google.com/places/web-service/supported_types
221    pub google_place_type: Option<String>,
222}
223
224/// This object contains information about a poll.
225#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
226pub struct Poll {
227    /// Unique poll identifier
228    pub id: String,
229    /// Poll question, 1-255 characters
230    pub question: String,
231    /// List of poll options
232    pub options: Vec<PollOption>,
233    /// Total number of users that voted in the poll
234    pub total_voter_count: usize,
235    /// True, if the poll is closed
236    #[serde(default)]
237    pub is_closed: bool,
238    /// True, if the poll is anonymous
239    #[serde(default)]
240    pub is_anonymous: bool,
241    /// True, if the poll allows multiple answers
242    #[serde(default)]
243    pub allows_multiple_answers: bool,
244    /// Poll type
245    #[serde(rename = "type")]
246    pub poll_type: PollType,
247    /// 0-based identifier of the correct answer option.
248    /// Available only for polls in the quiz mode, which are closed,
249    /// or was sent (not forwarded) by the bot or to the private chat with the
250    /// bot.
251    pub correct_option_id: Option<usize>,
252    /// Text that is shown when a user chooses an incorrect answer or taps on
253    /// the lamp icon in a quiz-style poll, 0-200 characters
254    pub explanation: Option<String>,
255    /// Special entities like usernames, URLs, bot commands, etc. that appear in
256    /// the explanation
257    pub explanation_entities: Option<Vec<MessageEntity>>,
258    /// Amount of time in seconds the poll will be active after creation
259    pub open_period: Option<i64>,
260    /// Point in time when the poll will be automatically closed
261    #[serde(default)]
262    #[serde(with = "unix_date_formatting::optional")]
263    pub close_date: Option<DateTime<Utc>>,
264}
265
266/// This object represents a dice with a random value from 1 to 6 for currently
267/// supported base emoji.
268#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
269pub struct Dice {
270    /// Emoji on which the dice throw animation is based
271    pub emoji: String,
272    /// Value of the dice, 1-6 for “🎲”, “🎯” and “🎳” base emoji, 1-5 for “🏀”
273    /// and “⚽” base emoji, 1-64 for “🎰” base emoji
274    pub value: u8,
275}
276
277/// This object contains information about one answer option in a poll.
278#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
279pub struct PollOption {
280    /// Option text, 1-100 characters
281    pub text: String,
282    /// Number of users that voted for this option
283    pub voter_count: usize,
284}
285
286/// This object represents an answer of a user in a non-anonymous poll.
287#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
288pub struct PollAnswer {
289    /// Unique poll identifier
290    pub poll_id: String,
291    /// The user, who changed the answer to the poll
292    pub user: User,
293    /// 0-based identifiers of answer options, chosen by the user.
294    /// May be empty if the user retracted their vote
295    pub option_ids: Vec<usize>,
296}
297
298/// The type of the [`Poll`]
299#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
300pub enum PollType {
301    #[serde(rename = "regular")]
302    Regular,
303    #[serde(rename = "quiz")]
304    Quiz,
305}
306
307/// This object represents a parameter of the inline keyboard button used to
308/// automatically authorize a user. Serves as a great replacement for the
309/// [Telegram Login Widget] when the user is coming from Telegram. All the user
310/// needs to do is tap/click a button and confirm that they want to log in
311///
312/// [Telegram Login Widget]: https://core.telegram.org/widgets/login
313#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
314pub struct LoginUrl {
315    /// An HTTP URL to be opened with user authorization data added to the query
316    /// string when the button is pressed. If the user refuses to provide
317    /// authorization data, the original URL without information about the user
318    /// will be opened. The data added is the same as described in
319    /// [Receiving authorization data].
320    ///
321    /// **NOTE:** You must always check the hash of the received data to verify
322    /// the authentication and the integrity of the data as described in
323    /// [Checking authorization].
324    ///
325    /// [Receiving authorization data]: https://core.telegram.org/widgets/login#receiving-authorization-data
326    /// [Checking authorization]: https://core.telegram.org/widgets/login#checking-authorization
327    pub url: String,
328    /// New text of the button in forwarded messages.
329    pub forward_text: Option<String>,
330    /// Username of a bot, which will be used for user authorization. See
331    /// [Setting up a bot][setup] for more details. If not specified, the
332    /// current bot's username will be assumed. The url's domain must be the
333    /// same as the domain linked with the bot. See [Linking your domain to
334    /// the bot][linking] for more details.
335    ///
336    /// [setup]: https://core.telegram.org/widgets/login#setting-up-a-bot
337    /// [linking]: https://core.telegram.org/widgets/login#linking-your-domain-to-the-bot
338    pub bot_username: Option<String>,
339    /// Pass True to request the permission for your bot to send messages to the
340    /// user.
341    #[serde(default)]
342    pub request_write_access: bool,
343}
344
345/// This object represents the content of a service message, sent whenever a
346/// user in the chat triggers a proximity alert set by another user.
347#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
348pub struct ProximityAlertTriggered {
349    /// User that triggered the alert
350    pub traveler: User,
351    /// User that set the alert
352    pub watcher: User,
353    /// The distance between the users
354    pub distance: i64,
355}
356
357/// This object represents a service message about a voice chat scheduled in the chat.
358#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
359pub struct VoiceChatScheduled {
360    /// Point in time when the voice chat is supposed to be started by a chat
361    /// administrator
362    #[serde(with = "unix_date_formatting")]
363    pub start_date: DateTime<Utc>,
364}
365
366/// This object represents a service message about a voice chat started in the
367/// chat. Currently holds no information.
368#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
369pub struct VoiceChatStarted {}
370
371/// This object represents a service message about a voice chat ended in the
372/// chat.
373#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
374pub struct VoiceChatEnded {
375    /// Voice chat duration; in seconds
376    pub duration: i64,
377}
378
379/// This object represents a service message about new members invited to a
380/// voice chat.
381#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
382pub struct VoiceChatParticipantsInvited {
383    /// New members that were invited to the voice chat.
384    #[serde(default)]
385    pub users: Option<Vec<User>>,
386}
387
388/// This object represents a service message about a change in auto-delete timer
389/// settings.
390#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
391pub struct MessageAutoDeleteTimerChanged {
392    /// New auto-delete time for messages in the chat
393    pub message_auto_delete_time: i64,
394}