Add td_api::getBotMediaPreviewInfo.
This commit is contained in:
parent
3611b7a87d
commit
61ce58b133
@ -4396,6 +4396,11 @@ publicForwards total_count:int32 forwards:vector<PublicForward> next_offset:stri
|
||||
//@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 media previews of a bot for the given language and the list of langauges for which the bot has dedicated previews
|
||||
//@previews List of media previews
|
||||
//@language_codes List of language codes for which the bot has dedicated previews
|
||||
botMediaPreviewInfo previews:vector<StoryContent> language_codes:vector<string> = BotMediaPreviewInfo;
|
||||
|
||||
|
||||
//@description Contains a list of features available on a specific chat boost level
|
||||
//@level Target chat boost level
|
||||
@ -10635,14 +10640,18 @@ 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. The bot must have the main Web App
|
||||
//@description Returns the list of media previews of a bot @bot_user_id Identifier of the target bot. The bot must have the main Web App
|
||||
getBotMediaPreviews bot_user_id:int53 = BotMediaPreviews;
|
||||
|
||||
//@description Returns the list of media previews for the given language and the list of langauges for which the bot has dedicated previews
|
||||
//@bot_user_id Identifier of the target bot. The bot must be owned and must have the main Web App
|
||||
//@language_code A two-letter ISO 639-1 language code for which to get previews. If empty, then default previews are returned
|
||||
getBotMediaPreviewInfo bot_user_id:int53 language_code:string = BotMediaPreviewInfo;
|
||||
|
||||
//@description Adds a new media preview to the beginning of the list of media previews of a bot. Returns the added preview after addition is completed server-side. The total number of previews must not exceed getOption("bot_media_preview_count_max") for the given language
|
||||
//@bot_user_id Identifier of the target bot. The bot must be owned and must have the main Web App
|
||||
//@language_code A two-letter ISO 639-1 language code for which preview is added. If empty, then the preview will be shown to all users for whose languages there are no dedicated previews.
|
||||
//-If non-empty, then there must be an official language pack with the same name as returned by getLocalizationTargetInfo
|
||||
//-If non-empty, then there must be an official language pack of the same name, which is returned by getLocalizationTargetInfo
|
||||
//@content Content of the added preview
|
||||
addBotMediaPreview bot_user_id:int53 language_code:string content:InputStoryContent = StoryContent;
|
||||
|
||||
|
@ -143,6 +143,58 @@ class GetPreviewMediasQuery final : public Td::ResultHandler {
|
||||
}
|
||||
};
|
||||
|
||||
class GetPreviewInfoQuery final : public Td::ResultHandler {
|
||||
Promise<td_api::object_ptr<td_api::botMediaPreviewInfo>> promise_;
|
||||
UserId bot_user_id_;
|
||||
string language_code_;
|
||||
|
||||
public:
|
||||
explicit GetPreviewInfoQuery(Promise<td_api::object_ptr<td_api::botMediaPreviewInfo>> &&promise)
|
||||
: promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(UserId bot_user_id, telegram_api::object_ptr<telegram_api::InputUser> input_user,
|
||||
const string &language_code) {
|
||||
bot_user_id_ = bot_user_id;
|
||||
language_code_ = language_code;
|
||||
send_query(G()->net_query_creator().create(telegram_api::bots_getPreviewInfo(std::move(input_user), language_code),
|
||||
{{bot_user_id}}));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::bots_getPreviewInfo>(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 GetPreviewInfoQuery: " << to_string(ptr);
|
||||
vector<td_api::object_ptr<td_api::StoryContent>> contents;
|
||||
vector<FileId> file_ids;
|
||||
for (auto &media_ptr : ptr->media_) {
|
||||
auto content = get_story_content(td_, std::move(media_ptr->media_), DialogId(bot_user_id_));
|
||||
if (content == nullptr) {
|
||||
LOG(ERROR) << "Receive invalid media preview for " << bot_user_id_;
|
||||
} else {
|
||||
append(file_ids, get_story_content_file_ids(td_, content.get()));
|
||||
contents.push_back(get_story_content_object(td_, content.get()));
|
||||
}
|
||||
}
|
||||
if (!file_ids.empty()) {
|
||||
// auto file_source_id = td_->bot_info_manager_->get_bot_media_preview_file_source_id(bot_user_id_);
|
||||
for (auto file_id : file_ids) {
|
||||
// td_->file_manager_->add_file_source(file_id, file_source_id);
|
||||
}
|
||||
}
|
||||
promise_.set_value(
|
||||
td_api::make_object<td_api::botMediaPreviewInfo>(std::move(contents), std::move(ptr->lang_codes_)));
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class BotInfoManager::AddPreviewMediaQuery final : public Td::ResultHandler {
|
||||
FileId file_id_;
|
||||
unique_ptr<PendingBotMediaPreview> pending_preview_;
|
||||
@ -641,6 +693,13 @@ void BotInfoManager::get_bot_media_previews(UserId bot_user_id,
|
||||
td_->create_handler<GetPreviewMediasQuery>(std::move(promise))->send(bot_user_id, std::move(input_user));
|
||||
}
|
||||
|
||||
void BotInfoManager::get_bot_media_preview_info(UserId bot_user_id, const string &language_code,
|
||||
Promise<td_api::object_ptr<td_api::botMediaPreviewInfo>> &&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));
|
||||
td_->create_handler<GetPreviewInfoQuery>(std::move(promise))->send(bot_user_id, std::move(input_user), language_code);
|
||||
}
|
||||
|
||||
void BotInfoManager::reload_bot_media_previews(UserId bot_user_id, Promise<Unit> &&promise) {
|
||||
get_bot_media_previews(
|
||||
bot_user_id, PromiseCreator::lambda([promise = std::move(promise)](
|
||||
|
@ -45,6 +45,9 @@ class BotInfoManager final : public Actor {
|
||||
|
||||
void get_bot_media_previews(UserId bot_user_id, Promise<td_api::object_ptr<td_api::botMediaPreviews>> &&promise);
|
||||
|
||||
void get_bot_media_preview_info(UserId bot_user_id, const string &language_code,
|
||||
Promise<td_api::object_ptr<td_api::botMediaPreviewInfo>> &&promise);
|
||||
|
||||
void reload_bot_media_previews(UserId bot_user_id, Promise<Unit> &&promise);
|
||||
|
||||
void add_bot_media_preview(UserId bot_user_id, const string &language_code,
|
||||
|
@ -7902,6 +7902,13 @@ void Td::on_request(uint64 id, const td_api::getBotMediaPreviews &request) {
|
||||
bot_info_manager_->get_bot_media_previews(UserId(request.bot_user_id_), std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::getBotMediaPreviewInfo &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_REQUEST_PROMISE();
|
||||
bot_info_manager_->get_bot_media_preview_info(UserId(request.bot_user_id_), request.language_code_,
|
||||
std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::addBotMediaPreview &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_REQUEST_PROMISE();
|
||||
|
@ -1459,6 +1459,8 @@ class Td final : public Actor {
|
||||
|
||||
void on_request(uint64 id, const td_api::getBotMediaPreviews &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::getBotMediaPreviewInfo &request);
|
||||
|
||||
void on_request(uint64 id, td_api::addBotMediaPreview &request);
|
||||
|
||||
void on_request(uint64 id, td_api::editBotMediaPreview &request);
|
||||
|
@ -6569,6 +6569,11 @@ class CliClient final : public Actor {
|
||||
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 == "gbmpi") {
|
||||
UserId bot_user_id;
|
||||
string language_code;
|
||||
get_args(args, bot_user_id, language_code);
|
||||
send_request(td_api::make_object<td_api::getBotMediaPreviewInfo>(bot_user_id, language_code));
|
||||
} else if (op == "abmpp") {
|
||||
UserId bot_user_id;
|
||||
string language_code;
|
||||
|
Loading…
Reference in New Issue
Block a user