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:
commit
dbff7cbb3e
@ -223,7 +223,7 @@ class Chat(JsonDeserializable):
|
||||
def __init__(self, id, type, title=None, username=None, first_name=None,
|
||||
last_name=None, all_members_are_administrators=None,
|
||||
photo=None, description=None, invite_link=None,
|
||||
pinned_message=None, permissions=None, slow_mode_delay=None,
|
||||
pinned_message=None, permissions=None, slow_mode_delay=None,
|
||||
sticker_set_name=None, can_set_sticker_set=None):
|
||||
self.id = id
|
||||
self.type = type
|
||||
@ -859,10 +859,11 @@ class ReplyKeyboardMarkup(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.request_contact = request_contact
|
||||
self.request_location = request_location
|
||||
self.request_poll = request_poll
|
||||
|
||||
def to_json(self):
|
||||
return json.dumps(self.to_dict())
|
||||
@ -873,9 +874,19 @@ class KeyboardButton(Dictionaryable, JsonSerializable):
|
||||
json_dict['request_contact'] = self.request_contact
|
||||
if 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
|
||||
|
||||
|
||||
class KeyboardButtonPollType(Dictionaryable):
|
||||
def __init__(self, type=''):
|
||||
self.type = type
|
||||
|
||||
def to_dict(self):
|
||||
return {'type': self.type}
|
||||
|
||||
|
||||
class InlineKeyboardMarkup(Dictionaryable, JsonSerializable):
|
||||
def __init__(self, row_width=3):
|
||||
"""
|
||||
|
@ -188,3 +188,11 @@ def test_json_poll_answer():
|
||||
assert poll_answer.poll_id == '5895675970559410186'
|
||||
assert isinstance(poll_answer.user, types.User)
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user