From e9d2d40b53e7874dfdbd8c8c9f93b243ed854a2e Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 16 Jul 2024 10:50:32 +0300 Subject: [PATCH] Add td_api::getPopularWebAppBots. --- td/generate/scheme/td_api.tl | 8 ++++++ td/telegram/AttachMenuManager.cpp | 45 +++++++++++++++++++++++++++++++ td/telegram/AttachMenuManager.h | 3 +++ td/telegram/Td.cpp | 7 +++++ td/telegram/Td.h | 2 ++ td/telegram/cli.cpp | 5 ++++ 6 files changed, 70 insertions(+) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 0ba8b14e2..30d509bd2 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -1065,6 +1065,9 @@ userFullInfo personal_photo:chatPhoto photo:chatPhoto public_photo:chatPhoto blo //@description Represents a list of users @total_count Approximate total number of users found @user_ids A list of user identifiers users total_count:int32 user_ids:vector = Users; +//@description Represents a list of found users @user_ids Identifiers of the found users @next_offset The offset for the next request. If empty, then there are no more results +foundUsers user_ids:vector next_offset:string = FoundUsers; + //@description Contains information about a chat administrator @user_id User identifier of the administrator @custom_title Custom title of the administrator @is_owner True, if the user is the owner of the chat chatAdministrator user_id:int53 custom_title:string is_owner:Bool = ChatAdministrator; @@ -9088,6 +9091,11 @@ getInlineQueryResults bot_user_id:int53 chat_id:int53 user_location:location que answerInlineQuery inline_query_id:int64 is_personal:Bool button:inlineQueryResultsButton results:vector cache_time:int32 next_offset:string = Ok; +//@description Returns popular Web App bots +//@offset Offset of the first entry to return as received from the previous request; use empty string to get the first chunk of results +//@limit The maximum number of bots to be returned; up to 100 +getPopularWebAppBots offset:string limit:int32 = FoundUsers; + //@description Returns information about a Web App by its short name. Returns a 404 error if the Web App is not found //@bot_user_id Identifier of the target bot //@web_app_short_name Short name of the Web App diff --git a/td/telegram/AttachMenuManager.cpp b/td/telegram/AttachMenuManager.cpp index 05a8902a7..deadd8bd9 100644 --- a/td/telegram/AttachMenuManager.cpp +++ b/td/telegram/AttachMenuManager.cpp @@ -40,6 +40,43 @@ namespace td { +class GetPopularAppBotsQuery final : public Td::ResultHandler { + Promise> promise_; + + public: + explicit GetPopularAppBotsQuery(Promise> &&promise) + : promise_(std::move(promise)) { + } + + void send(const string &offset, int32 limit) { + send_query(G()->net_query_creator().create(telegram_api::bots_getPopularAppBots(offset, limit))); + } + + 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 GetPopularAppBotsQuery: " << to_string(ptr); + + vector user_ids; + for (auto &user : ptr->users_) { + auto user_id = td_->user_manager_->get_user_id(user); + td_->user_manager_->on_get_user(std::move(user), "GetPopularAppBotsQuery"); + if (td_->user_manager_->is_user_bot(user_id)) { + user_ids.push_back(td_->user_manager_->get_user_id_object(user_id, "GetPopularAppBotsQuery")); + } + } + promise_.set_value(td_api::make_object(std::move(user_ids), ptr->next_offset_)); + } + + void on_error(Status status) final { + promise_.set_error(std::move(status)); + } +}; + class GetBotAppQuery final : public Td::ResultHandler { Promise> promise_; @@ -773,6 +810,14 @@ void AttachMenuManager::schedule_ping_web_view() { ping_web_view_timeout_.set_timeout_in(PING_WEB_VIEW_TIMEOUT); } +void AttachMenuManager::get_popular_app_bots(const string &offset, int32 limit, + Promise> &&promise) { + if (limit <= 0) { + return promise.set_error(Status::Error(400, "Limit must be positive")); + } + td_->create_handler(std::move(promise))->send(offset, limit); +} + void AttachMenuManager::get_web_app(UserId bot_user_id, const string &web_app_short_name, Promise> &&promise) { TRY_RESULT_PROMISE(promise, input_user, td_->user_manager_->get_input_user(bot_user_id)); diff --git a/td/telegram/AttachMenuManager.h b/td/telegram/AttachMenuManager.h index 3d2e85bfa..041e935e5 100644 --- a/td/telegram/AttachMenuManager.h +++ b/td/telegram/AttachMenuManager.h @@ -33,6 +33,9 @@ class AttachMenuManager final : public Actor { void init(); + void get_popular_app_bots(const string &offset, int32 limit, + Promise> &&promise); + void get_web_app(UserId bot_user_id, const string &web_app_short_name, Promise> &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 88090cd9b..08c0cc0a6 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -9018,6 +9018,13 @@ void Td::on_request(uint64 id, td_api::answerInlineQuery &request) { request.cache_time_, request.next_offset_, std::move(promise)); } +void Td::on_request(uint64 id, td_api::getPopularWebAppBots &request) { + CHECK_IS_USER(); + CLEAN_INPUT_STRING(request.offset_); + CREATE_REQUEST_PROMISE(); + attach_menu_manager_->get_popular_app_bots(request.offset_, request.limit_, std::move(promise)); +} + void Td::on_request(uint64 id, td_api::searchWebApp &request) { CHECK_IS_USER(); CLEAN_INPUT_STRING(request.web_app_short_name_); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 95882da56..0880f9aa9 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -1759,6 +1759,8 @@ class Td final : public Actor { void on_request(uint64 id, td_api::answerInlineQuery &request); + void on_request(uint64 id, td_api::getPopularWebAppBots &request); + void on_request(uint64 id, td_api::searchWebApp &request); void on_request(uint64 id, td_api::getWebAppLinkUrl &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 4509e6a72..07987c5a3 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -4846,6 +4846,11 @@ class CliClient final : public Actor { get_args(args, user_id, is_added, allow_write_access); send_request( td_api::make_object(user_id, is_added, allow_write_access)); + } else if (op == "gpwab") { + string offset; + string limit; + get_args(args, offset, limit); + send_request(td_api::make_object(offset, as_limit(limit))); } else if (op == "swa") { UserId bot_user_id; string short_name;