diff --git a/aiogram/bot/bot.py b/aiogram/bot/bot.py index d1d9b826..fda35703 100644 --- a/aiogram/bot/bot.py +++ b/aiogram/bot/bot.py @@ -1483,15 +1483,27 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): result = await self.request(api.Methods.PIN_CHAT_MESSAGE, payload) return result - async def unpin_chat_message(self, chat_id: typing.Union[base.Integer, base.String]) -> base.Boolean: + async def unpin_chat_message(self, + chat_id: typing.Union[base.Integer, base.String], + message_id: typing.Optional[base.Integer] = None, + ) -> base.Boolean: """ - Use this method to unpin a message in a supergroup chat. - The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. + Use this method to remove a message from the list of pinned messages in a + chat. If the chat is not a private chat, the bot must be an administrator in + the chat for this to work and must have the 'can_pin_messages' admin right in + a supergroup or 'can_edit_messages' admin right in a channel. Returns True on + success. Source: https://core.telegram.org/bots/api#unpinchatmessage - :param chat_id: Unique identifier for the target chat or username of the target supergroup + :param chat_id: Unique identifier for the target chat or username of the + target channel (in the format @channelusername) :type chat_id: :obj:`typing.Union[base.Integer, base.String]` + + :param message_id: Identifier of a message to unpin. If not specified, the + most recent pinned message (by sending date) will be unpinned. + :type message_id: :obj:`typing.Optional[base.Integer]` + :return: Returns True on success :rtype: :obj:`base.Boolean` """ diff --git a/aiogram/types/chat.py b/aiogram/types/chat.py index 6d2b6590..0380fbed 100644 --- a/aiogram/types/chat.py +++ b/aiogram/types/chat.py @@ -385,17 +385,29 @@ class Chat(base.TelegramObject): """ return await self.bot.pin_chat_message(self.id, message_id, disable_notification) - async def unpin_message(self) -> base.Boolean: + async def unpin_message(self, + message_id: typing.Optional[base.Integer] = None, + ) -> base.Boolean: """ - Use this method to unpin a message in a supergroup chat. - The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. + Use this method to remove a message from the list of pinned messages in a + chat. If the chat is not a private chat, the bot must be an administrator in + the chat for this to work and must have the 'can_pin_messages' admin right in + a supergroup or 'can_edit_messages' admin right in a channel. Returns True on + success. Source: https://core.telegram.org/bots/api#unpinchatmessage - :return: Returns True on success. + :param message_id: Identifier of a message to unpin. If not specified, the + most recent pinned message (by sending date) will be unpinned. + :type message_id: :obj:`typing.Optional[base.Integer]` + + :return: Returns True on success :rtype: :obj:`base.Boolean` """ - return await self.bot.unpin_chat_message(self.id) + return await self.bot.unpin_chat_message( + chat_id=self.id, + message_id=message_id, + ) async def leave(self) -> base.Boolean: """ diff --git a/aiogram/types/message.py b/aiogram/types/message.py index 3b0c4698..aadb56a1 100644 --- a/aiogram/types/message.py +++ b/aiogram/types/message.py @@ -2118,6 +2118,23 @@ class Message(base.TelegramObject): """ return await self.chat.pin_message(self.message_id, disable_notification) + async def unpin(self) -> base.Boolean: + """ + Use this method to remove a message from the list of pinned messages in a + chat. If the chat is not a private chat, the bot must be an administrator in + the chat for this to work and must have the 'can_pin_messages' admin right in + a supergroup or 'can_edit_messages' admin right in a channel. Returns True on + success. + + Source: https://core.telegram.org/bots/api#unpinchatmessage + + :return: Returns True on success + :rtype: :obj:`base.Boolean` + """ + return await self.chat.unpin_message( + message_id=self.message_id, + ) + async def send_copy( self: Message, chat_id: typing.Union[str, int],