Telegram.Bot icon indicating copy to clipboard operation
Telegram.Bot copied to clipboard

Manage error 429 (too many send)

Open mahdial opened this issue 8 years ago • 7 comments

Hello, I'm using sendasync... But many time mybot got error 429. Can u add a controller to check it and prevent this error? I think you must prevent to send more than 30 message in a second. Sorry for bad english... Tnx

mahdial avatar Dec 04 '17 13:12 mahdial

I don't think that this library is the appropriate place for such functionality. It's just a wrapper around HTTP API. There could be a framework around this library and thats where it fits better. Actually soon @pouladpld's framework can be moved to the repo's organization and there we can implement 429 error handling. Though it's just my opinion and the maintainers can have a different one.

tuscen avatar Dec 04 '17 16:12 tuscen

@mahdial It might be implemented in v14 of Client. We will check this in coming weeks when Request types are in place.

here is a suggestion:

var req = new SendTextMessageRequest(chatId, "Hello, World!", cancellationToken)
{
  RetryCount = 3;
  RetryAfter = TimeSpan.FromSeconds(2)
};

try {
  await BotClient.MakeRequestAsync(req);
} catch(ApiRequestException e) {
  // log 
  throw;
}

poulad avatar Dec 04 '17 18:12 poulad

@pouladpld @Tuscen Thank you. I hope to see it in v14. For now, i want to write a code to prevent send more than 29 messages in a second. After that , i will send it here. Tnx

mahdial avatar Dec 05 '17 10:12 mahdial

Any update on this feature?

jcmag avatar Mar 06 '18 19:03 jcmag

@jcmag We'd probably implement such features in a framework package. For the time being, I'd suggest you using Polly.

poulad avatar Mar 10 '18 17:03 poulad

I didn't know Polly, it seems very useful, thanks!

jcmag avatar Mar 11 '18 12:03 jcmag

@MihaZupan suggested this https://github.com/MihaZupan/TelegramBotClients - Telegram Bot Client with message queue, that prevents hitting rate limit

karb0f0s avatar May 11 '18 18:05 karb0f0s