telegram.Poll

class telegram.Poll(*args, **kwargs)[source]

Bases: telegram.TelegramObject

This object contains information about a poll.

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

See also

Pollbot Example

Parameters
id[source]

Unique poll identifier.

Type

str

question[source]

Poll question, 1-300 characters.

Type

str

options[source]

List of poll options.

Type

List[PollOption]

total_voter_count[source]

Total number of users that voted in the poll.

Type

int

is_closed[source]

True, if the poll is closed.

Type

bool

is_anonymous[source]

True, if the poll is anonymous.

Type

bool

type[source]

Poll type, currently can be REGULAR or QUIZ.

Type

str

allows_multiple_answers[source]

True, if the poll allows multiple answers.

Type

bool

correct_option_id[source]

Optional. Identifier of the correct answer option.

Type

int

explanation[source]

Optional. Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll.

Type

str

explanation_entities[source]

Special entities like usernames, URLs, bot commands, etc. that appear in the explanation. This list is empty if the message does not contain explanation entities.

Changed in version 20.0: This attribute is now always a (possibly empty) list and never None.

Type

List[telegram.MessageEntity]

open_period[source]

Optional. Amount of time in seconds the poll will be active after creation.

Type

int

close_date[source]

Optional. Point in time when the poll will be automatically closed.

Type

datetime.datetime

MAX_OPTION_LENGTH = 100[source]

telegram.constants.PollLimit.OPTION_LENGTH

MAX_OPTION_NUMBER = 10[source]

telegram.constants.PollLimit.OPTION_NUMBER

New in version 20.0.

MAX_QUESTION_LENGTH = 300[source]

telegram.constants.PollLimit.QUESTION_LENGTH

QUIZ = 'quiz'[source]

telegram.constants.PollType.QUIZ

REGULAR = 'regular'[source]

telegram.constants.PollType.REGULAR

classmethod de_json(data, bot)[source]

See telegram.TelegramObject.de_json().

parse_explanation_entities(types=None)[source]

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

parse_explanation_entity(entity)[source]

Returns the text from a given telegram.MessageEntity.

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 this message.

Returns

The text of the given entity.

Return type

str

Raises

RuntimeError – If the poll has no explanation.

to_dict()[source]

See telegram.TelegramObject.to_dict().