Fallback when local Telegram Bot API is down
This commit is contained in:
@@ -96,6 +96,7 @@ class TelegramStorageUploader:
|
||||
self.yt_dlp_timeout_sec = 300
|
||||
self.max_media_attempts = 3
|
||||
self.post_job_pause_sec = 0.2
|
||||
self.using_local_bot_api = False
|
||||
|
||||
async def init(self) -> None:
|
||||
self.pool = await get_pool()
|
||||
@@ -114,7 +115,14 @@ class TelegramStorageUploader:
|
||||
api=TelegramAPIServer.from_base(local_bot_api_url.rstrip("/"), is_local=True)
|
||||
)
|
||||
self.bot = Bot(token=settings.tg_bot_token, session=session)
|
||||
try:
|
||||
await self.bot.get_me()
|
||||
self.using_local_bot_api = True
|
||||
logger.info("Using local Telegram Bot API: {}", local_bot_api_url)
|
||||
except Exception as exc:
|
||||
logger.warning("Local Telegram Bot API unavailable at {}: {}. Falling back to cloud Bot API.", local_bot_api_url, exc)
|
||||
await self.bot.session.close()
|
||||
self.bot = Bot(token=settings.tg_bot_token)
|
||||
else:
|
||||
self.bot = Bot(token=settings.tg_bot_token)
|
||||
|
||||
@@ -127,6 +135,8 @@ class TelegramStorageUploader:
|
||||
self.text_overflow_marker = str(await fetch_setting("telegram_text_overflow_marker", self.text_overflow_marker))
|
||||
self.download_timeout_sec = max(5, await fetch_int_setting("uploader_download_timeout_sec", 45))
|
||||
self.video_max_size_mb = max(1, await fetch_int_setting("video_max_size_mb", 49))
|
||||
if not self.using_local_bot_api:
|
||||
self.video_max_size_mb = min(self.video_max_size_mb, 49)
|
||||
self.video_max_height = max(144, await fetch_int_setting("video_max_height", 720))
|
||||
self.video_max_duration_sec = max(1, await fetch_int_setting("video_max_duration_sec", 300))
|
||||
self.yt_dlp_timeout_sec = max(30, await fetch_int_setting("uploader_yt_dlp_timeout_sec", 300))
|
||||
|
||||
Reference in New Issue
Block a user