File size: 959 Bytes
222f19c
350b6eb
 
3140238
ffdffe9
350b6eb
222f19c
ffdffe9
 
3140238
ffdffe9
 
222f19c
ffdffe9
4b81f85
350b6eb
 
ffdffe9
 
4b81f85
350b6eb
ffdffe9
 
 
 
 
 
 
 
 
 
 
 
 
 
350b6eb
222f19c
ffdffe9
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
# main.py
import logging
import asyncio
from fastapi import FastAPI
from fastapi.responses import JSONResponse
import uvicorn

import bot  # import your bot.py (it already starts Dispatcher there)
import db_utils

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

app = FastAPI()

@app.on_event("startup")
async def on_startup():
    logger.info("Starting bot polling in background...")
    asyncio.create_task(bot.run_polling())

@app.get("/health")
async def health_check():
    return JSONResponse({
        "status": "ok",
        "workers": bot.config.CONCURRENT_WORKERS,
        "active_batches": len(bot.BATCH_JOBS),
        "active_users": await db_utils.get_all_active_user_ids_db(),
    })

@app.get("/")
async def root_page():
    return JSONResponse({
        "message": "🚀 TeraBox Bot is running.",
        "endpoints": ["/health"],
    })

if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=7860)