mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
send_poll fix with PollOptions
Now send_poll correctly operates with PollOptions passed as array of PollOption.
This commit is contained in:
@@ -1277,7 +1277,7 @@ def send_poll(
|
||||
payload = {
|
||||
'chat_id': str(chat_id),
|
||||
'question': question,
|
||||
'options': json.dumps(options)}
|
||||
'options': json.dumps(_convert_poll_options(options))}
|
||||
|
||||
if is_anonymous is not None:
|
||||
payload['is_anonymous'] = is_anonymous
|
||||
@@ -1347,6 +1347,20 @@ def _convert_entites(entites):
|
||||
return entites
|
||||
|
||||
|
||||
def _convert_poll_options(poll_options):
|
||||
if poll_options is None:
|
||||
return None
|
||||
elif len(poll_options) == 0:
|
||||
return []
|
||||
elif isinstance(poll_options[0], str):
|
||||
# Compatibility mode with previous bug when only list of string was accepted as poll_options
|
||||
return poll_options
|
||||
elif isinstance(poll_options[0], types.JsonSerializable):
|
||||
return [option.text for option in poll_options]
|
||||
else:
|
||||
return poll_options
|
||||
|
||||
|
||||
def convert_input_media(media):
|
||||
if isinstance(media, types.InputMedia):
|
||||
return media.convert_input_media()
|
||||
|
||||
Reference in New Issue
Block a user