Add td_api::deleteBotMediaPreviews.

This commit is contained in:
levlam 2024-07-19 14:38:38 +03:00
parent e8b477a3e3
commit 1abbbc3778
6 changed files with 73 additions and 1 deletions

View File

@ -10632,11 +10632,17 @@ addBotMediaPreview bot_user_id:int53 language_code:string content:InputStoryCont
//@description Replaces media preview in the list of bot's media previews. Returns the new preview
//@bot_user_id Identifier of the target bot
//@language_code Language code of the media preview
//@language_code Language code of the media preview to edit
//@file_id File identifier of the media to replace
//@content Content of the new preview
editBotMediaPreview bot_user_id:int53 language_code:string file_id:int32 content:InputStoryContent = StoryContent;
//@description Delete media preview from the list of bot's media previews
//@bot_user_id Identifier of the target bot
//@language_code Language code of the media previews to delete
//@file_ids File identifiers of the media to delete
deleteBotMediaPreviews bot_user_id:int53 language_code:string file_ids:vector<int32> = Ok;
//@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

View File

@ -221,6 +221,34 @@ class BotInfoManager::AddPreviewMediaQuery final : public Td::ResultHandler {
}
};
class DeletePreviewMediaQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
public:
explicit DeletePreviewMediaQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(UserId bot_user_id, telegram_api::object_ptr<telegram_api::InputUser> input_user,
const string &language_code, vector<telegram_api::object_ptr<telegram_api::InputMedia>> input_media) {
send_query(G()->net_query_creator().create(
telegram_api::bots_deletePreviewMedia(std::move(input_user), language_code, std::move(input_media)),
{{bot_user_id}}));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::bots_deletePreviewMedia>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
promise_.set_value(Unit());
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
class CanBotSendMessageQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
@ -723,6 +751,22 @@ telegram_api::object_ptr<telegram_api::InputMedia> BotInfoManager::get_fake_inpu
}
}
void BotInfoManager::delete_bot_media_previews(UserId bot_user_id, const string &language_code,
const vector<int32> &file_ids, Promise<Unit> &&promise) {
TRY_RESULT_PROMISE(promise, input_user, get_media_preview_bot_input_user(bot_user_id, true));
TRY_STATUS_PROMISE(promise, validate_bot_language_code(language_code));
vector<telegram_api::object_ptr<telegram_api::InputMedia>> input_medias;
for (auto file_id : file_ids) {
auto input_media = get_fake_input_media(FileId(file_id, 0));
if (input_media == nullptr) {
return promise.set_error(Status::Error(400, "Wrong media to delete specified"));
}
input_medias.push_back(std::move(input_media));
}
td_->create_handler<DeletePreviewMediaQuery>(std::move(promise))
->send(bot_user_id, std::move(input_user), language_code, std::move(input_medias));
}
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));

View File

@ -55,6 +55,9 @@ class BotInfoManager final : public Actor {
td_api::object_ptr<td_api::InputStoryContent> &&input_content,
Promise<td_api::object_ptr<td_api::StoryContent>> &&promise);
void delete_bot_media_previews(UserId bot_user_id, const string &language_code, const vector<int32> &file_ids,
Promise<Unit> &&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);

View File

@ -7897,23 +7897,33 @@ void Td::on_request(uint64 id, td_api::sendWebAppCustomRequest &request) {
}
void Td::on_request(uint64 id, const td_api::getBotMediaPreviews &request) {
CHECK_IS_USER();
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::addBotMediaPreview &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
bot_info_manager_->add_bot_media_preview(UserId(request.bot_user_id_), request.language_code_,
std::move(request.content_), std::move(promise));
}
void Td::on_request(uint64 id, td_api::editBotMediaPreview &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
bot_info_manager_->edit_bot_media_preview(UserId(request.bot_user_id_), request.language_code_,
FileId(request.file_id_, 0), std::move(request.content_),
std::move(promise));
}
void Td::on_request(uint64 id, const td_api::deleteBotMediaPreviews &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
bot_info_manager_->delete_bot_media_previews(UserId(request.bot_user_id_), request.language_code_, request.file_ids_,
std::move(promise));
}
void Td::on_request(uint64 id, td_api::setBotName &request) {
CLEAN_INPUT_STRING(request.name_);
CREATE_OK_REQUEST_PROMISE();

View File

@ -1463,6 +1463,8 @@ class Td final : public Actor {
void on_request(uint64 id, td_api::editBotMediaPreview &request);
void on_request(uint64 id, const td_api::deleteBotMediaPreviews &request);
void on_request(uint64 id, td_api::setBotName &request);
void on_request(uint64 id, const td_api::getBotName &request);

View File

@ -6596,6 +6596,13 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::editBotMediaPreview>(
bot_user_id, language_code, file_id,
td_api::make_object<td_api::inputStoryContentVideo>(as_input_file(video), Auto(), 0.0, 1.5, true)));
} else if (op == "dbmp") {
UserId bot_user_id;
string language_code;
string file_ids;
get_args(args, bot_user_id, language_code, file_ids);
send_request(td_api::make_object<td_api::deleteBotMediaPreviews>(bot_user_id, language_code,
to_integers<int32>(file_ids)));
} else if (op == "gbi") {
UserId bot_user_id;
string language_code;