diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 7f73d4d7f..55bdaf49f 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -4850,6 +4850,12 @@ getInlineQueryResults bot_user_id:int53 chat_id:int53 user_location:location que answerInlineQuery inline_query_id:int64 is_personal:Bool results:vector cache_time:int32 next_offset:string switch_pm_text:string switch_pm_parameter:string = Ok; +//@description Returns an HTTPS URL to open in a web view when keyboardButtonTypeWebView button is pressed +//@bot_user_id Identifier of the target bot +//@url The URL from the keyboardButtonTypeWebView button +//@theme Preferred web view theme; pass null to use the default theme +getSimpleWebViewUrl bot_user_id:int53 url:string theme:themeParameters = HttpUrl; + //@description Sends data received from keyboardButtonTypeWebView web view to a bot //@bot_user_id Identifier of the target bot @button_text Text of the keyboardButtonTypeWebView button, which opened the web view @data Received data sendWebViewData bot_user_id:int53 button_text:string data:string = Ok; diff --git a/td/telegram/InlineQueriesManager.cpp b/td/telegram/InlineQueriesManager.cpp index 904ecf72b..5ce49d65a 100644 --- a/td/telegram/InlineQueriesManager.cpp +++ b/td/telegram/InlineQueriesManager.cpp @@ -35,6 +35,7 @@ #include "td/telegram/TdDb.h" #include "td/telegram/TdParameters.h" #include "td/telegram/telegram_api.hpp" +#include "td/telegram/ThemeManager.h" #include "td/telegram/UpdatesManager.h" #include "td/telegram/Venue.h" #include "td/telegram/VideosManager.h" @@ -163,6 +164,43 @@ class SetInlineBotResultsQuery final : public Td::ResultHandler { } }; +class RequestSimpleWebViewQuery final : public Td::ResultHandler { + Promise promise_; + + public: + explicit RequestSimpleWebViewQuery(Promise &&promise) : promise_(std::move(promise)) { + } + + void send(tl_object_ptr &&input_user, const string &url, + const td_api::object_ptr &theme) { + tl_object_ptr theme_parameters; + 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); + } + send_query(G()->net_query_creator().create( + telegram_api::messages_requestSimpleWebView(flags, std::move(input_user), url, std::move(theme_parameters)))); + } + + void on_result(BufferSlice packet) final { + auto result_ptr = fetch_result(packet); + if (result_ptr.is_error()) { + return on_error(result_ptr.move_as_error()); + } + + auto ptr = result_ptr.move_as_ok(); + LOG(INFO) << "Receive result for RequestSimpleWebViewQuery: " << to_string(ptr); + promise_.set_value(std::move(ptr->url_)); + } + + void on_error(Status status) final { + promise_.set_error(std::move(status)); + } +}; + class SendWebViewDataQuery final : public Td::ResultHandler { Promise promise_; @@ -457,6 +495,15 @@ void InlineQueriesManager::answer_inline_query( switch_pm_text, switch_pm_parameter); } +void InlineQueriesManager::get_simple_web_view_url(UserId bot_user_id, string &&url, + const td_api::object_ptr &theme, + Promise &&promise) { + TRY_RESULT_PROMISE(promise, input_user, td_->contacts_manager_->get_input_user(bot_user_id)); + 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); +} + void InlineQueriesManager::send_web_view_data(UserId bot_user_id, string &&button_text, string &&data, Promise &&promise) const { TRY_RESULT_PROMISE(promise, bot_data, td_->contacts_manager_->get_bot_data(bot_user_id)); diff --git a/td/telegram/InlineQueriesManager.h b/td/telegram/InlineQueriesManager.h index 72f438b80..aec40304c 100644 --- a/td/telegram/InlineQueriesManager.h +++ b/td/telegram/InlineQueriesManager.h @@ -45,6 +45,9 @@ class InlineQueriesManager final : public Actor { const string &next_offset, const string &switch_pm_text, const string &switch_pm_parameter, Promise &&promise) const; + void get_simple_web_view_url(UserId bot_user_id, string &&url, + const td_api::object_ptr &theme, Promise &&promise); + void send_web_view_data(UserId bot_user_id, string &&button_text, string &&data, Promise &&promise) const; void answer_web_view_query(const string &web_view_query_id, diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 667565d8e..8e1cf7686 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -7336,6 +7336,21 @@ void Td::on_request(uint64 id, td_api::answerInlineQuery &request) { request.next_offset_, request.switch_pm_text_, request.switch_pm_parameter_, std::move(promise)); } +void Td::on_request(uint64 id, td_api::getSimpleWebViewUrl &request) { + CHECK_IS_USER(); + CLEAN_INPUT_STRING(request.url_); + CREATE_REQUEST_PROMISE(); + auto query_promise = PromiseCreator::lambda([promise = std::move(promise)](Result result) mutable { + if (result.is_error()) { + promise.set_error(result.move_as_error()); + } else { + promise.set_value(td_api::make_object(result.move_as_ok())); + } + }); + inline_queries_manager_->get_simple_web_view_url(UserId(request.bot_user_id_), std::move(request.url_), + std::move(request.theme_), std::move(query_promise)); +} + void Td::on_request(uint64 id, td_api::sendWebViewData &request) { CHECK_IS_USER(); CLEAN_INPUT_STRING(request.button_text_); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index bc545b6b4..6454f7aa3 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -1155,6 +1155,8 @@ class Td final : public Actor { void on_request(uint64 id, td_api::answerInlineQuery &request); + void on_request(uint64 id, td_api::getSimpleWebViewUrl &request); + void on_request(uint64 id, td_api::sendWebViewData &request); void on_request(uint64 id, td_api::answerWebViewQuery &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 2ade0ab9b..ee92b9876 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -3428,7 +3428,12 @@ class CliClient final : public Actor { bool is_added; get_args(args, user_id, is_added); send_request(td_api::make_object(user_id, is_added)); - } else if (op == "swwd") { + } else if (op == "gswvu") { + UserId user_id; + string url; + get_args(args, user_id, url); + send_request(td_api::make_object(user_id, url, get_theme_parameters())); + } else if (op == "swvd") { UserId user_id; string button_text; string data;