ExGram middleware that loads FSM state before every handler call.
This middleware is automatically registered by use ExGram.FSM. You don't
need to add it manually.
What it does
Before every handle/2 call, this middleware:
- Extracts a storage key from the update using the configured
ExGram.FSM.Keymodule - Reads the FSM state from the configured storage backend
- Writes the state and config into
context.extra
Context keys populated
After this middleware runs, context.extra contains:
| Key | Type | Description |
|---|---|---|
:fsm | %ExGram.FSM.State{} | Current flow + state + data |
:fsm_key | term() | The storage key (shape depends on configured key module) |
:fsm_storage | module | Storage backend module |
:fsm_flows | %{atom => module} | Map of registered flow name → flow module |
:fsm_on_invalid_transition | atom or tuple | Invalid transition policy |
FSM key strategy
The key is extracted by the module set via the key: option in use ExGram.FSM
(default: ExGram.FSM.Key.ChatUser). See ExGram.FSM.Key for built-in options
and how to implement a custom strategy.