This commit is contained in:
harold 2025-04-21 17:27:45 +05:00
parent caebd09c80
commit b1ee865124

View File

@ -1,7 +1,3 @@
from contextlib import asynccontextmanager
from fastapi import FastAPI
from pyrogram import Client, filters, idle
from pyrogram.handlers import MessageHandler
@ -10,26 +6,22 @@ from src.core.tg_service.messages_handler import message_listener
from src.core.rabbitmq.connect import broker, init_queue_and_publisher
tg_app = Client(
app = Client(
name=settings.ACCOUNT.NAME,
api_id=settings.ACCOUNT.API_ID,
api_hash=settings.ACCOUNT.API_HASH,
)
@asynccontextmanager
async def lifespan(fastapi_app: FastAPI):
await tg_app.start()
await broker.start()
await init_queue_and_publisher()
await idle()
yield
await tg_app.stop()
tg_app.add_handler(MessageHandler(
app.add_handler(MessageHandler(
callback=message_listener,
filters=filters.all
))
app = FastAPI(lifespan=lifespan)
async def main():
await app.start()
await broker.start()
await init_queue_and_publisher()
await idle()
await app.stop()
app.run(main())