JairoDanielMT commited on
Commit
3ffbfe0
·
verified ·
1 Parent(s): c26b7d8

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +5 -8
main.py CHANGED
@@ -1,17 +1,14 @@
1
- import threading
2
  from fastapi import FastAPI
3
  from core.integrations.telegram_bot import start_bot
 
4
 
5
  app = FastAPI()
6
 
7
- def run_telegram_bot():
8
- start_bot()
9
-
10
- # Lanzar bot Telegram en hilo aparte para no bloquear FastAPI
11
- bot_thread = threading.Thread(target=run_telegram_bot, daemon=True)
12
- bot_thread.start()
13
 
14
  @app.get("/")
15
  async def root():
16
  return {"status": "Bot de Telegram activo"}
17
-
 
 
1
  from fastapi import FastAPI
2
  from core.integrations.telegram_bot import start_bot
3
+ import asyncio
4
 
5
  app = FastAPI()
6
 
7
+ @app.on_event("startup")
8
+ async def on_startup():
9
+ # Ejecuta el bot como una tarea asincrónica en el mismo event loop
10
+ asyncio.create_task(start_bot())
 
 
11
 
12
  @app.get("/")
13
  async def root():
14
  return {"status": "Bot de Telegram activo"}