Fix Message.send_copy method for stories

Fixed an issue with the `Message.send_copy` method, which was not functioning properly with story-type messages. The `ForwardMessage` logic has been added to the method to enable copying of stories, in addition to other types. Tests and documentation have also been updated to reflect these changes.
This commit is contained in:
Alex Root Junior 2023-08-28 22:26:36 +03:00
parent 6eb5ef2606
commit e5016a0666
No known key found for this signature in database
GPG key ID: 074C1D455EBEA4AC
4 changed files with 12 additions and 2 deletions

1
CHANGES/1286.bugfi.rst Normal file
View file

@ -0,0 +1 @@
Fixed :code:`Message.send_copy` method, which was not working properly with stories, so not you can copy stories too (forwards messages).

View file

@ -2804,6 +2804,7 @@ class Message(TelegramObject):
allow_sending_without_reply: Optional[bool] = None,
message_thread_id: Optional[int] = None,
) -> Union[
ForwardMessage,
SendAnimation,
SendAudio,
SendContact,
@ -2839,6 +2840,7 @@ class Message(TelegramObject):
:return:
"""
from ..methods import (
ForwardMessage,
SendAnimation,
SendAudio,
SendContact,
@ -2957,6 +2959,12 @@ class Message(TelegramObject):
return SendDice(
**kwargs,
).as_(self._bot)
if self.story:
return ForwardMessage(
from_chat_id=self.chat.id,
message_id=self.message_id,
**kwargs,
).as_(self._bot)
raise TypeError("This type of message can't be copied.")

View file

@ -4,14 +4,14 @@ Dispatcher
Dispatcher is root :obj:`Router` and in code Dispatcher can be used directly for routing updates or attach another routers into dispatcher.
Here is only listed base information about Dispatcher. All about writing handlers, filters and etc. you can found in next pages:
Here is only listed base information about Dispatcher. All about writing handlers, filters and etc. you can find in next pages:
- :ref:`Router <Router>`
- :ref:`Filtering events`
.. autoclass:: aiogram.dispatcher.dispatcher.Dispatcher
:members: __init__, feed_update, feed_raw_update, feed_webhook_update, start_polling, run_polling
:members: __init__, feed_update, feed_raw_update, feed_webhook_update, start_polling, run_polling, stop_polling
Simple usage

View file

@ -649,6 +649,7 @@ class TestMessage:
[TEST_MESSAGE_CONTACT, SendContact],
[TEST_MESSAGE_VENUE, SendVenue],
[TEST_MESSAGE_LOCATION, SendLocation],
[TEST_MESSAGE_STORY, ForwardMessage],
[TEST_MESSAGE_NEW_CHAT_MEMBERS, None],
[TEST_MESSAGE_LEFT_CHAT_MEMBER, None],
[TEST_MESSAGE_INVOICE, None],