From c5bf6f82a3b0b4d468418de117ec43b32423dcee Mon Sep 17 00:00:00 2001 From: shriMADhav U k Date: Sun, 21 Apr 2024 18:17:18 +0200 Subject: [PATCH] ability to specify our own interactions in send_chat_action --- docs/source/releases/changes-in-this-fork.rst | 2 +- pyrogram/methods/messages/send_chat_action.py | 22 ++++++++++++------- pyrogram/types/messages_and_media/message.py | 9 ++++++-- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/docs/source/releases/changes-in-this-fork.rst b/docs/source/releases/changes-in-this-fork.rst index 05f84314a..cbff48fed 100644 --- a/docs/source/releases/changes-in-this-fork.rst +++ b/docs/source/releases/changes-in-this-fork.rst @@ -12,7 +12,7 @@ it can take advantage of new goodies! | Scheme layer used: 177 | +------------------------+ -- Updated :obj: +- Added ``emoji_message_interaction`` parameter to :meth:`~pyrogram.Client.send_chat_action` and :meth:`~pyrogram.types.Message.reply_chat_action`. - **BOTS ONLY**: Updated :obj:`~pyrogram.handlers.ChatMemberUpdatedHandler` to handle updates when the bot is blocked or unblocked by a user. - Added missing parameters in :meth:`~pyrogram.Client.create_group`, :meth:`~pyrogram.Client.create_supergroup`, :meth:`~pyrogram.Client.create_channel`. - Try to return the service message (when applicable) in the methods :meth:`~pyrogram.Client.add_chat_members`, :meth:`~pyrogram.Client.promote_chat_member` diff --git a/pyrogram/methods/messages/send_chat_action.py b/pyrogram/methods/messages/send_chat_action.py index 42e51cc79..925baa2e8 100644 --- a/pyrogram/methods/messages/send_chat_action.py +++ b/pyrogram/methods/messages/send_chat_action.py @@ -33,7 +33,8 @@ async def send_chat_action( message_thread_id: int = None, business_connection_id: str = None, emoji: str = None, - emoji_message_id: int = None + emoji_message_id: int = None, + emoji_message_interaction: "raw.types.DataJSON" = None ) -> bool: """Use this method when you need to tell the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). @@ -66,6 +67,9 @@ async def send_chat_action( emoji_message_id (``int``, *optional*): Message identifier of the message containing the animated emoji. Only supported for :obj:`~pyrogram.enums.ChatAction.TRIGGER_EMOJI_ANIMATION`. + emoji_message_interaction (:obj:`raw.types.DataJSON`, *optional*): + Only supported for :obj:`~pyrogram.enums.ChatAction.TRIGGER_EMOJI_ANIMATION`. + Returns: ``bool``: On success, True is returned. @@ -111,13 +115,11 @@ async def send_chat_action( raise ValueError( "Invalid Argument Provided" ) - _, sticker_set = await self._get_raw_stickers( - raw.types.InputStickerSetAnimatedEmojiAnimations() - ) - action = action.value( - emoticon=emoji, - msg_id=emoji_message_id, - interaction=raw.types.DataJSON( + if emoji_message_interaction is None: + _, sticker_set = await self._get_raw_stickers( + raw.types.InputStickerSetAnimatedEmojiAnimations() + ) + emoji_message_interaction = raw.types.DataJSON( data=dumps( { "v": 1, @@ -133,6 +135,10 @@ async def send_chat_action( } ) ) + action = action.value( + emoticon=emoji, + msg_id=emoji_message_id, + interaction=emoji_message_interaction ) else: action = action.value() diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index 73d799fd4..6d04aa114 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -1836,7 +1836,8 @@ async def reply_chat_action( action: "enums.ChatAction", progress: int = 0, emoji: str = None, - emoji_message_id: int = None + emoji_message_id: int = None, + emoji_message_interaction: "raw.types.DataJSON" = None ) -> bool: """Bound method *reply_chat_action* of :obj:`~pyrogram.types.Message`. @@ -1871,6 +1872,9 @@ async def reply_chat_action( emoji_message_id (``int``, *optional*): Message identifier of the message containing the animated emoji. Only supported for :obj:`~pyrogram.enums.ChatAction.TRIGGER_EMOJI_ANIMATION`. + emoji_message_interaction (:obj:`raw.types.DataJSON`, *optional*): + Only supported for :obj:`~pyrogram.enums.ChatAction.TRIGGER_EMOJI_ANIMATION`. + Returns: ``bool``: On success, True is returned. @@ -1885,7 +1889,8 @@ async def reply_chat_action( message_thread_id=self.message_thread_id, business_connection_id=self.business_connection_id, emoji=emoji, - emoji_message_id=emoji_message_id + emoji_message_id=emoji_message_id, + emoji_message_interaction=emoji_message_interaction ) async def reply_contact(