mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Fix copyMessage method, update alias (with deprecation)
Fix imports
This commit is contained in:
parent
c12a76e8c0
commit
9f70813f92
6 changed files with 56 additions and 4 deletions
|
|
@ -355,7 +355,7 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin):
|
|||
types.ReplyKeyboardMarkup,
|
||||
types.ReplyKeyboardRemove,
|
||||
types.ForceReply, None] = None,
|
||||
) -> types.Message:
|
||||
) -> types.MessageId:
|
||||
"""
|
||||
Use this method to copy messages of any kind. The method is analogous to the
|
||||
method forwardMessages, but the copied message doesn't have a link to the
|
||||
|
|
@ -416,7 +416,7 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin):
|
|||
payload.setdefault('parse_mode', self.parse_mode)
|
||||
|
||||
result = await self.request(api.Methods.COPY_MESSAGE, payload)
|
||||
return types.Message(**result)
|
||||
return types.MessageId(**result)
|
||||
|
||||
async def send_photo(self,
|
||||
chat_id: typing.Union[base.Integer, base.String],
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ from .bot_command import BotCommand
|
|||
from .callback_game import CallbackGame
|
||||
from .callback_query import CallbackQuery
|
||||
from .chat import Chat, ChatActions, ChatType
|
||||
from .chat_location import ChatLocation
|
||||
from .chat_member import ChatMember, ChatMemberStatus
|
||||
from .chat_permissions import ChatPermissions
|
||||
from .chat_photo import ChatPhoto
|
||||
|
|
@ -40,6 +41,7 @@ from .login_url import LoginUrl
|
|||
from .mask_position import MaskPosition
|
||||
from .message import ContentType, ContentTypes, Message, ParseMode
|
||||
from .message_entity import MessageEntity, MessageEntityType
|
||||
from .message_id import MessageId
|
||||
from .order_info import OrderInfo
|
||||
from .passport_data import PassportData
|
||||
from .passport_element_error import PassportElementError, PassportElementErrorDataField, PassportElementErrorFile, \
|
||||
|
|
@ -49,6 +51,7 @@ from .passport_file import PassportFile
|
|||
from .photo_size import PhotoSize
|
||||
from .poll import PollOption, Poll, PollAnswer, PollType
|
||||
from .pre_checkout_query import PreCheckoutQuery
|
||||
from .proximity_alert_triggered import ProximityAlertTriggered
|
||||
from .reply_keyboard import KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, KeyboardButtonPollType
|
||||
from .response_parameters import ResponseParameters
|
||||
from .shipping_address import ShippingAddress
|
||||
|
|
@ -76,6 +79,7 @@ __all__ = (
|
|||
'CallbackQuery',
|
||||
'Chat',
|
||||
'ChatActions',
|
||||
'ChatLocation',
|
||||
'ChatMember',
|
||||
'ChatMemberStatus',
|
||||
'ChatPermissions',
|
||||
|
|
@ -141,6 +145,7 @@ __all__ = (
|
|||
'Message',
|
||||
'MessageEntity',
|
||||
'MessageEntityType',
|
||||
'MessageId',
|
||||
'OrderInfo',
|
||||
'ParseMode',
|
||||
'PassportData',
|
||||
|
|
@ -158,6 +163,7 @@ __all__ = (
|
|||
'PollOption',
|
||||
'PollType',
|
||||
'PreCheckoutQuery',
|
||||
'ProximityAlertTriggered',
|
||||
'ReplyKeyboardMarkup',
|
||||
'ReplyKeyboardRemove',
|
||||
'ResponseParameters',
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
import typing
|
||||
|
||||
from . import base, MessageEntity
|
||||
from . import base
|
||||
from . import fields
|
||||
from .inline_keyboard import InlineKeyboardMarkup
|
||||
from .input_message_content import InputMessageContent
|
||||
from .message_entity import MessageEntity
|
||||
|
||||
|
||||
class InlineQueryResult(base.TelegramObject):
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import typing
|
||||
|
||||
from . import base, MessageEntity
|
||||
from . import base
|
||||
from . import fields
|
||||
from .message_entity import MessageEntity
|
||||
|
||||
|
||||
class InputMessageContent(base.TelegramObject):
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import typing
|
|||
|
||||
from ..utils import helper
|
||||
from ..utils import markdown as md
|
||||
from ..utils.deprecated import deprecated
|
||||
from ..utils.text_decorations import html_decoration, markdown_decoration
|
||||
from . import base, fields
|
||||
from .animation import Animation
|
||||
|
|
@ -21,6 +22,7 @@ from .input_media import InputMedia, MediaGroup
|
|||
from .invoice import Invoice
|
||||
from .location import Location
|
||||
from .message_entity import MessageEntity
|
||||
from .message_id import MessageId
|
||||
from .passport_data import PassportData
|
||||
from .photo_size import PhotoSize
|
||||
from .poll import Poll
|
||||
|
|
@ -2140,6 +2142,11 @@ class Message(base.TelegramObject):
|
|||
message_id=self.message_id,
|
||||
)
|
||||
|
||||
@deprecated(
|
||||
"This method deprecated since Bot API 4.5. Use method `copy_to` instead. \n"
|
||||
"Read more: https://core.telegram.org/bots/api#copymessage",
|
||||
stacklevel=3
|
||||
)
|
||||
async def send_copy(
|
||||
self: Message,
|
||||
chat_id: typing.Union[str, int],
|
||||
|
|
@ -2244,6 +2251,33 @@ class Message(base.TelegramObject):
|
|||
else:
|
||||
raise TypeError("This type of message can't be copied.")
|
||||
|
||||
async def copy_to(
|
||||
self,
|
||||
chat_id: typing.Union[base.Integer, base.String],
|
||||
caption: typing.Optional[base.String] = None,
|
||||
parse_mode: typing.Optional[base.String] = None,
|
||||
caption_entities: typing.Optional[typing.List[MessageEntity]] = None,
|
||||
disable_notification: typing.Optional[base.Boolean] = None,
|
||||
reply_to_message_id: typing.Optional[base.Integer] = None,
|
||||
allow_sending_without_reply: typing.Optional[base.Boolean] = None,
|
||||
reply_markup: typing.Union[InlineKeyboardMarkup,
|
||||
ReplyKeyboardMarkup,
|
||||
ReplyKeyboardRemove,
|
||||
ForceReply, None] = None,
|
||||
) -> MessageId:
|
||||
return await self.bot.copy_message(
|
||||
chat_id=chat_id,
|
||||
from_chat_id=self.chat.id,
|
||||
message_id=self.message_id,
|
||||
caption=caption,
|
||||
parse_mode=parse_mode,
|
||||
caption_entities=caption_entities,
|
||||
disable_notification=disable_notification,
|
||||
reply_to_message_id=reply_to_message_id,
|
||||
allow_sending_without_reply=allow_sending_without_reply,
|
||||
reply_markup=reply_markup
|
||||
)
|
||||
|
||||
def __int__(self):
|
||||
return self.message_id
|
||||
|
||||
|
|
|
|||
10
aiogram/types/message_id.py
Normal file
10
aiogram/types/message_id.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
from . import base, fields
|
||||
|
||||
|
||||
class MessageId(base.TelegramObject):
|
||||
"""
|
||||
This object represents a unique message identifier.
|
||||
|
||||
https://core.telegram.org/bots/api#messageid
|
||||
"""
|
||||
message_id: base.String = fields.Field()
|
||||
Loading…
Add table
Add a link
Reference in a new issue