diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 2065590..db14d10 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -42,6 +42,9 @@ fi if [ -n "$TELEGRAM_RELATIVE" ]; then CUSTOM_ARGS="${CUSTOM_ARGS} --relative" fi +if [ -n "$TELEGRAM_MAX_BATCH" ]; then + CUSTOM_ARGS="${CUSTOM_ARGS} ---max-batch-operations=$TELEGRAM_MAX_BATCH" +fi COMMAND="telegram-bot-api ${DEFAULT_ARGS}${CUSTOM_ARGS}" diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 674fbbc..c1d7a0b 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -7470,6 +7470,10 @@ td::Status Client::process_delete_messages_query(PromisedQueryPtr &query) { return Status::Error(400, "Initial message identifier is not lower than last message identifier"); } + if (static_cast(end-start) > parameters_->max_batch_operations) { + return Status::Error(400, PSLICE() << "Too many operations: maximum number of batch operation is " << parameters_->max_batch_operations); + } + check_chat(chat_id, AccessRights::Write, std::move(query), [this, start, end](int64 chat_id, PromisedQueryPtr query) { if (get_chat_type(chat_id) != ChatType::Supergroup) { return fail_query(400, "Bad Request: method is available only for supergroups", std::move(query)); diff --git a/telegram-bot-api/ClientParameters.h b/telegram-bot-api/ClientParameters.h index e08fbff..276b741 100644 --- a/telegram-bot-api/ClientParameters.h +++ b/telegram-bot-api/ClientParameters.h @@ -64,6 +64,7 @@ struct ClientParameters { td::int32 default_max_webhook_connections_ = 0; td::IPAddress webhook_proxy_ip_address_; + td::uint32 max_batch_operations = 10000; double start_timestamp_ = 0; td::ActorId get_host_by_name_actor_id_; diff --git a/telegram-bot-api/telegram-bot-api.cpp b/telegram-bot-api/telegram-bot-api.cpp index 889a80e..1405987 100644 --- a/telegram-bot-api/telegram-bot-api.cpp +++ b/telegram-bot-api/telegram-bot-api.cpp @@ -238,6 +238,9 @@ int main(int argc, char *argv[]) { options.add_checked_option('c', "max-connections", "maximum number of open file descriptors", td::OptionParser::parse_integer(max_connections)); + options.add_checked_option('\0', "max-batch-operations", PSLICE() << "maximum number of batch operations (default: " << parameters->max_batch_operations << ")", + td::OptionParser::parse_integer(parameters->max_batch_operations)); + options.add_checked_option( '\0', "proxy", PSLICE() << "HTTP proxy server for outgoing webhook requests in the format http://host:port", [&](td::Slice address) {