# main.py import logging import asyncio import uvicorn from fastapi import FastAPI from fastapi.responses import HTMLResponse from bot import start_bot # --- Setup --- logging.basicConfig( level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', ) logger = logging.getLogger("main") app = FastAPI() # Start bot dp, bot_instance = start_bot() @app.on_event("startup") async def startup_event(): logger.info("Starting bot polling in background...") asyncio.create_task(dp.start_polling(bot_instance)) @app.get("/", response_class=HTMLResponse) async def root(): html_content = """
You can check /health endpoint too.
""" return HTMLResponse(content=html_content) @app.get("/health") async def health(): return {"status": "ok", "bot": "running"} if __name__ == "__main__": logger.info("===== Application Startup =====") uvicorn.run("main:app", host="0.0.0.0", port=7860)