File size: 1,220 Bytes
222f19c
0d44831
350b6eb
41fd54e
350b6eb
0d44831
3cedaf4
3140238
3cedaf4
0d44831
3cedaf4
41fd54e
 
 
 
3cedaf4
 
 
 
 
 
 
4b81f85
3cedaf4
ffdffe9
41fd54e
3cedaf4
 
 
 
 
 
 
 
 
41fd54e
 
3cedaf4
 
 
 
 
 
 
 
 
 
 
 
350b6eb
222f19c
3cedaf4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# 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)