From bf500652dc63530f27b9608ee7588a5945895628 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 7 Sep 2023 21:40:47 +0300 Subject: [PATCH] Support opening of Web Apps from the side menu and internalLinkTypeSideMenuBot links. --- td/generate/scheme/td_api.tl | 6 +++--- td/telegram/InlineQueriesManager.cpp | 25 +++++++++++++++++++------ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 49135b6d4..0e9abeab9 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -7026,9 +7026,9 @@ searchWebApp bot_user_id:int53 web_app_short_name:string = FoundWebApp; //@allow_write_access Pass true if the current user allowed the bot to send them messages getWebAppLinkUrl chat_id:int53 bot_user_id:int53 web_app_short_name:string start_parameter:string theme:themeParameters application_name:string allow_write_access:Bool = HttpUrl; -//@description Returns an HTTPS URL of a Web App to open after keyboardButtonTypeWebApp or inlineQueryResultsButtonTypeWebApp button is pressed +//@description Returns an HTTPS URL of a Web App to open from the side menu, a keyboardButtonTypeWebApp button, an inlineQueryResultsButtonTypeWebApp button, or an internalLinkTypeSideMenuBot link //@bot_user_id Identifier of the target bot -//@url The URL from the keyboardButtonTypeWebApp or inlineQueryResultsButtonTypeWebApp button +//@url The URL from a keyboardButtonTypeWebApp button, inlineQueryResultsButtonTypeWebApp button, an internalLinkTypeSideMenuBot link, or an empty when the bot is opened from the side menu //@theme Preferred Web App theme; pass null to use the default theme //@application_name Short name of the application; 0-64 English letters, digits, and underscores getWebAppUrl bot_user_id:int53 url:string theme:themeParameters application_name:string = HttpUrl; @@ -7043,7 +7043,7 @@ sendWebAppData bot_user_id:int53 button_text:string data:string = Ok; //-For each bot, a confirmation alert about data sent to the bot must be shown once //@chat_id Identifier of the chat in which the Web App is opened. The Web App can't be opened in secret chats //@bot_user_id Identifier of the bot, providing the Web App -//@url The URL from an inlineKeyboardButtonTypeWebApp button, a botMenuButton button, or an internalLinkTypeAttachmentMenuBot link, or an empty string otherwise +//@url The URL from an inlineKeyboardButtonTypeWebApp button, a botMenuButton button, an internalLinkTypeAttachmentMenuBot link, or an empty string otherwise //@theme Preferred Web App theme; pass null to use the default theme //@application_name Short name of the application; 0-64 English letters, digits, and underscores //@message_thread_id If not 0, a message thread identifier in which the message will be sent diff --git a/td/telegram/InlineQueriesManager.cpp b/td/telegram/InlineQueriesManager.cpp index 88acea5cd..85987ed3a 100644 --- a/td/telegram/InlineQueriesManager.cpp +++ b/td/telegram/InlineQueriesManager.cpp @@ -176,27 +176,40 @@ class RequestSimpleWebViewQuery final : public Td::ResultHandler { explicit RequestSimpleWebViewQuery(Promise &&promise) : promise_(std::move(promise)) { } - void send(tl_object_ptr &&input_user, const string &url, + void send(tl_object_ptr &&input_user, string url, const td_api::object_ptr &theme, string &&platform) { tl_object_ptr theme_parameters; - int32 flags = telegram_api::messages_requestSimpleWebView::URL_MASK; + int32 flags = 0; if (theme != nullptr) { flags |= telegram_api::messages_requestSimpleWebView::THEME_PARAMS_MASK; theme_parameters = make_tl_object(string()); theme_parameters->data_ = ThemeManager::get_theme_parameters_json_string(theme, false); } + string start_parameter; if (ends_with(url, "#kb")) { // a URL from keyboard button + url.resize(url.size() - 3); + flags |= telegram_api::messages_requestSimpleWebView::URL_MASK; } else if (ends_with(url, "#iq")) { // a URL from inline query results button + url.resize(url.size() - 3); flags |= telegram_api::messages_requestSimpleWebView::FROM_SWITCH_WEBVIEW_MASK; + flags |= telegram_api::messages_requestSimpleWebView::URL_MASK; + } else if (url.empty()) { + flags |= telegram_api::messages_requestSimpleWebView::FROM_SIDE_MENU_MASK; + } else if (begins_with(url, "start://")) { + start_parameter = url.substr(8); + url = string(); + + flags |= telegram_api::messages_requestSimpleWebView::FROM_SIDE_MENU_MASK; + flags |= telegram_api::messages_requestSimpleWebView::START_PARAM_MASK; } else { return on_error(Status::Error(400, "Invalid URL specified")); } - send_query(G()->net_query_creator().create(telegram_api::messages_requestSimpleWebView( - flags, false /*ignored*/, false /*ignored*/, std::move(input_user), url.substr(0, url.size() - 3), string(), - std::move(theme_parameters), platform))); + send_query(G()->net_query_creator().create( + telegram_api::messages_requestSimpleWebView(flags, false /*ignored*/, false /*ignored*/, std::move(input_user), + url, start_parameter, std::move(theme_parameters), platform))); } void on_result(BufferSlice packet) final { @@ -547,7 +560,7 @@ void InlineQueriesManager::get_simple_web_view_url(UserId bot_user_id, string && TRY_RESULT_PROMISE(promise, bot_data, td_->contacts_manager_->get_bot_data(bot_user_id)); td_->create_handler(std::move(promise)) - ->send(std::move(input_user), url, theme, std::move(platform)); + ->send(std::move(input_user), std::move(url), theme, std::move(platform)); } void InlineQueriesManager::send_web_view_data(UserId bot_user_id, string &&button_text, string &&data,