diff --git a/src/quickbot_faststream/__init__.py b/src/quickbot_faststream/__init__.py index 7690dce..06d7ac1 100644 --- a/src/quickbot_faststream/__init__.py +++ b/src/quickbot_faststream/__init__.py @@ -1,3 +1,3 @@ from .main import FaststreamPlugin -__all__ = ["FaststreamPlugin"] \ No newline at end of file +__all__ = ["FaststreamPlugin"] diff --git a/src/quickbot_faststream/config.py b/src/quickbot_faststream/config.py index af791af..12c15fb 100644 --- a/src/quickbot_faststream/config.py +++ b/src/quickbot_faststream/config.py @@ -1,4 +1,3 @@ -from pydantic import Field from pydantic_settings import BaseSettings, SettingsConfigDict @@ -7,6 +6,14 @@ class Config(BaseSettings): env_file=".env", env_ignore_empty=True, extra="ignore" ) - RABBITMQ_URL: str + RABBITMQ_HOST: str + RABBITMQ_PORT: int + RABBITMQ_USER: str + RABBITMQ_PASSWORD: str -config = Config() \ No newline at end of file + @property + def RABBITMQ_URI(self) -> str: + return f"amqp://{self.RABBITMQ_USER}:{self.RABBITMQ_PASSWORD}@{self.RABBITMQ_HOST}:{self.RABBITMQ_PORT}/" + + +config = Config() diff --git a/src/quickbot_faststream/main.py b/src/quickbot_faststream/main.py index 2dd0b5b..083e976 100644 --- a/src/quickbot_faststream/main.py +++ b/src/quickbot_faststream/main.py @@ -1,5 +1,4 @@ from aiogram.types import Update -from typing import Literal from fastapi import Depends, Request, Response from fastapi.datastructures import State from faststream.rabbit.fastapi import ContextRepo @@ -16,6 +15,7 @@ from .utils import override_route logger = getLogger(__name__) + async def telegram_webhook( request: Request, ): @@ -52,11 +52,11 @@ class FaststreamPlugin: self.broker_router = None def register(self, app: QuickBot) -> None: - self.broker_router = RabbitRouter( - url=config.RABBITMQ_URL + self.broker_router = RabbitRouter(url=config.RABBITMQ_URI) + + @self.broker_router.subscriber( + queue=f"{app.config.STACK_NAME}.telegram_updates", no_reply=True ) - - @self.broker_router.subscriber(queue=f"{app.config.STACK_NAME}.telegram_updates", no_reply=True) async def telegram_updates_handler( message: dict, db_session: Annotated[AsyncSession, Depends(get_db)], @@ -83,4 +83,3 @@ class FaststreamPlugin: app.include_router(self.broker_router) override_route(app, name="telegram_webhook", new_endpoint=telegram_webhook) - \ No newline at end of file diff --git a/src/quickbot_faststream/utils.py b/src/quickbot_faststream/utils.py index 7b2172a..d592573 100644 --- a/src/quickbot_faststream/utils.py +++ b/src/quickbot_faststream/utils.py @@ -1,7 +1,8 @@ from typing import Callable, Optional -from fastapi import FastAPI, APIRouter +from fastapi import FastAPI from fastapi.routing import APIRoute + def override_route( app: FastAPI, *, @@ -39,4 +40,4 @@ def override_route( response_model_exclude_defaults=found.response_model_exclude_defaults, response_model_exclude_none=found.response_model_exclude_none, openapi_extra=found.openapi_extra, - ) \ No newline at end of file + )