Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/unreleased/5196.7keq7yJhXbMb9RyShLHz4D.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ features = "Full Support for Bot API 9.6"

pull_requests = [
{ uid = "5196", author_uid = "harshil21" },
{ uid = "5202", author_uid = "ouyooung" },
{ uid = "5197", author_uid = "harshil21" },
]
11 changes: 10 additions & 1 deletion src/telegram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@
"Poll",
"PollAnswer",
"PollOption",
"PollOptionAdded",
"PollOptionDeleted",
"PreCheckoutQuery",
"PreparedInlineMessage",
"PreparedKeyboardButton",
Expand Down Expand Up @@ -573,7 +575,14 @@
RevenueWithdrawalStateSucceeded,
)
from ._payment.successfulpayment import SuccessfulPayment
from ._poll import InputPollOption, Poll, PollAnswer, PollOption
from ._poll import (
InputPollOption,
Poll,
PollAnswer,
PollOption,
PollOptionAdded,
PollOptionDeleted,
)
from ._preparedkeyboardbutton import PreparedKeyboardButton
from ._proximityalerttriggered import ProximityAlertTriggered
from ._reaction import (
Expand Down
98 changes: 87 additions & 11 deletions src/telegram/_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
from telegram._utils.types import (
BaseUrl,
CorrectOptionID,
CorrectOptionIds,
FileInput,
JSONDict,
ODVInput,
Expand All @@ -116,7 +117,7 @@
from telegram.request import BaseRequest, RequestData
from telegram.request._httpxrequest import HTTPXRequest
from telegram.request._requestparameter import RequestParameter
from telegram.warnings import PTBUserWarning
from telegram.warnings import PTBDeprecationWarning, PTBUserWarning

if TYPE_CHECKING:
from telegram import (
Expand Down Expand Up @@ -7599,6 +7600,8 @@ async def send_poll(
is_anonymous: bool | None = None,
type: str | None = None, # pylint: disable=redefined-builtin
allows_multiple_answers: bool | None = None,
# tags: deprecated in NEXT.VERSION, to be removed
# replaced by `correct_option_ids`
correct_option_id: CorrectOptionID | None = None,
is_closed: bool | None = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
Expand All @@ -7616,6 +7619,14 @@ async def send_poll(
question_entities: Sequence["MessageEntity"] | None = None,
message_effect_id: str | None = None,
allow_paid_broadcast: bool | None = None,
allows_revoting: bool | None = None,
allow_adding_options: bool | None = None,
hide_results_until_closes: bool | None = None,
correct_option_ids: CorrectOptionIds | None = None,
description: str | None = None,
description_parse_mode: str | None = None,
description_entities: Sequence["MessageEntity"] | None = None,
shuffle_options: bool | None = None,
*,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: int | None = None,
Expand Down Expand Up @@ -7651,9 +7662,13 @@ async def send_poll(
type (:obj:`str`, optional): Poll type, :tg-const:`telegram.Poll.QUIZ` or
:tg-const:`telegram.Poll.REGULAR`, defaults to :tg-const:`telegram.Poll.REGULAR`.
allows_multiple_answers (:obj:`bool`, optional): :obj:`True`, if the poll allows
multiple answers, ignored for polls in quiz mode, defaults to :obj:`False`.
multiple answers, defaults to :obj:`False`.
correct_option_id (:obj:`int`, optional): 0-based identifier of the correct answer
option, required for polls in quiz mode.

.. deprecated:: NEXT.VERSION
Bot API 9.6 replaces this with :paramref:`correct_option_ids` instead.

explanation (:obj:`str`, optional): Text that is shown when a user chooses an incorrect
answer or taps on the lamp icon in a quiz-style poll,
0-:tg-const:`telegram.Poll.MAX_EXPLANATION_LENGTH` characters with at most
Expand Down Expand Up @@ -7718,6 +7733,43 @@ async def send_poll(
allow_paid_broadcast (:obj:`bool`, optional): |allow_paid_broadcast|

.. versionadded:: 21.7
allows_revoting (:obj:`bool`, optional): :obj:`True`, if the poll allows to
change the chosen answer options, defaults to :obj:`False`
for quizzes and to :obj:`True` for regular polls

.. versionadded:: NEXT.VERSION
allow_adding_options (:obj:`bool`, optional): :obj:`True`, if answer options can be
added to the poll after creation; not supported for anonymous polls and quizzes

.. versionadded:: NEXT.VERSION
hide_results_until_closes (:obj:`bool`, optional): :obj:`True`, if poll results
must be shown only after the poll closes

.. versionadded:: NEXT.VERSION
correct_option_ids (Sequence[:class:`int`], optional): A list of monotonically
increasing 0-based identifiers of the correct answer options,
required for polls in quiz mode.

.. versionadded:: NEXT.VERSION
description (:obj:`str`, optional): Description of the poll to be sent,
0-:tg-const:`telegram.Poll.MAX_DESCRIPTION_CHARACTERS` characters
after entities parsing.

.. versionadded:: NEXT.VERSION
description_parse_mode (:obj:`str`, optional): Mode for parsing entities
in the poll description. See the constants
in :class:`telegram.constants.ParseMode`

.. versionadded:: NEXT.VERSION
description_entities (Sequence[:class:`telegram.MessageEntity`], optional): A
JSON-serialized list of special entities that appear in the poll description,
which can be specified instead of :paramref:`description_parse_mode`

.. versionadded:: NEXT.VERSION
shuffle_options (:obj:`bool`, optional): :obj:`True`, if the poll options must be
shown in random order

.. versionadded:: NEXT.VERSION

Keyword Args:
allow_sending_without_reply (:obj:`bool`, optional): |allow_sending_without_reply|
Expand Down Expand Up @@ -7746,6 +7798,19 @@ async def send_poll(
:class:`telegram.error.TelegramError`

"""

if correct_option_id is not None:
warn(
PTBDeprecationWarning(
version="NEXT.VERSION",
message="Bot API 9.6 deprecated `correct_option_id` in favour of "
"`correct_option_ids`, please use that.",
),
stacklevel=2,
)
if correct_option_ids is None:
correct_option_ids = [correct_option_id]

data: JSONDict = {
"chat_id": chat_id,
"question": question,
Expand All @@ -7757,8 +7822,15 @@ async def send_poll(
"is_anonymous": is_anonymous,
"type": type,
"allows_multiple_answers": allows_multiple_answers,
"correct_option_id": correct_option_id,
"allow_adding_options": allow_adding_options,
"allows_revoting": allows_revoting,
"shuffle_options": shuffle_options,
"hide_results_until_closes": hide_results_until_closes,
"correct_option_ids": correct_option_ids,
"is_closed": is_closed,
"description": description,
"description_parse_mode": description_parse_mode,
"description_entities": description_entities,
"explanation": explanation,
"explanation_entities": explanation_entities,
"open_period": open_period,
Expand Down Expand Up @@ -9876,14 +9948,16 @@ async def gift_premium_subscription(
`formatting options <https://core.telegram.org/bots/api#formatting-options>`__ for
more details. Entities other than :attr:`~MessageEntity.BOLD`,
:attr:`~MessageEntity.ITALIC`, :attr:`~MessageEntity.UNDERLINE`,
:attr:`~MessageEntity.STRIKETHROUGH`, :attr:`~MessageEntity.SPOILER`, and
:attr:`~MessageEntity.CUSTOM_EMOJI` are ignored.
:attr:`~MessageEntity.STRIKETHROUGH`, :attr:`~MessageEntity.SPOILER`
:attr:`~MessageEntity.CUSTOM_EMOJI`, and :attr:`~MessageEntity.DATE_TIME` are
ignored.
text_entities (Sequence[:class:`telegram.MessageEntity`], optional): A list of special
entities that appear in the gift text. It can be specified instead of
:paramref:`text_parse_mode`. Entities other than :attr:`~MessageEntity.BOLD`,
:attr:`~MessageEntity.ITALIC`, :attr:`~MessageEntity.UNDERLINE`,
:attr:`~MessageEntity.STRIKETHROUGH`, :attr:`~MessageEntity.SPOILER`, and
:attr:`~MessageEntity.CUSTOM_EMOJI` are ignored.
:attr:`~MessageEntity.STRIKETHROUGH`, :attr:`~MessageEntity.SPOILER`,
:attr:`~MessageEntity.CUSTOM_EMOJI`, and :attr:`~MessageEntity.DATE_TIME` are
ignored.

Returns:
:obj:`bool`: On success, :obj:`True` is returned.
Expand Down Expand Up @@ -11364,14 +11438,16 @@ async def send_gift(
`formatting options <https://core.telegram.org/bots/api#formatting-options>`__ for
more details. Entities other than :attr:`~MessageEntity.BOLD`,
:attr:`~MessageEntity.ITALIC`, :attr:`~MessageEntity.UNDERLINE`,
:attr:`~MessageEntity.STRIKETHROUGH`, :attr:`~MessageEntity.SPOILER`, and
:attr:`~MessageEntity.CUSTOM_EMOJI` are ignored.
:attr:`~MessageEntity.STRIKETHROUGH`, :attr:`~MessageEntity.SPOILER`,
:attr:`~MessageEntity.CUSTOM_EMOJI`, and :attr:`~MessageEntity.DATE_TIME` are
ignored.
text_entities (Sequence[:class:`telegram.MessageEntity`], optional): A list of special
entities that appear in the gift text. It can be specified instead of
:paramref:`text_parse_mode`. Entities other than :attr:`~MessageEntity.BOLD`,
:attr:`~MessageEntity.ITALIC`, :attr:`~MessageEntity.UNDERLINE`,
:attr:`~MessageEntity.STRIKETHROUGH`, :attr:`~MessageEntity.SPOILER`, and
:attr:`~MessageEntity.CUSTOM_EMOJI` are ignored.
:attr:`~MessageEntity.STRIKETHROUGH`, :attr:`~MessageEntity.SPOILER`,
:attr:`~MessageEntity.CUSTOM_EMOJI`, and :attr:`~MessageEntity.DATE_TIME` are
ignored.
pay_for_upgrade (:obj:`bool`, optional): Pass :obj:`True` to pay for the gift upgrade
from the bot's balance, thereby making the upgrade free for the receiver.

Expand Down
17 changes: 17 additions & 0 deletions src/telegram/_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import (
CorrectOptionID,
CorrectOptionIds,
FileInput,
JSONDict,
ODVInput,
Expand Down Expand Up @@ -2296,6 +2297,14 @@ async def send_poll(
question_entities: Sequence["MessageEntity"] | None = None,
message_effect_id: str | None = None,
allow_paid_broadcast: bool | None = None,
shuffle_options: bool | None = None,
allows_revoting: bool | None = None,
correct_option_ids: CorrectOptionIds | None = None,
allow_adding_options: bool | None = None,
hide_results_until_closes: bool | None = None,
description: str | None = None,
description_parse_mode: str | None = None,
description_entities: Sequence["MessageEntity"] | None = None,
*,
reply_to_message_id: int | None = None,
Comment thread
Poolitzer marked this conversation as resolved.
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
Expand Down Expand Up @@ -2323,6 +2332,9 @@ async def send_poll(
type=type, # pylint=pylint,
allows_multiple_answers=allows_multiple_answers,
correct_option_id=correct_option_id,
allows_revoting=allows_revoting,
shuffle_options=shuffle_options,
correct_option_ids=correct_option_ids,
is_closed=is_closed,
disable_notification=disable_notification,
reply_to_message_id=reply_to_message_id,
Expand All @@ -2346,6 +2358,11 @@ async def send_poll(
business_connection_id=business_connection_id,
question_parse_mode=question_parse_mode,
question_entities=question_entities,
description=description,
description_parse_mode=description_parse_mode,
description_entities=description_entities,
hide_results_until_closes=hide_results_until_closes,
allow_adding_options=allow_adding_options,
)

async def send_copy(
Expand Down
10 changes: 5 additions & 5 deletions src/telegram/_inputchecklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class InputChecklistTask(TelegramObject):
|parse_mode|
text_entities (Sequence[:class:`telegram.MessageEntity`], optional):
List of special entities that appear in the text, which can be specified instead of
parse_mode. Currently, only bold, italic, underline, strikethrough, spoiler, and
custom_emoji entities are allowed.
parse_mode. Currently, only bold, italic, underline, strikethrough, spoiler,
custom_emoji, and date_time entities are allowed.

Attributes:
id (:obj:`int`):
Expand All @@ -66,7 +66,7 @@ class InputChecklistTask(TelegramObject):
text_entities (Sequence[:class:`telegram.MessageEntity`]):
Optional. List of special entities that appear in the text, which can be specified
instead of parse_mode. Currently, only bold, italic, underline, strikethrough, spoiler,
and custom_emoji entities are allowed.
custom_emoji, and date_time entities are allowed.

"""

Expand Down Expand Up @@ -117,7 +117,7 @@ class InputChecklist(TelegramObject):
title_entities (Sequence[:class:`telegram.MessageEntity`], optional):
List of special entities that appear in the title, which
can be specified instead of :paramref:`parse_mode`. Currently, only bold, italic,
underline, strikethrough, spoiler, and custom_emoji entities are allowed.
underline, strikethrough, spoiler, and custom_emoji, and date_time entities are allowed
tasks (Sequence[:class:`telegram.InputChecklistTask`]):
List of
:tg-const:`telegram.constants.InputChecklistLimit.MIN_TASK_NUMBER`\
Expand All @@ -139,7 +139,7 @@ class InputChecklist(TelegramObject):
title_entities (Sequence[:class:`telegram.MessageEntity`]):
Optional. List of special entities that appear in the title, which
can be specified instead of :paramref:`parse_mode`. Currently, only bold, italic,
underline, strikethrough, spoiler, and custom_emoji entities are allowed.
underline, strikethrough, spoiler, and custom_emoji, and date_time entities are allowed
tasks (Sequence[:class:`telegram.InputChecklistTask`]):
List of
:tg-const:`telegram.constants.InputChecklistLimit.MIN_TASK_NUMBER`\
Expand Down
Loading
Loading