Skip to content
Back to top
View this page

# GiftInfo

class telegram.GiftInfo(gift, owned_gift_id=None, convert_star_count=None, prepaid_upgrade_star_count=None, can_be_upgraded=None, text=None, entities=None, is_private=None, unique_gift_number=None, is_upgrade_separate=None, *, api_kwargs=None)

  Bases: `telegram.TelegramObject`

  Describes a service message about a regular gift that was sent or received.

  Objects of this class are comparable in terms of equality. Two objects of this class are considered equal if their `gift` is equal.

  Available In

  - `telegram.Message.gift_upgrade_sent`

  - `telegram.Message.gift`

  Added in version 22.1.

  Parameters:

    - gift (`Gift`) – Information about the gift.

    - owned_gift_id (`str`, optional) – Unique identifier of the received gift for the bot; only present for gifts received on behalf of business accounts.

    - convert_star_count (`int`, optional) – the receiver by converting the gift; omitted if conversion to Telegram Stars is impossible.

    - prepaid_upgrade_star_count (`int`, optional) – Number of Telegram Stars that were prepaid for the ability to upgrade the gift.

    - can_be_upgraded (`bool`, optional) – `True`, if the gift can be upgraded to a unique gift.

    - 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_upgrade_separate (`bool`, optional) –

      `True`, if the gift’s upgrade was purchased after the gift was sent.

      Added in version 22.6.

    - unique_gift_number (`int`, optional) –

      Unique number reserved for this gift when upgraded. See the number field in `UniqueGift`.

      Added in version 22.6.

  gift

    Information about the gift.

    Type:

      `Gift`

  owned_gift_id

    Optional. Unique identifier of the received gift for the bot; only present for gifts received on behalf of business accounts.

    Type:

      `str`

  convert_star_count

    Optional. Number of Telegram Stars that can be claimed by the receiver by converting the gift; omitted if conversion to Telegram Stars is impossible.

    Type:

      `int`

  prepaid_upgrade_star_count

    Optional. Number of Telegram Stars that were prepaid for the ability to upgrade the gift.

    Type:

      `int`

  can_be_upgraded

    Optional. `True`, if the gift can be upgraded to a unique gift.

    Type:

      `bool`

  text

    Optional. Text of the message that was added to the gift.

    Type:

      `str`

  entities

    Optional. Special entities that appear in the text.

    Type:

      Sequence[`telegram.MessageEntity`]

  is_private

    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_upgrade_separate

    Optional. `True`, if the gift’s upgrade was purchased after the gift was sent.

    Added in version 22.6.

    Type:

      `bool`

  unique_gift_number

    Optional. Unique number reserved for this gift when upgraded. See the number field in `UniqueGift`.

    Added in version 22.6.

    Type:

      `int`

  classmethod de_json(data, bot=None)

    See `telegram.TelegramObject.de_json()`.

  parse_entities(types=None)

    Returns a `dict` that maps `telegram.MessageEntity` to `str`. It contains entities from this gift info’s text filtered by their `type` attribute as the key, and the text that each entity belongs to as the value of the `dict`.

    Note

    This method should always be used instead of the `entities` attribute, since it calculates the correct substring from the message text based on UTF-16 codepoints. See `parse_entity` for more info.

    Parameters:

      types (list[`str`], optional) – List of `MessageEntity` types as strings. If the `type` attribute of an entity is contained in this list, it will be returned. Defaults to `telegram.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 gift info has no text.

  parse_entity(entity)

    Returns the text in `text` from a given `telegram.MessageEntity` of `entities`.

    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 `Message.text` with the offset and length.)

    Parameters:

      entity (`telegram.MessageEntity`) – The entity to extract the text from. It must be an entity that belongs to `entities`.

    Returns:

      The text of the given entity.

    Return type:

      `str`

    Raises:

      RuntimeError – If the gift info has no text.