mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
* 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
45 lines
1.2 KiB
Python
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
|