Ussd.Action behaviour (Ussd v0.2.0)

Copy Markdown View Source

A one-shot decision point that runs once, with no screen shown to the caller, and resolves to the next module in the flow.

Useful when the next state can't be expressed as a static transition/2 - e.g. it depends on an HTTP call or a database lookup:

defmodule MyApp.Actions.LoadAccount do
  @behaviour Ussd.Action

  @impl Ussd.Action
  def execute(context) do
    case Accounts.find(Ussd.Context.get(context, :phone)) do
      {:ok, _account} -> MyApp.States.Dashboard
      :error -> MyApp.States.Registration
    end
  end
end

The engine keeps calling execute/1 while the result is itself an Ussd.Action, so actions can chain, and stops once it reaches a real Ussd.State.

Summary

Callbacks

Resolves the next module in the flow: another Ussd.Action to keep chaining, or a Ussd.State to render.

Callbacks

execute(t)

@callback execute(Ussd.Context.t()) :: module()

Resolves the next module in the flow: another Ussd.Action to keep chaining, or a Ussd.State to render.