Add BusinessMessage variant to UpdateKind enum

This commit is contained in:
Akshett Rai Jindal 2024-08-21 01:46:53 +05:30
parent 2fe5daccff
commit 9e57d3acff
4 changed files with 34 additions and 21 deletions

View file

@ -8,6 +8,7 @@ pub enum AllowedUpdate {
ChannelPost, ChannelPost,
EditedChannelPost, EditedChannelPost,
BusinessConnection, BusinessConnection,
BusinessMessage,
MessageReaction, MessageReaction,
MessageReactionCount, MessageReactionCount,
InlineQuery, InlineQuery,

View file

@ -64,6 +64,9 @@ pub enum UpdateKind {
/// user edited an existing connection with the bot /// user edited an existing connection with the bot
BusinessConnection(BusinessConnection), BusinessConnection(BusinessConnection),
/// New non-service message from a connected business account
BusinessMessage(Message),
/// A reaction to a message was changed by a user. The bot must be an /// A reaction to a message was changed by a user. The bot must be an
/// administrator in the chat and must explicitly specify /// administrator in the chat and must explicitly specify
/// [`AllowedUpdate::MessageReaction`] in the list of `allowed_updates` /// [`AllowedUpdate::MessageReaction`] in the list of `allowed_updates`
@ -160,9 +163,8 @@ impl Update {
use UpdateKind::*; use UpdateKind::*;
let from = match &self.kind { let from = match &self.kind {
Message(m) | EditedMessage(m) | ChannelPost(m) | EditedChannelPost(m) => { Message(m) | EditedMessage(m) | ChannelPost(m) | EditedChannelPost(m)
m.from.as_ref()? | BusinessMessage(m) => m.from.as_ref()?,
}
BusinessConnection(conn) => &conn.user, BusinessConnection(conn) => &conn.user,
@ -227,7 +229,8 @@ impl Update {
UpdateKind::Message(message) UpdateKind::Message(message)
| UpdateKind::EditedMessage(message) | UpdateKind::EditedMessage(message)
| UpdateKind::ChannelPost(message) | UpdateKind::ChannelPost(message)
| UpdateKind::EditedChannelPost(message) => i0(message.mentioned_users()), | UpdateKind::EditedChannelPost(message)
| UpdateKind::BusinessMessage(message) => i0(message.mentioned_users()),
UpdateKind::MessageReaction(answer) => { UpdateKind::MessageReaction(answer) => {
if let Some(user) = answer.user() { if let Some(user) = answer.user() {
@ -280,7 +283,8 @@ impl Update {
use UpdateKind::*; use UpdateKind::*;
let chat = match &self.kind { let chat = match &self.kind {
Message(m) | EditedMessage(m) | ChannelPost(m) | EditedChannelPost(m) => &m.chat, Message(m) | EditedMessage(m) | ChannelPost(m) | EditedChannelPost(m)
| BusinessMessage(m) => &m.chat,
CallbackQuery(q) => q.message.as_ref()?.chat(), CallbackQuery(q) => q.message.as_ref()?.chat(),
ChatMember(m) => &m.chat, ChatMember(m) => &m.chat,
MyChatMember(m) => &m.chat, MyChatMember(m) => &m.chat,
@ -363,6 +367,9 @@ impl<'de> Deserialize<'de> for UpdateKind {
.next_value::<BusinessConnection>() .next_value::<BusinessConnection>()
.ok() .ok()
.map(UpdateKind::BusinessConnection), .map(UpdateKind::BusinessConnection),
"business_message" => {
map.next_value::<Message>().ok().map(UpdateKind::BusinessMessage)
}
"message_reaction" => map "message_reaction" => map
.next_value::<MessageReactionUpdated>() .next_value::<MessageReactionUpdated>()
.ok() .ok()
@ -436,40 +443,43 @@ impl Serialize for UpdateKind {
UpdateKind::EditedChannelPost(v) => { UpdateKind::EditedChannelPost(v) => {
s.serialize_newtype_variant(name, 3, "edited_channel_post", v) s.serialize_newtype_variant(name, 3, "edited_channel_post", v)
} }
UpdateKind::BusinessConnection(b) => { UpdateKind::BusinessConnection(v) => {
s.serialize_newtype_variant(name, 4, "business_connection", b) s.serialize_newtype_variant(name, 4, "business_connection", v)
}
UpdateKind::BusinessMessage(v) => {
s.serialize_newtype_variant(name, 5, "business_message", v)
} }
UpdateKind::MessageReaction(v) => { UpdateKind::MessageReaction(v) => {
s.serialize_newtype_variant(name, 5, "message_reaction", v) s.serialize_newtype_variant(name, 6, "message_reaction", v)
} }
UpdateKind::MessageReactionCount(v) => { UpdateKind::MessageReactionCount(v) => {
s.serialize_newtype_variant(name, 6, "message_reaction_count", v) s.serialize_newtype_variant(name, 7, "message_reaction_count", v)
} }
UpdateKind::InlineQuery(v) => s.serialize_newtype_variant(name, 7, "inline_query", v), UpdateKind::InlineQuery(v) => s.serialize_newtype_variant(name, 8, "inline_query", v),
UpdateKind::ChosenInlineResult(v) => { UpdateKind::ChosenInlineResult(v) => {
s.serialize_newtype_variant(name, 8, "chosen_inline_result", v) s.serialize_newtype_variant(name, 9, "chosen_inline_result", v)
} }
UpdateKind::CallbackQuery(v) => { UpdateKind::CallbackQuery(v) => {
s.serialize_newtype_variant(name, 9, "callback_query", v) s.serialize_newtype_variant(name, 10, "callback_query", v)
} }
UpdateKind::ShippingQuery(v) => { UpdateKind::ShippingQuery(v) => {
s.serialize_newtype_variant(name, 10, "shipping_query", v) s.serialize_newtype_variant(name, 11, "shipping_query", v)
} }
UpdateKind::PreCheckoutQuery(v) => { UpdateKind::PreCheckoutQuery(v) => {
s.serialize_newtype_variant(name, 11, "pre_checkout_query", v) s.serialize_newtype_variant(name, 12, "pre_checkout_query", v)
} }
UpdateKind::Poll(v) => s.serialize_newtype_variant(name, 12, "poll", v), UpdateKind::Poll(v) => s.serialize_newtype_variant(name, 13, "poll", v),
UpdateKind::PollAnswer(v) => s.serialize_newtype_variant(name, 13, "poll_answer", v), UpdateKind::PollAnswer(v) => s.serialize_newtype_variant(name, 14, "poll_answer", v),
UpdateKind::MyChatMember(v) => { UpdateKind::MyChatMember(v) => {
s.serialize_newtype_variant(name, 14, "my_chat_member", v) s.serialize_newtype_variant(name, 15, "my_chat_member", v)
} }
UpdateKind::ChatMember(v) => s.serialize_newtype_variant(name, 15, "chat_member", v), UpdateKind::ChatMember(v) => s.serialize_newtype_variant(name, 16, "chat_member", v),
UpdateKind::ChatJoinRequest(v) => { UpdateKind::ChatJoinRequest(v) => {
s.serialize_newtype_variant(name, 16, "chat_join_request", v) s.serialize_newtype_variant(name, 17, "chat_join_request", v)
} }
UpdateKind::ChatBoost(v) => s.serialize_newtype_variant(name, 17, "chat_boost", v), UpdateKind::ChatBoost(v) => s.serialize_newtype_variant(name, 18, "chat_boost", v),
UpdateKind::RemovedChatBoost(v) => { UpdateKind::RemovedChatBoost(v) => {
s.serialize_newtype_variant(name, 18, "removed_chat_boost", v) s.serialize_newtype_variant(name, 19, "removed_chat_boost", v)
} }
UpdateKind::Error(v) => v.serialize(s), UpdateKind::Error(v) => v.serialize(s),
} }

View file

@ -156,6 +156,7 @@ define_update_ext! {
(filter_channel_post, UpdateKind::ChannelPost, ChannelPost), (filter_channel_post, UpdateKind::ChannelPost, ChannelPost),
(filter_edited_channel_post, UpdateKind::EditedChannelPost, EditedChannelPost), (filter_edited_channel_post, UpdateKind::EditedChannelPost, EditedChannelPost),
(filter_business_connection, UpdateKind::BusinessConnection, BusinessConnection), (filter_business_connection, UpdateKind::BusinessConnection, BusinessConnection),
(filter_business_message, UpdateKind::BusinessMessage, BusinessMessage),
(filter_message_reaction_updated, UpdateKind::MessageReaction, MessageReaction), (filter_message_reaction_updated, UpdateKind::MessageReaction, MessageReaction),
(filter_message_reaction_count_updated, UpdateKind::MessageReactionCount, MessageReactionCount), (filter_message_reaction_count_updated, UpdateKind::MessageReactionCount, MessageReactionCount),
(filter_inline_query, UpdateKind::InlineQuery, InlineQuery), (filter_inline_query, UpdateKind::InlineQuery, InlineQuery),

View file

@ -66,6 +66,7 @@ impl EventKind for Kind {
ChannelPost, ChannelPost,
EditedChannelPost, EditedChannelPost,
BusinessConnection, BusinessConnection,
BusinessMessage,
MessageReaction, MessageReaction,
MessageReactionCount, MessageReactionCount,
InlineQuery, InlineQuery,