baha-99 commited on
Commit
ec49547
·
1 Parent(s): f0c781a

fix: req.txt modified

Browse files
Files changed (2) hide show
  1. app.py +23 -12
  2. requirements.txt +5 -5
app.py CHANGED
@@ -1,15 +1,26 @@
1
- import asyncio
 
 
2
  from bot_telegram import init_bot
3
 
4
- async def main():
 
 
 
 
 
 
5
  bot = init_bot()
6
- try:
7
- await bot.run()
8
- # Keep the bot running
9
- while True:
10
- await asyncio.sleep(1)
11
- except Exception as e:
12
- print(f"Bot error: {e}")
13
-
14
- if __name__ == "__main__":
15
- asyncio.run(main())
 
 
 
 
1
+ from fastapi import FastAPI
2
+ import logging
3
+
4
  from bot_telegram import init_bot
5
 
6
+ app = FastAPI()
7
+ bot = None
8
+
9
+ @app.on_event("startup")
10
+ async def startup_event():
11
+ """Start the Telegram bot when the FastAPI application starts."""
12
+ global bot
13
  bot = init_bot()
14
+ await bot.run()
15
+
16
+ @app.on_event("shutdown")
17
+ async def shutdown_event():
18
+ """Stop the Telegram bot when the FastAPI application stops."""
19
+ global bot
20
+ if bot:
21
+ logging.info("Stopping bot...")
22
+ await bot.bot_stop()
23
+
24
+ @app.get("/")
25
+ def greet_json():
26
+ return {"Hello": "World!"}
requirements.txt CHANGED
@@ -1,5 +1,5 @@
1
- python-telegram-bot==20.7
2
- requests==2.31.0
3
- aiohttp==3.9.1
4
- fastapi==0.105.0
5
- uvicorn[standard]==0.24.0.post1
 
1
+ python-telegram-bot
2
+ requests
3
+ aiohttp
4
+ fastapi
5
+ uvicorn[standard]