Add UpdateBusinessBotCallbackQuery in callback_query handler

Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
shriMADhav U k 2024-06-18 17:19:28 +02:00 committed by wulan17
parent 0387a09079
commit 3232a3f139
No known key found for this signature in database
GPG key ID: 318CD6CD3A6AC0A5
2 changed files with 21 additions and 8 deletions

View file

@ -61,7 +61,8 @@ from pyrogram.raw.types import (
UpdateBotChatInviteRequester, UpdateStory, UpdateBotChatInviteRequester, UpdateStory,
UpdateBotMessageReaction, UpdateBotMessageReaction,
UpdateBotMessageReactions, UpdateBotMessageReactions,
UpdateBotShippingQuery UpdateBotShippingQuery,
UpdateBusinessBotCallbackQuery
) )
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -74,7 +75,7 @@ class Dispatcher:
EDIT_BOT_BUSINESS_MESSAGE_UPDATES = (UpdateBotEditBusinessMessage,) EDIT_BOT_BUSINESS_MESSAGE_UPDATES = (UpdateBotEditBusinessMessage,)
DELETE_MESSAGES_UPDATES = (UpdateDeleteMessages, UpdateDeleteChannelMessages) DELETE_MESSAGES_UPDATES = (UpdateDeleteMessages, UpdateDeleteChannelMessages)
DELETE_BOT_BUSINESS_MESSAGES_UPDATES = (UpdateBotDeleteBusinessMessage,) DELETE_BOT_BUSINESS_MESSAGES_UPDATES = (UpdateBotDeleteBusinessMessage,)
CALLBACK_QUERY_UPDATES = (UpdateBotCallbackQuery, UpdateInlineBotCallbackQuery) CALLBACK_QUERY_UPDATES = (UpdateBotCallbackQuery, UpdateInlineBotCallbackQuery, UpdateBusinessBotCallbackQuery)
CHAT_MEMBER_UPDATES = (UpdateChatParticipant, UpdateChannelParticipant, UpdateBotStopped,) CHAT_MEMBER_UPDATES = (UpdateChatParticipant, UpdateChannelParticipant, UpdateBotStopped,)
USER_STATUS_UPDATES = (UpdateUserStatus,) USER_STATUS_UPDATES = (UpdateUserStatus,)
BOT_INLINE_QUERY_UPDATES = (UpdateBotInlineQuery,) BOT_INLINE_QUERY_UPDATES = (UpdateBotInlineQuery,)

View file

@ -102,13 +102,25 @@ class CallbackQuery(Object, Update):
message = await client.get_messages(chat_id, message_id) message = await client.get_messages(chat_id, message_id)
elif isinstance(callback_query, raw.types.UpdateInlineBotCallbackQuery): elif isinstance(callback_query, raw.types.UpdateInlineBotCallbackQuery):
inline_message_id = utils.pack_inline_message_id(callback_query.msg_id) inline_message_id = utils.pack_inline_message_id(callback_query.msg_id)
elif isinstance(callback_query, raw.types.UpdateBusinessBotCallbackQuery):
message = await types.Message._parse(
client,
callback_query.message,
users,
chats,
is_scheduled=False,
replies=0,
business_connection_id=callback_query.connection_id,
raw_reply_to_message=getattr(callback_query, "reply_to_message", None)
)
# Try to decode callback query data into string. If that fails, fallback to bytes instead of decoding by # Try to decode callback query data into string. If that fails, fallback to bytes instead of decoding by
# ignoring/replacing errors, this way, button clicks will still work. # ignoring/replacing errors, this way, button clicks will still work.
try: data = getattr(callback_query, "data", None)
data = callback_query.data.decode() if data:
except (UnicodeDecodeError, AttributeError): try:
data = callback_query.data data = data.decode()
except (UnicodeDecodeError, AttributeError):
data = data
return CallbackQuery( return CallbackQuery(
id=str(callback_query.query_id), id=str(callback_query.query_id),
@ -117,7 +129,7 @@ class CallbackQuery(Object, Update):
inline_message_id=inline_message_id, inline_message_id=inline_message_id,
chat_instance=str(callback_query.chat_instance), chat_instance=str(callback_query.chat_instance),
data=data, data=data,
game_short_name=callback_query.game_short_name, game_short_name=getattr(callback_query, "game_short_name", None),
client=client client=client
) )