From 0efb15aa6a00c477a51ded6ef06779a75e819deb Mon Sep 17 00:00:00 2001 From: Akshett Rai Jindal Date: Wed, 21 Aug 2024 01:52:44 +0530 Subject: [PATCH] Add `EditedBusinessMessage` variant to `UpdateKind` --- .../teloxide-core/src/types/allowed_update.rs | 1 + crates/teloxide-core/src/types/update.rs | 56 ++++++++++++------- crates/teloxide/src/dispatching/filter_ext.rs | 1 + .../src/dispatching/handler_description.rs | 1 + 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/crates/teloxide-core/src/types/allowed_update.rs b/crates/teloxide-core/src/types/allowed_update.rs index 15a184b9..17142bec 100644 --- a/crates/teloxide-core/src/types/allowed_update.rs +++ b/crates/teloxide-core/src/types/allowed_update.rs @@ -9,6 +9,7 @@ pub enum AllowedUpdate { EditedChannelPost, BusinessConnection, BusinessMessage, + EditedBusinessMessage, MessageReaction, MessageReactionCount, InlineQuery, diff --git a/crates/teloxide-core/src/types/update.rs b/crates/teloxide-core/src/types/update.rs index d244bc90..d72db1b7 100644 --- a/crates/teloxide-core/src/types/update.rs +++ b/crates/teloxide-core/src/types/update.rs @@ -67,6 +67,9 @@ pub enum UpdateKind { /// New non-service message from a connected business account BusinessMessage(Message), + /// New version of a message from a connected business account + EditedBusinessMessage(Message), + /// A reaction to a message was changed by a user. The bot must be an /// administrator in the chat and must explicitly specify /// [`AllowedUpdate::MessageReaction`] in the list of `allowed_updates` @@ -163,8 +166,12 @@ impl Update { use UpdateKind::*; let from = match &self.kind { - Message(m) | EditedMessage(m) | ChannelPost(m) | EditedChannelPost(m) - | BusinessMessage(m) => m.from.as_ref()?, + Message(m) + | EditedMessage(m) + | ChannelPost(m) + | EditedChannelPost(m) + | BusinessMessage(m) + | EditedBusinessMessage(m) => m.from.as_ref()?, BusinessConnection(conn) => &conn.user, @@ -230,7 +237,8 @@ impl Update { | UpdateKind::EditedMessage(message) | UpdateKind::ChannelPost(message) | UpdateKind::EditedChannelPost(message) - | UpdateKind::BusinessMessage(message) => i0(message.mentioned_users()), + | UpdateKind::BusinessMessage(message) + | UpdateKind::EditedBusinessMessage(message) => i0(message.mentioned_users()), UpdateKind::MessageReaction(answer) => { if let Some(user) = answer.user() { @@ -283,8 +291,12 @@ impl Update { use UpdateKind::*; let chat = match &self.kind { - Message(m) | EditedMessage(m) | ChannelPost(m) | EditedChannelPost(m) - | BusinessMessage(m) => &m.chat, + Message(m) + | EditedMessage(m) + | ChannelPost(m) + | EditedChannelPost(m) + | BusinessMessage(m) + | EditedBusinessMessage(m) => &m.chat, CallbackQuery(q) => q.message.as_ref()?.chat(), ChatMember(m) => &m.chat, MyChatMember(m) => &m.chat, @@ -370,6 +382,9 @@ impl<'de> Deserialize<'de> for UpdateKind { "business_message" => { map.next_value::().ok().map(UpdateKind::BusinessMessage) } + "edited_business_message" => { + map.next_value::().ok().map(UpdateKind::EditedBusinessMessage) + } "message_reaction" => map .next_value::() .ok() @@ -449,37 +464,40 @@ impl Serialize for UpdateKind { UpdateKind::BusinessMessage(v) => { s.serialize_newtype_variant(name, 5, "business_message", v) } + UpdateKind::EditedBusinessMessage(v) => { + s.serialize_newtype_variant(name, 6, "edited_business_message", v) + } UpdateKind::MessageReaction(v) => { - s.serialize_newtype_variant(name, 6, "message_reaction", v) + s.serialize_newtype_variant(name, 7, "message_reaction", v) } UpdateKind::MessageReactionCount(v) => { - s.serialize_newtype_variant(name, 7, "message_reaction_count", v) + s.serialize_newtype_variant(name, 8, "message_reaction_count", v) } - UpdateKind::InlineQuery(v) => s.serialize_newtype_variant(name, 8, "inline_query", v), + UpdateKind::InlineQuery(v) => s.serialize_newtype_variant(name, 9, "inline_query", v), UpdateKind::ChosenInlineResult(v) => { - s.serialize_newtype_variant(name, 9, "chosen_inline_result", v) + s.serialize_newtype_variant(name, 10, "chosen_inline_result", v) } UpdateKind::CallbackQuery(v) => { - s.serialize_newtype_variant(name, 10, "callback_query", v) + s.serialize_newtype_variant(name, 11, "callback_query", v) } UpdateKind::ShippingQuery(v) => { - s.serialize_newtype_variant(name, 11, "shipping_query", v) + s.serialize_newtype_variant(name, 12, "shipping_query", v) } UpdateKind::PreCheckoutQuery(v) => { - s.serialize_newtype_variant(name, 12, "pre_checkout_query", v) + s.serialize_newtype_variant(name, 13, "pre_checkout_query", v) } - UpdateKind::Poll(v) => s.serialize_newtype_variant(name, 13, "poll", v), - UpdateKind::PollAnswer(v) => s.serialize_newtype_variant(name, 14, "poll_answer", v), + UpdateKind::Poll(v) => s.serialize_newtype_variant(name, 14, "poll", v), + UpdateKind::PollAnswer(v) => s.serialize_newtype_variant(name, 15, "poll_answer", v), UpdateKind::MyChatMember(v) => { - s.serialize_newtype_variant(name, 15, "my_chat_member", v) + s.serialize_newtype_variant(name, 16, "my_chat_member", v) } - UpdateKind::ChatMember(v) => s.serialize_newtype_variant(name, 16, "chat_member", v), + UpdateKind::ChatMember(v) => s.serialize_newtype_variant(name, 17, "chat_member", v), UpdateKind::ChatJoinRequest(v) => { - s.serialize_newtype_variant(name, 17, "chat_join_request", v) + s.serialize_newtype_variant(name, 18, "chat_join_request", v) } - UpdateKind::ChatBoost(v) => s.serialize_newtype_variant(name, 18, "chat_boost", v), + UpdateKind::ChatBoost(v) => s.serialize_newtype_variant(name, 19, "chat_boost", v), UpdateKind::RemovedChatBoost(v) => { - s.serialize_newtype_variant(name, 19, "removed_chat_boost", v) + s.serialize_newtype_variant(name, 20, "removed_chat_boost", v) } UpdateKind::Error(v) => v.serialize(s), } diff --git a/crates/teloxide/src/dispatching/filter_ext.rs b/crates/teloxide/src/dispatching/filter_ext.rs index 305750ec..c74c008a 100644 --- a/crates/teloxide/src/dispatching/filter_ext.rs +++ b/crates/teloxide/src/dispatching/filter_ext.rs @@ -157,6 +157,7 @@ define_update_ext! { (filter_edited_channel_post, UpdateKind::EditedChannelPost, EditedChannelPost), (filter_business_connection, UpdateKind::BusinessConnection, BusinessConnection), (filter_business_message, UpdateKind::BusinessMessage, BusinessMessage), + (filter_edited_business_message, UpdateKind::EditedBusinessMessage, EditedBusinessMessage), (filter_message_reaction_updated, UpdateKind::MessageReaction, MessageReaction), (filter_message_reaction_count_updated, UpdateKind::MessageReactionCount, MessageReactionCount), (filter_inline_query, UpdateKind::InlineQuery, InlineQuery), diff --git a/crates/teloxide/src/dispatching/handler_description.rs b/crates/teloxide/src/dispatching/handler_description.rs index 37e740b5..c3e16369 100644 --- a/crates/teloxide/src/dispatching/handler_description.rs +++ b/crates/teloxide/src/dispatching/handler_description.rs @@ -67,6 +67,7 @@ impl EventKind for Kind { EditedChannelPost, BusinessConnection, BusinessMessage, + EditedBusinessMessage, MessageReaction, MessageReactionCount, InlineQuery,