mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
feat: make InlineKeyboardMarkup JsonDeserializable
feat: make InlineKeyboardMarkup JsonDeserializable, add de_json func to InlineKeyboardMarkup object
This commit is contained in:
parent
630a9a5b2c
commit
decad450d0
@ -941,10 +941,18 @@ class KeyboardButtonPollType(Dictionaryable):
|
|||||||
return {'type': self.type}
|
return {'type': self.type}
|
||||||
|
|
||||||
|
|
||||||
class InlineKeyboardMarkup(Dictionaryable, JsonSerializable):
|
class InlineKeyboardMarkup(Dictionaryable, JsonSerializable, JsonDeserializable)):
|
||||||
max_row_keys = 8
|
max_row_keys = 8
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def de_json(cls, json_string):
|
||||||
|
if (json_string is None):
|
||||||
|
return None
|
||||||
|
obj = cls.check_json(json_string)
|
||||||
|
keyboard = [[button for button in row] for row in obj['inline_keyboard']]
|
||||||
|
return cls(keyboard)
|
||||||
|
|
||||||
def __init__(self, row_width=3):
|
def __init__(self, keyboard=[] ,row_width=3):
|
||||||
"""
|
"""
|
||||||
This object represents an inline keyboard that appears
|
This object represents an inline keyboard that appears
|
||||||
right next to the message it belongs to.
|
right next to the message it belongs to.
|
||||||
@ -957,7 +965,7 @@ class InlineKeyboardMarkup(Dictionaryable, JsonSerializable):
|
|||||||
row_width = self.max_row_keys
|
row_width = self.max_row_keys
|
||||||
|
|
||||||
self.row_width = row_width
|
self.row_width = row_width
|
||||||
self.keyboard = []
|
self.keyboard = keyboard
|
||||||
|
|
||||||
def add(self, *args, row_width=None):
|
def add(self, *args, row_width=None):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user