apid_telegram_bot/types/
update.rs

1use serde::{Deserialize, Serialize};
2use serde_enum_str::{Deserialize_enum_str, Serialize_enum_str};
3
4use crate::types::{
5    CallbackQuery, ChatJoinRequest, ChatMemberUpdated, ChosenInlineResult, InlineQuery, Message,
6    Poll, PollAnswer, PreCheckoutQuery, ShippingQuery,
7};
8
9/// This [object](https://core.telegram.org/bots/api#available-types) represents an incoming update.
10/// At most **one** of the optional parameters can be present in any given update.
11#[derive(Debug, PartialEq, Serialize, Deserialize)]
12pub struct Update {
13    /// The update's unique identifier.
14    /// Update identifiers start from a certain positive number and increase sequentially.
15    /// This ID becomes especially handy if you're using webhooks,
16    /// since it allows you to ignore repeated updates or to restore the correct update sequence, should they get out of order.
17    /// If there are no new updates for at least a week,
18    /// then identifier of the next update will be chosen randomly instead of sequentially.
19    pub update_id: i32,
20
21    /// The event encoded in the update.
22    /// As specified above, the optional parameters can be present at most one.
23    /// Thus we provide event separated for ease of use.
24    #[serde(flatten)]
25    pub event: Option<UpdateEvent>,
26}
27
28/// The kind of event can be taken from an [`Update`].
29#[derive(Debug, PartialEq, Serialize_enum_str, Deserialize_enum_str)]
30#[serde(rename_all = "snake_case")]
31pub enum UpdateKind {
32    /// New incoming message of any kind - text, photo, sticker, etc.
33    Message,
34
35    /// New version of a message that is known to the bot and was edited
36    #[serde(rename = "edited_message")]
37    MessageEdit,
38
39    /// New incoming channel post of any kind - text, photo, sticker, etc.
40    ChannelPost,
41
42    /// New version of a channel post that is known to the bot and was edited
43    #[serde(rename = "edited_channel_post")]
44    ChannelPostEdit,
45
46    /// New incoming [inline](https://core.telegram.org/bots/api#inline-mode) query
47    InlineQuery,
48
49    /// The result of an [inline](https://core.telegram.org/bots/api#inline-mode) query that was chosen by a user and sent to their chat partner.
50    /// Please see our documentation on the [feedback collecting](https://core.telegram.org/bots/inline#collecting-feedback) for details on how to enable these updates for your bot.
51    ChosenInlineResult,
52
53    /// New incoming callback query
54    CallbackQuery,
55
56    /// New incoming shipping query.
57    /// Only for invoices with flexible price
58    ShippingQuery,
59
60    /// New incoming pre-checkout query.
61    /// Contains full information about checkout
62    PreCheckoutQuery,
63
64    /// New poll state.
65    /// Bots receive only updates about stopped polls and polls, which are sent by the bot
66    Poll,
67
68    /// A user changed their answer in a non-anonymous poll.
69    /// Bots receive new votes only in polls that were sent by the bot itself.
70    PollAnswer,
71
72    /// The bot's chat member status was updated in a chat.
73    /// For private chats, this update is received only when the bot is blocked or unblocked by the user.
74    #[serde(rename = "my_chat_member")]
75    PrivateChatMemberUpdated,
76
77    /// A chat member's status was updated in a chat.
78    /// The bot must be an administrator in the chat and must explicitly specify “chat_member” in the list of *allowed_updates* to receive these updates.
79    #[serde(rename = "chat_member")]
80    ChatMemberUpdated,
81
82    /// A request to join the chat has been sent.
83    /// The bot must have the *can_invite_users* administrator right in the chat to receive these updates.
84    ChatJoinRequest,
85}
86
87/// The update event can be taken from an [`Update`].
88#[derive(Debug, PartialEq, Serialize, Deserialize)]
89#[serde(untagged)]
90pub enum UpdateEvent {
91    /// New incoming message of any kind - text, photo, sticker, etc.
92    Message {
93        /// New incoming message of any kind - text, photo, sticker, etc.
94        message: Message,
95    },
96
97    /// New version of a message that is known to the bot and was edited
98    MessageEdit {
99        /// New version of a message that is known to the bot and was edited
100        edited_message: Message,
101    },
102
103    /// New incoming channel post of any kind - text, photo, sticker, etc.
104    ChannelPost {
105        /// New incoming channel post of any kind - text, photo, sticker, etc.
106        channel_post: Message,
107    },
108
109    /// New version of a channel post that is known to the bot and was edited
110    ChannelPostEdit {
111        /// New version of a channel post that is known to the bot and was edited
112        edited_channel_post: Message,
113    },
114
115    /// New incoming [inline](https://core.telegram.org/bots/api#inline-mode) query
116    InlineQuery {
117        /// New incoming [inline](https://core.telegram.org/bots/api#inline-mode) query
118        inline_query: InlineQuery,
119    },
120
121    /// The result of an [inline](https://core.telegram.org/bots/api#inline-mode) query that was chosen by a user and sent to their chat partner.
122    /// Please see our documentation on the [feedback collecting](https://core.telegram.org/bots/inline#collecting-feedback) for details on how to enable these updates for your bot.
123    ChosenInlineResult {
124        /// The result of an [inline](https://core.telegram.org/bots/api#inline-mode) query that was chosen by a user and sent to their chat partner.
125        /// Please see our documentation on the [feedback collecting](https://core.telegram.org/bots/inline#collecting-feedback) for details on how to enable these updates for your bot.
126        chosen_inline_result: ChosenInlineResult,
127    },
128
129    /// New incoming callback query
130    CallbackQuery {
131        /// New incoming callback query
132        callback_query: CallbackQuery,
133    },
134
135    /// New incoming shipping query.
136    /// Only for invoices with flexible price
137    ShippingQuery {
138        /// New incoming shipping query.
139        /// Only for invoices with flexible price
140        shipping_query: ShippingQuery,
141    },
142
143    /// New incoming pre-checkout query.
144    /// Contains full information about checkout
145    PreCheckoutQuery {
146        /// New incoming pre-checkout query.
147        /// Contains full information about checkout
148        pre_checkout_query: PreCheckoutQuery,
149    },
150
151    /// New poll state.
152    /// Bots receive only updates about stopped polls and polls, which are sent by the bot
153    Poll {
154        /// New poll state.
155        /// Bots receive only updates about stopped polls and polls, which are sent by the bot
156        poll: Poll,
157    },
158
159    /// A user changed their answer in a non-anonymous poll.
160    /// Bots receive new votes only in polls that were sent by the bot itself.
161    PollAnswer {
162        /// A user changed their answer in a non-anonymous poll.
163        /// Bots receive new votes only in polls that were sent by the bot itself.
164        poll_answer: PollAnswer,
165    },
166
167    /// The bot's chat member status was updated in a chat.
168    /// For private chats, this update is received only when the bot is blocked or unblocked by the user.
169    PrivateChatMemberUpdated {
170        /// The bot's chat member status was updated in a chat.
171        /// For private chats, this update is received only when the bot is blocked or unblocked by the user.
172        my_chat_member: ChatMemberUpdated,
173    },
174
175    /// A chat member's status was updated in a chat.
176    /// The bot must be an administrator in the chat and must explicitly specify “chat_member” in the list of *allowed_updates* to receive these updates.
177    ChatMemberUpdated {
178        /// A chat member's status was updated in a chat.
179        /// The bot must be an administrator in the chat and must explicitly specify “chat_member” in the list of *allowed_updates* to receive these updates.
180        chat_member: ChatMemberUpdated,
181    },
182
183    /// A request to join the chat has been sent.
184    /// The bot must have the *can_invite_users* administrator right in the chat to receive these updates.
185    ChatJoinRequest {
186        /// A request to join the chat has been sent.
187        /// The bot must have the *can_invite_users* administrator right in the chat to receive these updates.
188        chat_join_request: ChatJoinRequest,
189    },
190}