Add td_api::getPopularWebAppBots.

This commit is contained in:
levlam 2024-07-16 10:50:32 +03:00
parent c3f32a2090
commit e9d2d40b53
6 changed files with 70 additions and 0 deletions

View File

@ -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<int53> = 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<int53> 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<InputInlineQueryResult> 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

View File

@ -40,6 +40,43 @@
namespace td {
class GetPopularAppBotsQuery final : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::foundUsers>> promise_;
public:
explicit GetPopularAppBotsQuery(Promise<td_api::object_ptr<td_api::foundUsers>> &&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<telegram_api::bots_getPopularAppBots>(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<int64> 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<td_api::foundUsers>(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<telegram_api::object_ptr<telegram_api::messages_botApp>> 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<td_api::object_ptr<td_api::foundUsers>> &&promise) {
if (limit <= 0) {
return promise.set_error(Status::Error(400, "Limit must be positive"));
}
td_->create_handler<GetPopularAppBotsQuery>(std::move(promise))->send(offset, limit);
}
void AttachMenuManager::get_web_app(UserId bot_user_id, const string &web_app_short_name,
Promise<td_api::object_ptr<td_api::foundWebApp>> &&promise) {
TRY_RESULT_PROMISE(promise, input_user, td_->user_manager_->get_input_user(bot_user_id));

View File

@ -33,6 +33,9 @@ class AttachMenuManager final : public Actor {
void init();
void get_popular_app_bots(const string &offset, int32 limit,
Promise<td_api::object_ptr<td_api::foundUsers>> &&promise);
void get_web_app(UserId bot_user_id, const string &web_app_short_name,
Promise<td_api::object_ptr<td_api::foundWebApp>> &&promise);

View File

@ -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_);

View File

@ -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);

View File

@ -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<td_api::toggleBotIsAddedToAttachmentMenu>(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<td_api::getPopularWebAppBots>(offset, as_limit(limit)));
} else if (op == "swa") {
UserId bot_user_id;
string short_name;