- Added notifications for successful payments in `api/core/notifications.py`. - Created main API entry point in `api/main.py` with FastAPI integration. - Established routing structure in `api/routes/__init__.py` and `api/routes/pally.py` for handling payment callbacks. - Developed billing handlers in `bot/handlers/billing.py` and `bot/handlers/buy.py` for subscription management. - Introduced state management for user interactions in `bot/states/`. - Created user interface elements in `bot/keyboards/` for navigation and payment processing. - Set up middleware for dependency injection in `bot/middlewares/di.py`. - Added support for user commands and interactions in `bot/handlers/common.py` and `bot/handlers/support.py`. - Implemented logging and error handling throughout the bot's functionality. - Created entry point script for API server in `entrypoints/api.sh`.
27 lines
807 B
Python
27 lines
807 B
Python
from collections.abc import Awaitable, Callable
|
|
from typing import Any
|
|
|
|
from aiogram import BaseMiddleware
|
|
from aiogram.types import TelegramObject
|
|
from sqlalchemy.ext.asyncio import async_sessionmaker
|
|
|
|
from schemas.di import DependenciesDTO
|
|
|
|
|
|
class DIMiddleware(BaseMiddleware):
|
|
def __init__(self, deps: DependenciesDTO, session_factory: async_sessionmaker) -> None:
|
|
self.deps = deps
|
|
self.session_factory = session_factory
|
|
|
|
async def __call__(
|
|
self,
|
|
handler: Callable[[TelegramObject, dict[str, Any]], Awaitable[Any]],
|
|
event: TelegramObject,
|
|
data: dict[str, Any],
|
|
) -> Any:
|
|
data["deps"] = self.deps
|
|
|
|
async with self.session_factory() as session:
|
|
data["session"] = session
|
|
return await handler(event, data)
|