mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-03-29 01:37:28 +01:00
Adding InlineKeyboardMarkup #232
This commit is contained in:
parent
23eba8a24e
commit
1657e43904
2 changed files with 47 additions and 0 deletions
|
@ -45,3 +45,15 @@ class InlineKeyboardButton(TelegramObject):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return InlineKeyboardButton(**data)
|
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
|
||||||
|
|
|
@ -16,3 +16,38 @@
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU Lesser Public License
|
# You should have received a copy of the GNU Lesser Public License
|
||||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
# 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
|
||||||
|
|
Loading…
Add table
Reference in a new issue