Router
Hierarchical routers with 25+ Pyrogram event decorators, sub-router nesting, and deferred handler registration.
Basic Usage
from pyrogram import filters
from pyrogram_patch.router import Router
router = Router()
@router.on_message(filters.command("start"))
async def start(client, message):
await message.reply("Hello!")
@router.on_callback_query(filters.regex("^menu_"))
async def handle_menu(client, callback_query):
await callback_query.answer("Selected!")Sub-Routers
Split handlers across multiple routers for modular bot architecture:
# admin_router.py
admin_router = Router()
@admin_router.on_message(filters.command("ban"))
async def ban_user(client, message):
...
# main.py
main_router = Router()
main_router.include_router(admin_router)
manager = await patch(app)
manager.include_router(main_router)Available Decorators
on_messageon_callback_queryon_inline_queryon_chosen_inline_resulton_edited_messageon_deleted_messageson_chat_member_updatedon_chat_join_requeston_raw_updateon_disconnecton_user_statuson_pollon_storyon_bot_business_connecton_bot_business_messageon_edited_bot_business_messageon_deleted_bot_business_messageson_message_reaction_updatedon_message_reaction_count_updatedon_chat_boost_updatedon_removed_chat_booston_pre_checkout_queryon_shipping_queryon_paid_media_purchasedHandler DI
Handlers receive dependencies via their parameter names. Add a patch_helper: PatchHelperparameter to get FSM and data access:
from pyrogram_patch.patch_helper import PatchHelper
@router.on_message(filters.command("profile"))
async def profile(client, message, patch_helper: PatchHelper):
state = await patch_helper.get_state()
data = await patch_helper.get_data()
await message.reply(f"State: {state}, Data: {data}")