File size: 1,116 Bytes
f644bf3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from contextlib import asynccontextmanager, suppress

from fastapi import FastAPI, Response

from bot import build_application


telegram_application = None


@asynccontextmanager
async def lifespan(app: FastAPI):
    # Startup
    global telegram_application
    telegram_application = build_application()
    await telegram_application.initialize()
    await telegram_application.start()
    if telegram_application.updater:
        await telegram_application.updater.start_polling()

    yield

    # Shutdown
    if telegram_application:
        if telegram_application.updater:
            with suppress(Exception):
                await telegram_application.updater.stop()
        with suppress(Exception):
            await telegram_application.stop()
        with suppress(Exception):
            await telegram_application.shutdown()


app = FastAPI(title="Telegram Credit Card Generator Bot", lifespan=lifespan)


@app.get("/")
async def root() -> dict[str, str]:
    return {"status": "ok"}


@app.get("/healthz")
async def health() -> Response:
    return Response(content="ok", media_type="text/plain")