Add support for user profile buttons

This commit is contained in:
Dan 2021-12-22 14:36:02 +01:00
parent d103ae48fe
commit a909dc12e7

View File

@ -43,6 +43,9 @@ class InlineKeyboardButton(Object):
An HTTP URL used to automatically authorize the user. Can be used as a replacement for An HTTP URL used to automatically authorize the user. Can be used as a replacement for
the `Telegram Login Widget <https://core.telegram.org/widgets/login>`_. the `Telegram Login Widget <https://core.telegram.org/widgets/login>`_.
user_id (``id``, *optional*):
User id, for links to the user profile.
switch_inline_query (``str``, *optional*): switch_inline_query (``str``, *optional*):
If set, pressing the button will prompt the user to select one of their chats, open that chat and insert If set, pressing the button will prompt the user to select one of their chats, open that chat and insert
the bot's username and the specified inline query in the input field. Can be empty, in which case just the bot's username and the specified inline query in the input field. Can be empty, in which case just
@ -68,6 +71,7 @@ class InlineKeyboardButton(Object):
callback_data: Union[str, bytes] = None, callback_data: Union[str, bytes] = None,
url: str = None, url: str = None,
login_url: "types.LoginUrl" = None, login_url: "types.LoginUrl" = None,
user_id: int = None,
switch_inline_query: str = None, switch_inline_query: str = None,
switch_inline_query_current_chat: str = None, switch_inline_query_current_chat: str = None,
callback_game: "types.CallbackGame" = None callback_game: "types.CallbackGame" = None
@ -75,9 +79,10 @@ class InlineKeyboardButton(Object):
super().__init__() super().__init__()
self.text = str(text) self.text = str(text)
self.callback_data = callback_data
self.url = url self.url = url
self.login_url = login_url self.login_url = login_url
self.callback_data = callback_data self.user_id = user_id
self.switch_inline_query = switch_inline_query self.switch_inline_query = switch_inline_query
self.switch_inline_query_current_chat = switch_inline_query_current_chat self.switch_inline_query_current_chat = switch_inline_query_current_chat
self.callback_game = callback_game self.callback_game = callback_game
@ -110,6 +115,12 @@ class InlineKeyboardButton(Object):
login_url=types.LoginUrl.read(b) login_url=types.LoginUrl.read(b)
) )
if isinstance(b, raw.types.KeyboardButtonUserProfile):
return InlineKeyboardButton(
text=b.text,
user_id=b.user_id
)
if isinstance(b, raw.types.KeyboardButtonSwitchInline): if isinstance(b, raw.types.KeyboardButtonSwitchInline):
if b.same_peer: if b.same_peer:
return InlineKeyboardButton( return InlineKeyboardButton(
@ -150,6 +161,12 @@ class InlineKeyboardButton(Object):
bot=await client.resolve_peer(self.login_url.bot_username) bot=await client.resolve_peer(self.login_url.bot_username)
) )
if self.user_id is not None:
return raw.types.InputKeyboardButtonUserProfile(
text=self.text,
user_id=await client.resolve_peer(self.user_id)
)
if self.switch_inline_query is not None: if self.switch_inline_query is not None:
return raw.types.KeyboardButtonSwitchInline( return raw.types.KeyboardButtonSwitchInline(
text=self.text, text=self.text,