Add getSimpleWebViewUrl.
This commit is contained in:
parent
1780780caf
commit
29ab44b5d2
@ -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<InputInlineQueryResult> 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;
|
||||
|
@ -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<string> promise_;
|
||||
|
||||
public:
|
||||
explicit RequestSimpleWebViewQuery(Promise<string> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(tl_object_ptr<telegram_api::InputUser> &&input_user, const string &url,
|
||||
const td_api::object_ptr<td_api::themeParameters> &theme) {
|
||||
tl_object_ptr<telegram_api::dataJSON> theme_parameters;
|
||||
int32 flags = 0;
|
||||
if (theme != nullptr) {
|
||||
flags |= telegram_api::messages_requestSimpleWebView::THEME_PARAMS_MASK;
|
||||
|
||||
theme_parameters = make_tl_object<telegram_api::dataJSON>(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<telegram_api::messages_requestSimpleWebView>(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<Unit> 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<td_api::themeParameters> &theme,
|
||||
Promise<string> &&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<RequestSimpleWebViewQuery>(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<Unit> &&promise) const {
|
||||
TRY_RESULT_PROMISE(promise, bot_data, td_->contacts_manager_->get_bot_data(bot_user_id));
|
||||
|
@ -45,6 +45,9 @@ class InlineQueriesManager final : public Actor {
|
||||
const string &next_offset, const string &switch_pm_text, const string &switch_pm_parameter,
|
||||
Promise<Unit> &&promise) const;
|
||||
|
||||
void get_simple_web_view_url(UserId bot_user_id, string &&url,
|
||||
const td_api::object_ptr<td_api::themeParameters> &theme, Promise<string> &&promise);
|
||||
|
||||
void send_web_view_data(UserId bot_user_id, string &&button_text, string &&data, Promise<Unit> &&promise) const;
|
||||
|
||||
void answer_web_view_query(const string &web_view_query_id,
|
||||
|
@ -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<string> result) mutable {
|
||||
if (result.is_error()) {
|
||||
promise.set_error(result.move_as_error());
|
||||
} else {
|
||||
promise.set_value(td_api::make_object<td_api::httpUrl>(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_);
|
||||
|
@ -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);
|
||||
|
@ -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<td_api::toggleBotIsAddedToAttachMenu>(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<td_api::getSimpleWebViewUrl>(user_id, url, get_theme_parameters()));
|
||||
} else if (op == "swvd") {
|
||||
UserId user_id;
|
||||
string button_text;
|
||||
string data;
|
||||
|
Loading…
Reference in New Issue
Block a user