FSM Injection

Automatic FSM state injection into handler parameters via middleware.

How It Works

When you add patch_helper: PatchHelper as a handler parameter, the framework automatically injects a configured PatchHelper instance. This is handled by the FSM injection middleware, registered automatically when you call patch().

from pyrogram_patch.patch_helper import PatchHelper

@router.on_message(filters.command("status"))
async def status(client, message, patch_helper: PatchHelper):
    state = await patch_helper.get_state()
    data = await patch_helper.get_data()
    await message.reply(f"State: {state}\nData: {data}")

Automatic Registration

You do not need to manually register this middleware. Calling patch(app) and manager.set_storage(storage) handles everything. The PatchHelper is created per-update with a pooled lifecycle.