ExGram.FSM.Filter.State (ExGram FSM v0.1.0)

Copy Markdown View Source

An ExGram.Router.Filter that matches on the current FSM state or FSM data.

This filter is automatically registered as the :fsm_state alias when use ExGram.FSM detects that use ExGram.Router has also been called on the same module.

Usage

Match on FSM state atom:

scope do
  filter :fsm_state, :get_name
  filter :text
  handle &MyBot.Handlers.got_name/1
end

Match on a key in FSM data:

scope do
  filter :fsm_state, {:step, :confirm}
  handle &MyBot.Handlers.confirm/1
end

Options

  • atom — matches when context.extra.fsm.state == atom
  • {key, value} — matches when context.extra.fsm.data[key] == value
  • nil — matches when there is no FSM state set (state == nil)

Summary

Functions

call(update_info, context, expected_state)

@spec call(term(), ExGram.Cnt.t(), atom() | nil | {term(), term()}) :: boolean()

Filter callback.

  • opts is an atom: returns true when the current FSM state equals that atom.
  • opts is {key, value}: returns true when context.extra.fsm.data[key] == value.