aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorlevlam <levlam@telegram.org>2026-05-05 01:14:08 +0300
committerlevlam <levlam@telegram.org>2026-05-05 01:14:08 +0300
commit25e4994382ef07c8d0d061b42e89a65fae9f595e (patch)
treee66e445d6917029d8ee69aa00dc38d5b6ac123f6
parentd85ae5ad101fbb58dc88871e95b8ac4c1db188c4 (diff)
Add Client::get_input_poll_media.
-rw-r--r--telegram-bot-api/Client.cpp59
-rw-r--r--telegram-bot-api/Client.h7
2 files changed, 66 insertions, 0 deletions
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<td_api::object_ptr<td_api::InputMessageContent>> Client::get_input_me
return r_input_message_content.move_as_ok();
}
+td::Result<td_api::object_ptr<td_api::InputMessageContent>> 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<td_api::inputMessageLocation>(std::move(location), 0, 0, 0);
+ }
+ if (type == "venue") {
+ TRY_RESULT(venue, get_venue(object));
+ return make_object<td_api::inputMessageVenue>(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<td_api::inputMessageSticker>(std::move(input_file), nullptr, 0, 0, td::string());
+ }
+
+ return get_input_media(query, object, type, nullptr, false, false, false);
+}
+
+td::Result<td_api::object_ptr<td_api::InputMessageContent>> 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<td::vector<td_api::object_ptr<td_api::InputMessageContent>>> 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<object_ptr<td_api::InputMessageContent>> get_input_media(const Query *query, td::Slice field_name) const;
+ td::Result<object_ptr<td_api::InputMessageContent>> get_input_poll_media(const Query *query,
+ td::JsonValue &&input_media,
+ bool for_option) const;
+
+ td::Result<object_ptr<td_api::InputMessageContent>> get_input_poll_media(const Query *query,
+ td::Slice field_name) const;
+
td::Result<td::vector<object_ptr<td_api::InputMessageContent>>> get_input_message_contents(
const Query *query, td::Slice field_name) const;