diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 739cdf8..a2cd9aa 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -11727,6 +11727,65 @@ td::Result> Client::get_input_me return r_input_message_content.move_as_ok(); } +td::Result> Client::get_input_poll_media(const Query *query, + td::JsonValue &&input_media, + bool for_option) const { + if (input_media.type() != td::JsonValue::Type::Object) { + if (input_media.type() == td::JsonValue::Type::Null) { + return nullptr; + } + return td::Status::Error("expected an Object"); + } + + auto &object = input_media.get_object(); + + TRY_RESULT(type, object.get_required_string_field("type")); + if (type == "location") { + TRY_RESULT(location, get_location(object)); + return make_object(std::move(location), 0, 0, 0); + } + if (type == "venue") { + TRY_RESULT(venue, get_venue(object)); + return make_object(std::move(venue)); + } + if (type != "animation" && type != "photo" && type != "video" && + (for_option ? type != "sticker" : type != "audio" && type != "document")) { + return td::Status::Error("invalid type specified"); + } + if (type == "sticker") { + TRY_RESULT(media, object.get_optional_string_field("media")); + auto input_file = get_input_file(query, td::Slice(), media, false); + if (input_file == nullptr) { + return td::Status::Error("media not found"); + } + return make_object(std::move(input_file), nullptr, 0, 0, td::string()); + } + + return get_input_media(query, object, type, nullptr, false, false, false); +} + +td::Result> Client::get_input_poll_media(const Query *query, + td::Slice field_name) const { + auto media = query->arg(field_name); + if (media.empty()) { + return nullptr; + } + + LOG(INFO) << "Parsing JSON object: " << media; + auto r_value = json_decode(media); + if (r_value.is_error()) { + LOG(INFO) << "Can't parse JSON object: " << r_value.error(); + return td::Status::Error(400, PSLICE() << "Can't parse InputPollMedia JSON object"); + } + + auto r_input_message_content = get_input_poll_media(query, r_value.move_as_ok(), false); + if (r_input_message_content.is_error()) { + return td::Status::Error(400, PSLICE() + << "Can't parse InputPollMedia: " << r_input_message_content.error().message()); + } + return r_input_message_content.move_as_ok(); +} + td::Result>> Client::get_input_message_contents( const Query *query, td::Slice field_name) const { TRY_RESULT(media, get_required_string_arg(query, field_name)); diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index 39a4e56..f2150d1 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -678,6 +678,13 @@ class Client final : public WebhookActor::Callback { td::Result> get_input_media(const Query *query, td::Slice field_name) const; + td::Result> get_input_poll_media(const Query *query, + td::JsonValue &&input_media, + bool for_option) const; + + td::Result> get_input_poll_media(const Query *query, + td::Slice field_name) const; + td::Result>> get_input_message_contents( const Query *query, td::Slice field_name) const;