aiogram/docs2/dispatcher/class_based_handlers/base.rst
Alex Root Junior 0e72d8e65b
[3.0] Bot API 5.1 + FSM + Utils (#525)
* Regenerate corresponding to Bot API 5.1

* Added base of FSM. Markup constructor and small refactoring

* Fix dependencies

* Fix mypy windows error

* Move StatesGroup.get_root() from meta to class

* Fixed chat and user constraints

* Update pipeline

* Remove docs pipeline

* Added GLOBAL_USER FSM strategy

* Reformat code

* Fixed Dispatcher._process_update

* Bump Bot API 5.2. Added integration with MagicFilter

* Coverage
2021-05-11 23:04:32 +03:00

26 lines
860 B
ReStructuredText

.. _cbh-base-handler:
===========
BaseHandler
===========
Base handler is generic abstract class and should be used in all other class-based handlers.
Import: :code:`from aiogram.handler import BaseHandler`
By default you will need to override only method :code:`async def handle(self) -> Any: ...`
This class is also have an default initializer and you don't need to change it.
Initializer accepts current event and all contextual data and which
can be accessed from the handler through attributes: :code:`event: TelegramEvent` and :code:`data: Dict[Any, str]`
If instance of the bot is specified in context data or current context it can be accessed through *bot* class attribute.
Example
=======
.. code-block:: python
class MyHandler(BaseHandler[Message]):
async def handle(self) -> Any:
await self.event.answer("Hello!")