mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 18:19:34 +00:00
Add docs for class-based handlers
This commit is contained in:
parent
b82a1a6fb0
commit
62bce34b49
6 changed files with 61 additions and 4 deletions
25
docs/dispatcher/class_based_handlers/message.md
Normal file
25
docs/dispatcher/class_based_handlers/message.md
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# MessageHandler
|
||||
|
||||
There is base class for message handlers.
|
||||
|
||||
## Simple usage:
|
||||
```pyhton3
|
||||
from aiogram.handlers import MessageHandler
|
||||
|
||||
...
|
||||
|
||||
@router.message_handler()
|
||||
class MyTestMessageHandler(MessageHandler):
|
||||
filters = [Text(text="test")]
|
||||
|
||||
async def handle() -> Any:
|
||||
return SendMessage(chat_id=self.chat.id, text="PASS")
|
||||
|
||||
```
|
||||
|
||||
## Extension
|
||||
|
||||
This base handler is subclass of [BaseHandler](basics.md#basehandler) with some extensions:
|
||||
|
||||
- `self.chat` is alias for `self.event.chat`
|
||||
- `self.from_user` is alias for `self.event.from_user`
|
||||
Loading…
Add table
Add a link
Reference in a new issue