File size: 579 Bytes
ec49547
 
 
eec9416
8a58abc
ec49547
 
 
 
 
 
 
eec9416
ec49547
 
 
 
 
 
 
 
 
 
 
 
0d81ef0
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
from fastapi import FastAPI
import logging

from bot_telegram import init_bot

app = FastAPI()
bot = None

@app.on_event("startup")
async def startup_event():
    """Start the Telegram bot when the FastAPI application starts."""
    global bot
    bot = init_bot()
    await bot.run()

@app.on_event("shutdown")
async def shutdown_event():
    """Stop the Telegram bot when the FastAPI application stops."""
    global bot
    if bot:
        logging.info("Stopping bot...")
        await bot.bot_stop()

@app.get("/")
def greet_json():
    return {"The bot is running": "True"}