Skip to content

Commit 48d9111

Browse files
committed
[keyboard button] added support for request_name, request_username and request_photo
1 parent dfcd9e9 commit 48d9111

3 files changed

Lines changed: 65 additions & 11 deletions

File tree

pyrogram/types/bots_and_keyboards/keyboard_button.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,11 @@ def read(b):
118118
chat_has_username=getattr(b.peer_type, "has_username", None),
119119
chat_is_forum=getattr(b.peer_type, "forum", None),
120120
user_administrator_rights=types.ChatAdministratorRights._parse(user_privileges),
121-
bot_administrator_rights=types.ChatAdministratorRights._parse(bot_privileges)
121+
bot_administrator_rights=types.ChatAdministratorRights._parse(bot_privileges),
122+
request_title = getattr(b, "name_requested", None),
123+
request_username = getattr(b, "username_requested", None),
124+
request_photo = getattr(b, "photo_requested", None),
125+
max_quantity = getattr(b, "max_quantity", None),
122126
)
123127
)
124128

@@ -129,7 +133,10 @@ def read(b):
129133
button_id=b.button_id,
130134
user_is_bot=getattr(b.peer_type, "bot", None),
131135
user_is_premium=getattr(b.peer_type, "premium", None),
132-
max_quantity=getattr(b, "max_quantity", None)
136+
request_name=getattr(b, "name_requested", None),
137+
request_username=getattr(b, "username_requested", None),
138+
request_photo=getattr(b, "photo_requested", None),
139+
max_quantity = getattr(b, "max_quantity", None),
133140
)
134141
)
135142

@@ -206,21 +213,29 @@ def write(self):
206213
bot_admin_rights=bot_admin_rights
207214
)
208215

209-
return raw.types.KeyboardButtonRequestPeer(
216+
return raw.types.InputKeyboardButtonRequestPeer(
210217
text=self.text,
211218
button_id=self.request_chat.button_id,
212219
peer_type=peer_type,
213-
max_quantity=1
220+
max_quantity=self.request_chat.max_quantity,
221+
name_requested=self.request_chat.request_title,
222+
username_requested=self.request_chat.request_username,
223+
photo_requested=self.request_chat.request_photo,
214224
)
215225
elif self.request_users:
216-
return raw.types.KeyboardButtonRequestPeer(
226+
peer_type = raw.types.RequestPeerTypeUser(
227+
bot=self.request_users.user_is_bot,
228+
premium=self.request_users.user_is_premium
229+
)
230+
231+
return raw.types.InputKeyboardButtonRequestPeer(
217232
text=self.text,
218233
button_id=self.request_users.button_id,
219-
peer_type=raw.types.RequestPeerTypeUser(
220-
bot=self.request_users.user_is_bot,
221-
premium=self.request_users.user_is_premium
222-
),
223-
max_quantity=self.request_users.max_quantity
234+
peer_type=peer_type,
235+
max_quantity=self.request_users.max_quantity,
236+
name_requested=self.request_users.request_name,
237+
username_requested=self.request_users.request_username,
238+
photo_requested=self.request_users.request_photo,
224239
)
225240
elif self.web_app:
226241
return raw.types.KeyboardButtonSimpleWebView(text=self.text, url=self.web_app.url)

pyrogram/types/bots_and_keyboards/keyboard_button_request_chat.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ class KeyboardButtonRequestChat(Object):
5252
5353
bot_administrator_rights (:obj:`~pyrogram.types.ChatAdministratorRights`, *optional*):
5454
Privileged actions that an bot administrator is able to take.
55+
56+
request_title (``bool``, *optional*):
57+
Pass True to request the chats' title
58+
If not specified, the title won't be requested.
59+
60+
request_username (``bool``, *optional*):
61+
Pass True to request the chats' username
62+
If not specified, the username won't be requested.
63+
64+
request_photo (``bool``, *optional*):
65+
Pass True to request the chats' photo
66+
If not specified, the photo won't be requested.
5567
"""
5668

5769
def __init__(
@@ -63,7 +75,11 @@ def __init__(
6375
chat_is_created: bool = None,
6476
bot_is_member: bool = None,
6577
user_administrator_rights: "types.ChatAdministratorRights" = None,
66-
bot_administrator_rights: "types.ChatAdministratorRights" = None
78+
bot_administrator_rights: "types.ChatAdministratorRights" = None,
79+
request_title: bool = None,
80+
request_username: bool = None,
81+
request_photo: bool = None,
82+
max_quantity: int = 1, # Telegram ignores this field for chats
6783
):
6884
super().__init__()
6985

@@ -75,3 +91,7 @@ def __init__(
7591
self.chat_is_forum = chat_is_forum
7692
self.user_administrator_rights = user_administrator_rights
7793
self.bot_administrator_rights = bot_administrator_rights
94+
self.request_title = request_title
95+
self.request_username = request_username
96+
self.request_photo = request_photo
97+
self.max_quantity = max_quantity

pyrogram/types/bots_and_keyboards/keyboard_button_request_users.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ class KeyboardButtonRequestUsers(Object):
3737
max_quantity(``int``, *optional*):
3838
The maximum number of users to be selected; 1-10.
3939
Defaults to 1.
40+
41+
request_name (``bool``, *optional*):
42+
Pass True to request the users' first and last name
43+
If not specified, the name won't be requested.
44+
45+
request_username (``bool``, *optional*):
46+
Pass True to request the users' username
47+
If not specified, the username won't be requested.
48+
49+
request_photo (``bool``, *optional*):
50+
Pass True to request the users' photo
51+
If not specified, the photo won't be requested.
52+
4053
"""
4154

4255
def __init__(
@@ -45,10 +58,16 @@ def __init__(
4558
user_is_bot: bool = None,
4659
user_is_premium: bool = None,
4760
max_quantity: int = 1,
61+
request_name: bool = None,
62+
request_username: bool = None,
63+
request_photo: bool = None,
4864
):
4965
super().__init__()
5066

5167
self.button_id = button_id
5268
self.user_is_bot = user_is_bot
5369
self.user_is_premium = user_is_premium
5470
self.max_quantity = max_quantity
71+
self.request_name = request_name
72+
self.request_username = request_username
73+
self.request_photo = request_photo

0 commit comments

Comments
 (0)