Add td_api::editBotMediaPreview.
This commit is contained in:
parent
c3ded2ade5
commit
e8b477a3e3
@ -10630,6 +10630,13 @@ getBotMediaPreviews bot_user_id:int53 = BotMediaPreviews;
|
||||
//@content Content of the added preview
|
||||
addBotMediaPreview bot_user_id:int53 language_code:string content:InputStoryContent = StoryContent;
|
||||
|
||||
//@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
|
||||
//@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 Sets the name of a bot. Can be called only if userTypeBot.can_be_edited == true
|
||||
//@bot_user_id Identifier of the target bot
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "td/utils/Status.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <type_traits>
|
||||
|
||||
namespace td {
|
||||
|
||||
@ -157,13 +158,27 @@ class BotInfoManager::AddPreviewMediaQuery final : public Td::ResultHandler {
|
||||
CHECK(input_file != nullptr);
|
||||
auto input_media = get_story_content_input_media(td_, content, std::move(input_file));
|
||||
CHECK(input_media != nullptr);
|
||||
send_query(G()->net_query_creator().create(
|
||||
telegram_api::bots_addPreviewMedia(std::move(input_user), pending_preview_->language_code_,
|
||||
std::move(input_media)),
|
||||
{{pending_preview_->bot_user_id_}}));
|
||||
if (pending_preview_->edited_file_id_.is_valid()) {
|
||||
auto edited_input_media = td_->bot_info_manager_->get_fake_input_media(pending_preview_->edited_file_id_);
|
||||
if (edited_input_media == nullptr) {
|
||||
return on_error(Status::Error(400, "Wrong media to edit specified"));
|
||||
}
|
||||
send_query(G()->net_query_creator().create(
|
||||
telegram_api::bots_editPreviewMedia(std::move(input_user), pending_preview_->language_code_,
|
||||
std::move(edited_input_media), std::move(input_media)),
|
||||
{{pending_preview_->bot_user_id_}}));
|
||||
} else {
|
||||
send_query(G()->net_query_creator().create(
|
||||
telegram_api::bots_addPreviewMedia(std::move(input_user), pending_preview_->language_code_,
|
||||
std::move(input_media)),
|
||||
{{pending_preview_->bot_user_id_}}));
|
||||
}
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
static_assert(std::is_same<telegram_api::bots_addPreviewMedia::ReturnType,
|
||||
telegram_api::bots_editPreviewMedia::ReturnType>::value,
|
||||
"");
|
||||
auto result_ptr = fetch_result<telegram_api::bots_addPreviewMedia>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
@ -582,7 +597,28 @@ void BotInfoManager::add_bot_media_preview(UserId bot_user_id, const string &lan
|
||||
pending_preview->bot_user_id_ = bot_user_id;
|
||||
pending_preview->language_code_ = language_code;
|
||||
pending_preview->content_ = dup_story_content(td_, content.get());
|
||||
pending_preview->upload_order_ = bot_media_preview_upload_order_;
|
||||
pending_preview->upload_order_ = ++bot_media_preview_upload_order_;
|
||||
pending_preview->promise_ = std::move(promise);
|
||||
|
||||
do_add_bot_media_preview(std::move(pending_preview), {});
|
||||
}
|
||||
|
||||
void BotInfoManager::edit_bot_media_preview(UserId bot_user_id, const string &language_code, FileId file_id,
|
||||
td_api::object_ptr<td_api::InputStoryContent> &&input_content,
|
||||
Promise<td_api::object_ptr<td_api::StoryContent>> &&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));
|
||||
TRY_RESULT_PROMISE(promise, content, get_input_story_content(td_, std::move(input_content), DialogId(bot_user_id)));
|
||||
auto input_media = get_fake_input_media(file_id);
|
||||
if (input_media == nullptr) {
|
||||
return promise.set_error(Status::Error(400, "Wrong media to edit specified"));
|
||||
}
|
||||
auto pending_preview = make_unique<PendingBotMediaPreview>();
|
||||
pending_preview->edited_file_id_ = file_id;
|
||||
pending_preview->bot_user_id_ = bot_user_id;
|
||||
pending_preview->language_code_ = language_code;
|
||||
pending_preview->content_ = dup_story_content(td_, content.get());
|
||||
pending_preview->upload_order_ = ++bot_media_preview_upload_order_;
|
||||
pending_preview->promise_ = std::move(promise);
|
||||
|
||||
do_add_bot_media_preview(std::move(pending_preview), {});
|
||||
|
@ -51,6 +51,10 @@ class BotInfoManager final : public Actor {
|
||||
td_api::object_ptr<td_api::InputStoryContent> &&input_content,
|
||||
Promise<td_api::object_ptr<td_api::StoryContent>> &&promise);
|
||||
|
||||
void edit_bot_media_preview(UserId bot_user_id, const string &language_code, FileId file_id,
|
||||
td_api::object_ptr<td_api::InputStoryContent> &&input_content,
|
||||
Promise<td_api::object_ptr<td_api::StoryContent>> &&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);
|
||||
@ -73,6 +77,7 @@ class BotInfoManager final : public Actor {
|
||||
class AddPreviewMediaQuery;
|
||||
|
||||
struct PendingBotMediaPreview {
|
||||
FileId edited_file_id_;
|
||||
UserId bot_user_id_;
|
||||
string language_code_;
|
||||
unique_ptr<StoryContent> content_;
|
||||
|
@ -7907,6 +7907,13 @@ void Td::on_request(uint64 id, td_api::addBotMediaPreview &request) {
|
||||
std::move(request.content_), std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::editBotMediaPreview &request) {
|
||||
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, td_api::setBotName &request) {
|
||||
CLEAN_INPUT_STRING(request.name_);
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
|
@ -1461,6 +1461,8 @@ class Td final : public Actor {
|
||||
|
||||
void on_request(uint64 id, td_api::addBotMediaPreview &request);
|
||||
|
||||
void on_request(uint64 id, td_api::editBotMediaPreview &request);
|
||||
|
||||
void on_request(uint64 id, td_api::setBotName &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::getBotName &request);
|
||||
|
@ -6578,6 +6578,24 @@ class CliClient final : public Actor {
|
||||
send_request(td_api::make_object<td_api::addBotMediaPreview>(
|
||||
bot_user_id, language_code,
|
||||
td_api::make_object<td_api::inputStoryContentVideo>(as_input_file(video), Auto(), 0.0, 1.5, true)));
|
||||
} else if (op == "ebmpp") {
|
||||
UserId bot_user_id;
|
||||
string language_code;
|
||||
FileId file_id;
|
||||
string photo;
|
||||
get_args(args, bot_user_id, language_code, file_id, photo);
|
||||
send_request(td_api::make_object<td_api::editBotMediaPreview>(
|
||||
bot_user_id, language_code, file_id,
|
||||
td_api::make_object<td_api::inputStoryContentPhoto>(as_input_file(photo), Auto())));
|
||||
} else if (op == "ebmpv") {
|
||||
UserId bot_user_id;
|
||||
string language_code;
|
||||
FileId file_id;
|
||||
string video;
|
||||
get_args(args, bot_user_id, language_code, file_id, video);
|
||||
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 == "gbi") {
|
||||
UserId bot_user_id;
|
||||
string language_code;
|
||||
|
Loading…
Reference in New Issue
Block a user