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

Copy Markdown View Source

An ExGram.Router.Filter that matches on the current active FSM flow name.

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

Usage

Combine with :fsm_state to scope routes to a specific flow and step:

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

scope do
  filter :fsm_flow, :settings
  filter :fsm_state, :choose_language
  filter :text
  handle &MyBot.Handlers.set_language/1
end

Match on "no active flow":

scope do
  filter :fsm_flow, nil
  filter :command, :start
  handle &MyBot.Handlers.start/1
end

Options

  • nil — matches when there is no active flow (flow == nil)
  • atom — matches when context.extra.fsm.flow == atom

Summary

Functions

call(update_info, context, expected_flow)

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

Filter callback.

Returns true when the current FSM flow name equals expected_flow.