Skip to content

Commit 9c89dc8

Browse files
Add get_web_app_link_url and get_web_app_url method
1 parent bfa578c commit 9c89dc8

4 files changed

Lines changed: 159 additions & 0 deletions

File tree

compiler/docs/compiler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ def get_title_list(s: str) -> list:
260260
get_messages
261261
get_scheduled_messages
262262
get_stickers
263+
get_web_app_link_url
264+
get_web_app_url
263265
mark_checklist_tasks_as_done
264266
get_media_group
265267
get_chat_history

pyrogram/methods/messages/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
from .get_messages import GetMessages
5050
from .get_scheduled_messages import GetScheduledMessages
5151
from .get_stickers import GetStickers
52+
from .get_web_app_link_url import GetWebAppLinkUrl
53+
from .get_web_app_url import GetWebAppUrl
5254
from .mark_checklist_tasks_as_done import MarkChecklistTasksAsDone
5355
from .read_chat_history import ReadChatHistory
5456
from .read_mentions import ReadMentions
@@ -111,6 +113,8 @@ class Messages(
111113
GetMessages,
112114
GetScheduledMessages,
113115
GetStickers,
116+
GetWebAppLinkUrl,
117+
GetWebAppUrl,
114118
MarkChecklistTasksAsDone,
115119
SendAudio,
116120
SendChatAction,
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
3+
#
4+
# This file is part of Pyrogram.
5+
#
6+
# Pyrogram is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Lesser General Public License as published
8+
# by the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# Pyrogram is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
18+
19+
from typing import Union
20+
21+
import pyrogram
22+
from pyrogram import raw, enums
23+
24+
25+
class GetWebAppLinkUrl:
26+
async def get_web_app_link_url(
27+
self: "pyrogram.Client",
28+
chat_id: Union[int, str],
29+
bot_user_id: Union[int, str],
30+
web_app_short_name: str,
31+
start_parameter: str = "",
32+
allow_write_access: bool = False,
33+
platform: "enums.ClientPlatform" = None
34+
) -> str:
35+
"""Returns an HTTPS URL of a Web App to open.
36+
37+
.. include:: /_includes/usable-by/users.rst
38+
39+
Parameters:
40+
chat_id (``int`` | ``str``):
41+
Unique identifier (int) or username (str) of the target chat.
42+
43+
bot_user_id (``int`` | ``str``):
44+
Unique identifier (int) or username (str) of the target bot.
45+
46+
web_app_short_name (``str``):
47+
Short name of the Web App.
48+
49+
start_parameter (``str``, *optional*):
50+
Start parameter.
51+
52+
allow_write_access (``bool``, *optional*):
53+
Pass True if the current user allowed the bot to send them messages.
54+
55+
platform (:obj:`~pyrogram.enums.ClientPlatform`, *optional*):
56+
The platform on which the link will be opened.
57+
58+
Returns:
59+
``str``: On success, returns the url of a Web App.
60+
61+
Example:
62+
.. code-block:: python
63+
64+
link = await app.get_web_app_link_url(chat_id, bot_user_id, web_app_short_name)
65+
"""
66+
if platform is None:
67+
platform = self.client_platform
68+
69+
r = await self.invoke(
70+
raw.functions.messages.RequestAppWebView(
71+
peer=await self.resolve_peer(chat_id),
72+
app=raw.types.InputBotAppShortName(
73+
bot_id=await self.resolve_peer(bot_user_id),
74+
short_name=web_app_short_name
75+
),
76+
platform=platform.value,
77+
write_allowed=allow_write_access,
78+
start_param=start_parameter,
79+
80+
)
81+
)
82+
83+
return r.url
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
3+
#
4+
# This file is part of Pyrogram.
5+
#
6+
# Pyrogram is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Lesser General Public License as published
8+
# by the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# Pyrogram is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
18+
19+
from typing import Union
20+
21+
import pyrogram
22+
from pyrogram import raw, enums
23+
24+
25+
class GetWebAppUrl:
26+
async def get_web_app_url(
27+
self: "pyrogram.Client",
28+
bot_user_id: Union[int, str],
29+
url: str = None,
30+
platform: "enums.ClientPlatform" = None
31+
) -> str:
32+
"""Returns an HTTPS URL of a Web App to open from the side menu,
33+
a :obj:`~pyrogram.types.KeyboardButton` button with web app type,
34+
or an :obj:`~pyrogram.types.InlineKeyboardButton` button with web app type.
35+
36+
.. include:: /_includes/usable-by/users.rst
37+
38+
Parameters:
39+
bot_user_id (``int`` | ``str``):
40+
Unique identifier (int) or username (str) of the target bot.
41+
42+
url (``str``, *optional*):
43+
The URL from :obj:`~pyrogram.types.KeyboardButton` button with web app type,
44+
or an :obj:`~pyrogram.types.InlineKeyboardButton` button with web app type,
45+
or an None when the bot is opened from the side menu.
46+
47+
platform (:obj:`~pyrogram.enums.ClientPlatform`, *optional*):
48+
The platform on which the link will be opened.
49+
50+
Returns:
51+
``str``: On success, returns the url of a Web App.
52+
53+
Example:
54+
.. code-block:: python
55+
56+
link = await client.get_web_app_url(bot_user_id)
57+
"""
58+
if platform is None:
59+
platform = self.client_platform
60+
61+
r = await self.invoke(
62+
raw.functions.messages.RequestSimpleWebView(
63+
bot=await self.resolve_peer(bot_user_id),
64+
platform=platform.value,
65+
from_side_menu=True if url is None else None,
66+
url=url
67+
)
68+
)
69+
70+
return r.url

0 commit comments

Comments
 (0)