Skip to content

API 7.6 - paid_media for Message and ExternalReplyInfo #4340

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 2 commits into from
Jul 4, 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
18 changes: 18 additions & 0 deletions telegram/_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
from telegram._linkpreviewoptions import LinkPreviewOptions
from telegram._messageautodeletetimerchanged import MessageAutoDeleteTimerChanged
from telegram._messageentity import MessageEntity
from telegram._paidmedia import PaidMediaInfo
from telegram._passport.passportdata import PassportData
from telegram._payment.invoice import Invoice
from telegram._payment.successfulpayment import SuccessfulPayment
Expand Down Expand Up @@ -571,6 +572,10 @@ class Message(MaybeInaccessibleMessage):
background set.

.. versionadded:: 21.2
paid_media (:obj:`telegram.PaidMediaInfo`, optional): Message contains paid media;
information about the paid media.

.. versionadded:: NEXT.VERSION

Attributes:
message_id (:obj:`int`): Unique message identifier inside this chat.
Expand Down Expand Up @@ -884,6 +889,10 @@ class Message(MaybeInaccessibleMessage):
background set

.. versionadded:: 21.2
paid_media (:obj:`telegram.PaidMediaInfo`): Optional. Message contains paid media;
information about the paid media.

.. versionadded:: NEXT.VERSION

.. |custom_emoji_no_md1_support| replace:: Since custom emoji entities are not supported by
:attr:`~telegram.constants.ParseMode.MARKDOWN`, this method now raises a
Expand Down Expand Up @@ -950,6 +959,7 @@ class Message(MaybeInaccessibleMessage):
"new_chat_members",
"new_chat_photo",
"new_chat_title",
"paid_media",
"passport_data",
"photo",
"pinned_message",
Expand Down Expand Up @@ -1067,6 +1077,7 @@ def __init__(
chat_background_set: Optional[ChatBackground] = None,
effect_id: Optional[str] = None,
show_caption_above_media: Optional[bool] = None,
paid_media: Optional[PaidMediaInfo] = None,
*,
api_kwargs: Optional[JSONDict] = None,
):
Expand Down Expand Up @@ -1168,6 +1179,7 @@ def __init__(
self.chat_background_set: Optional[ChatBackground] = chat_background_set
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._effective_attachment = DEFAULT_NONE

Expand Down Expand Up @@ -1283,6 +1295,7 @@ def de_json(cls, data: Optional[JSONDict], bot: Optional["Bot"] = None) -> Optio
data["users_shared"] = UsersShared.de_json(data.get("users_shared"), bot)
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)

# Unfortunately, this needs to be here due to cyclic imports
from telegram._giveaway import ( # pylint: disable=import-outside-toplevel
Expand Down Expand Up @@ -1346,6 +1359,7 @@ def effective_attachment(
Location,
PassportData,
Sequence[PhotoSize],
PaidMediaInfo,
Poll,
Sticker,
Story,
Expand All @@ -1369,6 +1383,7 @@ def effective_attachment(
* :class:`telegram.Location`
* :class:`telegram.PassportData`
* List[:class:`telegram.PhotoSize`]
* :class:`telegram.PaidMediaInfo`
* :class:`telegram.Poll`
* :class:`telegram.Sticker`
* :class:`telegram.Story`
Expand All @@ -1386,6 +1401,9 @@ def effective_attachment(
:attr:`dice`, :attr:`passport_data` and :attr:`poll` are now also considered to be an
attachment.

.. versionchanged:: NEXT.VERSION
:attr:`paid_media` is now also considered to be an attachment.

"""
if not isinstance(self._effective_attachment, DefaultValue):
return self._effective_attachment
Expand Down
13 changes: 13 additions & 0 deletions telegram/_reply.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from telegram._linkpreviewoptions import LinkPreviewOptions
from telegram._messageentity import MessageEntity
from telegram._messageorigin import MessageOrigin
from telegram._paidmedia import PaidMediaInfo
from telegram._payment.invoice import Invoice
from telegram._poll import Poll
from telegram._story import Story
Expand Down Expand Up @@ -101,6 +102,10 @@ class ExternalReplyInfo(TelegramObject):
poll (:class:`telegram.Poll`, optional): Message is a native poll, information about the
poll.
venue (:class:`telegram.Venue`, optional): Message is a venue, information about the venue.
paid_media (:class:`telegram.PaidMedia`, optional): Message contains paid media;
information about the paid media.

.. versionadded:: NEXT.VERSION

Attributes:
origin (:class:`telegram.MessageOrigin`): Origin of the message replied to by the given
Expand Down Expand Up @@ -144,6 +149,10 @@ class ExternalReplyInfo(TelegramObject):
poll (:class:`telegram.Poll`): Optional. Message is a native poll, information about the
poll.
venue (:class:`telegram.Venue`): Optional. Message is a venue, information about the venue.
paid_media (:class:`telegram.PaidMedia`): Optional. Message contains paid media;
information about the paid media.

.. versionadded:: NEXT.VERSION
"""

__slots__ = (
Expand All @@ -162,6 +171,7 @@ class ExternalReplyInfo(TelegramObject):
"location",
"message_id",
"origin",
"paid_media",
"photo",
"poll",
"sticker",
Expand Down Expand Up @@ -197,6 +207,7 @@ def __init__(
location: Optional[Location] = None,
poll: Optional[Poll] = None,
venue: Optional[Venue] = None,
paid_media: Optional[PaidMediaInfo] = None,
*,
api_kwargs: Optional[JSONDict] = None,
):
Expand Down Expand Up @@ -225,6 +236,7 @@ def __init__(
self.location: Optional[Location] = location
self.poll: Optional[Poll] = poll
self.venue: Optional[Venue] = venue
self.paid_media: Optional[PaidMediaInfo] = paid_media

self._id_attrs = (self.origin,)

Expand Down Expand Up @@ -263,6 +275,7 @@ def de_json(
data["location"] = Location.de_json(data.get("location"), bot)
data["poll"] = Poll.de_json(data.get("poll"), bot)
data["venue"] = Venue.de_json(data.get("venue"), bot)
data["paid_media"] = PaidMediaInfo.de_json(data.get("paid_media"), bot)

return super().de_json(data=data, bot=bot)

Expand Down
10 changes: 10 additions & 0 deletions telegram/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,11 @@ class MessageAttachmentType(StringEnum):
""":obj:`str`: Messages with :attr:`telegram.Message.invoice`."""
LOCATION = "location"
""":obj:`str`: Messages with :attr:`telegram.Message.location`."""
PAID_MEDIA = "paid_media"
""":obj:`str`: Messages with :attr:`telegram.Message.paid_media`.

.. versionadded:: NEXT.VERSION
"""
PASSPORT_DATA = "passport_data"
""":obj:`str`: Messages with :attr:`telegram.Message.passport_data`."""
PHOTO = "photo"
Expand Down Expand Up @@ -1884,6 +1889,11 @@ class MessageType(StringEnum):
""":obj:`str`: Messages with :attr:`telegram.Message.new_chat_title`."""
NEW_CHAT_PHOTO = "new_chat_photo"
""":obj:`str`: Messages with :attr:`telegram.Message.new_chat_photo`."""
PAID_MEDIA = "paid_media"
""":obj:`str`: Messages with :attr:`telegram.Message.paid_media`.

.. versionadded:: NEXT.VERSION
"""
PASSPORT_DATA = "passport_data"
""":obj:`str`: Messages with :attr:`telegram.Message.passport_data`."""
PHOTO = "photo"
Expand Down
2 changes: 2 additions & 0 deletions tests/test_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ def test_message_attachment_type_completeness_reverse(self):
name = to_snake_case(match.group(1))
if name == "photo_size":
name = "photo"
if name == "paid_media_info":
name = "paid_media"
try:
constants.MessageAttachmentType(name)
except ValueError:
Expand Down
5 changes: 5 additions & 0 deletions tests/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
MessageAutoDeleteTimerChanged,
MessageEntity,
MessageOriginChat,
PaidMediaInfo,
PaidMediaPreview,
PassportData,
PhotoSize,
Poll,
Expand Down Expand Up @@ -275,6 +277,7 @@ def message(bot):
{"chat_background_set": ChatBackground(type=BackgroundTypeChatTheme("ice"))},
{"effect_id": "123456789"},
{"show_caption_above_media": True},
{"paid_media": PaidMediaInfo(5, [PaidMediaPreview(10, 10, 10)])},
],
ids=[
"reply",
Expand Down Expand Up @@ -346,6 +349,7 @@ def message(bot):
"chat_background_set",
"effect_id",
"show_caption_above_media",
"paid_media",
],
)
def message_params(bot, request):
Expand Down Expand Up @@ -1221,6 +1225,7 @@ def test_effective_attachment(self, message_params):
"game",
"invoice",
"location",
"paid_media",
"passport_data",
"photo",
"poll",
Expand Down
7 changes: 7 additions & 0 deletions tests/test_reply.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
LinkPreviewOptions,
MessageEntity,
MessageOriginUser,
PaidMediaInfo,
PaidMediaPreview,
ReplyParameters,
TextQuote,
User,
Expand All @@ -44,6 +46,7 @@ def external_reply_info():
message_id=TestExternalReplyInfoBase.message_id,
link_preview_options=TestExternalReplyInfoBase.link_preview_options,
giveaway=TestExternalReplyInfoBase.giveaway,
paid_media=TestExternalReplyInfoBase.paid_media,
)


Expand All @@ -59,6 +62,7 @@ class TestExternalReplyInfoBase:
dtm.datetime.now(dtm.timezone.utc).replace(microsecond=0),
1,
)
paid_media = PaidMediaInfo(5, [PaidMediaPreview(10, 10, 10)])


class TestExternalReplyInfoWithoutRequest(TestExternalReplyInfoBase):
Expand All @@ -76,6 +80,7 @@ def test_de_json(self, bot):
"message_id": self.message_id,
"link_preview_options": self.link_preview_options.to_dict(),
"giveaway": self.giveaway.to_dict(),
"paid_media": self.paid_media.to_dict(),
}

external_reply_info = ExternalReplyInfo.de_json(json_dict, bot)
Expand All @@ -86,6 +91,7 @@ def test_de_json(self, bot):
assert external_reply_info.message_id == self.message_id
assert external_reply_info.link_preview_options == self.link_preview_options
assert external_reply_info.giveaway == self.giveaway
assert external_reply_info.paid_media == self.paid_media

assert ExternalReplyInfo.de_json(None, bot) is None

Expand All @@ -98,6 +104,7 @@ def test_to_dict(self, external_reply_info):
assert ext_reply_info_dict["message_id"] == self.message_id
assert ext_reply_info_dict["link_preview_options"] == self.link_preview_options.to_dict()
assert ext_reply_info_dict["giveaway"] == self.giveaway.to_dict()
assert ext_reply_info_dict["paid_media"] == self.paid_media.to_dict()

def test_equality(self, external_reply_info):
a = external_reply_info
Expand Down
2 changes: 2 additions & 0 deletions tests/test_stars.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ def test_de_json(self, bot):
}
st = StarTransaction.de_json(json_dict, bot)
st_none = StarTransaction.de_json(None, bot)
assert st.api_kwargs == {}
assert st.id == self.id
assert st.amount == self.amount
assert st.date == from_timestamp(self.date)
Expand Down Expand Up @@ -329,6 +330,7 @@ def test_de_json(self, bot):
}
st = StarTransactions.de_json(json_dict, bot)
st_none = StarTransactions.de_json(None, bot)
assert st.api_kwargs == {}
assert st.transactions == tuple(self.transactions)
assert st_none is None

Expand Down
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