From 9f8256607afa58472b78eb1cb46fdd0a87abf330 Mon Sep 17 00:00:00 2001 From: coder2020official Date: Fri, 30 Dec 2022 20:23:53 +0400 Subject: [PATCH] Added the parameter message_thread_id to the method sendChatAction for sending chat actions to a specific message thread or a forum topic. Added the parameter message_thread_id to the method sendChatAction for sending chat actions to a specific message thread or a forum topic. --- telebot/__init__.py | 7 +++++-- telebot/apihelper.py | 4 +++- telebot/async_telebot.py | 7 +++++-- telebot/asyncio_helper.py | 4 +++- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index fa0c11b..ef8ab71 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -2806,7 +2806,7 @@ class TeleBot: allow_sending_without_reply, protect_content, message_thread_id)) def send_chat_action( - self, chat_id: Union[int, str], action: str, timeout: Optional[int]=None) -> bool: + self, chat_id: Union[int, str], action: str, timeout: Optional[int]=None, message_thread_id: Optional[int]=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). @@ -2829,10 +2829,13 @@ class TeleBot: :param timeout: Timeout in seconds for the request. :type timeout: :obj:`int` + :param message_thread_id: The thread identifier of a message from which the reply will be sent(supergroups only) + :type message_thread_id: :obj:`int` + :return: Returns True on success. :rtype: :obj:`bool` """ - return apihelper.send_chat_action(self.token, chat_id, action, timeout) + return apihelper.send_chat_action(self.token, chat_id, action, timeout, message_thread_id) @util.deprecated(deprecation_text="Use ban_chat_member instead") def kick_chat_member( diff --git a/telebot/apihelper.py b/telebot/apihelper.py index f1fdb7c..1086f54 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -657,11 +657,13 @@ def send_contact( return _make_request(token, method_url, params=payload) -def send_chat_action(token, chat_id, action, timeout=None): +def send_chat_action(token, chat_id, action, timeout=None, message_thread_id=None): method_url = r'sendChatAction' payload = {'chat_id': chat_id, 'action': action} if timeout: payload['timeout'] = timeout + if message_thread_id is not None: + payload['message_thread_id'] = message_thread_id return _make_request(token, method_url, params=payload) diff --git a/telebot/async_telebot.py b/telebot/async_telebot.py index 0ee8f06..6e3ec9a 100644 --- a/telebot/async_telebot.py +++ b/telebot/async_telebot.py @@ -3664,7 +3664,7 @@ class AsyncTeleBot: ) async def send_chat_action( - self, chat_id: Union[int, str], action: str, timeout: Optional[int]=None) -> bool: + self, chat_id: Union[int, str], action: str, timeout: Optional[int]=None, message_thread_id: Optional[int]=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). @@ -3687,10 +3687,13 @@ class AsyncTeleBot: :param timeout: Timeout in seconds for the request. :type timeout: :obj:`int` + :param message_thread_id: The thread to which the message will be sent(supergroups only) + :type message_thread_id: :obj:`int` + :return: Returns True on success. :rtype: :obj:`bool` """ - return await asyncio_helper.send_chat_action(self.token, chat_id, action, timeout) + return await asyncio_helper.send_chat_action(self.token, chat_id, action, timeout, message_thread_id) async def kick_chat_member( self, chat_id: Union[int, str], user_id: int, diff --git a/telebot/asyncio_helper.py b/telebot/asyncio_helper.py index 86468d0..4371885 100644 --- a/telebot/asyncio_helper.py +++ b/telebot/asyncio_helper.py @@ -649,11 +649,13 @@ async def send_contact( return await _process_request(token, method_url, params=payload) -async def send_chat_action(token, chat_id, action, timeout=None): +async def send_chat_action(token, chat_id, action, timeout=None, message_thread_id=None): method_url = r'sendChatAction' payload = {'chat_id': chat_id, 'action': action} if timeout: payload['timeout'] = timeout + if message_thread_id: + payload['message_thread_id'] = message_thread_id return await _process_request(token, method_url, params=payload)