Add td_api::getBotMediaPreviews.
This commit is contained in:
parent
d79a350492
commit
5a5a9a28a4
@ -4387,6 +4387,10 @@ publicForwardStory story:story = PublicForward;
|
||||
publicForwards total_count:int32 forwards:vector<PublicForward> next_offset:string = PublicForwards;
|
||||
|
||||
|
||||
//@description Contains a list of media previews of a bot @previews List of media previews
|
||||
botMediaPreviews previews:vector<StoryContent> = BotMediaPreviews;
|
||||
|
||||
|
||||
//@description Contains a list of features available on a specific chat boost level
|
||||
//@level Target chat boost level
|
||||
//@story_per_day_count Number of stories that the chat can publish daily
|
||||
@ -10616,6 +10620,11 @@ allowBotToSendMessages bot_user_id:int53 = Ok;
|
||||
sendWebAppCustomRequest bot_user_id:int53 method:string parameters:string = CustomRequestResult;
|
||||
|
||||
|
||||
//@description Returns the list of media previews of a bot
|
||||
//@bot_user_id Identifier of the target bot
|
||||
getBotMediaPreviews bot_user_id:int53 = BotMediaPreviews;
|
||||
|
||||
|
||||
//@description Sets the name of a bot. Can be called only if userTypeBot.can_be_edited == true
|
||||
//@bot_user_id Identifier of the target bot
|
||||
//@language_code A two-letter ISO 639-1 language code. If empty, the name will be shown to all users for whose languages there is no dedicated name
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "td/telegram/Global.h"
|
||||
#include "td/telegram/misc.h"
|
||||
#include "td/telegram/net/NetQueryCreator.h"
|
||||
#include "td/telegram/StoryContent.h"
|
||||
#include "td/telegram/Td.h"
|
||||
#include "td/telegram/telegram_api.h"
|
||||
#include "td/telegram/UpdatesManager.h"
|
||||
@ -90,6 +91,46 @@ class SetBotBroadcastDefaultAdminRightsQuery final : public Td::ResultHandler {
|
||||
}
|
||||
};
|
||||
|
||||
class GetPreviewMediasQuery final : public Td::ResultHandler {
|
||||
Promise<td_api::object_ptr<td_api::botMediaPreviews>> promise_;
|
||||
UserId bot_user_id_;
|
||||
|
||||
public:
|
||||
explicit GetPreviewMediasQuery(Promise<td_api::object_ptr<td_api::botMediaPreviews>> &&promise)
|
||||
: promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(UserId bot_user_id, telegram_api::object_ptr<telegram_api::InputUser> input_user) {
|
||||
bot_user_id_ = bot_user_id;
|
||||
send_query(
|
||||
G()->net_query_creator().create(telegram_api::bots_getPreviewMedias(std::move(input_user)), {{bot_user_id}}));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::bots_getPreviewMedias>(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 GetPreviewMediasQuery: " << to_string(ptr);
|
||||
vector<td_api::object_ptr<td_api::StoryContent>> contents;
|
||||
for (auto &media_ptr : ptr) {
|
||||
auto content = get_story_content(td_, std::move(media_ptr->media_), DialogId(bot_user_id_));
|
||||
if (content == nullptr) {
|
||||
LOG(ERROR) << "Receive invalid preview media for " << bot_user_id_;
|
||||
} else {
|
||||
contents.push_back(get_story_content_object(td_, content.get()));
|
||||
}
|
||||
}
|
||||
promise_.set_value(td_api::make_object<td_api::botMediaPreviews>(std::move(contents)));
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class CanBotSendMessageQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
@ -392,6 +433,21 @@ void BotInfoManager::allow_bot_to_send_messages(UserId bot_user_id, Promise<Unit
|
||||
td_->create_handler<AllowBotSendMessageQuery>(std::move(promise))->send(bot_user_id);
|
||||
}
|
||||
|
||||
Result<telegram_api::object_ptr<telegram_api::InputUser>> BotInfoManager::get_media_preview_bot_input_user(
|
||||
UserId user_id, bool can_be_edited) {
|
||||
TRY_RESULT(bot_data, td_->user_manager_->get_bot_data(user_id));
|
||||
if (can_be_edited && !bot_data.can_be_edited) {
|
||||
return Status::Error(400, "Bot must be owned");
|
||||
}
|
||||
return td_->user_manager_->get_input_user(user_id);
|
||||
}
|
||||
|
||||
void BotInfoManager::get_bot_media_previews(UserId bot_user_id,
|
||||
Promise<td_api::object_ptr<td_api::botMediaPreviews>> &&promise) {
|
||||
TRY_RESULT_PROMISE(promise, input_user, get_media_preview_bot_input_user(bot_user_id));
|
||||
td_->create_handler<GetPreviewMediasQuery>(std::move(promise))->send(bot_user_id, std::move(input_user));
|
||||
}
|
||||
|
||||
void BotInfoManager::add_pending_set_query(UserId bot_user_id, const string &language_code, int type,
|
||||
const string &value, Promise<Unit> &&promise) {
|
||||
pending_set_bot_info_queries_.emplace_back(bot_user_id, language_code, type, value, std::move(promise));
|
||||
|
@ -30,6 +30,8 @@ class BotInfoManager final : public Actor {
|
||||
|
||||
void allow_bot_to_send_messages(UserId bot_user_id, Promise<Unit> &&promise);
|
||||
|
||||
void get_bot_media_previews(UserId bot_user_id, Promise<td_api::object_ptr<td_api::botMediaPreviews>> &&promise);
|
||||
|
||||
void set_bot_name(UserId bot_user_id, const string &language_code, const string &name, Promise<Unit> &&promise);
|
||||
|
||||
void get_bot_name(UserId bot_user_id, const string &language_code, Promise<string> &&promise);
|
||||
@ -81,6 +83,9 @@ class BotInfoManager final : public Actor {
|
||||
|
||||
void timeout_expired() final;
|
||||
|
||||
Result<telegram_api::object_ptr<telegram_api::InputUser>> get_media_preview_bot_input_user(
|
||||
UserId user_id, bool can_be_edited = false);
|
||||
|
||||
void add_pending_set_query(UserId bot_user_id, const string &language_code, int type, const string &value,
|
||||
Promise<Unit> &&promise);
|
||||
|
||||
|
@ -7895,6 +7895,11 @@ void Td::on_request(uint64 id, td_api::sendWebAppCustomRequest &request) {
|
||||
request.parameters_, std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::getBotMediaPreviews &request) {
|
||||
CREATE_REQUEST_PROMISE();
|
||||
bot_info_manager_->get_bot_media_previews(UserId(request.bot_user_id_), std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::setBotName &request) {
|
||||
CLEAN_INPUT_STRING(request.name_);
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
|
@ -1457,6 +1457,8 @@ class Td final : public Actor {
|
||||
|
||||
void on_request(uint64 id, td_api::sendWebAppCustomRequest &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::getBotMediaPreviews &request);
|
||||
|
||||
void on_request(uint64 id, td_api::setBotName &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::getBotName &request);
|
||||
|
@ -6558,6 +6558,10 @@ class CliClient final : public Actor {
|
||||
string parameters;
|
||||
get_args(args, bot_user_id, method, parameters);
|
||||
send_request(td_api::make_object<td_api::sendWebAppCustomRequest>(bot_user_id, method, parameters));
|
||||
} else if (op == "gbmp") {
|
||||
UserId bot_user_id;
|
||||
get_args(args, bot_user_id);
|
||||
send_request(td_api::make_object<td_api::getBotMediaPreviews>(bot_user_id));
|
||||
} else if (op == "gbi") {
|
||||
UserId bot_user_id;
|
||||
string language_code;
|
||||
|
Loading…
Reference in New Issue
Block a user