A screen in a USSD flow.
defmodule MyApp.States.Welcome do
use Ussd.State, initial: true
alias Ussd.Decisions.Equal
transition Equal.new("1"), to: MyApp.States.Airtime
transition Equal.new("2"), to: MyApp.States.DataBundle
@impl Ussd.State
def render(_context) do
Ussd.Menu.build()
|> Ussd.Menu.line("Welcome")
|> Ussd.Menu.listing(["Airtime", "Data Bundle"])
end
enduse Ussd.State accepts:
:initial- advisory metadata (defaultfalse) read bymix ussd.lintto auto-discover flow entry points when none are given explicitly. It is not enforced byUssd.use_initial_state/2.:continue- whentrue, also requires@behaviour Ussd.ContinueState(aconfirm/0callback), and marks this state eligible as thecontinuing_stateargument toUssd.use_continuing_state/4.
Inside the module body, five macros build the state's routing:
transition(decision, to: Module, callback: fun \\ nil)- repeatable; the first one whose decision matches the input wins.back(decision, callback: fun \\ nil)- returns to whatever state pushed this one onto the session's back-stack.paginate(next: decision, previous: decision \\ nil, callback: fun \\ nil)- requiresuse Ussd.Paginationin the same module.truncate(limit: n, ending: string, more: decision)- caps how much ofrender/1's output is returned per screen.terminate()- marks this state as ending the session once reached with no further input expected.
A state with none of these raises Ussd.Exceptions.NextStateNotFoundError the
moment it's reached with input that doesn't match anything - mix ussd.lint finds
these before your users do.
Summary
Functions
Registers this state's back-navigation rule.
Registers this state's pagination rule. Requires use Ussd.Pagination.
Marks this state as ending the session once reached.
Registers a routing rule: when decision matches the input, move to to:.
Registers this state's response-truncation rule.
Callbacks
@callback render(Ussd.Context.t()) :: Ussd.Menu.t()
Functions
Registers this state's back-navigation rule.
Registers this state's pagination rule. Requires use Ussd.Pagination.
Marks this state as ending the session once reached.
Registers a routing rule: when decision matches the input, move to to:.
Registers this state's response-truncation rule.