From d30cad1a2dccfca1fc2b8386732b35711a937a7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joscha=20G=C3=B6tzer?= Date: Tue, 30 Apr 2019 11:49:18 +0200 Subject: [PATCH] Use str or bytes for callback_data and CallbackQuery.data (#241) --- pyrogram/client/types/bots/callback_query.py | 2 +- pyrogram/client/types/bots/inline_keyboard_button.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pyrogram/client/types/bots/callback_query.py b/pyrogram/client/types/bots/callback_query.py index 4497747e..ac58338a 100644 --- a/pyrogram/client/types/bots/callback_query.py +++ b/pyrogram/client/types/bots/callback_query.py @@ -79,7 +79,7 @@ class CallbackQuery(PyrogramType, Update): self.chat_instance = chat_instance self.message = message self.inline_message_id = inline_message_id - self.data = data + self.data = str(data, "utf-8") self.game_short_name = game_short_name @staticmethod diff --git a/pyrogram/client/types/bots/inline_keyboard_button.py b/pyrogram/client/types/bots/inline_keyboard_button.py index c0c3eb8c..a26d6ca6 100644 --- a/pyrogram/client/types/bots/inline_keyboard_button.py +++ b/pyrogram/client/types/bots/inline_keyboard_button.py @@ -16,6 +16,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Union + from pyrogram.api.types import ( KeyboardButtonUrl, KeyboardButtonCallback, KeyboardButtonSwitchInline, KeyboardButtonGame @@ -61,7 +63,7 @@ class InlineKeyboardButton(PyrogramType): def __init__( self, text: str, - callback_data: bytes = None, + callback_data: Union[str, bytes] = None, url: str = None, switch_inline_query: str = None, switch_inline_query_current_chat: str = None, @@ -71,7 +73,7 @@ class InlineKeyboardButton(PyrogramType): self.text = str(text) self.url = url - self.callback_data = callback_data + self.callback_data = bytes(callback_data, "utf-8") if isinstance(callback_data, str) else callback_data self.switch_inline_query = switch_inline_query self.switch_inline_query_current_chat = switch_inline_query_current_chat self.callback_game = callback_game