1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Merge pull request #852 from olegshek/keyboard_button_poll_type

Keyboard button poll type
This commit is contained in:
Badiboy 2020-05-18 11:23:02 +03:00 committed by GitHub
commit dbff7cbb3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions

View File

@ -859,10 +859,11 @@ class ReplyKeyboardMarkup(JsonSerializable):
class KeyboardButton(Dictionaryable, JsonSerializable): class KeyboardButton(Dictionaryable, JsonSerializable):
def __init__(self, text, request_contact=None, request_location=None): def __init__(self, text, request_contact=None, request_location=None, request_poll=None):
self.text = text self.text = text
self.request_contact = request_contact self.request_contact = request_contact
self.request_location = request_location self.request_location = request_location
self.request_poll = request_poll
def to_json(self): def to_json(self):
return json.dumps(self.to_dict()) return json.dumps(self.to_dict())
@ -873,9 +874,19 @@ class KeyboardButton(Dictionaryable, JsonSerializable):
json_dict['request_contact'] = self.request_contact json_dict['request_contact'] = self.request_contact
if self.request_location: if self.request_location:
json_dict['request_location'] = self.request_location json_dict['request_location'] = self.request_location
if self.request_poll:
json_dict['request_poll'] = self.request_poll.to_dict()
return json_dict return json_dict
class KeyboardButtonPollType(Dictionaryable):
def __init__(self, type=''):
self.type = type
def to_dict(self):
return {'type': self.type}
class InlineKeyboardMarkup(Dictionaryable, JsonSerializable): class InlineKeyboardMarkup(Dictionaryable, JsonSerializable):
def __init__(self, row_width=3): def __init__(self, row_width=3):
""" """

View File

@ -188,3 +188,11 @@ def test_json_poll_answer():
assert poll_answer.poll_id == '5895675970559410186' assert poll_answer.poll_id == '5895675970559410186'
assert isinstance(poll_answer.user, types.User) assert isinstance(poll_answer.user, types.User)
assert poll_answer.options_ids == [1] assert poll_answer.options_ids == [1]
def test_KeyboardButtonPollType():
markup = types.ReplyKeyboardMarkup()
markup.add(types.KeyboardButton('send me a poll', request_poll=types.KeyboardButtonPollType(type='quiz')))
json_str = markup.to_json()
assert 'request_poll' in json_str
assert 'quiz' in json_str