Skip to main content

pilot/
typing.rs

1use serde::{Deserialize, Serialize};
2use serde_with::skip_serializing_none;
3
4#[skip_serializing_none]
5#[derive(Debug, Serialize, Deserialize, Clone)]
6pub struct User {
7    /// Unique identifier for this user or bot
8    pub id: i32,
9    /// True, if this user is a bot
10    pub is_bot: bool,
11    /// User‘s or bot’s first name
12    pub first_name: String,
13    /// User‘s or bot’s last name
14    pub last_name: Option<String>,
15    /// User‘s or bot’s username
16    pub username: Option<String>,
17    /// [IETF language tag](https://en.wikipedia.org/wiki/IETF_language_tag) of the user's language
18    pub language_code: Option<String>,
19}
20
21#[skip_serializing_none]
22#[derive(Debug, Serialize, Deserialize, Clone)]
23pub struct WebhookInfo {
24    /// Webhook URL, may be empty if webhook is not set up
25    pub url: String,
26    /// True, if a custom certificate was provided for webhook certificate checks
27    pub has_custom_certificate: bool,
28    /// Number of updates awaiting delivery
29    pub pending_update_count: i32,
30    /// Unix time for the most recent error that happened when trying to deliver an update via webhook
31    pub last_error_date: Option<i32>,
32    /// Error message in human-readable format for the most recent error that happened when trying to deliver an update via webhook
33    pub last_error_message: Option<String>,
34    /// Maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery
35    pub max_connections: Option<i32>,
36    /// A list of update types the bot is subscribed to. Defaults to all update types
37    pub allowed_updates: Option<Vec<String>>,
38}
39
40/// This object represents an incoming update.
41/// At most one of the optional parameters can be present in any given update.
42#[skip_serializing_none]
43#[derive(Debug, Serialize, Deserialize, Clone)]
44pub struct Update {
45    /// The update‘s unique identifier. Update identifiers start from a certain positive number and increase sequentially. This ID becomes especially handy if you’re using Webhooks, since it allows you to ignore repeated updates or to restore the correct update sequence, should they get out of order. If there are no new updates for at least a week, then identifier of the next update will be chosen randomly instead of sequentially.
46    pub update_id: i32,
47    /// New incoming message of any kind — text, photo, sticker, etc.
48    #[serde(flatten)]
49    pub message: UpdateMessage,
50}
51
52#[derive(Debug, Serialize, Deserialize, Clone)]
53#[serde(rename_all = "snake_case")]
54pub enum UpdateMessage {
55    /// New incoming message of any kind — text, photo, sticker, etc.
56    Message(Message),
57    /// New version of a message that is known to the bot and was edited
58    EditedMessage(Message),
59    /// New incoming channel post of any kind — text, photo, sticker, etc.
60    ChannelPost(Message),
61    /// New version of a channel post that is known to the bot and was edited
62    EditedChannelPost(Message),
63    /// New incoming inline query
64    InlineQuery(InlineQuery),
65    /// The result of an inline query that was chosen by a user and sent to their chat partner. Please see our documentation on the feedback collecting for details on how to enable these updates for your bot.
66    ChosenInlineResult(ChosenInlineResult),
67    /// New incoming callback query
68    CallbackQuery(CallbackQuery),
69    /// New incoming shipping query. Only for invoices with flexible price
70    ShippingQuery(ShippingAddress),
71    /// New incoming pre-checkout query. Contains full information about checkout
72    PreCheckoutQuery(PreCheckoutQuery),
73    /// New poll state. Bots receive only updates about polls, which are sent or stopped by the bot
74    Poll(Poll),
75    #[serde(other)]
76    Unknown,
77}
78
79#[skip_serializing_none]
80#[derive(Debug, Serialize, Deserialize, Clone)]
81#[serde(rename_all(serialize = "lowercase", deserialize = "lowercase"))]
82pub enum ChatType {
83    Private,
84    Group,
85    SuperGroup,
86    Channel,
87}
88
89#[skip_serializing_none]
90#[derive(Debug, Serialize, Deserialize, Clone)]
91pub struct Chat {
92    /// Unique identifier for this chat.
93    pub id: i64,
94    /// Type of chat
95    #[serde(rename = "type")]
96    pub chat_type: ChatType,
97    /// Title, for supergroups, channels and group chats
98    pub title: Option<String>,
99    /// Username, for private chats, supergroups and channels if available
100    pub username: Option<String>,
101    /// First name of the other party in a private chat
102    pub first_name: Option<String>,
103    /// Last name of the other party in a private chat
104    pub last_name: Option<String>,
105    /// True if a group has ‘All Members Are Admins’ enabled.
106    pub all_members_are_administrators: Option<bool>,
107    /// Chat photo. Returned only in getChat.
108    pub photo: Option<ChatPhoto>,
109    /// Description, for supergroups and channel chats. Returned only in getChat.
110    pub description: Option<String>,
111    /// Chat invite link, for supergroups and channel chats. Each administrator in a chat generates their own invite links, so the bot must first generate the link using exportChatInviteLink. Returned only in getChat.
112    pub invite_link: Option<String>,
113    /// Pinned message, for groups, supergroups and channels. Returned only in getChat.
114    pub pinned_message: Option<Box<Message>>,
115    /// For supergroups, name of group sticker set. Returned only in getChat.
116    pub sticker_set_name: Option<String>,
117    /// True, if the bot can change the group sticker set. Returned only in getChat.
118    pub can_set_sticker_set: Option<bool>,
119}
120
121#[skip_serializing_none]
122#[derive(Debug, Serialize, Deserialize, Clone)]
123pub struct Message {
124    pub message_id: i32,
125    pub from: Option<User>,
126    pub date: i32,
127    pub chat: Box<Chat>,
128    pub forward_from: Option<User>,
129    pub forward_from_chat: Option<Box<Chat>>,
130    pub forward_from_message_id: Option<i32>,
131    pub forward_signature: Option<String>,
132    pub forward_sender_name: Option<String>,
133    pub forward_date: Option<i32>,
134    pub reply_to_message: Option<Box<Message>>,
135    pub edit_date: Option<i32>,
136    pub media_group_id: Option<String>,
137    pub author_signature: Option<String>,
138    pub text: Option<String>,
139    pub entities: Option<Vec<MessageEntity>>,
140    pub caption_entities: Option<Vec<MessageEntity>>,
141    pub audio: Option<Audio>,
142    pub document: Option<Document>,
143    pub animation: Option<Animation>,
144    pub game: Option<Game>,
145    pub photo: Option<Vec<PhotoSize>>,
146    pub sticker: Option<Sticker>,
147    pub video: Option<Video>,
148    pub voice: Option<Voice>,
149    pub video_note: Option<VideoNote>,
150    pub caption: Option<String>,
151    pub contact: Option<Contact>,
152    pub location: Option<Location>,
153    pub venue: Option<Venue>,
154    pub poll: Option<Poll>,
155    pub new_chat_members: Option<Vec<User>>,
156    pub left_chat_member: Option<User>,
157    pub new_chat_title: Option<String>,
158    pub new_chat_photo: Option<Vec<PhotoSize>>,
159    pub delete_chat_photo: Option<bool>,
160    pub group_chat_created: Option<bool>,
161    pub supergroup_chat_created: Option<bool>,
162    pub channel_chat_created: Option<bool>,
163    pub migrate_to_chat_id: Option<bool>,
164    pub migrate_from_chat_id: Option<i64>,
165    pub pinned_message: Option<Box<Message>>,
166    pub invoice: Option<Invoice>,
167    pub successful_payment: Option<SuccessfulPayment>,
168    pub connected_website: Option<String>,
169    pub passport_data: Option<PassportData>,
170}
171
172#[skip_serializing_none]
173#[derive(Debug, Serialize, Deserialize, Clone)]
174pub struct MessageEntity {
175    #[serde(rename = "type")]
176    pub message_type: MessageEntityType,
177    pub offset: i32,
178    pub length: i32,
179    pub url: Option<String>,
180    pub user: Option<User>,
181}
182#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord)]
183#[serde(rename_all="snake_case")]
184pub enum MessageEntityType {
185    Mention,
186    Hashtag,
187    Cashtag,
188    BotCommand,
189    Url,
190    Email,
191    PhoneNumber,
192    Bold,
193    Italic,
194    Underline,
195    Strikethough,
196    Code,
197    Pre,
198    TextLink,
199    TextMention,
200}
201
202
203#[skip_serializing_none]
204#[derive(Debug, Serialize, Deserialize, Clone)]
205pub struct InlineQuery {
206    pub id: String,
207    pub from: User,
208    pub location: Option<Location>,
209    pub query: String,
210    pub offset: String,
211}
212
213#[skip_serializing_none]
214#[derive(Debug, Serialize, Deserialize, Clone)]
215pub struct PhotoSize {
216    pub file_id: String,
217    pub width: i32,
218    pub height: i32,
219    pub file_size: Option<i32>,
220}
221
222#[skip_serializing_none]
223#[derive(Debug, Serialize, Deserialize, Clone)]
224pub struct Audio {
225    pub file_id: String,
226    pub duration: i32,
227    pub performer: Option<String>,
228    pub title: Option<String>,
229    pub mime_type: Option<String>,
230    pub file_size: Option<i32>,
231    pub thumb: Option<PhotoSize>,
232}
233
234#[skip_serializing_none]
235#[derive(Debug, Serialize, Deserialize, Clone)]
236pub struct Document {
237    pub file_id: String,
238    pub thumb: Option<PhotoSize>,
239    pub file_name: Option<String>,
240    pub mime_type: Option<String>,
241    pub file_size: Option<i32>,
242}
243
244#[skip_serializing_none]
245#[derive(Debug, Serialize, Deserialize, Clone)]
246pub struct Video {
247    pub file_id: String,
248    pub width: i32,
249    pub height: i32,
250    pub duration: i32,
251    pub thumb: Option<PhotoSize>,
252    pub mime_type: Option<String>,
253    pub file_size: Option<i32>,
254}
255
256#[skip_serializing_none]
257#[derive(Debug, Serialize, Deserialize, Clone)]
258pub struct Animation {
259    pub file_id: String,
260    pub width: i32,
261    pub height: i32,
262    pub duration: i32,
263    pub thumb: Option<PhotoSize>,
264    pub file_name: Option<String>,
265    pub mime_type: Option<String>,
266    pub file_size: Option<i32>,
267}
268
269#[skip_serializing_none]
270#[derive(Debug, Serialize, Deserialize, Clone)]
271pub struct ChosenInlineResult {
272    pub result_id: String,
273    pub from: User,
274    pub location: Option<Location>,
275    pub inline_message_id: Option<String>,
276    pub query: String,
277}
278
279#[skip_serializing_none]
280#[derive(Debug, Serialize, Deserialize, Clone)]
281pub struct ShippingQuery {
282    pub id: String,
283    pub from: User,
284    pub invoice_payload: String,
285    pub shipping_address: ShippingAddress,
286}
287
288#[skip_serializing_none]
289#[derive(Debug, Serialize, Deserialize, Clone)]
290pub struct PreCheckoutQuery {
291    pub id: String,
292    pub from: User,
293    pub currency: String,
294    pub total_amount: i32,
295    pub invoice_payload: String,
296    pub shipping_option_id: Option<String>,
297    pub order_info: Option<OrderInfo>,
298}
299
300#[skip_serializing_none]
301#[derive(Debug, Serialize, Deserialize, Clone)]
302pub struct Voice {
303    file_id: String,
304    duration: i32,
305    mime_type: Option<String>,
306    file_size: Option<i32>,
307}
308
309#[skip_serializing_none]
310#[derive(Debug, Serialize, Deserialize, Clone)]
311pub struct VideoNote {
312    file_id: String,
313    length: i32,
314    duration: i32,
315    thumb: Option<PhotoSize>,
316    file_size: Option<i32>,
317}
318
319#[skip_serializing_none]
320#[derive(Debug, Serialize, Deserialize, Clone)]
321pub struct Contact {
322    phone_number: String,
323    first_name: String,
324    last_name: Option<String>,
325    user_id: Option<i32>,
326    vcard: Option<String>,
327}
328
329#[skip_serializing_none]
330#[derive(Debug, Serialize, Deserialize, Clone)]
331pub struct Location {
332    longitude: f64,
333    latitude: f64,
334}
335
336#[skip_serializing_none]
337#[derive(Debug, Serialize, Deserialize, Clone)]
338pub struct Venue {
339    location: Location,
340    title: String,
341    address: String,
342    foursquare_id: Option<String>,
343    foursquare_type: Option<String>,
344}
345
346#[skip_serializing_none]
347#[derive(Debug, Serialize, Deserialize, Clone)]
348pub struct PollOption {
349    text: String,
350    voter_count: i32,
351}
352
353#[skip_serializing_none]
354#[derive(Debug, Serialize, Deserialize, Clone)]
355pub struct Poll {
356    id: String,
357    question: String,
358    options: Vec<PollOption>,
359    is_closed: bool,
360}
361
362#[skip_serializing_none]
363#[derive(Debug, Serialize, Deserialize, Clone)]
364pub struct UserProfilePhotos {
365    total_count: i32,
366    photo: Vec<Vec<PhotoSize>>,
367}
368
369#[skip_serializing_none]
370#[derive(Debug, Serialize, Deserialize, Clone)]
371pub struct File {
372    file_id: String,
373    file_unique_id: String,
374    file_size: Option<i32>,
375    file_path: Option<String>,
376}
377
378#[skip_serializing_none]
379#[derive(Debug, Serialize, Deserialize, Clone)]
380pub struct ReplyKeyboardMarkup {
381    keyboard: Vec<Vec<KeyboardButton>>,
382    resize_keyboard: Option<bool>,
383    one_time_keyboard: Option<bool>,
384    selective: Option<bool>,
385}
386
387#[skip_serializing_none]
388#[derive(Debug, Serialize, Deserialize, Clone)]
389pub struct KeyboardButton {
390    text: String,
391    request_contact: Option<bool>,
392    request_location: Option<bool>,
393}
394
395#[skip_serializing_none]
396#[derive(Debug, Serialize, Deserialize, Clone)]
397pub struct ReplyKeyboardRemove {
398    /// should be true
399    remove_keyboard: bool,
400    selective: Option<bool>,
401}
402
403#[skip_serializing_none]
404#[derive(Debug, Serialize, Deserialize, Clone)]
405pub struct InlineKeyboardMarkup {
406    pub inline_keyboard: Vec<Vec<InlineKeyboardButton>>,
407}
408
409#[skip_serializing_none]
410#[derive(Debug, Serialize, Deserialize, Clone)]
411pub struct InlineKeyboardButton {
412    pub text: String,
413    pub url: Option<String>,
414    pub callback_data: Option<String>,
415    pub switch_inline_query: Option<String>,
416    pub switch_inline_query_current_chat: Option<String>,
417    pub callback_game: Option<CallbackGame>,
418    pub pay: Option<bool>,
419}
420
421#[skip_serializing_none]
422#[derive(Debug, Serialize, Deserialize, Clone)]
423pub struct CallbackQuery {
424    id: String,
425    from: User,
426    message: Option<Message>,
427    inline_message_id: Option<String>,
428    chat_instance: String,
429    data: Option<String>,
430    game_short_name: Option<String>,
431}
432
433#[skip_serializing_none]
434#[derive(Debug, Serialize, Deserialize, Clone)]
435pub struct ForceReply {
436    /// should be true
437    force_reply: bool,
438    selective: Option<bool>,
439}
440
441#[skip_serializing_none]
442#[derive(Debug, Serialize, Deserialize, Clone)]
443pub struct ChatPhoto {
444    small_file_id: String,
445    big_file_id: String,
446}
447
448#[skip_serializing_none]
449#[derive(Debug, Serialize, Deserialize, Clone)]
450pub enum ChatMemberStatus {
451    Creator,
452    Administrator,
453    Member,
454    Restricted,
455    Left,
456    Kicked,
457}
458
459#[skip_serializing_none]
460#[derive(Debug, Serialize, Deserialize, Clone)]
461pub struct ChatMember {
462    user: User,
463    status: ChatMemberStatus,
464    until_date: Option<i32>,
465    can_be_edited: Option<bool>,
466    can_change_info: Option<bool>,
467    can_post_messages: Option<bool>,
468    can_edit_messages: Option<bool>,
469    can_delete_messages: Option<bool>,
470    can_invite_users: Option<bool>,
471    can_restrict_members: Option<bool>,
472    can_pin_messages: Option<bool>,
473    can_promote_members: Option<bool>,
474    is_member: Option<bool>,
475    can_send_messages: Option<bool>,
476    can_send_media_messages: Option<bool>,
477    can_send_other_message: Option<bool>,
478    can_add_web_page_previews: Option<bool>,
479}
480
481#[skip_serializing_none]
482#[derive(Debug, Serialize, Deserialize, Clone)]
483pub struct ResponseParameters {
484    migrate_to_chat_id: Option<i32>,
485    retry_after: Option<i32>,
486}
487
488#[derive(Debug, Serialize, Deserialize, Clone)]
489pub enum InputMedia {
490    Animation(InputMediaAnimation),
491    Document(InputMediaDocument),
492    Audio(InputMediaAudio),
493    Photo(InputMediaPhoto),
494    Video(InputMediaVideo),
495}
496
497#[derive(Debug, Serialize, Deserialize, Clone)]
498pub enum ParseMode {
499    Markdown,
500    Html,
501}
502
503#[derive(Debug, Serialize, Deserialize, Clone)]
504pub struct InputMediaPhoto {
505    /// always be photo
506    #[serde(rename = "type")]
507    photo_type: String,
508    media: String,
509    caption: Option<String>,
510    parse_mode: Option<ParseMode>,
511}
512
513#[derive(Debug, Serialize, Deserialize, Clone)]
514pub struct InputMediaVideo {
515    #[serde(rename = "type")]
516    video_type: String,
517    media: String,
518    /// TODO inputFile
519    thumb: Option<String>,
520    caption: Option<String>,
521    parse_mode: Option<ParseMode>,
522    width: Option<i32>,
523    height: Option<i32>,
524    duration: Option<i32>,
525    supports_streaming: Option<bool>,
526}
527
528#[derive(Debug, Serialize, Deserialize, Clone)]
529pub struct InputMediaAudio {
530    #[serde(rename = "type")]
531    audio_type: String,
532    media: String,
533    thumb: Option<String>,
534    caption: Option<String>,
535    parse_mod: Option<ParseMode>,
536    duration: Option<i32>,
537    performer: Option<String>,
538    title: Option<String>,
539}
540
541#[derive(Debug, Serialize, Deserialize, Clone)]
542pub struct InputMediaAnimation {
543    #[serde(rename = "type")]
544    animation_type: String,
545    media: String,
546    thumb: Option<String>,
547    caption: Option<String>,
548    parse_mode: Option<ParseMode>,
549    width: Option<i32>,
550    height: Option<i32>,
551    duration: Option<i32>,
552}
553
554#[derive(Debug, Serialize, Deserialize, Clone)]
555pub struct InputMediaDocument {
556    #[serde(rename = "type")]
557    document_type: String,
558    media: String,
559    thumb: Option<String>,
560    caption: Option<String>,
561    parse_mode: Option<ParseMode>,
562}
563
564#[derive(Debug, Serialize, Deserialize, Clone)]
565pub struct Sticker {
566    file_id: String,
567    width: i32,
568    height: i32,
569    thumb: Option<PhotoSize>,
570    emoji: Option<String>,
571    set_name: Option<String>,
572    mask_position: Option<String>,
573    fil_size: Option<i32>,
574}
575
576#[derive(Debug, Serialize, Deserialize, Clone)]
577pub struct Game {
578    title: String,
579    description: String,
580    photo: Vec<PhotoSize>,
581    text: Option<String>,
582    text_entities: Option<Vec<MessageEntity>>,
583    animation: Option<Animation>,
584}
585
586#[derive(Debug, Serialize, Deserialize, Clone)]
587pub struct CallbackGame;
588
589#[derive(Debug, Serialize, Deserialize, Clone)]
590pub struct Invoice {
591    title: String,
592    description: String,
593    start_parameter: String,
594    currency: String,
595    total_amount: i32,
596}
597
598#[derive(Debug, Serialize, Deserialize, Clone)]
599pub struct SuccessfulPayment {
600    currency: String,
601    total_amount: i32,
602    invoice_payload: String,
603    shipping_option_id: Option<String>,
604    order_info: Option<OrderInfo>,
605    telegram_payment_charge_id: String,
606    provider_payment_charge_id: String,
607}
608
609#[derive(Debug, Serialize, Deserialize, Clone)]
610pub struct OrderInfo {
611    name: Option<String>,
612    phone_number: Option<String>,
613    email: Option<String>,
614    shipping_address: Option<ShippingAddress>,
615}
616
617#[derive(Debug, Serialize, Deserialize, Clone)]
618pub struct ShippingAddress {
619    country_code: String,
620    state: String,
621    city: String,
622    street_line1: String,
623    street_line2: String,
624    post_code: String,
625}
626
627#[derive(Debug, Serialize, Deserialize, Clone)]
628pub struct PassportData;
629
630
631#[derive(Debug, Serialize, Deserialize, Clone)]
632#[serde(untagged)]
633pub enum ReplyMarkup {
634    InlineKeyboardMarkup(InlineKeyboardMarkup),
635    ReplyKeyboardMarkup(ReplyKeyboardMarkup),
636    ReplyKeyboardRemove(ReplyKeyboardRemove),
637    ForceReply(ForceReply),
638}