Skip to content

Commit a909dc1

Browse files
committed
Add support for user profile buttons
1 parent d103ae4 commit a909dc1

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

pyrogram/types/bots_and_keyboards/inline_keyboard_button.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ class InlineKeyboardButton(Object):
4343
An HTTP URL used to automatically authorize the user. Can be used as a replacement for
4444
the `Telegram Login Widget <https://core.telegram.org/widgets/login>`_.
4545
46+
user_id (``id``, *optional*):
47+
User id, for links to the user profile.
48+
4649
switch_inline_query (``str``, *optional*):
4750
If set, pressing the button will prompt the user to select one of their chats, open that chat and insert
4851
the bot's username and the specified inline query in the input field. Can be empty, in which case just
@@ -68,16 +71,18 @@ def __init__(
6871
callback_data: Union[str, bytes] = None,
6972
url: str = None,
7073
login_url: "types.LoginUrl" = None,
74+
user_id: int = None,
7175
switch_inline_query: str = None,
7276
switch_inline_query_current_chat: str = None,
7377
callback_game: "types.CallbackGame" = None
7478
):
7579
super().__init__()
7680

7781
self.text = str(text)
82+
self.callback_data = callback_data
7883
self.url = url
7984
self.login_url = login_url
80-
self.callback_data = callback_data
85+
self.user_id = user_id
8186
self.switch_inline_query = switch_inline_query
8287
self.switch_inline_query_current_chat = switch_inline_query_current_chat
8388
self.callback_game = callback_game
@@ -110,6 +115,12 @@ def read(b: "raw.base.KeyboardButton"):
110115
login_url=types.LoginUrl.read(b)
111116
)
112117

118+
if isinstance(b, raw.types.KeyboardButtonUserProfile):
119+
return InlineKeyboardButton(
120+
text=b.text,
121+
user_id=b.user_id
122+
)
123+
113124
if isinstance(b, raw.types.KeyboardButtonSwitchInline):
114125
if b.same_peer:
115126
return InlineKeyboardButton(
@@ -150,6 +161,12 @@ async def write(self, client: "pyrogram.Client"):
150161
bot=await client.resolve_peer(self.login_url.bot_username)
151162
)
152163

164+
if self.user_id is not None:
165+
return raw.types.InputKeyboardButtonUserProfile(
166+
text=self.text,
167+
user_id=await client.resolve_peer(self.user_id)
168+
)
169+
153170
if self.switch_inline_query is not None:
154171
return raw.types.KeyboardButtonSwitchInline(
155172
text=self.text,

0 commit comments

Comments
 (0)