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
andvoter_count
are equal.Available In
- Parameters:
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_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
]
- 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.
- parse_entities(types=None)[source]¶
Returns a
dict
that mapstelegram.MessageEntity
tostr
. It contains entities from this polls question filtered by theirtype
attribute 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
text_entities
attribute, since it calculates the correct substring from the message text based on UTF-16 codepoints. Seeparse_entity
for more info.Added in version 21.2.
- Parameters:
types (list[
str
], optional) – List ofMessageEntity
types as strings. If thetype
attribute 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
]
- parse_entity(entity)[source]¶
Returns the text in
text
from a giventelegram.MessageEntity
oftext_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 totext_entities
.- Returns:
The text of the given entity.
- Return type: