From beed137855e5930b24b5fe713d138896f2ee8a24 Mon Sep 17 00:00:00 2001 From: KurimuzonAkuma Date: Fri, 2 May 2025 21:42:18 +0300 Subject: [PATCH] Add delete_business_messages method Signed-off-by: wulan17 --- compiler/docs/compiler.py | 1 + pyrogram/methods/business/__init__.py | 3 + .../business/delete_business_messages.py | 71 +++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 pyrogram/methods/business/delete_business_messages.py diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 39c037fb..91ce8d19 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -408,6 +408,7 @@ def pyrogram_api(): Telegram Business answer_pre_checkout_query answer_shipping_query + delete_business_messages get_business_connection """, authorization=""" diff --git a/pyrogram/methods/business/__init__.py b/pyrogram/methods/business/__init__.py index ac8140fb..2bf6fd21 100644 --- a/pyrogram/methods/business/__init__.py +++ b/pyrogram/methods/business/__init__.py @@ -1,5 +1,6 @@ # Pyrogram - Telegram MTProto API Client Library for Python # Copyright (C) 2017-present Dan +# Copyright (C) 2022-present Mayuri-Chan # # This file is part of Pyrogram. # @@ -18,12 +19,14 @@ from .answer_pre_checkout_query import AnswerPreCheckoutQuery from .answer_shipping_query import AnswerShippingQuery +from .delete_business_messages import DeleteBusinessMessages from .get_business_connection import GetBusinessConnection class TelegramBusiness( AnswerPreCheckoutQuery, AnswerShippingQuery, + DeleteBusinessMessages, GetBusinessConnection, ): pass diff --git a/pyrogram/methods/business/delete_business_messages.py b/pyrogram/methods/business/delete_business_messages.py new file mode 100644 index 00000000..12011e2b --- /dev/null +++ b/pyrogram/methods/business/delete_business_messages.py @@ -0,0 +1,71 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# Copyright (C) 2022-present Mayuri-Chan +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from typing import Iterable, Union + +import pyrogram +from pyrogram import raw + + +class DeleteBusinessMessages: + async def delete_business_messages( + self: "pyrogram.Client", + business_connection_id: str, + message_ids: Union[int, Iterable[int]] + ) -> int: + """Delete messages on behalf of a business account. + + .. note:: + + Requires the `can_delete_sent_messages` business bot right to delete messages sent by the bot itself, + or the `can_delete_all_messages` business bot right to delete any message. + + .. include:: /_includes/usable-by/bots.rst + + Parameters: + business_connection_id (``str``): + Unique identifier of business connection on behalf of which to send the request. + + message_ids (``int`` | Iterable of ``int``): + An iterable of message identifiers to delete (integers) or a single message id. + All messages must be from the same chat. + + Returns: + ``int``: Amount of affected messages + + Example: + .. code-block:: python + + # Delete one message + await app.delete_business_messages(connection_id, message_id) + + # Delete multiple messages at once + await app.delete_business_messages(connection_id, list_of_message_ids) + """ + message_ids = list(message_ids) if not isinstance(message_ids, int) else [message_ids] + + r = await self.invoke( + raw.functions.messages.DeleteMessages( + id=message_ids, + revoke=True + ), + business_connection_id=business_connection_id + ) + + return r.pts_count