From d7671c8d26e733596abac47770101313cd709349 Mon Sep 17 00:00:00 2001 From: Alexander Kalinovsky Date: Thu, 20 Mar 2025 02:00:54 +0700 Subject: [PATCH] retry register webhook --- src/qbot/main.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/qbot/main.py b/src/qbot/main.py index 00979d9..cf4d46e 100644 --- a/src/qbot/main.py +++ b/src/qbot/main.py @@ -1,3 +1,4 @@ +from asyncio import sleep from contextlib import asynccontextmanager from typing import Callable, Any from aiogram import Bot, Dispatcher @@ -194,12 +195,18 @@ class QBotApp[UserType: UserBase](FastAPI): language_code=None if locale == "default" else locale, ) - await self.bot.set_webhook( - url=f"{self.config.TELEGRAM_WEBHOOK_URL}/telegram/webhook", - drop_pending_updates=True, - allowed_updates=self.allowed_updates, - secret_token=self.bot_auth_token, - ) + while True: + try: + await self.bot.set_webhook( + url=f"{self.config.TELEGRAM_WEBHOOK_URL}/telegram/webhook", + drop_pending_updates=True, + allowed_updates=self.allowed_updates, + secret_token=self.bot_auth_token, + ) + break + except Exception: + logger.error("Error setting webhook", exc_info=True) + await sleep(5) async def bot_close(self): await self.bot.delete_webhook()