2021-01-26 21:20:52 +02:00
|
|
|
##########
|
2022-04-11 05:34:24 +05:00
|
|
|
Dispatcher
|
2021-01-26 21:20:52 +02:00
|
|
|
##########
|
|
|
|
|
|
|
|
|
|
Dispatcher is root :obj:`Router` and in code Dispatcher can be used directly for routing updates or attach another routers into dispatcher.
|
|
|
|
|
|
|
|
|
|
Here is only listed base information about Dispatcher. All about writing handlers, filters and etc. you can found in next pages:
|
|
|
|
|
|
|
|
|
|
- `Router <router.html>`__
|
|
|
|
|
- `Observer <observer.html>`__
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. autoclass:: aiogram.dispatcher.dispatcher.Dispatcher
|
2021-09-07 00:32:43 +03:00
|
|
|
:members: __init__, feed_update, feed_raw_update, feed_webhook_update, start_polling, run_polling
|
2021-01-26 21:20:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
Simple usage
|
|
|
|
|
============
|
|
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
dp = Dispatcher()
|
|
|
|
|
|
|
|
|
|
@dp.message()
|
|
|
|
|
async def message_handler(message: types.Message) -> None:
|
|
|
|
|
await SendMessage(chat_id=message.from_user.id, text=message.text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Including routers
|
|
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
dp = Dispatcher()
|
|
|
|
|
router1 = Router()
|
|
|
|
|
dp.include_router(router1)
|
|
|
|
|
|
|
|
|
|
Handling updates
|
|
|
|
|
================
|
|
|
|
|
|
|
|
|
|
All updates can be propagated to the dispatcher by :obj:`Dispatcher.feed_update(bot=..., update=...)` method:
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
bot = Bot(...)
|
|
|
|
|
dp = Dispathcher()
|
|
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
result = await dp.feed_update(bot=bot, update=incoming_update)
|