ExGram.FSM.Middleware (ExGram FSM v0.1.0)

Copy Markdown View Source

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:

  1. Extracts a storage key from the update using the configured ExGram.FSM.Key module
  2. Reads the FSM state from the configured storage backend
  3. Writes the state and config into context.extra

Context keys populated

After this middleware runs, context.extra contains:

KeyTypeDescription
:fsm%ExGram.FSM.State{}Current flow + state + data
:fsm_keyterm()The storage key (shape depends on configured key module)
:fsm_storagemoduleStorage backend module
:fsm_flows%{atom => module}Map of registered flow name → flow module
:fsm_on_invalid_transitionatom or tupleInvalid 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.