aiogram/aiogram/client/session/middlewares/base.py
Alex Root Junior 286cf39c8a
Beta 3 (#884)
* Rework middlewares, separate management to `MiddlewareManager` class

* Rework middlewares

* Added changes description for redis

* Added changes description for redis

* Fixed tests with Redis // aioredis replacement

* Changed msg.<html/md>_text attributes behaviour

* Added changelog for spoilers

* Added possibility to get command magic result as handler arguments
2022-04-16 19:07:32 +03:00

45 lines
1.2 KiB
Python

from __future__ import annotations
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, Awaitable, Callable, Union
from aiogram.methods import Response, TelegramMethod
from aiogram.methods.base import TelegramType
if TYPE_CHECKING:
from ...bot import Bot
NextRequestMiddlewareType = Callable[
["Bot", TelegramMethod[TelegramType]], Awaitable[Response[TelegramType]]
]
RequestMiddlewareType = Union[
"BaseRequestMiddleware",
Callable[
[NextRequestMiddlewareType[TelegramType], "Bot", TelegramMethod[TelegramType]],
Awaitable[Response[TelegramType]],
],
]
class BaseRequestMiddleware(ABC):
"""
Generic middleware class
"""
@abstractmethod
async def __call__(
self,
make_request: NextRequestMiddlewareType[TelegramType],
bot: "Bot",
method: TelegramMethod[TelegramType],
) -> Response[TelegramType]:
"""
Execute middleware
:param make_request: Wrapped make_request in middlewares chain
:param bot: bot for request making
:param method: Request method (Subclass of :class:`aiogram.methods.base.TelegramMethod`)
:return: :class:`aiogram.methods.Response`
"""
pass