2025-04-21 13:40:12 +05:00

36 lines
804 B
Python

from contextlib import asynccontextmanager
from fastapi import FastAPI
from pyrogram import Client, filters, idle
from pyrogram.handlers import MessageHandler
from src.core.settings.base import settings
from src.core.tg_service.messages_handler import message_listener
from src.core.rabbitmq.connect import broker, init_queue_and_publisher
tg_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(
callback=message_listener,
filters=filters.all
))
app = FastAPI(lifespan=lifespan)