send_poll()

Client.send_poll()

A message with a poll.

Note

Polls can’t be sent to secret chats and channel direct messages chats. Polls can be sent to a private chat only if the chat is a chat with a bot or the Saved Messages chat.

Usable by Users Bots

Parameters:
  • chat_id (int | str) – Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use “me” or “self”. For a contact that exists in your Telegram address book you can use his phone number (str).

  • question (str | FormattedText) – Poll question, 1-255 characters (up to 300 characters for bots). Only custom emoji entities are allowed to be added and only by Premium users.

  • options (List of InputPollOption) – List of 1-12 answer options.

  • media (InputMediaPhoto | InputMediaVideo | InputMediaSticker | Location, optional) – Media attached to the poll. Currently supports only photo, video, sticker or location.

  • message_thread_id (int, optional) – Unique identifier for the target message thread (topic) of the forum. For supergroups only.

  • business_connection_id (str, optional) – Unique identifier of the business connection on behalf of which the message will be sent.

  • is_anonymous (bool, optional) – True, if the poll needs to be anonymous. Defaults to True.

  • type ( – obj`~pyrogram.enums.PollType`, optional): Poll type, QUIZ or REGULAR. Defaults to REGULAR.

  • allows_multiple_answers (bool, optional) – Pass True, if the poll allows multiple answers. Defaults to False.

  • allows_revoting (bool, optional) – Pass True, if the poll allows to change chosen answer options. Defaults to False for quizzes and to True for regular polls.

  • members_only (bool, optional) – True, if only the users that are members of the chat for more than a day will be able to vote. For channel chats only.

  • country_codes (List of str, optional) – The list of two-letter ISO 3166-1 alpha-2 codes of countries, users from which will be able to vote. For channel chats only. If None, then all users can participate in the poll.

  • shuffle_options (bool, optional) – Pass True, if the poll options must be shown in random order.

  • allow_adding_options (bool, optional) – Pass True, if answer options can be added to the poll after creation, not supported for anonymous polls and quizzes.

  • hide_results_until_closes (bool, optional) – Pass True, if poll results must be shown only after the poll closes.

  • correct_option_ids (List of int, optional) – List of monotonically increasing 0-based identifiers of the correct answer options, required for polls in quiz mode.

  • correct_option_id (int, optional) – 0-based identifier of the correct answer option for single-answer quizzes. Alternative to correct_option_ids.

  • explanation (str | FormattedText, optional) – Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters with at most 2 line feeds after entities parsing.

  • open_period (int, optional) – Amount of time in seconds the poll will be active after creation, 5-2628000. Can’t be used together with close_date.

  • close_date (datetime, optional) – Point in time when the poll will be automatically closed. Must be at least 5 and no more than 2628000 seconds in the future. Can’t be used together with open_period.

  • is_closed (bool, optional) – Pass True, if the poll needs to be immediately closed. This can be useful for poll preview. For bots only.

  • description (str | FormattedText, optional) – Description of the poll to be sent, 0-1024 characters after entities parsing.

  • disable_notification (bool, optional) – Sends the message silently. Users will receive a notification with no sound.

  • protect_content (bool, optional) – Protects the contents of the sent message from forwarding and saving.

  • allow_paid_broadcast (bool, optional) – If True, you will be allowed to send up to 1000 messages per second. Ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot’s balance. For bots only.

  • effect_id (int, optional) – Unique identifier of the message effect. For private chats only.

  • reply_parameters (ReplyParameters, optional) – Describes reply parameters for the message that is being sent.

  • schedule_date (datetime, optional) – Date when the message will be automatically sent.

  • repeat_period (int, optional) – Period after which the message will be sent again in seconds.

  • paid_message_star_count (int, optional) – The number of Telegram Stars the user agreed to pay to send the messages.

  • reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply, optional) – Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

Returns:

Message – On success, the sent poll message is returned.

Example

await app.send_poll(
    chat_id=chat_id,
    question="Is this a poll question?",
    options=[
        types.InputPollOption(text="Yes"),
        types.InputPollOption(text="No"),
        types.InputPollOption(text="Maybe")
    ]
)

await app.send_poll(
    chat_id=chat_id,
    question="2 + 2 = ?",
    options=["3", "4", "5"],
    type="quiz",
    correct_option_id=1
)

await app.send_poll(
    chat_id=chat_id,
    question="Where we are?",
    media=types.InputMediaPhoto("photo.jpg"),
    options=[
        types.InputPollOption(
            text="Maybe here?",
            media=types.InputMediaPhoto("photo1.jpg")
        ),
        types.InputPollOption(
            text="Or here?",
            media=types.Location(
                longitude=49.807760,
                latitude=73.088504
            ),
        ),
    ]
)