PollOptionAdded¶
- class telegram.PollOptionAdded(option_persistent_id, option_text, poll_message=None, option_text_entities=None, *, api_kwargs=None)[source]¶
Bases:
telegram.TelegramObjectDescribes a service message about an option added to a poll.
Objects of this class are comparable in terms of equality. Two objects of this class are considered equal, if their
option_persistent_id, andoption_textare equal.Available In
Added in version 22.8.
- Parameters:
option_persistent_id (
str) – Unique identifier of the added option.option_text (
str) – Option text.poll_message (
telegram.MaybeInaccessibleMessage, optional) – Message containing the poll to which the option was added, if known. Note that the Message object in this field will not contain thereply_to_messagefield even if it itself is a reply.option_text_entities (Sequence[
telegram.MessageEntity], optional) – Special entities that appear in theoption_text.
- poll_message[source]¶
Optional. Message containing the poll to which the option was added, if known. Note that the Message object in this field will not contain the
reply_to_messagefield even if it itself is a reply.
- option_text_entities[source]¶
Optional. Special entities that appear in the
option_text.- Type:
tuple[
telegram.MessageEntity]
- parse_option_text_entities(types=None)[source]¶
Returns a
dictthat mapstelegram.MessageEntitytostr. It contains entities from this polls option 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
option_text_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]
- parse_option_text_entity(entity)[source]¶
Returns the text in
option_textfrom a giventelegram.MessageEntityofoption_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.textwith the offset and length.)- Parameters:
entity (
telegram.MessageEntity) – The entity to extract the text from. It must be an entity that belongs tooption_text_entities.- Returns:
The text of the given entity.
- Return type: