fix(telegram): handle RetryAfter delay internally in channel (#2552)

This commit is contained in:
Flo 2026-04-01 09:13:08 +03:00 committed by GitHub
parent 94e6d569b3
commit ebf6201b42
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -432,7 +432,9 @@ class TelegramChannel(BaseChannel):
await self._send_text(chat_id, chunk, reply_params, thread_kwargs)
async def _call_with_retry(self, fn, *args, **kwargs):
"""Call an async Telegram API function with retry on pool/network timeout."""
"""Call an async Telegram API function with retry on pool/network timeout and RetryAfter."""
from telegram.error import RetryAfter
for attempt in range(1, _SEND_MAX_RETRIES + 1):
try:
return await fn(*args, **kwargs)
@ -445,6 +447,15 @@ class TelegramChannel(BaseChannel):
attempt, _SEND_MAX_RETRIES, delay,
)
await asyncio.sleep(delay)
except RetryAfter as e:
if attempt == _SEND_MAX_RETRIES:
raise
delay = float(e.retry_after)
logger.warning(
"Telegram Flood Control (attempt {}/{}), retrying in {:.1f}s",
attempt, _SEND_MAX_RETRIES, delay,
)
await asyncio.sleep(delay)
async def _send_text(
self,