diff --git a/telethon/types/_custom/button.py b/telethon/types/_custom/button.py index ffac7c99..27f1aae9 100644 --- a/telethon/types/_custom/button.py +++ b/telethon/types/_custom/button.py @@ -1,6 +1,8 @@ +import typing + from .messagebutton import MessageButton from ... import _tl -from ..._misc import utils +from ..._misc import utils, hints class Button: @@ -54,6 +56,7 @@ class Button: _tl.KeyboardButtonCallback, _tl.KeyboardButtonGame, _tl.KeyboardButtonSwitchInline, + _tl.KeyboardButtonUserProfile, _tl.KeyboardButtonUrl, _tl.InputKeyboardButtonUrlAuth )) @@ -166,6 +169,29 @@ class Button: fwd_text=fwd_text ) + @staticmethod + def mention(text, input_entity): + """ + Creates a new inline button linked to the profile of user. + + Args: + input_entity: + Input entity of :tl:User to use for profile button. + By default, this is the logged in user (itself), although + you may pass a different input peer. + + .. note:: + + For now, you cannot use ID or username for this argument. + If you want to use different user, you must manually use + `client.get_input_entity() `. + """ + return _tl.InputKeyboardButtonUserProfile( + text, + utils.get_input_user(input_entity or _tl.InputUserSelf()) + ) + + @classmethod def text(cls, text, *, resize=None, single_use=None, selective=None): """ @@ -387,4 +413,4 @@ def build_reply_markup( return _tl.ReplyInlineMarkup(rows) # elif is_normal: return _tl.ReplyKeyboardMarkup( - rows, resize=resize, single_use=single_use, selective=selective) + rows, resize=resize, single_use=single_use, selective=selective) \ No newline at end of file diff --git a/telethon/types/_custom/messagebutton.py b/telethon/types/_custom/messagebutton.py index 2d588727..eee4486e 100644 --- a/telethon/types/_custom/messagebutton.py +++ b/telethon/types/_custom/messagebutton.py @@ -71,6 +71,10 @@ class MessageButton: If it's an inline :tl:`KeyboardButtonCallback` with text and data, it will be "clicked" and the :tl:`BotCallbackAnswer` returned. + If it's an inline :tl:`KeyboardButtonUserProfile` button, the + `client.get_entity` will be called and the resulting :tl:User will be + returned. + If it's an inline :tl:`KeyboardButtonSwitchInline` button, the :tl:`StartBot` will be invoked and the resulting updates returned. @@ -107,6 +111,8 @@ class MessageButton: return await self._client(req) except BotResponseTimeoutError: return None + elif isinstance(self.button, _tl.KeyboardButtonUserProfile): + return await self._client.get_entity(self.button.user_id) elif isinstance(self.button, _tl.KeyboardButtonSwitchInline): return await self._client(_tl.fn.messages.StartBot( bot=self._bot, peer=self._chat, start_param=self.button.query @@ -143,4 +149,4 @@ class MessageButton: long, lat = share_geo share_geo = _tl.InputMediaGeoPoint(_tl.InputGeoPoint(lat=lat, long=long)) - return await self._client.send_file(self._chat, share_geo) + return await self._client.send_file(self._chat, share_geo) \ No newline at end of file