Add sendPaidMedia.

This commit is contained in:
levlam 2024-06-30 14:16:49 +03:00
parent 4fe3ba9c99
commit 5e11cbe53e
2 changed files with 50 additions and 0 deletions

View File

@ -223,6 +223,7 @@ bool Client::init_methods() {
methods_.emplace("sendvideo", &Client::process_send_video_query);
methods_.emplace("sendvideonote", &Client::process_send_video_note_query);
methods_.emplace("sendvoice", &Client::process_send_voice_query);
methods_.emplace("sendpaidmedia", &Client::process_send_paid_media_query);
methods_.emplace("sendgame", &Client::process_send_game_query);
methods_.emplace("sendinvoice", &Client::process_send_invoice_query);
methods_.emplace("sendlocation", &Client::process_send_location_query);
@ -9550,6 +9551,37 @@ td::Result<td_api::object_ptr<td_api::inputPaidMedia>> Client::get_input_paid_me
return r_input_paid_media.move_as_ok();
}
td::Result<td::vector<td_api::object_ptr<td_api::inputPaidMedia>>> Client::get_paid_media(const Query *query,
td::Slice field_name) const {
TRY_RESULT(media, get_required_string_arg(query, field_name));
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, "Can't parse paid media JSON object");
}
return get_paid_media(query, r_value.move_as_ok());
}
td::Result<td::vector<td_api::object_ptr<td_api::inputPaidMedia>>> Client::get_paid_media(const Query *query,
td::JsonValue &&value) const {
if (value.type() != td::JsonValue::Type::Array) {
return td::Status::Error(400, "Expected an Array of InputPaidMedia");
}
td::vector<object_ptr<td_api::inputPaidMedia>> paid_media;
for (auto &input_media : value.get_array()) {
auto r_paid_media = get_input_paid_media(query, std::move(input_media));
if (r_paid_media.is_error()) {
return td::Status::Error(400, PSLICE() << "Can't parse InputPaidMedia: " << r_paid_media.error().message());
}
paid_media.push_back(r_paid_media.move_as_ok());
}
return std::move(paid_media);
}
td::Result<td_api::object_ptr<td_api::inputMessageInvoice>> Client::get_input_message_invoice(
const Query *query) const {
TRY_RESULT(title, get_required_string_arg(query, "title"));
@ -10255,6 +10287,17 @@ td::Status Client::process_send_voice_query(PromisedQueryPtr &query) {
return td::Status::OK();
}
td::Status Client::process_send_paid_media_query(PromisedQueryPtr &query) {
int32 star_count = get_integer_arg(query.get(), "star_count", 0, 0, 1000000000);
TRY_RESULT(paid_media, get_paid_media(query.get(), "media"));
TRY_RESULT(caption, get_caption(query.get()));
auto show_caption_above_media = to_bool(query->arg("show_caption_above_media"));
do_send_message(make_object<td_api::inputMessagePaidMedia>(star_count, std::move(paid_media), std::move(caption),
show_caption_above_media),
std::move(query));
return td::Status::OK();
}
td::Status Client::process_send_game_query(PromisedQueryPtr &query) {
TRY_RESULT(game_short_name, get_required_string_arg(query.get(), "game_short_name"));
do_send_message(make_object<td_api::inputMessageGame>(my_id_, game_short_name.str()), std::move(query));

View File

@ -575,6 +575,12 @@ class Client final : public WebhookActor::Callback {
td::Result<object_ptr<td_api::inputPaidMedia>> get_input_paid_media(const Query *query, td::Slice field_name) const;
td::Result<td::vector<object_ptr<td_api::inputPaidMedia>>> get_paid_media(const Query *query,
td::Slice field_name) const;
td::Result<td::vector<object_ptr<td_api::inputPaidMedia>>> get_paid_media(const Query *query,
td::JsonValue &&value) const;
td::Result<object_ptr<td_api::inputMessageInvoice>> get_input_message_invoice(const Query *query) const;
static object_ptr<td_api::messageSendOptions> get_message_send_options(bool disable_notification,
@ -642,6 +648,7 @@ class Client final : public WebhookActor::Callback {
td::Status process_send_video_query(PromisedQueryPtr &query);
td::Status process_send_video_note_query(PromisedQueryPtr &query);
td::Status process_send_voice_query(PromisedQueryPtr &query);
td::Status process_send_paid_media_query(PromisedQueryPtr &query);
td::Status process_send_game_query(PromisedQueryPtr &query);
td::Status process_send_invoice_query(PromisedQueryPtr &query);
td::Status process_send_location_query(PromisedQueryPtr &query);