From c944357716b46be75ddbb96d840c00d571302b24 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 3 Jul 2026 12:04:45 +0300 Subject: Support rich messages in get_input_media. --- telegram-bot-api/Client.cpp | 24 +++++++++++++++++++++--- telegram-bot-api/Client.h | 5 ++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 71d1ff7..62f17db 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -12262,6 +12262,13 @@ td::Result> Client::get_input_video( supports_streaming); } +td::Result> Client::get_input_voice_note( + const td::JsonObject &object, object_ptr &&input_file) { + TRY_RESULT(duration, object.get_optional_int_field("duration")); + duration = td::clamp(duration, 0, MAX_DURATION); + return make_object(std::move(input_file), duration, td::string()); +} + td::Result> Client::get_input_checklist_task( td::JsonValue &&input_task) const { if (input_task.type() != td::JsonValue::Type::Object) { @@ -12350,13 +12357,14 @@ td::Result> Client::get_input_me TRY_RESULT(has_spoiler, object.get_optional_bool_field("has_spoiler")); TRY_RESULT(type, object.get_required_string_field("type")); - return get_input_media(query, object, type, std::move(caption), show_caption_above_media, has_spoiler, for_album); + return get_input_media(query, object, type, std::move(caption), show_caption_above_media, has_spoiler, for_album, + false); } td::Result> Client::get_input_media( const Query *query, const td::JsonObject &object, const td::string &type, - object_ptr &&caption, bool show_caption_above_media, bool has_spoiler, - bool for_album) const { + object_ptr &&caption, bool show_caption_above_media, bool has_spoiler, bool for_album, + bool for_rich_message) const { TRY_RESULT(media, object.get_optional_string_field("media")); auto input_file = get_input_file(query, td::Slice(), media, false); @@ -12388,12 +12396,22 @@ td::Result> Client::get_input_me return make_object(std::move(input_audio), std::move(caption)); } if (type == "document") { + if (for_rich_message) { + return td::Status::Error(PSLICE() << "type \"" << type << "\" is not allowed"); + } TRY_RESULT(disable_content_type_detection, object.get_optional_bool_field("disable_content_type_detection")); return make_object( make_object(std::move(input_file), std::move(input_thumbnail), disable_content_type_detection || for_album), std::move(caption)); } + if (type == "voice_note") { + if (!for_rich_message) { + return td::Status::Error(PSLICE() << "type \"" << type << "\" is not allowed"); + } + TRY_RESULT(input_voice_note, get_input_voice_note(object, std::move(input_file))); + return make_object(std::move(input_voice_note), std::move(caption), nullptr); + } return td::Status::Error(PSLICE() << "type \"" << type << "\" is unsupported"); } diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index bc7b1e7..fe3dd5c 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -692,6 +692,9 @@ class Client final : public WebhookActor::Callback { const Query *query, const td::JsonObject &object, object_ptr &&input_file, object_ptr &&input_thumbnail) const; + static td::Result> get_input_voice_note( + const td::JsonObject &object, object_ptr &&input_file); + td::Result> get_input_checklist_task(td::JsonValue &&input_task) const; td::Result>> get_input_checklist_tasks(td::JsonValue &&value) const; @@ -708,7 +711,7 @@ class Client final : public WebhookActor::Callback { const td::string &type, object_ptr &&caption, bool show_caption_above_media, bool has_spoiler, - bool for_album) const; + bool for_album, bool for_rich_message) const; td::Result> get_input_media(const Query *query, td::Slice field_name) const; -- cgit v1.2.3