aiogram icon indicating copy to clipboard operation
aiogram copied to clipboard

Adding more control on sending requests to BotAPI

Open Forden opened this issue 5 years ago • 5 comments

Is your feature request related to a problem? Please describe. Sometimes it's useful to modify, cancel or delay sending request to BotAPI.

Describe the solution you'd like Adding 2 new middleware triggers, before and after making request.

Forden avatar Apr 23 '20 19:04 Forden

@Forden, I don't quite understand why do we need request feature. Could you please provide use cases?

uwinx avatar Apr 23 '20 20:04 uwinx

@uwinx, for me the most important case is creating of "smart" outcoming queue as middleware.

Forden avatar Apr 23 '20 20:04 Forden

Delay is a bad thing! VERY BAD! You can't receive update via webhook and postpone the answer. Telegram will repeat webhook and u'll get doubled update.

If you mean delay for outcoming request, why don't you use aio.sleep()?

Olegt0rr avatar Apr 26 '20 12:04 Olegt0rr

@Olegt0rr I think he meant something like anti-flood queue. We're not allowed to send more than 30 requests per second, so this kind of "smart queue" can help us avoid these limits by throttling outgoing requests.

evgfilim1 avatar Apr 26 '20 13:04 evgfilim1

@evgfilim1 First of all, 30 rps is not a fixed limit. If your bot size doesn't fit the limit, you can ask botsupport to increase the limits.

Antiflood shoud be implemented as inbound filter so as not to damage the business logic of your application. Throttling / delaying outgoing requests can make application behavior unpredictable.

@JrooTJunior, It's up to you, but I think that it's not a good thing to make global solutions for such a private case. If some bots require a solution with throttling of outgoing requests, we can add the feature with setting custom host instead of api.telegram.org. It'll add the ability to create post-processing proxy app outside the aiogram

Olegt0rr avatar Apr 27 '20 08:04 Olegt0rr

Implemented in v3: https://docs.aiogram.dev/en/dev-3.x/api/session/middleware.html

JrooTJunior avatar Aug 04 '23 18:08 JrooTJunior