diff --git a/docs/source/inclusions/bot_methods.rst b/docs/source/inclusions/bot_methods.rst index bece5296e22..f79f5bd959c 100644 --- a/docs/source/inclusions/bot_methods.rst +++ b/docs/source/inclusions/bot_methods.rst @@ -369,6 +369,8 @@ - Used for getting basic info about a file * - :meth:`~telegram.Bot.get_me` - Used for getting basic information about the bot + * - :meth:`~telegram.Bot.get_star_transactions` + - Used for obtaining the bot's Telegram Stars transactions * - :meth:`~telegram.Bot.refund_star_payment` - Used for refunding a payment in Telegram Stars diff --git a/telegram/_bot.py b/telegram/_bot.py index d79d1e08800..eb7b7641d8a 100644 --- a/telegram/_bot.py +++ b/telegram/_bot.py @@ -88,6 +88,7 @@ from telegram._reaction import ReactionType, ReactionTypeCustomEmoji, ReactionTypeEmoji from telegram._reply import ReplyParameters from telegram._sentwebappmessage import SentWebAppMessage +from telegram._stars import StarTransactions from telegram._telegramobject import TelegramObject from telegram._update import Update from telegram._user import User @@ -9105,6 +9106,50 @@ async def refund_star_payment( api_kwargs=api_kwargs, ) + async def get_star_transactions( + self, + offset: Optional[int] = None, + limit: Optional[int] = None, + *, + read_timeout: ODVInput[float] = DEFAULT_NONE, + write_timeout: ODVInput[float] = DEFAULT_NONE, + connect_timeout: ODVInput[float] = DEFAULT_NONE, + pool_timeout: ODVInput[float] = DEFAULT_NONE, + api_kwargs: Optional[JSONDict] = None, + ) -> StarTransactions: + """Returns the bot's Telegram Star transactions in chronological order. + + .. versionadded:: NEXT.VERSION + + Args: + offset (:obj:`int`, optional): Number of transactions to skip in the response. + limit (:obj:`int`, optional): The maximum number of transactions to be retrieved. + Values between :tg-const:`telegram.constants.StarTransactionsLimit.MIN_LIMIT`- + :tg-const:`telegram.constants.StarTransactionsLimit.MAX_LIMIT` are accepted. + Defaults to :tg-const:`telegram.constants.StarTransactionsLimit.MAX_LIMIT`. + + Returns: + :class:`telegram.StarTransactions`: On success. + + Raises: + :class:`telegram.error.TelegramError` + """ + + data: JSONDict = {"offset": offset, "limit": limit} + + return StarTransactions.de_json( # type: ignore[return-value] + await self._post( + "getStarTransactions", + data, + read_timeout=read_timeout, + write_timeout=write_timeout, + connect_timeout=connect_timeout, + pool_timeout=pool_timeout, + api_kwargs=api_kwargs, + ), + bot=self, + ) + def to_dict(self, recursive: bool = True) -> JSONDict: # noqa: ARG002 """See :meth:`telegram.TelegramObject.to_dict`.""" data: JSONDict = {"id": self.id, "username": self.username, "first_name": self.first_name} @@ -9357,3 +9402,5 @@ def to_dict(self, recursive: bool = True) -> JSONDict: # noqa: ARG002 """Alias for :meth:`replace_sticker_in_set`""" refundStarPayment = refund_star_payment """Alias for :meth:`refund_star_payment`""" + getStarTransactions = get_star_transactions + """Alias for :meth:`get_star_transactions`""" diff --git a/telegram/constants.py b/telegram/constants.py index 20afda89578..5cd6e7ffc2c 100644 --- a/telegram/constants.py +++ b/telegram/constants.py @@ -91,6 +91,7 @@ "ReactionType", "ReplyLimit", "RevenueWithdrawalStateType", + "StarTransactionsLimit", "StickerFormat", "StickerLimit", "StickerSetLimit", @@ -2322,6 +2323,25 @@ class RevenueWithdrawalStateType(StringEnum): """:obj:`str`: A withdrawal failed and the transaction was refunded.""" +class StarTransactionsLimit(IntEnum): + """This enum contains limitations for :class:`telegram.Bot.get_star_transactions`. + The enum members of this enumeration are instances of :class:`int` and can be treated as such. + + .. versionadded:: NEXT.VERSION + """ + + __slots__ = () + + MIN_LIMIT = 1 + """:obj:`int`: Minimum value allowed for the + :paramref:`~telegram.Bot.get_star_transactions.limit` parameter of + :meth:`telegram.Bot.get_star_transactions`.""" + MAX_LIMIT = 100 + """:obj:`int`: Maximum value allowed for the + :paramref:`~telegram.Bot.get_star_transactions.limit` parameter of + :meth:`telegram.Bot.get_star_transactions`.""" + + class StickerFormat(StringEnum): """This enum contains the available formats of :class:`telegram.Sticker` in the set. The enum members of this enumeration are instances of :class:`str` and can be treated as such. diff --git a/telegram/ext/_extbot.py b/telegram/ext/_extbot.py index 67139a96379..3cd4ab389e7 100644 --- a/telegram/ext/_extbot.py +++ b/telegram/ext/_extbot.py @@ -76,6 +76,7 @@ ReactionType, ReplyParameters, SentWebAppMessage, + StarTransactions, Sticker, StickerSet, TelegramObject, @@ -4193,6 +4194,28 @@ async def refund_star_payment( api_kwargs=self._merge_api_rl_kwargs(api_kwargs, rate_limit_args), ) + async def get_star_transactions( + self, + offset: Optional[int] = None, + limit: Optional[int] = None, + *, + read_timeout: ODVInput[float] = DEFAULT_NONE, + write_timeout: ODVInput[float] = DEFAULT_NONE, + connect_timeout: ODVInput[float] = DEFAULT_NONE, + pool_timeout: ODVInput[float] = DEFAULT_NONE, + api_kwargs: Optional[JSONDict] = None, + rate_limit_args: Optional[RLARGS] = None, + ) -> StarTransactions: + return await super().get_star_transactions( + offset=offset, + limit=limit, + read_timeout=read_timeout, + write_timeout=write_timeout, + connect_timeout=connect_timeout, + pool_timeout=pool_timeout, + api_kwargs=self._merge_api_rl_kwargs(api_kwargs, rate_limit_args), + ) + # updated camelCase aliases getMe = get_me sendMessage = send_message @@ -4315,3 +4338,4 @@ async def refund_star_payment( getBusinessConnection = get_business_connection replaceStickerInSet = replace_sticker_in_set refundStarPayment = refund_star_payment + getStarTransactions = get_star_transactions diff --git a/tests/test_bot.py b/tests/test_bot.py index 957798125b4..05d655450f3 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -73,6 +73,8 @@ ReplyParameters, SentWebAppMessage, ShippingOption, + StarTransaction, + StarTransactions, Update, User, WebAppInfo, @@ -2224,6 +2226,20 @@ async def make_assertion(url, request_data: RequestData, *args, **kwargs): monkeypatch.setattr(bot.request, "post", make_assertion) assert await bot.refund_star_payment(42, "37") + async def test_get_star_transactions(self, bot, monkeypatch): + # we just want to test the offset parameter + st = StarTransactions([StarTransaction("1", 1, dtm.datetime.now())]).to_json() + + async def do_request(url, request_data: RequestData, *args, **kwargs): + offset = request_data.parameters.get("offset") == 3 + if offset: + return 200, f'{{"ok": true, "result": {st}}}'.encode() + return 400, b'{"ok": false, "result": []}' + + monkeypatch.setattr(bot.request, "do_request", do_request) + obj = await bot.get_star_transactions(offset=3) + assert isinstance(obj, StarTransactions) + class TestBotWithRequest: """ @@ -4211,3 +4227,8 @@ async def test_do_api_request_list_return_type(self, bot, chat_id, return_type): @pytest.mark.parametrize("return_type", [Message, None]) async def test_do_api_request_bool_return_type(self, bot, chat_id, return_type): assert await bot.do_api_request("delete_my_commands", return_type=return_type) is True + + async def test_get_star_transactions(self, bot): + transactions = await bot.get_star_transactions(limit=1) + assert isinstance(transactions, StarTransactions) + assert len(transactions.transactions) == 0 pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy