Source code for litegram.dispatcher.middlewares.base
from __future__ import annotations
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, Any
from litegram.types import TelegramObject
if TYPE_CHECKING:
from collections.abc import Awaitable, Callable
[docs]
class BaseMiddleware[T: TelegramObject](ABC):
"""
Generic middleware class
"""
[docs]
@abstractmethod
async def __call__(
self,
handler: Callable[[T, dict[str, Any]], Awaitable[Any]],
event: T,
data: dict[str, Any],
) -> Any: # pragma: no cover
"""
Execute middleware
:param handler: Wrapped handler in middlewares chain
:param event: Incoming event (Subclass of :class:`litegram.types.base.TelegramObject`)
:param data: Contextual data. Will be mapped to handler arguments
:return: :class:`Any`
"""