From 93e19dc2aee38b57686f2ebf7bf0c166b141221d Mon Sep 17 00:00:00 2001 From: Leandro Toledo Date: Wed, 13 Apr 2016 21:10:04 -0300 Subject: [PATCH] Adding CallbackQuery #232 --- telegram/__init__.py | 2 ++ telegram/callbackquery.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/telegram/__init__.py b/telegram/__init__.py index 416b7e559..3bde1e1d8 100644 --- a/telegram/__init__.py +++ b/telegram/__init__.py @@ -43,6 +43,7 @@ from .nullhandler import NullHandler from .emoji import Emoji from .parsemode import ParseMode from .message import Message +from .callbackquery import CallbackQuery from .choseninlineresult import ChosenInlineResult from .inlinekeyboardbutton import InlineKeyboardButton from .inlinekeyboardmarkup import InlineKeyboardMarkup @@ -116,6 +117,7 @@ __all__ = ('Audio', 'Chat', 'ChatAction', 'ChosenInlineResult', + 'CallbackQuery', 'Contact', 'Document', 'Emoji', diff --git a/telegram/callbackquery.py b/telegram/callbackquery.py index 3d29ea07b..b6beaa178 100644 --- a/telegram/callbackquery.py +++ b/telegram/callbackquery.py @@ -16,3 +16,34 @@ # # 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 +CallbackQuery""" + +from telegram import TelegramObject, Message, User + + +class CallbackQuery(TelegramObject): + """This object represents a Telegram CallbackQuery.""" + + def __init__(self, + id, + from_user, + data): + # Required + self.id = id + self.from_user = from_user + self.data = data + # Optionals + self.message = kwargs.get('message') + self.inline_message_id = kwargs.get('inline_message_id', '') + + @staticmethod + def de_json(data): + if not data: + return None + + data['from_user'] = User.de_json(data.get('from')) + data['message'] = Message.de_json(data.get('message')) + + return CallbackQuery(**data)