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
##########
2024-07-06 20:33:01 +03:00
Dispatcher is root :class: `~aiogram.dispatcher.router.Router` and in code Dispatcher can be used directly for routing updates or attach another routers into dispatcher.
2021-01-26 21:20:52 +02:00
2023-08-28 22:32:11 +03:00
Here is only listed base information about Dispatcher. All about writing handlers, filters and etc. you can find in next pages:
2021-01-26 21:20:52 +02:00
2023-08-26 23:18:20 +03:00
- :ref: `Router <Router>`
- :ref: `Filtering events`
2021-01-26 21:20:52 +02:00
.. autoclass :: aiogram.dispatcher.dispatcher.Dispatcher
2023-08-28 22:32:11 +03:00
:members: __init__, feed_update, feed_raw_update, feed_webhook_update, start_polling, run_polling, stop_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)
2024-07-06 20:33:01 +03:00
.. _Handling updates:
2021-01-26 21:20:52 +02:00
Handling updates
================
2024-07-06 20:33:01 +03:00
All updates can be propagated to the dispatcher by :meth: `~aiogram.dispatcher.dispatcher.Dispatcher.feed_update` method:
2021-01-26 21:20:52 +02:00
.. code-block :: python
2024-07-06 20:33:01 +03:00
from aiogram import Bot, Dispatcher
async def update_handler(update: Update, bot: Bot, dispatcher: Dispatcher):
result = await dp.feed_update(bot, update)
Also you can feed raw update (dictionary) object to the dispatcher by :meth: `~aiogram.dispatcher.dispatcher.Dispatcher.feed_raw_update` method:
.. code-block :: python
2021-01-26 21:20:52 +02:00
2024-07-06 20:33:01 +03:00
from aiogram import Bot, Dispatcher
2021-01-26 21:20:52 +02:00
2024-07-06 20:33:01 +03:00
async def update_handler(raw_update: dict[str, Any], bot: Bot, dispatcher: Dispatcher):
result = await dp.feed_raw_update(bot, raw_update)