From 9e4180139f5d2390e0104a5dffb86da261b8f0b9 Mon Sep 17 00:00:00 2001 From: "pineda.er" Date: Sun, 17 Aug 2025 13:04:38 +0800 Subject: [PATCH 1/3] Add cancel subscription for star subscriptions --- pyrogram/methods/bots/__init__.py | 2 + .../methods/bots/cancel_stars_subscription.py | 52 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 pyrogram/methods/bots/cancel_stars_subscription.py diff --git a/pyrogram/methods/bots/__init__.py b/pyrogram/methods/bots/__init__.py index 336fd11092..94728bfbb9 100644 --- a/pyrogram/methods/bots/__init__.py +++ b/pyrogram/methods/bots/__init__.py @@ -22,6 +22,7 @@ from .answer_shipping_query import AnswerShippingQuery from .answer_web_app_query import AnswerWebAppQuery from .create_invoice_link import CreateInvoiceLink +from .cancel_stars_subscription import CancelStarSubscription from .delete_bot_commands import DeleteBotCommands from .get_bot_commands import GetBotCommands from .get_bot_default_privileges import GetBotDefaultPrivileges @@ -51,6 +52,7 @@ class Bots( AnswerInlineQuery, AnswerPreCheckoutQuery, AnswerShippingQuery, + CancelStarSubscription, CreateInvoiceLink, GetInlineBotResults, GetOwnedBots, diff --git a/pyrogram/methods/bots/cancel_stars_subscription.py b/pyrogram/methods/bots/cancel_stars_subscription.py new file mode 100644 index 0000000000..8efb9574eb --- /dev/null +++ b/pyrogram/methods/bots/cancel_stars_subscription.py @@ -0,0 +1,52 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 Union +import pyrogram +from pyrogram import raw, types + +class CancelStarSubscription: + async def cancel_stars_subscription( + self: "pyrogram.Client", + user_id: Union[int, types.InputUser], + charge_id: str, + restore: bool = False + ) -> bool: + """ + Cancel a Telegram Stars subscription for a user. + + Parameters: + user_id (``int`` | ``pyrogram.types.InputUser``): + The user whose subscription will be cancelled. Can be a user ID or an InputUser object. + + charge_id (``str``): + The unique identifier of the payment charge to cancel. + + restore (``bool``, *optional*): + If True, the subscription will be restored instead of cancelled. Defaults to False. + + Returns: + ``bool``: True on success, False otherwise. + """ + return await self.invoke( + raw.functions.payments.BotCancelStarsSubscription( + user_id=raw.types.InputUser(user_id) if isinstance(user_id, int) else user_id, + charge_id=charge_id, + restore=restore + ) + ) From 37a29b1194433a77c15979ae74e718471fba064a Mon Sep 17 00:00:00 2001 From: "pineda.er" Date: Sun, 17 Aug 2025 13:39:17 +0800 Subject: [PATCH 2/3] Use resolve_peer for user_id --- pyrogram/methods/bots/cancel_stars_subscription.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pyrogram/methods/bots/cancel_stars_subscription.py b/pyrogram/methods/bots/cancel_stars_subscription.py index 8efb9574eb..5df6860bc0 100644 --- a/pyrogram/methods/bots/cancel_stars_subscription.py +++ b/pyrogram/methods/bots/cancel_stars_subscription.py @@ -18,12 +18,12 @@ from typing import Union import pyrogram -from pyrogram import raw, types +from pyrogram import raw class CancelStarSubscription: - async def cancel_stars_subscription( + async def cancel_star_subscription( self: "pyrogram.Client", - user_id: Union[int, types.InputUser], + user_id: Union[int, str], charge_id: str, restore: bool = False ) -> bool: @@ -45,7 +45,7 @@ async def cancel_stars_subscription( """ return await self.invoke( raw.functions.payments.BotCancelStarsSubscription( - user_id=raw.types.InputUser(user_id) if isinstance(user_id, int) else user_id, + user_id=await self.resolve_peer(user_id), charge_id=charge_id, restore=restore ) From c129276d024cb4ff0464bd72b36d37040bb4be32 Mon Sep 17 00:00:00 2001 From: V <143077844+Vlatsky@users.noreply.github.com> Date: Mon, 18 Aug 2025 02:02:21 +0800 Subject: [PATCH 3/3] Change parameters description on user_id --- pyrogram/methods/bots/cancel_stars_subscription.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/methods/bots/cancel_stars_subscription.py b/pyrogram/methods/bots/cancel_stars_subscription.py index 5df6860bc0..1b293db06e 100644 --- a/pyrogram/methods/bots/cancel_stars_subscription.py +++ b/pyrogram/methods/bots/cancel_stars_subscription.py @@ -31,7 +31,7 @@ async def cancel_star_subscription( Cancel a Telegram Stars subscription for a user. Parameters: - user_id (``int`` | ``pyrogram.types.InputUser``): + user_id (``int`` | ``str``): The user whose subscription will be cancelled. Can be a user ID or an InputUser object. charge_id (``str``):