mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 02:03:04 +00:00
More class based handlers
This commit is contained in:
parent
b144332287
commit
895b727ddf
24 changed files with 506 additions and 30 deletions
|
|
@ -7,11 +7,16 @@ There are some base class based handlers what you need to use in your own handle
|
|||
|
||||
- [BaseHandler](#basehandler)
|
||||
- [MessageHandler](message.md)
|
||||
|
||||
- [CallbackQueryHandler](callback_query.md)
|
||||
- [ChosenInlineResultHandler](chosen_inline_result.md)
|
||||
- [InlineQueryHandler](inline_query.md)
|
||||
- [PollHandler](poll.md)
|
||||
- [PreCheckoutQueryHandler](pre_checkout_query.md)
|
||||
- [ShippingQueryHandler](shipping_query.md)
|
||||
|
||||
## BaseHandler
|
||||
|
||||
Base handler is abstract class and should be used in all other class-based handlers.
|
||||
Base handler is generic abstract class and should be used in all other class-based handlers.
|
||||
|
||||
Import: `#!python3 from aiogram.hanler import BaseHandler`
|
||||
|
||||
|
|
@ -21,3 +26,11 @@ 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: `event: TelegramEvent` and `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.
|
||||
|
||||
|
||||
### For example:
|
||||
```python3
|
||||
class MyHandler(BaseHandler[Message]):
|
||||
async def handle(self) -> Any:
|
||||
await self.event.answer("Hello!")
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue