-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Api 7.7 #4356
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
Api 7.7 #4356
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b24d09b
Feat: Api 7.7
Poolitzer a27755a
Fix: Align docs formatting to telegrams
Poolitzer b2191bc
Fix: Properly name TestBase class
Poolitzer 003aa79
Fix: Forgot README.rst
Poolitzer d0b8c04
Missed version added
Poolitzer e2d3b69
Update telegram/ext/filters.py
Bibo-Joshi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
RefundedPayment | ||
=============== | ||
|
||
.. autoclass:: telegram.RefundedPayment | ||
:members: | ||
:show-inheritance: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -55,6 +55,7 @@ | |||||||||||
from telegram._paidmedia import PaidMediaInfo | ||||||||||||
from telegram._passport.passportdata import PassportData | ||||||||||||
from telegram._payment.invoice import Invoice | ||||||||||||
from telegram._payment.refundedpayment import RefundedPayment | ||||||||||||
from telegram._payment.successfulpayment import SuccessfulPayment | ||||||||||||
from telegram._poll import Poll | ||||||||||||
from telegram._proximityalerttriggered import ProximityAlertTriggered | ||||||||||||
|
@@ -576,6 +577,10 @@ class Message(MaybeInaccessibleMessage): | |||||||||||
paid_media (:obj:`telegram.PaidMediaInfo`, optional): Message contains paid media; | ||||||||||||
information about the paid media. | ||||||||||||
|
||||||||||||
.. versionadded:: NEXT.VERSION | ||||||||||||
refunded_payment (:obj:`telegram.RefundedPayment`, optional): Message is a service message | ||||||||||||
about a refunded payment, information about the payment. | ||||||||||||
|
||||||||||||
.. versionadded:: NEXT.VERSION | ||||||||||||
|
||||||||||||
Attributes: | ||||||||||||
|
@@ -894,6 +899,10 @@ class Message(MaybeInaccessibleMessage): | |||||||||||
paid_media (:obj:`telegram.PaidMediaInfo`): Optional. Message contains paid media; | ||||||||||||
information about the paid media. | ||||||||||||
|
||||||||||||
.. versionadded:: NEXT.VERSION | ||||||||||||
refunded_payment (:obj:`telegram.RefundedPayment`): Optional. Message is a service message | ||||||||||||
about a refunded payment, information about the payment. | ||||||||||||
|
||||||||||||
Comment on lines
+904
to
+905
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
.. versionadded:: NEXT.VERSION | ||||||||||||
|
||||||||||||
.. |custom_emoji_no_md1_support| replace:: Since custom emoji entities are not supported by | ||||||||||||
|
@@ -968,6 +977,7 @@ class Message(MaybeInaccessibleMessage): | |||||||||||
"poll", | ||||||||||||
"proximity_alert_triggered", | ||||||||||||
"quote", | ||||||||||||
"refunded_payment", | ||||||||||||
"reply_markup", | ||||||||||||
"reply_to_message", | ||||||||||||
"reply_to_story", | ||||||||||||
|
@@ -1080,6 +1090,7 @@ def __init__( | |||||||||||
effect_id: Optional[str] = None, | ||||||||||||
show_caption_above_media: Optional[bool] = None, | ||||||||||||
paid_media: Optional[PaidMediaInfo] = None, | ||||||||||||
refunded_payment: Optional[RefundedPayment] = None, | ||||||||||||
*, | ||||||||||||
api_kwargs: Optional[JSONDict] = None, | ||||||||||||
): | ||||||||||||
|
@@ -1182,6 +1193,7 @@ def __init__( | |||||||||||
self.effect_id: Optional[str] = effect_id | ||||||||||||
self.show_caption_above_media: Optional[bool] = show_caption_above_media | ||||||||||||
self.paid_media: Optional[PaidMediaInfo] = paid_media | ||||||||||||
self.refunded_payment: Optional[RefundedPayment] = refunded_payment | ||||||||||||
|
||||||||||||
self._effective_attachment = DEFAULT_NONE | ||||||||||||
|
||||||||||||
|
@@ -1298,6 +1310,7 @@ def de_json(cls, data: Optional[JSONDict], bot: Optional["Bot"] = None) -> Optio | |||||||||||
data["chat_shared"] = ChatShared.de_json(data.get("chat_shared"), bot) | ||||||||||||
data["chat_background_set"] = ChatBackground.de_json(data.get("chat_background_set"), bot) | ||||||||||||
data["paid_media"] = PaidMediaInfo.de_json(data.get("paid_media"), bot) | ||||||||||||
data["refunded_payment"] = RefundedPayment.de_json(data.get("refunded_payment"), bot) | ||||||||||||
|
||||||||||||
# Unfortunately, this needs to be here due to cyclic imports | ||||||||||||
from telegram._giveaway import ( # pylint: disable=import-outside-toplevel | ||||||||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#!/usr/bin/env python | ||
# | ||
# A library that provides a Python interface to the Telegram Bot API | ||
# Copyright (C) 2015-2024 | ||
# Leandro Toledo de Souza <[email protected]> | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Lesser Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program 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 Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser Public License | ||
# along with this program. If not, see [http://www.gnu.org/licenses/]. | ||
"""This module contains an object that represents a Telegram RefundedPayment.""" | ||
|
||
from typing import Optional | ||
|
||
from telegram._telegramobject import TelegramObject | ||
from telegram._utils.types import JSONDict | ||
|
||
|
||
class RefundedPayment(TelegramObject): | ||
"""This object contains basic information about a refunded payment. | ||
|
||
Objects of this class are comparable in terms of equality. Two objects of this class are | ||
considered equal, if their :attr:`telegram_payment_charge_id` is equal. | ||
|
||
Args: | ||
currency (:obj:`str`): Three-letter ISO 4217 `currency | ||
<https://core.telegram.org/bots/payments#supported-currencies>`_ code, or ``XTR`` for | ||
payments in |tg_stars|. Currently, always ``XTR``. | ||
total_amount (:obj:`int`): Total refunded price in the *smallest units* of the currency | ||
(integer, **not** float/double). For example, for a price of ``US$ 1.45``, | ||
``total_amount = 145``. See the *exp* parameter in | ||
`currencies.json <https://core.telegram.org/bots/payments/currencies.json>`_, | ||
it shows the number of digits past the decimal point for each currency | ||
(2 for the majority of currencies). | ||
invoice_payload (:obj:`str`): Bot-specified invoice payload. | ||
telegram_payment_charge_id (:obj:`str`): Telegram payment identifier. | ||
provider_payment_charge_id (:obj:`str`, optional): Provider payment identifier. | ||
|
||
Attributes: | ||
currency (:obj:`str`): Three-letter ISO 4217 `currency | ||
<https://core.telegram.org/bots/payments#supported-currencies>`_ code, or ``XTR`` for | ||
payments in |tg_stars|. Currently, always ``XTR``. | ||
total_amount (:obj:`int`): Total refunded price in the *smallest units* of the currency | ||
(integer, **not** float/double). For example, for a price of ``US$ 1.45``, | ||
``total_amount = 145``. See the *exp* parameter in | ||
`currencies.json <https://core.telegram.org/bots/payments/currencies.json>`_, | ||
it shows the number of digits past the decimal point for each currency | ||
(2 for the majority of currencies). | ||
invoice_payload (:obj:`str`): Bot-specified invoice payload. | ||
telegram_payment_charge_id (:obj:`str`): Telegram payment identifier. | ||
provider_payment_charge_id (:obj:`str`): Optional. Provider payment identifier. | ||
|
||
""" | ||
|
||
__slots__ = ( | ||
"currency", | ||
"invoice_payload", | ||
"provider_payment_charge_id", | ||
"telegram_payment_charge_id", | ||
"total_amount", | ||
) | ||
|
||
def __init__( | ||
self, | ||
currency: str, | ||
total_amount: int, | ||
invoice_payload: str, | ||
telegram_payment_charge_id: str, | ||
provider_payment_charge_id: Optional[str] = None, | ||
*, | ||
api_kwargs: Optional[JSONDict] = None, | ||
): | ||
super().__init__(api_kwargs=api_kwargs) | ||
self.currency: str = currency | ||
self.total_amount: int = total_amount | ||
self.invoice_payload: str = invoice_payload | ||
self.telegram_payment_charge_id: str = telegram_payment_charge_id | ||
# Optional | ||
self.provider_payment_charge_id: Optional[str] = provider_payment_charge_id | ||
|
||
self._id_attrs = (self.telegram_payment_charge_id,) | ||
|
||
self._freeze() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#!/usr/bin/env python | ||
# | ||
# A library that provides a Python interface to the Telegram Bot API | ||
# Copyright (C) 2015-2024 | ||
# Leandro Toledo de Souza <[email protected]> | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Lesser Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program 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 Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser Public License | ||
# along with this program. If not, see [http://www.gnu.org/licenses/]. | ||
import pytest | ||
|
||
from telegram import RefundedPayment | ||
from tests.auxil.slots import mro_slots | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def refunded_payment(): | ||
return RefundedPayment( | ||
TestRefundedPaymentBase.currency, | ||
TestRefundedPaymentBase.total_amount, | ||
TestRefundedPaymentBase.invoice_payload, | ||
TestRefundedPaymentBase.telegram_payment_charge_id, | ||
TestRefundedPaymentBase.provider_payment_charge_id, | ||
) | ||
|
||
|
||
class TestRefundedPaymentBase: | ||
invoice_payload = "invoice_payload" | ||
currency = "EUR" | ||
total_amount = 100 | ||
telegram_payment_charge_id = "telegram_payment_charge_id" | ||
provider_payment_charge_id = "provider_payment_charge_id" | ||
|
||
|
||
class TestRefundedPaymentWithoutRequest(TestRefundedPaymentBase): | ||
def test_slot_behaviour(self, refunded_payment): | ||
inst = refunded_payment | ||
for attr in inst.__slots__: | ||
assert getattr(inst, attr, "err") != "err", f"got extra slot '{attr}'" | ||
assert len(mro_slots(inst)) == len(set(mro_slots(inst))), "duplicate slot" | ||
|
||
def test_de_json(self, bot): | ||
json_dict = { | ||
"invoice_payload": self.invoice_payload, | ||
"currency": self.currency, | ||
"total_amount": self.total_amount, | ||
"telegram_payment_charge_id": self.telegram_payment_charge_id, | ||
"provider_payment_charge_id": self.provider_payment_charge_id, | ||
} | ||
refunded_payment = RefundedPayment.de_json(json_dict, bot) | ||
assert refunded_payment.api_kwargs == {} | ||
|
||
assert refunded_payment.invoice_payload == self.invoice_payload | ||
assert refunded_payment.currency == self.currency | ||
assert refunded_payment.total_amount == self.total_amount | ||
assert refunded_payment.telegram_payment_charge_id == self.telegram_payment_charge_id | ||
assert refunded_payment.provider_payment_charge_id == self.provider_payment_charge_id | ||
|
||
def test_to_dict(self, refunded_payment): | ||
refunded_payment_dict = refunded_payment.to_dict() | ||
|
||
assert isinstance(refunded_payment_dict, dict) | ||
assert refunded_payment_dict["invoice_payload"] == refunded_payment.invoice_payload | ||
assert refunded_payment_dict["currency"] == refunded_payment.currency | ||
assert refunded_payment_dict["total_amount"] == refunded_payment.total_amount | ||
assert ( | ||
refunded_payment_dict["telegram_payment_charge_id"] | ||
== refunded_payment.telegram_payment_charge_id | ||
) | ||
assert ( | ||
refunded_payment_dict["provider_payment_charge_id"] | ||
== refunded_payment.provider_payment_charge_id | ||
) | ||
|
||
def test_equality(self): | ||
a = RefundedPayment( | ||
self.currency, | ||
self.total_amount, | ||
self.invoice_payload, | ||
self.telegram_payment_charge_id, | ||
self.provider_payment_charge_id, | ||
) | ||
b = RefundedPayment( | ||
self.currency, | ||
self.total_amount, | ||
self.invoice_payload, | ||
self.telegram_payment_charge_id, | ||
self.provider_payment_charge_id, | ||
) | ||
c = RefundedPayment("", 0, "", self.telegram_payment_charge_id) | ||
d = RefundedPayment( | ||
self.currency, | ||
self.total_amount, | ||
self.invoice_payload, | ||
"", | ||
) | ||
|
||
assert a == b | ||
assert hash(a) == hash(b) | ||
assert a is not b | ||
|
||
assert a == c | ||
assert hash(a) == hash(c) | ||
|
||
assert a != d | ||
assert hash(a) != hash(d) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While we could definitely add this, it would also need to be added to successful_payment and paid_media.
All of them getting this big block might take up unnecessary amount of screen time, I would do an inline link then instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm I was just following what hinrich started with 027263a, inline link also works with me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that is really a lot of wasted screen space