Add inlineQueryResultsButtonTypeWebApp.
This commit is contained in:
parent
651bb7a156
commit
46fab0cbac
@ -3539,11 +3539,17 @@ inlineQueryResultVideo id:string video:video title:string description:string = I
|
||||
inlineQueryResultVoiceNote id:string voice_note:voiceNote title:string = InlineQueryResult;
|
||||
|
||||
|
||||
//@class InlineQueryResultsButtonType @description Represents a type of a button in results of inline query
|
||||
|
||||
//@description Describes the button that opens a private chat with the bot and sends a start message to the bot with the given parameter @parameter The parameter for the bot start message
|
||||
inlineQueryResultsButtonTypeSwitchToPrivateChat parameter:string = InlineQueryResultsButtonTypeSwitchToPrivateChat;
|
||||
inlineQueryResultsButtonTypeStartBot parameter:string = InlineQueryResultsButtonType;
|
||||
|
||||
//@description Describes the button that opens a Web App by calling getWebAppUrl @url An HTTP URL to pass to getWebAppUrl
|
||||
inlineQueryResultsButtonTypeWebApp url:string = InlineQueryResultsButtonType;
|
||||
|
||||
|
||||
//@description Represents a button to be shown above inline query results @text The text of the button @type Type of the button
|
||||
inlineQueryResultsButton text:string type:inlineQueryResultsButtonTypeSwitchToPrivateChat = InlineQueryResultsButton;
|
||||
inlineQueryResultsButton text:string type:InlineQueryResultsButtonType = InlineQueryResultsButton;
|
||||
|
||||
|
||||
//@description Represents the results of the inline query. Use sendInlineQueryResultMessage to send the result of the query
|
||||
@ -6508,9 +6514,9 @@ getInlineQueryResults bot_user_id:int53 chat_id:int53 user_location:location que
|
||||
answerInlineQuery inline_query_id:int64 is_personal:Bool button:inlineQueryResultsButton results:vector<InputInlineQueryResult> cache_time:int32 next_offset:string = Ok;
|
||||
|
||||
|
||||
//@description Returns an HTTPS URL of a Web App to open after keyboardButtonTypeWebApp button is pressed
|
||||
//@description Returns an HTTPS URL of a Web App to open after keyboardButtonTypeWebApp or inlineQueryResultsButtonTypeWebApp button is pressed
|
||||
//@bot_user_id Identifier of the target bot
|
||||
//@url The URL from the keyboardButtonTypeWebApp button
|
||||
//@url The URL from the keyboardButtonTypeWebApp or inlineQueryResultsButtonTypeWebApp button
|
||||
//@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;
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "td/telegram/Global.h"
|
||||
#include "td/telegram/InputInvoice.h"
|
||||
#include "td/telegram/InputMessageText.h"
|
||||
#include "td/telegram/LinkManager.h"
|
||||
#include "td/telegram/Location.h"
|
||||
#include "td/telegram/MessageContent.h"
|
||||
#include "td/telegram/MessageContentType.h"
|
||||
@ -127,6 +128,7 @@ class SetInlineBotResultsQuery final : public Td::ResultHandler {
|
||||
|
||||
void send(int64 inline_query_id, bool is_gallery, bool is_personal,
|
||||
telegram_api::object_ptr<telegram_api::inlineBotSwitchPM> switch_pm,
|
||||
telegram_api::object_ptr<telegram_api::inlineBotWebView> web_view,
|
||||
vector<tl_object_ptr<telegram_api::InputBotInlineResult>> &&results, int32 cache_time,
|
||||
const string &next_offset) {
|
||||
int32 flags = 0;
|
||||
@ -142,9 +144,12 @@ class SetInlineBotResultsQuery final : public Td::ResultHandler {
|
||||
if (switch_pm != nullptr) {
|
||||
flags |= telegram_api::messages_setInlineBotResults::SWITCH_PM_MASK;
|
||||
}
|
||||
if (web_view != nullptr) {
|
||||
flags |= telegram_api::messages_setInlineBotResults::SWITCH_WEBVIEW_MASK;
|
||||
}
|
||||
send_query(G()->net_query_creator().create(telegram_api::messages_setInlineBotResults(
|
||||
flags, false /*ignored*/, false /*ignored*/, inline_query_id, std::move(results), cache_time, next_offset,
|
||||
std::move(switch_pm), nullptr)));
|
||||
std::move(switch_pm), std::move(web_view))));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
@ -182,8 +187,17 @@ class RequestSimpleWebViewQuery final : public Td::ResultHandler {
|
||||
theme_parameters = make_tl_object<telegram_api::dataJSON>(string());
|
||||
theme_parameters->data_ = ThemeManager::get_theme_parameters_json_string(theme, false);
|
||||
}
|
||||
if (ends_with(url, "#kb")) {
|
||||
// a URL from keyboard button
|
||||
} else if (ends_with(url, "#iq")) {
|
||||
// a URL from inline query results button
|
||||
flags |= telegram_api::messages_requestSimpleWebView::FROM_SWITCH_WEBVIEW_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*/, std::move(input_user), url, std::move(theme_parameters), platform)));
|
||||
flags, false /*ignored*/, std::move(input_user), url.substr(0, url.size() - 3), std::move(theme_parameters),
|
||||
platform)));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
@ -471,6 +485,7 @@ void InlineQueriesManager::answer_inline_query(
|
||||
CHECK(td_->auth_manager_->is_bot());
|
||||
|
||||
telegram_api::object_ptr<telegram_api::inlineBotSwitchPM> switch_pm;
|
||||
telegram_api::object_ptr<telegram_api::inlineBotWebView> web_view;
|
||||
if (button != nullptr) {
|
||||
if (!clean_input_string(button->text_)) {
|
||||
return promise.set_error(Status::Error(400, "Strings must be encoded in UTF-8"));
|
||||
@ -479,8 +494,8 @@ void InlineQueriesManager::answer_inline_query(
|
||||
return promise.set_error(Status::Error(400, "Button type must be non-empty"));
|
||||
}
|
||||
switch (button->type_->get_id()) {
|
||||
case td_api::inlineQueryResultsButtonTypeSwitchToPrivateChat::ID: {
|
||||
auto type = td_api::move_object_as<td_api::inlineQueryResultsButtonTypeSwitchToPrivateChat>(button->type_);
|
||||
case td_api::inlineQueryResultsButtonTypeStartBot::ID: {
|
||||
auto type = td_api::move_object_as<td_api::inlineQueryResultsButtonTypeStartBot>(button->type_);
|
||||
if (type->parameter_.empty()) {
|
||||
return promise.set_error(Status::Error(400, "Can't use empty switch_pm_parameter"));
|
||||
}
|
||||
@ -493,6 +508,20 @@ void InlineQueriesManager::answer_inline_query(
|
||||
switch_pm = telegram_api::make_object<telegram_api::inlineBotSwitchPM>(button->text_, type->parameter_);
|
||||
break;
|
||||
}
|
||||
case td_api::inlineQueryResultsButtonTypeWebApp::ID: {
|
||||
auto type = td_api::move_object_as<td_api::inlineQueryResultsButtonTypeWebApp>(button->type_);
|
||||
auto user_id = LinkManager::get_link_user_id(type->url_);
|
||||
if (user_id.is_valid()) {
|
||||
return promise.set_error(Status::Error(400, "Link to a user can't be used in the Web App button"));
|
||||
}
|
||||
auto r_url = LinkManager::check_link(type->url_, true, !G()->is_test_dc());
|
||||
if (r_url.is_error()) {
|
||||
return promise.set_error(
|
||||
Status::Error(400, PSLICE() << "Inline query button Web App " << r_url.error().message()));
|
||||
}
|
||||
web_view = telegram_api::make_object<telegram_api::inlineBotWebView>(button->text_, type->url_);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
@ -508,8 +537,8 @@ void InlineQueriesManager::answer_inline_query(
|
||||
}
|
||||
|
||||
td_->create_handler<SetInlineBotResultsQuery>(std::move(promise))
|
||||
->send(inline_query_id, is_gallery && !force_vertical, is_personal, std::move(switch_pm), std::move(results),
|
||||
cache_time, next_offset);
|
||||
->send(inline_query_id, is_gallery && !force_vertical, is_personal, std::move(switch_pm), std::move(web_view),
|
||||
std::move(results), cache_time, next_offset);
|
||||
}
|
||||
|
||||
void InlineQueriesManager::get_simple_web_view_url(UserId bot_user_id, string &&url,
|
||||
@ -1333,9 +1362,18 @@ tl_object_ptr<td_api::game> copy(const td_api::game &obj) {
|
||||
}
|
||||
|
||||
template <>
|
||||
tl_object_ptr<td_api::inlineQueryResultsButtonTypeSwitchToPrivateChat> copy(
|
||||
const td_api::inlineQueryResultsButtonTypeSwitchToPrivateChat &obj) {
|
||||
return td_api::make_object<td_api::inlineQueryResultsButtonTypeSwitchToPrivateChat>(obj.parameter_);
|
||||
tl_object_ptr<td_api::InlineQueryResultsButtonType> copy(const td_api::InlineQueryResultsButtonType &obj) {
|
||||
switch (obj.get_id()) {
|
||||
case td_api::inlineQueryResultsButtonTypeStartBot::ID:
|
||||
return td_api::make_object<td_api::inlineQueryResultsButtonTypeStartBot>(
|
||||
static_cast<const td_api::inlineQueryResultsButtonTypeStartBot &>(obj).parameter_);
|
||||
case td_api::inlineQueryResultsButtonTypeWebApp::ID:
|
||||
return td_api::make_object<td_api::inlineQueryResultsButtonTypeWebApp>(
|
||||
static_cast<const td_api::inlineQueryResultsButtonTypeWebApp &>(obj).url_);
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template <>
|
||||
@ -1943,8 +1981,12 @@ void InlineQueriesManager::on_get_inline_query_results(DialogId dialog_id, UserI
|
||||
td_api::object_ptr<td_api::inlineQueryResultsButton> button;
|
||||
if (results->switch_pm_ != nullptr) {
|
||||
button = td_api::make_object<td_api::inlineQueryResultsButton>(
|
||||
results->switch_pm_->text_, td_api::make_object<td_api::inlineQueryResultsButtonTypeSwitchToPrivateChat>(
|
||||
results->switch_pm_->start_param_));
|
||||
results->switch_pm_->text_,
|
||||
td_api::make_object<td_api::inlineQueryResultsButtonTypeStartBot>(results->switch_pm_->start_param_));
|
||||
} else if (results->switch_webview_) {
|
||||
button = td_api::make_object<td_api::inlineQueryResultsButton>(
|
||||
results->switch_webview_->text_,
|
||||
td_api::make_object<td_api::inlineQueryResultsButtonTypeWebApp>(results->switch_webview_->url_ + "#iq"));
|
||||
}
|
||||
|
||||
it->second.results = make_tl_object<td_api::inlineQueryResults>(results->query_id_, std::move(button),
|
||||
|
@ -947,7 +947,7 @@ static tl_object_ptr<td_api::keyboardButton> get_keyboard_button_object(const Ke
|
||||
type = make_tl_object<td_api::keyboardButtonTypeRequestPoll>(true, false);
|
||||
break;
|
||||
case KeyboardButton::Type::WebView:
|
||||
type = make_tl_object<td_api::keyboardButtonTypeWebApp>(keyboard_button.url);
|
||||
type = make_tl_object<td_api::keyboardButtonTypeWebApp>(keyboard_button.url + "#kb");
|
||||
break;
|
||||
case KeyboardButton::Type::RequestDialog:
|
||||
type = keyboard_button.requested_dialog_type->get_keyboard_button_type_object();
|
||||
|
Loading…
x
Reference in New Issue
Block a user