PollOption

class telegram.PollOption(text, voter_count, text_entities=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 and voter_count are equal.

Parameters:
  • 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.

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]

Available In

telegram.Poll.options

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)[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