mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-06-18 11:06:39 +00:00
Add open_url param to control browser opening on click (#4607)
This commit is contained in:
parent
77b7edcd6e
commit
6a7331b7dc
@ -871,7 +871,7 @@ class Message(ChatGetter, SenderGetter, TLObject):
|
|||||||
|
|
||||||
async def click(self, i=None, j=None,
|
async def click(self, i=None, j=None,
|
||||||
*, text=None, filter=None, data=None, share_phone=None,
|
*, text=None, filter=None, data=None, share_phone=None,
|
||||||
share_geo=None, password=None):
|
share_geo=None, password=None, open_url=None):
|
||||||
"""
|
"""
|
||||||
Calls :tl:`SendVote` with the specified poll option
|
Calls :tl:`SendVote` with the specified poll option
|
||||||
or `button.click <telethon.tl.custom.messagebutton.MessageButton.click>`
|
or `button.click <telethon.tl.custom.messagebutton.MessageButton.click>`
|
||||||
@ -956,6 +956,12 @@ class Message(ChatGetter, SenderGetter, TLObject):
|
|||||||
you need to provide your account's password. Otherwise,
|
you need to provide your account's password. Otherwise,
|
||||||
`teltehon.errors.PasswordHashInvalidError` is raised.
|
`teltehon.errors.PasswordHashInvalidError` is raised.
|
||||||
|
|
||||||
|
open_url (`bool`):
|
||||||
|
When clicking on an inline keyboard URL button :tl:`KeyboardButtonUrl`
|
||||||
|
By default it will return URL of the button, passing ``click(open_url=True)``
|
||||||
|
will lunch the default browser with given URL of the button and
|
||||||
|
return `True` on success.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
@ -985,7 +991,7 @@ class Message(ChatGetter, SenderGetter, TLObject):
|
|||||||
|
|
||||||
but = types.KeyboardButtonCallback('', data)
|
but = types.KeyboardButtonCallback('', data)
|
||||||
return await MessageButton(self._client, but, chat, None, self.id).click(
|
return await MessageButton(self._client, but, chat, None, self.id).click(
|
||||||
share_phone=share_phone, share_geo=share_geo, password=password)
|
share_phone=share_phone, share_geo=share_geo, password=password, open_url=open_url)
|
||||||
|
|
||||||
if sum(int(x is not None) for x in (i, text, filter)) >= 2:
|
if sum(int(x is not None) for x in (i, text, filter)) >= 2:
|
||||||
raise ValueError('You can only set either of i, text or filter')
|
raise ValueError('You can only set either of i, text or filter')
|
||||||
@ -1058,7 +1064,7 @@ class Message(ChatGetter, SenderGetter, TLObject):
|
|||||||
button = find_button()
|
button = find_button()
|
||||||
if button:
|
if button:
|
||||||
return await button.click(
|
return await button.click(
|
||||||
share_phone=share_phone, share_geo=share_geo, password=password)
|
share_phone=share_phone, share_geo=share_geo, password=password, open_url=open_url)
|
||||||
|
|
||||||
async def mark_read(self):
|
async def mark_read(self):
|
||||||
"""
|
"""
|
||||||
|
@ -65,7 +65,7 @@ class MessageButton:
|
|||||||
if isinstance(self.button, types.KeyboardButtonUrl):
|
if isinstance(self.button, types.KeyboardButtonUrl):
|
||||||
return self.button.url
|
return self.button.url
|
||||||
|
|
||||||
async def click(self, share_phone=None, share_geo=None, *, password=None):
|
async def click(self, share_phone=None, share_geo=None, *, password=None, open_url=None):
|
||||||
"""
|
"""
|
||||||
Emulates the behaviour of clicking this button.
|
Emulates the behaviour of clicking this button.
|
||||||
|
|
||||||
@ -79,7 +79,8 @@ class MessageButton:
|
|||||||
:tl:`StartBotRequest` will be invoked and the resulting updates
|
:tl:`StartBotRequest` will be invoked and the resulting updates
|
||||||
returned.
|
returned.
|
||||||
|
|
||||||
If it's a :tl:`KeyboardButtonUrl`, the URL of the button will
|
If it's a :tl:`KeyboardButtonUrl`, the ``URL`` of the button will
|
||||||
|
be returned. If you pass ``open_url=True`` the URL of the button will
|
||||||
be passed to ``webbrowser.open`` and return `True` on success.
|
be passed to ``webbrowser.open`` and return `True` on success.
|
||||||
|
|
||||||
If it's a :tl:`KeyboardButtonRequestPhone`, you must indicate that you
|
If it's a :tl:`KeyboardButtonRequestPhone`, you must indicate that you
|
||||||
@ -116,8 +117,10 @@ class MessageButton:
|
|||||||
bot=self._bot, peer=self._chat, start_param=self.button.query
|
bot=self._bot, peer=self._chat, start_param=self.button.query
|
||||||
))
|
))
|
||||||
elif isinstance(self.button, types.KeyboardButtonUrl):
|
elif isinstance(self.button, types.KeyboardButtonUrl):
|
||||||
|
if open_url:
|
||||||
if "webbrowser" in sys.modules:
|
if "webbrowser" in sys.modules:
|
||||||
return webbrowser.open(self.button.url)
|
return webbrowser.open(self.button.url)
|
||||||
|
return self.button.url
|
||||||
elif isinstance(self.button, types.KeyboardButtonGame):
|
elif isinstance(self.button, types.KeyboardButtonGame):
|
||||||
req = functions.messages.GetBotCallbackAnswerRequest(
|
req = functions.messages.GetBotCallbackAnswerRequest(
|
||||||
peer=self._chat, msg_id=self._msg_id, game=True
|
peer=self._chat, msg_id=self._msg_id, game=True
|
||||||
|
Loading…
Reference in New Issue
Block a user