File size: 1,389 Bytes
b2c9746
36251af
322a4b8
 
 
36251af
 
322a4b8
 
36251af
322a4b8
 
 
 
 
 
 
 
c069614
322a4b8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36251af
 
322a4b8
 
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
import os
import threading
import uvicorn
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
from bot import main as start_bot

# Define lifespan to manage startup/shutdown
from contextlib import asynccontextmanager

@asynccontextmanager
async def lifespan(app: FastAPI):
    # Startup: Run bot in background thread
    print("Starting Telegram Bot in background thread...")
    bot_thread = threading.Thread(target=start_bot, daemon=True)
    bot_thread.start()
    yield
    # Shutdown logic (if any)

app = FastAPI(lifespan=lifespan)

@app.get("/", response_class=HTMLResponse)
def home():
    return """
    <html>
        <head>
            <title>AI Quiz Bot Status</title>
            <style>
                body { font-family: sans-serif; text-align: center; padding-top: 50px; background-color: #f0f2f5; }
                .card { background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); display: inline-block; }
                h1 { color: #2e7d32; }
            </style>
        </head>
        <body>
            <div class="card">
                <h1>✅ AI Quiz Bot is Running</h1>
                <p>The bot is active and polling for updates.</p>
            </div>
        </body>
    </html>
    """

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