Skip to content

API 7.5 - get_star_transactions #4328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/source/inclusions/bot_methods.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
47 changes: 47 additions & 0 deletions telegram/_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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`"""
20 changes: 20 additions & 0 deletions telegram/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"ReactionType",
"ReplyLimit",
"RevenueWithdrawalStateType",
"StarTransactionsLimit",
"StickerFormat",
"StickerLimit",
"StickerSetLimit",
Expand Down Expand Up @@ -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.
Expand Down
24 changes: 24 additions & 0 deletions telegram/ext/_extbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
ReactionType,
ReplyParameters,
SentWebAppMessage,
StarTransactions,
Sticker,
StickerSet,
TelegramObject,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
21 changes: 21 additions & 0 deletions tests/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
ReplyParameters,
SentWebAppMessage,
ShippingOption,
StarTransaction,
StarTransactions,
Update,
User,
WebAppInfo,
Expand Down Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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
Loading
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