Allow to specify application name when opening Web App.

This commit is contained in:
levlam 2022-08-25 23:15:53 +03:00
parent 2e31ba5188
commit df238a7034
7 changed files with 27 additions and 20 deletions

View File

@ -5235,7 +5235,8 @@ answerInlineQuery inline_query_id:int64 is_personal:Bool results:vector<InputInl
//@bot_user_id Identifier of the target bot
//@url The URL from the keyboardButtonTypeWebApp button
//@theme Preferred Web App theme; pass null to use the default theme
getWebAppUrl bot_user_id:int53 url:string theme:themeParameters = HttpUrl;
//@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;
//@description Sends data received from a keyboardButtonTypeWebApp Web App to a bot
//@bot_user_id Identifier of the target bot @button_text Text of the keyboardButtonTypeWebApp button, which opened the Web App @data Received data
@ -5247,8 +5248,9 @@ sendWebAppData bot_user_id:int53 button_text:string data:string = Ok;
//@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
//@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
//@reply_to_message_id Identifier of the replied message for the message sent by the Web App; 0 if none
openWebApp chat_id:int53 bot_user_id:int53 url:string theme:themeParameters reply_to_message_id:int53 = WebAppInfo;
openWebApp chat_id:int53 bot_user_id:int53 url:string theme:themeParameters application_name:string reply_to_message_id:int53 = WebAppInfo;
//@description Informs TDLib that a previously opened Web App was closed @web_app_launch_id Identifier of Web App launch, received from openWebApp
closeWebApp web_app_launch_id:int64 = Ok;

View File

@ -49,8 +49,8 @@ class RequestWebViewQuery final : public Td::ResultHandler {
}
void send(DialogId dialog_id, UserId bot_user_id, tl_object_ptr<telegram_api::InputUser> &&input_user, string &&url,
td_api::object_ptr<td_api::themeParameters> &&theme, MessageId reply_to_message_id, bool silent,
DialogId as_dialog_id) {
td_api::object_ptr<td_api::themeParameters> &&theme, string &&platform, MessageId reply_to_message_id,
bool silent, DialogId as_dialog_id) {
dialog_id_ = dialog_id;
bot_user_id_ = bot_user_id;
reply_to_message_id_ = reply_to_message_id;
@ -104,7 +104,7 @@ class RequestWebViewQuery final : public Td::ResultHandler {
send_query(G()->net_query_creator().create(telegram_api::messages_requestWebView(
flags, false /*ignored*/, false /*ignored*/, std::move(input_peer), std::move(input_user), url, start_parameter,
std::move(theme_parameters), string(), reply_to_message_id.get_server_message_id().get(),
std::move(theme_parameters), platform, reply_to_message_id.get_server_message_id().get(),
std::move(as_input_peer))));
}
@ -601,7 +601,7 @@ void AttachMenuManager::schedule_ping_web_view() {
void AttachMenuManager::request_web_view(DialogId dialog_id, UserId bot_user_id, MessageId reply_to_message_id,
string &&url, td_api::object_ptr<td_api::themeParameters> &&theme,
Promise<td_api::object_ptr<td_api::webAppInfo>> &&promise) {
string &&platform, Promise<td_api::object_ptr<td_api::webAppInfo>> &&promise) {
TRY_STATUS_PROMISE(promise, td_->contacts_manager_->get_bot_data(bot_user_id));
TRY_RESULT_PROMISE(promise, input_user, td_->contacts_manager_->get_input_user(bot_user_id));
@ -635,8 +635,8 @@ void AttachMenuManager::request_web_view(DialogId dialog_id, UserId bot_user_id,
DialogId as_dialog_id = td_->messages_manager_->get_dialog_default_send_message_as_dialog_id(dialog_id);
td_->create_handler<RequestWebViewQuery>(std::move(promise))
->send(dialog_id, bot_user_id, std::move(input_user), std::move(url), std::move(theme), reply_to_message_id,
silent, as_dialog_id);
->send(dialog_id, bot_user_id, std::move(input_user), std::move(url), std::move(theme), std::move(platform),
reply_to_message_id, silent, as_dialog_id);
}
void AttachMenuManager::open_web_view(int64 query_id, DialogId dialog_id, UserId bot_user_id,

View File

@ -33,7 +33,7 @@ class AttachMenuManager final : public Actor {
void init();
void request_web_view(DialogId dialog_id, UserId bot_user_id, MessageId reply_to_message_id, string &&url,
td_api::object_ptr<td_api::themeParameters> &&theme,
td_api::object_ptr<td_api::themeParameters> &&theme, string &&platform,
Promise<td_api::object_ptr<td_api::webAppInfo>> &&promise);
void open_web_view(int64 query_id, DialogId dialog_id, UserId bot_user_id, MessageId reply_to_message_id,

View File

@ -174,7 +174,7 @@ class RequestSimpleWebViewQuery final : public Td::ResultHandler {
}
void send(tl_object_ptr<telegram_api::InputUser> &&input_user, const string &url,
const td_api::object_ptr<td_api::themeParameters> &theme) {
const td_api::object_ptr<td_api::themeParameters> &theme, string &&platform) {
tl_object_ptr<telegram_api::dataJSON> theme_parameters;
int32 flags = 0;
if (theme != nullptr) {
@ -184,7 +184,7 @@ class RequestSimpleWebViewQuery final : public Td::ResultHandler {
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), string())));
flags, std::move(input_user), url, std::move(theme_parameters), platform)));
}
void on_result(BufferSlice packet) final {
@ -499,11 +499,12 @@ void InlineQueriesManager::answer_inline_query(
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) {
string &&platform, 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);
td_->create_handler<RequestSimpleWebViewQuery>(std::move(promise))
->send(std::move(input_user), url, theme, std::move(platform));
}
void InlineQueriesManager::send_web_view_data(UserId bot_user_id, string &&button_text, string &&data,

View File

@ -46,7 +46,8 @@ class InlineQueriesManager final : public Actor {
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);
const td_api::object_ptr<td_api::themeParameters> &theme, string &&platform,
Promise<string> &&promise);
void send_web_view_data(UserId bot_user_id, string &&button_text, string &&data, Promise<Unit> &&promise) const;

View File

@ -7398,6 +7398,7 @@ void Td::on_request(uint64 id, td_api::answerInlineQuery &request) {
void Td::on_request(uint64 id, td_api::getWebAppUrl &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.url_);
CLEAN_INPUT_STRING(request.application_name_);
CREATE_REQUEST_PROMISE();
auto query_promise = PromiseCreator::lambda([promise = std::move(promise)](Result<string> result) mutable {
if (result.is_error()) {
@ -7407,7 +7408,8 @@ void Td::on_request(uint64 id, td_api::getWebAppUrl &request) {
}
});
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));
std::move(request.theme_), std::move(request.application_name_),
std::move(query_promise));
}
void Td::on_request(uint64 id, td_api::sendWebAppData &request) {
@ -7422,10 +7424,11 @@ void Td::on_request(uint64 id, td_api::sendWebAppData &request) {
void Td::on_request(uint64 id, td_api::openWebApp &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.url_);
CLEAN_INPUT_STRING(request.application_name_);
CREATE_REQUEST_PROMISE();
attach_menu_manager_->request_web_view(DialogId(request.chat_id_), UserId(request.bot_user_id_),
MessageId(request.reply_to_message_id_), std::move(request.url_),
std::move(request.theme_), std::move(promise));
attach_menu_manager_->request_web_view(
DialogId(request.chat_id_), UserId(request.bot_user_id_), MessageId(request.reply_to_message_id_),
std::move(request.url_), std::move(request.theme_), std::move(request.application_name_), std::move(promise));
}
void Td::on_request(uint64 id, const td_api::closeWebApp &request) {

View File

@ -3582,7 +3582,7 @@ class CliClient final : public Actor {
UserId user_id;
string url;
get_args(args, user_id, url);
send_request(td_api::make_object<td_api::getWebAppUrl>(user_id, url, get_theme_parameters()));
send_request(td_api::make_object<td_api::getWebAppUrl>(user_id, url, get_theme_parameters(), "android"));
} else if (op == "swad") {
UserId user_id;
string button_text;
@ -3595,7 +3595,7 @@ class CliClient final : public Actor {
string url;
MessageId reply_to_message_id;
get_args(args, chat_id, bot_user_id, url, reply_to_message_id);
send_request(td_api::make_object<td_api::openWebApp>(chat_id, bot_user_id, url, get_theme_parameters(),
send_request(td_api::make_object<td_api::openWebApp>(chat_id, bot_user_id, url, get_theme_parameters(), "android",
reply_to_message_id));
} else if (op == "cwa") {
int64 launch_id;