File size: 1,150 Bytes
222f19c
0d44831
350b6eb
41fd54e
350b6eb
0d44831
41fd54e
0d44831
3140238
41fd54e
 
 
 
0d44831
 
41fd54e
 
 
 
 
 
4b81f85
350b6eb
0d44831
ffdffe9
41fd54e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
350b6eb
222f19c
41fd54e
0d44831
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
# 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 = """
    <html>
        <head><title>Terabox Bot Status</title></head>
        <body style="font-family:sans-serif;">
            <h1>✅ Terabox Bot is Running</h1>
            <p>You can check /health endpoint too.</p>
        </body>
    </html>
    """
    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)