From b10216322068553fa2f5841762c4106c429fe520 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 30 May 2022 21:32:01 +0300 Subject: [PATCH] Improve sendMediaGroup error message. --- telegram-bot-api/Client.cpp | 16 +++++++++++++--- telegram-bot-api/Client.h | 1 + 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index c30f54a..b7a87c7 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -6851,8 +6851,15 @@ void Client::on_message_send_failed(int64 chat_id, int64 old_message_id, int64 n auto query_id = extract_yet_unsent_message_query_id(chat_id, old_message_id, nullptr); auto &query = *pending_send_message_queries_[query_id]; if (query.is_multisend) { - if (query.error == nullptr) { - query.error = std::move(error); + if (query.error == nullptr || query.error->message_ == "Group send failed") { + if (error->code_ == 429 || error->message_ == "Group send failed") { + query.error = std::move(error); + } else { + auto pos = (query.total_message_count - query.awaited_message_count + 1); + query.error = make_object(error->code_, PSTRING() << "Failed to send message #" << pos + << " with the error message \"" + << error->message_ << '"'); + } } query.awaited_message_count--; @@ -8750,7 +8757,10 @@ void Client::on_sent_message(object_ptr &&message, int64 query_ auto emplace_result = yet_unsent_messages_.emplace(yet_unsent_message_id, yet_unsent_message); CHECK(emplace_result.second); yet_unsent_message_count_[chat_id]++; - pending_send_message_queries_[query_id]->awaited_message_count++; + + auto &query = *pending_send_message_queries_[query_id]; + query.awaited_message_count++; + query.total_message_count++; } void Client::abort_long_poll(bool from_set_webhook) { diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index 8bcc5c8..852c309 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -936,6 +936,7 @@ class Client final : public WebhookActor::Callback { struct PendingSendMessageQuery { PromisedQueryPtr query; bool is_multisend = false; + int32 total_message_count = 0; int32 awaited_message_count = 0; td::vector messages; object_ptr error;