Support opening of Web Apps from the side menu and internalLinkTypeSideMenuBot links.

This commit is contained in:
levlam 2023-09-07 21:40:47 +03:00
parent a7d9da0229
commit bf500652dc
2 changed files with 22 additions and 9 deletions

View File

@ -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 //@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; 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 //@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 //@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 //@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; 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 //-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 //@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 //@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 //@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 //@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 //@message_thread_id If not 0, a message thread identifier in which the message will be sent

View File

@ -176,27 +176,40 @@ class RequestSimpleWebViewQuery final : public Td::ResultHandler {
explicit RequestSimpleWebViewQuery(Promise<string> &&promise) : promise_(std::move(promise)) { explicit RequestSimpleWebViewQuery(Promise<string> &&promise) : promise_(std::move(promise)) {
} }
void send(tl_object_ptr<telegram_api::InputUser> &&input_user, const string &url, void send(tl_object_ptr<telegram_api::InputUser> &&input_user, string url,
const td_api::object_ptr<td_api::themeParameters> &theme, string &&platform) { const td_api::object_ptr<td_api::themeParameters> &theme, string &&platform) {
tl_object_ptr<telegram_api::dataJSON> theme_parameters; tl_object_ptr<telegram_api::dataJSON> theme_parameters;
int32 flags = telegram_api::messages_requestSimpleWebView::URL_MASK; int32 flags = 0;
if (theme != nullptr) { if (theme != nullptr) {
flags |= telegram_api::messages_requestSimpleWebView::THEME_PARAMS_MASK; flags |= telegram_api::messages_requestSimpleWebView::THEME_PARAMS_MASK;
theme_parameters = make_tl_object<telegram_api::dataJSON>(string()); theme_parameters = make_tl_object<telegram_api::dataJSON>(string());
theme_parameters->data_ = ThemeManager::get_theme_parameters_json_string(theme, false); theme_parameters->data_ = ThemeManager::get_theme_parameters_json_string(theme, false);
} }
string start_parameter;
if (ends_with(url, "#kb")) { if (ends_with(url, "#kb")) {
// a URL from keyboard button // a URL from keyboard button
url.resize(url.size() - 3);
flags |= telegram_api::messages_requestSimpleWebView::URL_MASK;
} else if (ends_with(url, "#iq")) { } else if (ends_with(url, "#iq")) {
// a URL from inline query results button // 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::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 { } else {
return on_error(Status::Error(400, "Invalid URL specified")); return on_error(Status::Error(400, "Invalid URL specified"));
} }
send_query(G()->net_query_creator().create(telegram_api::messages_requestSimpleWebView( send_query(G()->net_query_creator().create(
flags, false /*ignored*/, false /*ignored*/, std::move(input_user), url.substr(0, url.size() - 3), string(), telegram_api::messages_requestSimpleWebView(flags, false /*ignored*/, false /*ignored*/, std::move(input_user),
std::move(theme_parameters), platform))); url, start_parameter, std::move(theme_parameters), platform)));
} }
void on_result(BufferSlice packet) final { 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)); TRY_RESULT_PROMISE(promise, bot_data, td_->contacts_manager_->get_bot_data(bot_user_id));
td_->create_handler<RequestSimpleWebViewQuery>(std::move(promise)) td_->create_handler<RequestSimpleWebViewQuery>(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, void InlineQueriesManager::send_web_view_data(UserId bot_user_id, string &&button_text, string &&data,