fix(bot): Telegram through TG_PROXY_URL — docker on the RF server has no IPv4 route to Telegram
CI / ruff · pytest (pull_request) Successful in 2m28s
CI / ruff · pytest (pull_request) Successful in 2m28s
Closes #108 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -19,6 +19,7 @@ from typing import Protocol
|
||||
|
||||
import yaml
|
||||
from aiogram import Bot, Dispatcher, F, Router
|
||||
from aiogram.client.session.aiohttp import AiohttpSession
|
||||
from aiogram.filters import CommandObject, CommandStart
|
||||
from aiogram.types import CallbackQuery, InlineKeyboardButton, InlineKeyboardMarkup, Message
|
||||
from pydantic import BaseModel
|
||||
@@ -272,6 +273,12 @@ _task: asyncio.Task[None] | None = None
|
||||
_prev_outbox: Outbox | None = None
|
||||
|
||||
|
||||
def make_bot(token: str) -> Bot:
|
||||
"""aiogram `Bot`, through `TG_PROXY_URL` when it is set."""
|
||||
proxy = get_settings().tg_proxy_url
|
||||
return Bot(token, session=AiohttpSession(proxy=proxy)) if proxy else Bot(token)
|
||||
|
||||
|
||||
async def start() -> None:
|
||||
"""Start polling if TG_BOT_TOKEN is set; no-op otherwise."""
|
||||
global _bot, _dp, _task, _prev_outbox
|
||||
@@ -280,7 +287,7 @@ async def start() -> None:
|
||||
if not token:
|
||||
log.info("telegram disabled: TG_BOT_TOKEN is empty")
|
||||
return
|
||||
bot = Bot(token)
|
||||
bot = make_bot(token)
|
||||
channel = TelegramChannel(bot)
|
||||
dp = Dispatcher()
|
||||
dp.include_router(build_router(channel))
|
||||
|
||||
Reference in New Issue
Block a user