Repository: aiogram/aiogram

Issue:
Add 'messge_thread_id' parameter in 'ChatActionSender'
**Is your feature request related to a problem? Please describe.**
No.

**Describe the solution you'd like**
Add "message_thread_id" parameter to "ChatActionSender" in "aiogram/utils/chat_action.py" to send actions to a specific topic.



Discussion:
github-actions[bot]: # :heavy_check_mark: Changelog found.

Thank you for adding a description of the changes

Patch:
diff --git a/CHANGES/1249.feature.rst b/CHANGES/1249.feature.rst
new file mode 100644
index 00000000..147b407b
--- /dev/null
+++ b/CHANGES/1249.feature.rst
@@ -0,0 +1,1 @@
+Added support for message_thread_id in ChatActionSender
diff --git a/aiogram/utils/chat_action.py b/aiogram/utils/chat_action.py
index d4778443..6d7b7400 100644
--- a/aiogram/utils/chat_action.py
+++ b/aiogram/utils/chat_action.py
@@ -33,6 +33,7 @@ class ChatActionSender:
         *,
         bot: Bot,
         chat_id: Union[str, int],
+        message_thread_id: Optional[int] = None,
         action: str = "typing",
         interval: float = DEFAULT_INTERVAL,
         initial_sleep: float = DEFAULT_INITIAL_SLEEP,
@@ -45,6 +46,7 @@ class ChatActionSender:
         :param initial_sleep: sleep before first iteration
         """
         self.chat_id = chat_id
+        self.message_thread_id = message_thread_id
         self.action = action
         self.interval = interval
         self.initial_sleep = initial_sleep
@@ -82,7 +84,11 @@ class ChatActionSender:
                     self.bot.id,
                     counter,
                 )
-                await self.bot.send_chat_action(chat_id=self.chat_id, action=self.action)
+                await self.bot.send_chat_action(
+                    chat_id=self.chat_id,
+                    action=self.action,
+                    message_thread_id=self.message_thread_id,
+                )
                 counter += 1
 
                 interval = self.interval - (time.monotonic() - start)
@@ -341,5 +347,10 @@ class ChatActionMiddleware(BaseMiddleware):
             kwargs["action"] = "typing"
         else:
             kwargs["action"] = chat_action
+        kwargs["message_thread_id"] = (
+            event.message_thread_id
+            if isinstance(event, Message) and event.is_topic_message
+            else None
+        )
         async with ChatActionSender(bot=bot, chat_id=event.chat.id, **kwargs):
             return await handler(event, data)


Test patch:
diff --git a/tests/test_utils/test_chat_action.py b/tests/test_utils/test_chat_action.py
index 84cb8abb..d6041c37 100644
--- a/tests/test_utils/test_chat_action.py
+++ b/tests/test_utils/test_chat_action.py
@@ -54,7 +54,11 @@ class TestChatActionSender:
             ):
                 await asyncio.sleep(0.1)
                 assert mocked_send_chat_action.await_count > 1
-                mocked_send_chat_action.assert_awaited_with(action="typing", chat_id=42)
+                mocked_send_chat_action.assert_awaited_with(
+                    action="typing",
+                    chat_id=42,
+                    message_thread_id=None,
+                )
 
     async def test_contextmanager(self, bot: MockedBot):
         sender: ChatActionSender = ChatActionSender.typing(bot=bot, chat_id=42)