mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 10:11:52 +00:00
Oops. Include lost files
This commit is contained in:
parent
8a94dde7fb
commit
66f0868f45
16 changed files with 619 additions and 0 deletions
26
docs2/dispatcher/class_based_handlers/base.rst
Normal file
26
docs2/dispatcher/class_based_handlers/base.rst
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
.. _cbh-base-handler:
|
||||
|
||||
===========
|
||||
BaseHandler
|
||||
===========
|
||||
|
||||
Base handler is generic abstract class and should be used in all other class-based handlers.
|
||||
|
||||
Import: :code:`from aiogram.hanler 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!")
|
||||
27
docs2/dispatcher/class_based_handlers/callback_query.rst
Normal file
27
docs2/dispatcher/class_based_handlers/callback_query.rst
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
====================
|
||||
CallbackQueryHandler
|
||||
====================
|
||||
|
||||
There is base class for callback query handlers.
|
||||
|
||||
Simple usage
|
||||
============
|
||||
.. code-block:: python
|
||||
|
||||
from aiogram.handlers import CallbackQueryHandler
|
||||
|
||||
...
|
||||
|
||||
@router.callback_query()
|
||||
class MyHandler(CallbackQueryHandler):
|
||||
async def handle(self) -> Any: ...
|
||||
|
||||
|
||||
Extension
|
||||
=========
|
||||
|
||||
This base handler is subclass of :ref:`BaseHandler <cbh-base-handler>` with some extensions:
|
||||
|
||||
- :code:`self.from_user` is alias for :code:`self.event.from_user`
|
||||
- :code:`self.message` is alias for :code:`self.event.message`
|
||||
- :code:`self.callback_data` is alias for :code:`self.event.data`
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
=========================
|
||||
ChosenInlineResultHandler
|
||||
=========================
|
||||
|
||||
There is base class for chosen inline result handlers.
|
||||
|
||||
Simple usage
|
||||
============
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from aiogram.handlers import ChosenInlineResultHandler
|
||||
|
||||
...
|
||||
|
||||
@router.chosen_inline_result()
|
||||
class MyHandler(ChosenInlineResultHandler):
|
||||
async def handle(self) -> Any: ...
|
||||
|
||||
|
||||
Extension
|
||||
=========
|
||||
|
||||
This base handler is subclass of :ref:`BaseHandler <cbh-base-handler>` with some extensions:
|
||||
|
||||
- :code:`self.chat` is alias for :code:`self.event.chat`
|
||||
- :code:`self.from_user` is alias for :code:`self.event.from_user`
|
||||
32
docs2/dispatcher/class_based_handlers/error.rst
Normal file
32
docs2/dispatcher/class_based_handlers/error.rst
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
============
|
||||
ErrorHandler
|
||||
============
|
||||
|
||||
There is base class for error handlers.
|
||||
|
||||
Simple usage
|
||||
============
|
||||
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from aiogram.handlers import ErrorHandler
|
||||
|
||||
...
|
||||
|
||||
@router.errors()
|
||||
class MyHandler(ErrorHandler):
|
||||
async def handle(self) -> Any:
|
||||
log.exception(
|
||||
"Cause unexpected exception %s: %s",
|
||||
self.exception_name,
|
||||
self.exception_message
|
||||
)
|
||||
|
||||
Extension
|
||||
=========
|
||||
|
||||
This base handler is subclass of :ref:`BaseHandler <cbh-base-handler>` with some extensions:
|
||||
|
||||
- :code:`self.exception_name` is alias for :code:`self.event.__class__.__name__`
|
||||
- :code:`self.exception_message` is alias for :code:`str(self.event)`
|
||||
22
docs2/dispatcher/class_based_handlers/index.rst
Normal file
22
docs2/dispatcher/class_based_handlers/index.rst
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
====================
|
||||
Class based handlers
|
||||
====================
|
||||
|
||||
A handler is a async callable which takes a event with contextual data and returns a response.
|
||||
|
||||
In **aiogram** it can be more than just an async function, these allow you to use classes
|
||||
which can be used as Telegram event handlers to structure your event handlers and reuse code by harnessing inheritance and mixins.
|
||||
|
||||
There are some base class based handlers what you need to use in your own handlers:
|
||||
|
||||
.. toctree::
|
||||
|
||||
base
|
||||
callback_query
|
||||
chosen_inline_result
|
||||
error
|
||||
inline_query
|
||||
message
|
||||
poll
|
||||
pre_checkout_query
|
||||
shipping_query
|
||||
27
docs2/dispatcher/class_based_handlers/inline_query.rst
Normal file
27
docs2/dispatcher/class_based_handlers/inline_query.rst
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
==================
|
||||
InlineQueryHandler
|
||||
==================
|
||||
|
||||
There is base class for inline query handlers.
|
||||
|
||||
Simple usage
|
||||
============
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from aiogram.handlers import InlineQueryHandler
|
||||
|
||||
...
|
||||
|
||||
@router.inline_query()
|
||||
class MyHandler(InlineQueryHandler):
|
||||
async def handle(self) -> Any: ...
|
||||
|
||||
|
||||
Extension
|
||||
=========
|
||||
|
||||
This base handler is subclass of :ref:`BaseHandler <cbh-base-handler>` with some extensions:
|
||||
|
||||
- :code:`self.chat` is alias for :code:`self.event.chat`
|
||||
- :code:`self.query` is alias for :code:`self.event.query`
|
||||
27
docs2/dispatcher/class_based_handlers/message.rst
Normal file
27
docs2/dispatcher/class_based_handlers/message.rst
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
==============
|
||||
MessageHandler
|
||||
==============
|
||||
|
||||
There is base class for message handlers.
|
||||
|
||||
Simple usage
|
||||
============
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from aiogram.handlers import MessageHandler
|
||||
|
||||
...
|
||||
|
||||
@router.message()
|
||||
class MyHandler(MessageHandler):
|
||||
async def handle(self) -> Any:
|
||||
return SendMessage(chat_id=self.chat.id, text="PASS")
|
||||
|
||||
Extension
|
||||
=========
|
||||
|
||||
This base handler is subclass of [BaseHandler](basics.md#basehandler) with some extensions:
|
||||
|
||||
- :code:`self.chat` is alias for :code:`self.event.chat`
|
||||
- :code:`self.from_user` is alias for :code:`self.event.from_user`
|
||||
26
docs2/dispatcher/class_based_handlers/poll.rst
Normal file
26
docs2/dispatcher/class_based_handlers/poll.rst
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
===========
|
||||
PollHandler
|
||||
===========
|
||||
|
||||
There is base class for poll handlers.
|
||||
|
||||
Simple usage
|
||||
============
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from aiogram.handlers import PollHandler
|
||||
|
||||
...
|
||||
|
||||
@router.poll()
|
||||
class MyHandler(PollHandler):
|
||||
async def handle(self) -> Any: ...
|
||||
|
||||
Extension
|
||||
=========
|
||||
|
||||
This base handler is subclass of :ref:`BaseHandler <cbh-base-handler>` with some extensions:
|
||||
|
||||
- :code:`self.question` is alias for :code:`self.event.question`
|
||||
- :code:`self.options` is alias for :code:`self.event.options`
|
||||
25
docs2/dispatcher/class_based_handlers/pre_checkout_query.rst
Normal file
25
docs2/dispatcher/class_based_handlers/pre_checkout_query.rst
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
=======================
|
||||
PreCheckoutQueryHandler
|
||||
=======================
|
||||
|
||||
There is base class for callback query handlers.
|
||||
|
||||
Simple usage
|
||||
============
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from aiogram.handlers import PreCheckoutQueryHandler
|
||||
|
||||
...
|
||||
|
||||
@router.pre_checkout_query()
|
||||
class MyHandler(PreCheckoutQueryHandler):
|
||||
async def handle(self) -> Any: ...
|
||||
|
||||
Extension
|
||||
=========
|
||||
|
||||
This base handler is subclass of :ref:`BaseHandler <cbh-base-handler>` with some extensions:
|
||||
|
||||
- :code:`self.from_user` is alias for :code:`self.event.from_user`
|
||||
25
docs2/dispatcher/class_based_handlers/shipping_query.rst
Normal file
25
docs2/dispatcher/class_based_handlers/shipping_query.rst
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
====================
|
||||
ShippingQueryHandler
|
||||
====================
|
||||
|
||||
There is base class for callback query handlers.
|
||||
|
||||
Simple usage
|
||||
============
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from aiogram.handlers import ShippingQueryHandler
|
||||
|
||||
...
|
||||
|
||||
@router.shipping_query()
|
||||
class MyHandler(ShippingQueryHandler):
|
||||
async def handle(self) -> Any: ...
|
||||
|
||||
Extension
|
||||
=========
|
||||
|
||||
This base handler is subclass of :ref:`BaseHandler <cbh-base-handler>` with some extensions:
|
||||
|
||||
- :code:`self.from_user` is alias for :code:`self.event.from_user`
|
||||
Loading…
Add table
Add a link
Reference in a new issue