PollOption

class telegram.PollOption(text, voter_count, text_entities=None, added_by_user=None, added_by_chat=None, addition_date=None, media=None, persistent_id=None, *, api_kwargs=None)[source]

Bases: telegram.TelegramObject

This object contains information about one answer option in a poll.

Objects of this class are comparable in terms of equality. Two objects of this class are considered equal, if their text, voter_count and persistent_id are equal.

Available In

telegram.Poll.options

Changed in version 22.8: Added attribute persistent_id to equality checks.

Parameters:
  • persistent_id (str) –

    Unique identifier of the option, persistent on option addition and deletion.

    Added in version 22.8.

  • text (str) – Option text, 1-100 characters.

  • voter_count (int) – Number of users that voted for this option.

  • text_entities (Sequence[telegram.MessageEntity], optional) –

    Special entities that appear in the option text. Currently, only custom emoji entities are allowed in poll option texts.

    Added in version 21.2.

  • media (telegram.PollMedia, optional) –

    Media added to the poll option.

    Added in version 22.8.

  • added_by_user (telegram.User, optional) –

    User who added the option; omitted if the option wasn’t added by a user after poll creation.

    Added in version 22.8.

  • added_by_chat (telegram.Chat, optional) –

    Chat that added the option; omitted if the option wasn’t added by a chat after poll creation.

    Added in version 22.8.

  • addition_date (datetime.datetime, optional) –

    Point in time when the option was added; omitted if the option existed in the original poll.

    Added in version 22.8.

persistent_id[source]

Unique identifier of the option, persistent on option addition and deletion.

Added in version 22.8.

Type:

str

text[source]

Option text, 1-100 characters.

Type:

str

voter_count[source]

Number of users that voted for this option.

Type:

int

text_entities[source]

Special entities that appear in the option text. Currently, only custom emoji entities are allowed in poll option texts. This list is empty if the question does not contain entities.

Added in version 21.2.

Type:

tuple[telegram.MessageEntity]

media[source]

Optional. Media added to the poll option.

Added in version 22.8.

Type:

telegram.PollMedia

added_by_user[source]

Optional. User who added the option; omitted if the option wasn’t added by a user after poll creation.

Added in version 22.8.

Type:

telegram.User

added_by_chat[source]

Optional. Chat that added the option; omitted if the option wasn’t added by a chat after poll creation.

Added in version 22.8.

Type:

telegram.Chat

addition_date[source]

Optional. Point in time when the option was added; omitted if the option existed in the original poll.

Added in version 22.8.

Type:

datetime.datetime

MAX_LENGTH = 100[source]

telegram.constants.PollLimit.MAX_OPTION_LENGTH

Added in version 20.0.

MIN_LENGTH = 1[source]

telegram.constants.PollLimit.MIN_OPTION_LENGTH

Added in version 20.0.

classmethod de_json(data, bot=None)[source]

See telegram.TelegramObject.de_json().

parse_entities(types=None)[source]

Returns a dict that maps telegram.MessageEntity to str. It contains entities from this polls question 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 text_entities attribute, since it calculates the correct substring from the message text based on UTF-16 codepoints. See parse_entity for more info.

Added in version 21.2.

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]

parse_entity(entity)[source]

Returns the text in text from a given telegram.MessageEntity of text_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.)

Added in version 21.2.

Parameters:

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

Returns:

The text of the given entity.

Return type:

str