This commit is contained in:
xds
2026-03-16 14:46:20 +03:00
parent 00db55720c
commit de8c2472e2
45 changed files with 3714 additions and 140 deletions

View File

@@ -1,3 +1,5 @@
import asyncio
import logging
from contextlib import asynccontextmanager
from fastapi import FastAPI
@@ -6,12 +8,29 @@ from fastapi.middleware.cors import CORSMiddleware
from backend.app.api.router import api_router
from backend.app.core.config import settings
logger = logging.getLogger(__name__)
@asynccontextmanager
async def lifespan(app: FastAPI):
# Startup
# Start Telegram bot polling in background
bot_task = None
if settings.TELEGRAM_BOT_TOKEN:
from backend.app.bot import create_bot
bot, dp = create_bot()
bot_task = asyncio.create_task(dp.start_polling(bot))
logger.info("Telegram bot polling started")
yield
# Shutdown
if bot_task:
bot_task.cancel()
try:
await bot_task
except asyncio.CancelledError:
pass
logger.info("Telegram bot polling stopped")
app = FastAPI(