diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index b383f824..7aa7d6d2 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -846,7 +846,7 @@ personalDetails first_name:string last_name:string birthdate:date gender:string //@description An identity document @number Document's number; 1-24 characters @expiry_date Document's expiry date; may be null @files List of files with the document images @selfie Selfie with the document; may be null identityDocument number:string expiry_date:date files:vector selfie:datedFile = IdentityDocument; -//@description An identity document to save @number Document's number @expiry_date Document's expiry date, if available @files List of files with the document images @selfie Selfie with the document, if available +//@description An identity document to save @number Document's number @expiry_date Document's expiry date, if available @files List of files with the document images; must be non-empty @selfie Selfie with the document, if available inputIdentityDocument number:string expiry_date:date files:vector selfie:InputFile = InputIdentityDocument; diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 5d5e99e6..b85b617b 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -18,6 +18,7 @@ #include "td/net/HttpQuery.h" #include "td/net/HttpReader.h" +#include "td/utils/base64.h" #include "td/utils/buffer.h" #include "td/utils/BufferedFd.h" #include "td/utils/FileLog.h" @@ -448,11 +449,30 @@ class CliClient final : public Actor { return make_tl_object(trim(std::move(path))); } + static tl_object_ptr as_remote_file(string id) { + return make_tl_object(trim(std::move(id))); + } + static tl_object_ptr as_generated_file(string original_path, string conversion, int32 expected_size = 0) { return make_tl_object(trim(original_path), trim(conversion), expected_size); } + static tl_object_ptr as_input_file(string str) { + if ((str.size() >= 20 && is_base64(str)) || begins_with(str, "http")) { + return as_remote_file(str); + } + auto r_id = to_integer_safe(trim(str)); + if (r_id.is_ok()) { + return as_input_file_id(str); + } + if (str.find(';') < str.size()) { + auto res = split(str, ';'); + return as_generated_file(res.first, res.second); + } + return as_local_file(str); + } + static tl_object_ptr as_location(string latitude, string longitude) { return make_tl_object(to_double(latitude), to_double(longitude)); } @@ -945,6 +965,15 @@ class CliClient final : public Actor { if (passport_data_type == "pd") { return make_tl_object(); } + if (passport_data_type == "dl") { + return make_tl_object(); + } + if (passport_data_type == "ic") { + return make_tl_object(); + } + if (passport_data_type == "ra") { + return make_tl_object(); + } return make_tl_object(); } @@ -952,10 +981,20 @@ class CliClient final : public Actor { return transform(full_split(types, delimiter), [](Slice str) { return as_passport_data_type(str); }); } - static tl_object_ptr as_input_passport_data(string passport_data_type, string arg) { - vector> files; + static tl_object_ptr as_input_passport_data(string passport_data_type, string arg, + bool with_selfie) { + vector> input_files; + td_api::object_ptr selfie; if (!arg.empty()) { - files.push_back(make_tl_object(arg)); + auto files = full_split(arg); + CHECK(!files.empty()); + if (with_selfie) { + selfie = as_input_file(files.back()); + files.pop_back(); + } + for (auto file : files) { + input_files.push_back(as_input_file(file)); + } } if (passport_data_type == "address" || passport_data_type == "a") { return make_tl_object( @@ -969,9 +1008,12 @@ class CliClient final : public Actor { "Mike", "Towers", make_tl_object(29, 2, 2000), "male", "US")); } else if (passport_data_type == "driver_license" || passport_data_type == "dl") { return make_tl_object(make_tl_object( - "1234567890", make_tl_object(1, 3, 2029), std::move(files), nullptr)); + "1234567890", make_tl_object(1, 3, 2029), std::move(input_files), std::move(selfie))); + } else if (passport_data_type == "identity_card" || passport_data_type == "ic") { + return make_tl_object(make_tl_object( + "1234567890", nullptr, std::move(input_files), std::move(selfie))); } else if (passport_data_type == "rental_aggrement" || passport_data_type == "ra") { - return make_tl_object(std::move(files)); + return make_tl_object(std::move(input_files)); } LOG(ERROR) << "Unsupported passport data type " << passport_data_type; @@ -1142,13 +1184,14 @@ class CliClient final : public Actor { } else if (op == "gapd") { string password = args; send_request(make_tl_object(password)); - } else if (op == "spd") { + } else if (op == "spd" || op == "spds") { string password; string passport_data_type; string arg; std::tie(password, args) = split(args); std::tie(passport_data_type, arg) = split(args); - send_request(make_tl_object(as_input_passport_data(passport_data_type, arg), password)); + send_request(make_tl_object( + as_input_passport_data(passport_data_type, arg, op == "spds"), password)); } else if (op == "dpd") { string passport_data_type = args; send_request(make_tl_object(as_passport_data_type(passport_data_type))); @@ -2321,16 +2364,15 @@ class CliClient final : public Actor { string url; std::tie(chat_id, url) = split(args); - send_message(chat_id, make_tl_object( - td_api::make_object(url, "#url#", 0), nullptr, 0, 0, 0, - as_caption(""))); + send_message(chat_id, make_tl_object(as_generated_file(url, "#url#"), nullptr, 0, + 0, 0, as_caption(""))); } else if (op == "sanurl2") { string chat_id; string url; std::tie(chat_id, url) = split(args); - send_message(chat_id, make_tl_object( - td_api::make_object(url), nullptr, 0, 0, 0, as_caption(""))); + send_message(chat_id, make_tl_object(as_remote_file(url), nullptr, 0, 0, 0, + as_caption(""))); } else if (op == "sau") { string chat_id; string audio_path;