Adding InlineKeyboardMarkup #232

This commit is contained in:
Leandro Toledo 2016-04-13 20:38:45 -03:00
parent 23eba8a24e
commit 1657e43904
2 changed files with 47 additions and 0 deletions

View file

@ -45,3 +45,15 @@ class InlineKeyboardButton(TelegramObject):
return None
return InlineKeyboardButton(**data)
@staticmethod
def de_list(data):
if not data:
return []
inline_keyboard = list()
for inline_keyboard in data:
inline_keyboard.append(InlineKeyboardButton.
de_json(inline_keyboard))
return inline_keyboard

View file

@ -16,3 +16,38 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains a object that represents a Telegram
InlineKeyboardMarkup"""
from telegram import ReplyMarkup, InlineKeyboardButton
class InlineKeyboardMarkup(ReplyMarkup):
"""This object represents a Telegram InlineKeyboardMarkup."""
def __init__(self,
inline_keyboard):
# Required
self.inline_keyboard = inline_keyboard
@staticmethod
def de_json(data):
if not data:
return None
data['inline_keyboard'] = \
[InlineKeyboardButton.de_list(inline_keyboard) for inline_keyboard
in data['inline_keyboard']]
return InlineKeyboardMarkup(**data)
def to_dict(self):
data = super(InlineKeyboardMarkup, self).to_dict()
data['inline_keyboard'] = []
for inline_keyboard in self.inline_keyboard:
data['inline_keyboard'].append(
[x.to_dict() for x in inline_keyboard])
return data