1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
use crate::types::{
CallbackQuery, ChosenInlineResult, InlineQuery, Message, Poll, PreCheckoutQuery, ShippingQuery,
UpdateId,
};
/// This object represents an incoming update.At most one of the optional parameters can be present in any given update.
#[derive(Deserialize, Debug, Clone)]
#[serde(untagged)]
#[allow(clippy::large_enum_variant)]
pub enum Update {
Message(MessageUpdate),
EditedMessage(EditedMessageUpdate),
ChannelPost(ChannelPostUpdate),
EditedChannelPost(EditedChannelPostUpdate),
InlineQuery(InlineQueryUpdate),
ChosenInlineResult(ChosenInlineResultUpdate),
CallbackQuery(CallbackQueryUpdate),
ShippingQuery(ShippingQueryUpdate),
PreCheckoutQuery(PreCheckoutQueryUpdate),
Poll(PollUpdate),
Unknown(UnknownUpdate),
}
#[derive(Debug, Clone)]
pub enum UpdateKind<'a> {
/// New incoming message of any kind — text, photo, sticker, etc.
Message(&'a Message),
/// New version of a message that is known to the bot and was edited
EditedMessage(&'a Message),
/// New incoming channel post of any kind — text, photo, sticker, etc.
ChannelPost(&'a Message),
/// New version of a channel post that is known to the bot and was edited
EditedChannelPost(&'a Message),
/// New incoming inline query
InlineQuery(&'a InlineQuery),
/// 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.
ChosenInlineResult(&'a ChosenInlineResult),
/// New incoming callback query
CallbackQuery(&'a CallbackQuery),
/// New incoming shipping query. Only for invoices with flexible price
ShippingQuery(&'a ShippingQuery),
/// New incoming pre-checkout query. Contains full information about checkout
PreCheckoutQuery(&'a PreCheckoutQuery),
/// New poll state. Bots receive only updates about stopped polls and polls, which are sent by the bot
Poll(&'a Poll),
/// Uknown update. Should not happen
Unknown,
}
impl Update {
#[inline]
/// 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.
pub fn update_id(&self) -> UpdateId {
match self {
Update::Message(update) => update.update_id,
Update::EditedMessage(update) => update.update_id,
Update::ChannelPost(update) => update.update_id,
Update::EditedChannelPost(update) => update.update_id,
Update::InlineQuery(update) => update.update_id,
Update::ChosenInlineResult(update) => update.update_id,
Update::CallbackQuery(update) => update.update_id,
Update::ShippingQuery(update) => update.update_id,
Update::PreCheckoutQuery(update) => update.update_id,
Update::Poll(update) => update.update_id,
Update::Unknown(update) => update.update_id,
}
}
#[inline]
pub fn kind(&self) -> UpdateKind {
match self {
Update::Message(update) => UpdateKind::Message(&update.message),
Update::EditedMessage(update) => UpdateKind::EditedMessage(&update.edited_message),
Update::ChannelPost(update) => UpdateKind::ChannelPost(&update.channel_post),
Update::EditedChannelPost(update) => {
UpdateKind::EditedChannelPost(&update.edited_channel_post)
}
Update::InlineQuery(update) => UpdateKind::InlineQuery(&update.inline_query),
Update::ChosenInlineResult(update) => {
UpdateKind::ChosenInlineResult(&update.chosen_inline_result)
}
Update::CallbackQuery(update) => UpdateKind::CallbackQuery(&update.callback_query),
Update::ShippingQuery(update) => UpdateKind::ShippingQuery(&update.shipping_query),
Update::PreCheckoutQuery(update) => {
UpdateKind::PreCheckoutQuery(&update.pre_checkout_query)
}
Update::Poll(update) => UpdateKind::Poll(&update.poll),
Update::Unknown(_) => UpdateKind::Unknown,
}
}
}
#[derive(Deserialize, Debug, Clone)]
pub struct MessageUpdate {
/// 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.
pub update_id: UpdateId,
/// New incoming message of any kind — text, photo, sticker, etc.
pub message: Message,
}
#[derive(Deserialize, Debug, Clone)]
pub struct EditedMessageUpdate {
/// 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.
pub update_id: UpdateId,
/// New version of a message that is known to the bot and was edited
pub edited_message: Message,
}
#[derive(Deserialize, Debug, Clone)]
pub struct ChannelPostUpdate {
/// 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.
pub update_id: UpdateId,
/// New incoming channel post of any kind — text, photo, sticker, etc.
pub channel_post: Message,
}
#[derive(Deserialize, Debug, Clone)]
pub struct EditedChannelPostUpdate {
/// 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.
pub update_id: UpdateId,
/// New version of a channel post that is known to the bot and was edited
pub edited_channel_post: Message,
}
#[derive(Deserialize, Debug, Clone)]
pub struct InlineQueryUpdate {
/// 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.
pub update_id: UpdateId,
/// New incoming inline query
pub inline_query: InlineQuery,
}
#[derive(Deserialize, Debug, Clone)]
pub struct ChosenInlineResultUpdate {
/// 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.
pub update_id: UpdateId,
/// 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.
pub chosen_inline_result: ChosenInlineResult,
}
#[derive(Deserialize, Debug, Clone)]
pub struct CallbackQueryUpdate {
/// 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.
pub update_id: UpdateId,
/// New incoming callback query
pub callback_query: CallbackQuery,
}
#[derive(Deserialize, Debug, Clone)]
pub struct ShippingQueryUpdate {
/// 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.
pub update_id: UpdateId,
/// New incoming shipping query. Only for invoices with flexible price
pub shipping_query: ShippingQuery,
}
#[derive(Deserialize, Debug, Clone)]
pub struct PreCheckoutQueryUpdate {
/// 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.
pub update_id: UpdateId,
/// New incoming pre-checkout query. Contains full information about checkout
pub pre_checkout_query: PreCheckoutQuery,
}
#[derive(Deserialize, Debug, Clone)]
pub struct PollUpdate {
/// 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.
pub update_id: UpdateId,
/// New poll state. Bots receive only updates about stopped polls and polls, which are sent by the bot
pub poll: Poll,
}
#[derive(Deserialize, Debug, Clone)]
pub struct UnknownUpdate {
/// 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.
pub update_id: UpdateId,
}