From a08408541503d69ab1eca4ad4d45cccc78fc0e03 Mon Sep 17 00:00:00 2001 From: nimmadev <116873964+nimmadev@users.noreply.github.com> Date: Sun, 25 Feb 2024 12:13:03 +0530 Subject: [PATCH] Update button.py Add inline_webapp static methods - `webapp`: Creates KeyboardButtonWebView for inline webapp views. check url and replace space for saftey reason --- telethon/tl/custom/button.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/telethon/tl/custom/button.py b/telethon/tl/custom/button.py index 1b7d71e4..3da5fd87 100644 --- a/telethon/tl/custom/button.py +++ b/telethon/tl/custom/button.py @@ -307,3 +307,21 @@ class Button: documentation for more information on using games. """ return types.KeyboardButtonGame(text) + + @staticmethod + def webapp(text, url=None): + """ + Creates a new inline webapp button to open the desired webapp on click. + + If no `url` is given, the `text` will be used as said URL instead. + + When the user clicks this button, a one time confirmation box will be shown + to the user asking whether they want to connect to the website and lauch web app. + """ + if url: + url = url.replace(' ', '%20') + if not url.startswith("https://"): + url = "https://" + url.lstrip("http://") + elif not url: + url = "https://" + text.replace(' ', '%20') + return types.KeyboardButtonWebView(text, url)