BaseHandler#
Базовий обробник є загальним абстрактним класом і повинен використовуватися в усіх інших обробниках на основі класу.
Import: from aiogram.handlers import BaseHandler
За замовчуванням вам потрібно буде перевизначити лише метод async def handle(self) -> Any: ...
This class also has a default initializer and you don’t need to change it.
The initializer accepts the incoming event and all contextual data, which
can be accessed from the handler through attributes: event: TelegramEvent
and data: Dict[Any, str]
If an instance of the bot is specified in context data or current context it can be accessed through bot class attribute.
Приклад#
class MyHandler(BaseHandler[Message]):
async def handle(self) -> Any:
await self.event.answer("Hello!")