Skip to content

Commit bbbee7b

Browse files
sendPoll updated fully
1 parent 4936dd6 commit bbbee7b

File tree

4 files changed

+144
-20
lines changed

4 files changed

+144
-20
lines changed

telebot/__init__.py

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6089,7 +6089,6 @@ def create_invoice_link(self,
60896089
send_email_to_provider=send_email_to_provider, is_flexible=is_flexible ,subscription_period=subscription_period,
60906090
business_connection_id=business_connection_id)
60916091

6092-
60936092
# noinspection PyShadowingBuiltins
60946093
def send_poll(
60956094
self, chat_id: Union[int, str], question: str, options: List[Union[str, types.InputPollOption]],
@@ -6114,7 +6113,15 @@ def send_poll(
61146113
question_parse_mode: Optional[str] = None,
61156114
question_entities: Optional[List[types.MessageEntity]] = None,
61166115
message_effect_id: Optional[str]=None,
6117-
allow_paid_broadcast: Optional[bool]=None) -> types.Message:
6116+
allow_paid_broadcast: Optional[bool]=None,
6117+
allows_revoting: Optional[bool]=None,
6118+
shuffle_options: Optional[bool]=None,
6119+
allow_adding_options: Optional[bool]=None,
6120+
hide_results_until_closes: Optional[bool]=None,
6121+
correct_option_ids: Optional[List[int]]=None,
6122+
description: Optional[str]=None,
6123+
description_parse_mode: Optional[str]=None,
6124+
description_entities: Optional[List[types.MessageEntity]]=None) -> types.Message:
61186125
"""
61196126
Use this method to send a native poll.
61206127
On success, the sent Message is returned.
@@ -6136,10 +6143,10 @@ def send_poll(
61366143
:param type: Poll type, “quiz” or “regular”, defaults to “regular”
61376144
:type type: :obj:`str`
61386145
6139-
:param allows_multiple_answers: True, if the poll allows multiple answers, ignored for polls in quiz mode, defaults to False
6146+
:param allows_multiple_answers: True, if the poll allows multiple answers, defaults to False
61406147
:type allows_multiple_answers: :obj:`bool`
61416148
6142-
:param correct_option_id: 0-based identifier of the correct answer option. Available only for polls in quiz mode, defaults to None
6149+
:param correct_option_id: Deprecated, use correct_option_ids instead.
61436150
:type correct_option_id: :obj:`int`
61446151
61456152
:param explanation: 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
@@ -6200,6 +6207,30 @@ def send_poll(
62006207
of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance
62016208
:type allow_paid_broadcast: :obj:`bool`
62026209
6210+
:param allows_revoting: Pass True, if the poll allows to change chosen answer options, defaults to False for quizzes and to True for regular polls
6211+
:type allows_revoting: :obj:`bool`
6212+
6213+
:param shuffle_options: Pass True, if the poll options must be shown in random order
6214+
:type shuffle_options: :obj:`bool`
6215+
6216+
:param allow_adding_options: Pass True, if answer options can be added to the poll after creation; not supported for anonymous polls and quizzes
6217+
:type allow_adding_options: :obj:`bool`
6218+
6219+
:param hide_results_until_closes: Pass True, if poll results must be shown only after the poll closes
6220+
:type hide_results_until_closes: :obj:`bool`
6221+
6222+
:param correct_option_ids: A JSON-serialized list of monotonically increasing 0-based identifiers of the correct answer options, required for polls in quiz mode
6223+
:type correct_option_ids: :obj:`list` of :obj:`int`
6224+
6225+
:param description: Description of the poll to be sent, 0-1024 characters after entities parsing
6226+
:type description: :obj:`str`
6227+
6228+
:param description_parse_mode: Mode for parsing entities in the poll description. See formatting options for more details.
6229+
:type description_parse_mode: :obj:`str`
6230+
6231+
:param description_entities: A JSON-serialized list of special entities that appear in the poll description, which can be specified instead of description_parse_mode
6232+
:type description_entities: :obj:`list` of :obj:`MessageEntity`
6233+
62036234
:return: On success, the sent Message is returned.
62046235
:rtype: :obj:`types.Message`
62056236
"""
@@ -6232,6 +6263,7 @@ def send_poll(
62326263

62336264
explanation_parse_mode = self.parse_mode if (explanation_parse_mode is None) else explanation_parse_mode
62346265
question_parse_mode = self.parse_mode if (question_parse_mode is None) else question_parse_mode
6266+
description_parse_mode = self.parse_mode if (description_parse_mode is None) else description_parse_mode
62356267

62366268
if options and (not isinstance(options[0], types.InputPollOption)):
62376269
# show a deprecation warning
@@ -6243,19 +6275,33 @@ def send_poll(
62436275
options = [types.InputPollOption(option.text, text_entities=option.text_entities) for option in options]
62446276
else:
62456277
raise RuntimeError("Type of 'options' items is unknown. Options should be List[types.InputPollOption], other types are deprecated.")
6278+
6279+
# handle deprecated correct_option_id parameter
6280+
if correct_option_id is not None and type=="quiz":
6281+
if correct_option_ids is not None:
6282+
# show a conflict warning
6283+
logger.warning("Both 'correct_option_id' and 'correct_option_ids' parameters are set: use 'correct_option_ids' instead.")
6284+
else:
6285+
# convert correct_option_id to correct_option_ids
6286+
correct_option_ids = [correct_option_id]
6287+
logger.warning("The parameter 'correct_option_id' is deprecated, use 'correct_option_ids' instead.")
6288+
62466289

62476290
return types.Message.de_json(
62486291
apihelper.send_poll(
62496292
self.token, chat_id, question, options,
62506293
is_anonymous=is_anonymous, type=type, allows_multiple_answers=allows_multiple_answers,
6251-
correct_option_id=correct_option_id, explanation=explanation,
6294+
explanation=explanation,
62526295
explanation_parse_mode=explanation_parse_mode, open_period=open_period,
62536296
close_date=close_date, is_closed=is_closed, disable_notification=disable_notification,
62546297
reply_markup=reply_markup, timeout=timeout, explanation_entities=explanation_entities,
62556298
protect_content=protect_content, message_thread_id=message_thread_id,
62566299
reply_parameters=reply_parameters, business_connection_id=business_connection_id,
62576300
question_parse_mode=question_parse_mode, question_entities=question_entities,
6258-
message_effect_id=message_effect_id, allow_paid_broadcast=allow_paid_broadcast)
6301+
message_effect_id=message_effect_id, allow_paid_broadcast=allow_paid_broadcast,
6302+
allows_revoting=allows_revoting, shuffle_options=shuffle_options,
6303+
allow_adding_options=allow_adding_options, hide_results_until_closes=hide_results_until_closes, correct_option_ids=correct_option_ids,
6304+
description=description, description_parse_mode=description_parse_mode, description_entities=description_entities)
62596305
)
62606306

62616307

telebot/apihelper.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2550,11 +2550,12 @@ def create_invoice_link(token, title, description, payload, provider_token,
25502550
# noinspection PyShadowingBuiltins
25512551
def send_poll(
25522552
token, chat_id, question, options,
2553-
is_anonymous = None, type = None, allows_multiple_answers = None, correct_option_id = None, explanation = None,
2553+
is_anonymous = None, type = None, allows_multiple_answers = None, explanation = None,
25542554
explanation_parse_mode=None, open_period = None, close_date = None, is_closed = None, disable_notification=False,
25552555
reply_markup=None, timeout=None, explanation_entities=None, protect_content=None, message_thread_id=None,
25562556
reply_parameters=None, business_connection_id=None, question_parse_mode=None, question_entities=None, message_effect_id=None,
2557-
allow_paid_broadcast=None):
2557+
allow_paid_broadcast=None, allows_revoting=None, shuffle_options=None, allow_adding_options=None, hide_results_until_closes=None,
2558+
correct_option_ids=None, description=None, description_parse_mode=None, description_entities=None):
25582559
method_url = r'sendPoll'
25592560
payload = {
25602561
'chat_id': str(chat_id),
@@ -2568,8 +2569,6 @@ def send_poll(
25682569
payload['type'] = type
25692570
if allows_multiple_answers is not None:
25702571
payload['allows_multiple_answers'] = allows_multiple_answers
2571-
if correct_option_id is not None:
2572-
payload['correct_option_id'] = correct_option_id
25732572
if explanation:
25742573
payload['explanation'] = explanation
25752574
if explanation_parse_mode:
@@ -2607,6 +2606,22 @@ def send_poll(
26072606
payload['message_effect_id'] = message_effect_id
26082607
if allow_paid_broadcast is not None:
26092608
payload['allow_paid_broadcast'] = allow_paid_broadcast
2609+
if allows_revoting is not None:
2610+
payload['allows_revoting'] = allows_revoting
2611+
if shuffle_options is not None:
2612+
payload['shuffle_options'] = shuffle_options
2613+
if allow_adding_options is not None:
2614+
payload['allow_adding_options'] = allow_adding_options
2615+
if hide_results_until_closes is not None:
2616+
payload['hide_results_until_closes'] = hide_results_until_closes
2617+
if correct_option_ids is not None:
2618+
payload['correct_option_ids'] = json.dumps(correct_option_ids)
2619+
if description is not None:
2620+
payload['description'] = description
2621+
if description_parse_mode is not None:
2622+
payload['description_parse_mode'] = description_parse_mode
2623+
if description_entities is not None:
2624+
payload['description_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(description_entities))
26102625
return _make_request(token, method_url, params=payload)
26112626

26122627
def create_forum_topic(token, chat_id, name, icon_color=None, icon_custom_emoji_id=None):

telebot/async_telebot.py

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7606,6 +7606,7 @@ async def create_invoice_link(self,
76067606
send_email_to_provider, is_flexible, subscription_period=subscription_period, business_connection_id=business_connection_id)
76077607
return result
76087608

7609+
76097610
# noinspection PyShadowingBuiltins
76107611
async def send_poll(
76117612
self, chat_id: Union[int, str], question: str, options: List[Union[str, types.InputPollOption]],
@@ -7630,7 +7631,15 @@ async def send_poll(
76307631
question_parse_mode: Optional[str] = None,
76317632
question_entities: Optional[List[types.MessageEntity]] = None,
76327633
message_effect_id: Optional[str]=None,
7633-
allow_paid_broadcast: Optional[bool]=None) -> types.Message:
7634+
allow_paid_broadcast: Optional[bool]=None,
7635+
allows_revoting: Optional[bool]=None,
7636+
shuffle_options: Optional[bool]=None,
7637+
allow_adding_options: Optional[bool]=None,
7638+
hide_results_until_closes: Optional[bool]=None,
7639+
correct_option_ids: Optional[List[int]]=None,
7640+
description: Optional[str]=None,
7641+
description_parse_mode: Optional[str]=None,
7642+
description_entities: Optional[List[types.MessageEntity]]=None) -> types.Message:
76347643
"""
76357644
Use this method to send a native poll.
76367645
On success, the sent Message is returned.
@@ -7652,10 +7661,10 @@ async def send_poll(
76527661
:param type: Poll type, “quiz” or “regular”, defaults to “regular”
76537662
:type type: :obj:`str`
76547663
7655-
:param allows_multiple_answers: True, if the poll allows multiple answers, ignored for polls in quiz mode, defaults to False
7664+
:param allows_multiple_answers: True, if the poll allows multiple answers, defaults to False
76567665
:type allows_multiple_answers: :obj:`bool`
76577666
7658-
:param correct_option_id: 0-based identifier of the correct answer option. Available only for polls in quiz mode,
7667+
:param correct_option_id: Deprecated, use correct_option_ids instead.
76597668
defaults to None
76607669
:type correct_option_id: :obj:`int`
76617670
@@ -7720,6 +7729,30 @@ async def send_poll(
77207729
of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance
77217730
:type allow_paid_broadcast: :obj:`bool`
77227731
7732+
:param allows_revoting: Pass True, if the poll allows to change chosen answer options, defaults to False for quizzes and to True for regular polls
7733+
:type allows_revoting: :obj:`bool`
7734+
7735+
:param shuffle_options: Pass True, if the poll options must be shown in random order
7736+
:type shuffle_options: :obj:`bool`
7737+
7738+
:param allow_adding_options: Pass True, if answer options can be added to the poll after creation; not supported for anonymous polls and quizzes
7739+
:type allow_adding_options: :obj:`bool`
7740+
7741+
:param hide_results_until_closes: Pass True, if poll results must be shown only after the poll closes
7742+
:type hide_results_until_closes: :obj:`bool`
7743+
7744+
:param correct_option_ids: A JSON-serialized list of monotonically increasing 0-based identifiers of the correct answer options, required for polls in quiz mode
7745+
:type correct_option_ids: :obj:`list` of :obj:`int`
7746+
7747+
:param description: Description of the poll to be sent, 0-1024 characters after entities parsing
7748+
:type description: :obj:`str`
7749+
7750+
:param description_parse_mode: Mode for parsing entities in the poll description. See formatting options for more details.
7751+
:type description_parse_mode: :obj:`str`
7752+
7753+
:param description_entities: A JSON-serialized list of special entities that appear in the poll description, which can be specified instead of description_parse_mode
7754+
:type description_entities: :obj:`list` of :obj:`MessageEntity`
7755+
77237756
:return: On success, the sent Message is returned.
77247757
:rtype: :obj:`types.Message`
77257758
"""
@@ -7728,6 +7761,7 @@ async def send_poll(
77287761

77297762
explanation_parse_mode = self.parse_mode if (explanation_parse_mode is None) else explanation_parse_mode
77307763
question_parse_mode = self.parse_mode if (question_parse_mode is None) else question_parse_mode
7764+
description_parse_mode = self.parse_mode if (description_parse_mode is None) else description_parse_mode
77317765

77327766
if allow_sending_without_reply is not None:
77337767
logger.warning("The parameter 'allow_sending_without_reply' is deprecated. Use 'reply_parameters' instead.")
@@ -7762,17 +7796,32 @@ async def send_poll(
77627796
options = [types.InputPollOption(option.text, text_entities=option.text_entities) for option in options]
77637797
else:
77647798
raise RuntimeError("Type of 'options' items is unknown. Options should be List[types.InputPollOption], other types are deprecated.")
7799+
7800+
# handle deprecated correct_option_id parameter
7801+
if correct_option_id is not None and type=="quiz":
7802+
if correct_option_ids is not None:
7803+
# show a conflict warning
7804+
logger.warning("Both 'correct_option_id' and 'correct_option_ids' parameters are set: use 'correct_option_ids' instead.")
7805+
else:
7806+
# convert correct_option_id to correct_option_ids
7807+
correct_option_ids = [correct_option_id]
7808+
logger.warning("The parameter 'correct_option_id' is deprecated, use 'correct_option_ids' instead.")
77657809

77667810
return types.Message.de_json(
77677811
await asyncio_helper.send_poll(
77687812
self.token, chat_id,
77697813
question, options,
7770-
is_anonymous, type, allows_multiple_answers, correct_option_id,
7814+
is_anonymous, type, allows_multiple_answers,
77717815
explanation, explanation_parse_mode, open_period, close_date, is_closed,
77727816
disable_notification,
77737817
reply_markup, timeout, explanation_entities, protect_content, message_thread_id, reply_parameters,
77747818
business_connection_id, question_parse_mode=question_parse_mode, question_entities=question_entities,
7775-
message_effect_id=message_effect_id, allow_paid_broadcast=allow_paid_broadcast))
7819+
message_effect_id=message_effect_id, allow_paid_broadcast=allow_paid_broadcast,
7820+
allows_revoting=allows_revoting, shuffle_options=shuffle_options, allow_adding_options=allow_adding_options,
7821+
hide_results_until_closes=hide_results_until_closes, correct_option_ids=correct_option_ids, description=description,
7822+
description_parse_mode=description_parse_mode, description_entities=description_entities
7823+
)
7824+
)
77767825

77777826
async def stop_poll(
77787827
self, chat_id: Union[int, str], message_id: int,

telebot/asyncio_helper.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,16 +2523,16 @@ async def create_invoice_link(token, title, description, payload, provider_token
25232523
return await _process_request(token, method_url, params=payload, method='post')
25242524

25252525

2526-
25272526
# noinspection PyShadowingBuiltins
25282527
async def send_poll(
25292528
token, chat_id, question, options,
2530-
is_anonymous = None, type = None, allows_multiple_answers = None, correct_option_id = None,
2529+
is_anonymous = None, type = None, allows_multiple_answers = None,
25312530
explanation = None, explanation_parse_mode=None, open_period = None, close_date = None, is_closed = None,
25322531
disable_notification=False,
25332532
reply_markup=None, timeout=None, explanation_entities=None, protect_content=None, message_thread_id=None,
25342533
reply_parameters=None,business_connection_id=None, question_parse_mode=None, question_entities=None, message_effect_id=None,
2535-
allow_paid_broadcast=None):
2534+
allow_paid_broadcast=None, allows_revoting=None, shuffle_options=None, allow_adding_options=None, hide_results_until_closes=None,
2535+
correct_option_ids=None, description=None, description_parse_mode=None, description_entities=None):
25362536
method_url = r'sendPoll'
25372537
payload = {
25382538
'chat_id': str(chat_id),
@@ -2546,8 +2546,6 @@ async def send_poll(
25462546
payload['type'] = type
25472547
if allows_multiple_answers is not None:
25482548
payload['allows_multiple_answers'] = allows_multiple_answers
2549-
if correct_option_id is not None:
2550-
payload['correct_option_id'] = correct_option_id
25512549
if explanation is not None:
25522550
payload['explanation'] = explanation
25532551
if explanation_parse_mode is not None:
@@ -2586,6 +2584,22 @@ async def send_poll(
25862584
payload['message_effect_id'] = message_effect_id
25872585
if allow_paid_broadcast is not None:
25882586
payload['allow_paid_broadcast'] = allow_paid_broadcast
2587+
if allows_revoting is not None:
2588+
payload['allows_revoting'] = allows_revoting
2589+
if shuffle_options is not None:
2590+
payload['shuffle_options'] = shuffle_options
2591+
if allow_adding_options is not None:
2592+
payload['allow_adding_options'] = allow_adding_options
2593+
if hide_results_until_closes is not None:
2594+
payload['hide_results_until_closes'] = hide_results_until_closes
2595+
if correct_option_ids is not None:
2596+
payload['correct_option_ids'] = correct_option_ids
2597+
if description is not None:
2598+
payload['description'] = description
2599+
if description_parse_mode is not None:
2600+
payload['description_parse_mode'] = description_parse_mode
2601+
if description_entities is not None:
2602+
payload['description_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(description_entities))
25892603
return await _process_request(token, method_url, params=payload)
25902604

25912605

0 commit comments

Comments
 (0)