# main.py import logging import asyncio import uvicorn from fastapi import FastAPI from contextlib import asynccontextmanager from bot import start_bot logging.basicConfig(level=logging.INFO) logger = logging.getLogger("main") app = FastAPI() # Lifespan event for startup/shutdown (new style → no deprecation warning!) @asynccontextmanager async def lifespan(app: FastAPI): logger.info("===== Application Startup =====") # Start bot in background dp, bot = start_bot() asyncio.create_task(dp.start_polling(bot)) logger.info("Starting bot polling in background...") yield logger.info("===== Application Shutdown =====") await bot.session.close() # Set FastAPI lifespan app.router.lifespan_context = lifespan # Healthcheck endpoint @app.get("/health") async def health(): return {"status": "ok", "message": "Terabox Bot is running 🚀"} # Optionally index page @app.get("/") async def index(): return { "bot": "Terabox Downloader Bot", "version": "1.0", "health": "/health", "workers": "4", "note": "Send /start to the bot in Telegram to begin." } if __name__ == "__main__": uvicorn.run(app, host="0.0.0.0", port=7860)