OwnedGiftRegular¶
- class telegram.OwnedGiftRegular(gift, send_date, owned_gift_id=None, sender_user=None, text=None, entities=None, is_private=None, is_saved=None, can_be_upgraded=None, was_refunded=None, convert_star_count=None, prepaid_upgrade_star_count=None, is_upgrade_separate=None, unique_gift_number=None, *, api_kwargs=None)[source]¶
Bases:
telegram.OwnedGiftDescribes a regular gift owned by a user or a chat.
Objects of this class are comparable in terms of equality. Two objects of this class are considered equal, if their
giftandsend_dateare equal.Available In
Added in version 22.1.
- Parameters:
gift (
telegram.Gift) – Information about the regular gift.owned_gift_id (
str, optional) – Unique identifier of the gift for the bot; for gifts received on behalf of business accounts only.sender_user (
telegram.User, optional) – Sender of the gift if it is a known user.send_date (
datetime.datetime) – Date the gift was sent asdatetime.datetime. The default timezone of the bot is used for localization, which is UTC unlesstelegram.ext.Defaults.tzinfois used..text (
str, optional) – Text of the message that was added to the gift.entities (Sequence[
telegram.MessageEntity], optional) – Special entities that appear in the text.is_private (
bool, optional) –True, if the sender and gift text are shown only to the gift receiver; otherwise, everyone will be able to see them.is_saved (
bool, optional) –True, if the gift is displayed on the account’s profile page; for gifts received on behalf of business accounts only.can_be_upgraded (
bool, optional) –True, if the gift can be upgraded to a unique gift; for gifts received on behalf of business accounts only.was_refunded (
bool, optional) –True, if the gift was refunded and isn’t available anymore.convert_star_count (
int, optional) – Number of Telegram Stars that can be claimed by the receiver instead of the gift; omitted if the gift cannot be converted to Telegram Stars; for gifts received on behalf of business accounts only.prepaid_upgrade_star_count (
int, optional) – Number of Telegram Stars that were paid for the ability to upgrade the gift.is_upgrade_separate (
bool, optional) –True, if the gift’s upgrade was purchased after the gift was sent; for gifts received on behalf of business accountsAdded in version 22.6.
unique_gift_number (
int, optional) –Unique number reserved for this gift when upgraded. See the number field in
UniqueGift… versionadded:: 22.6
- owned_gift_id[source]¶
Optional. Unique identifier of the gift for the bot; for gifts received on behalf of business accounts only.
- Type:
str
- send_date[source]¶
Date the gift was sent as
datetime.datetime. The default timezone of the bot is used for localization, which is UTC unlesstelegram.ext.Defaults.tzinfois used..- Type:
datetime.datetime
- entities[source]¶
Optional. Special entities that appear in the text.
- Type:
Sequence[
telegram.MessageEntity]
- is_private[source]¶
Optional.
True, if the sender and gift text are shown only to the gift receiver; otherwise, everyone will be able to see them.- Type:
bool
- is_saved[source]¶
Optional.
True, if the gift is displayed on the account’s profile page; for gifts received on behalf of business accounts only.- Type:
bool
- can_be_upgraded[source]¶
Optional.
True, if the gift can be upgraded to a unique gift; for gifts received on behalf of business accounts only.- Type:
bool
- was_refunded[source]¶
Optional.
True, if the gift was refunded and isn’t available anymore.- Type:
bool
- convert_star_count[source]¶
Optional. Number of Telegram Stars that can be claimed by the receiver instead of the gift; omitted if the gift cannot be converted to Telegram Stars; for gifts received on behalf of business accounts only.
- Type:
int
- prepaid_upgrade_star_count[source]¶
Optional. Number of Telegram Stars that were paid for the ability to upgrade the gift.
- Type:
int
- is_upgrade_separate[source]¶
Optional.
True, if the gift’s upgrade was purchased after the gift was sent; for gifts received on behalf of business accountsAdded in version 22.6.
- Type:
bool
- unique_gift_number[source]¶
Optional. Unique number reserved for this gift when upgraded. See the number field in
UniqueGift… versionadded:: 22.6
- Type:
int
- parse_entities(types=None)[source]¶
Returns a
dictthat mapstelegram.MessageEntitytostr. It contains entities from this owned gift’s text filtered by theirtypeattribute as the key, and the text that each entity belongs to as the value of thedict.Note
This method should always be used instead of the
entitiesattribute, since it calculates the correct substring from the message text based on UTF-16 codepoints. Seeparse_entityfor more info.- Parameters:
types (list[
str], optional) – List ofMessageEntitytypes as strings. If thetypeattribute of an entity is contained in this list, it will be returned. Defaults totelegram.MessageEntity.ALL_TYPES.- Returns:
A dictionary of entities mapped to the text that belongs to them, calculated based on UTF-16 codepoints.
- Return type:
dict[
telegram.MessageEntity,str]- Raises:
RuntimeError – If the owned gift has no text.
- parse_entity(entity)[source]¶
Returns the text in
textfrom a giventelegram.MessageEntityofentities.Note
This method is present because Telegram calculates the offset and length in UTF-16 codepoint pairs, which some versions of Python don’t handle automatically. (That is, you can’t just slice
OwnedGiftRegular.textwith the offset and length.)- Parameters:
entity (
telegram.MessageEntity) – The entity to extract the text from. It must be an entity that belongs toentities.- Returns:
The text of the given entity.
- Return type:
str- Raises:
RuntimeError – If the owned gift has no text.