FlowRunner. Spec. Block behaviour
(flow_runner v6.15.1)
Copy Markdown
A Block is a unit of execution within a flow. It may wait for user input and provide content that should be rendered to the user.
Summary
Callbacks
Evaluate the block we have transitioned to and return updated container, flow, block and context
On leaving a block give the block an opportunity to evaluate the inputs received. This allows the block to fulfill tasks such as validation.
Load the raw config received from the original JSON, validate it and return a map with atom keys with the correct configuration
Functions
Cast the received fields to their internal representation
Load the map or list of maps into Elixir.FlowRunner.Spec.Block structs.
Validate a Elixir.FlowRunner.Spec.Block struct using Vex.validate
Types
Callbacks
@callback evaluate_incoming( FlowRunner.Spec.Container.t(), FlowRunner.Spec.Flow.t(), t(), FlowRunner.Context.t() ) :: {:ok, FlowRunner.Spec.Container.t(), FlowRunner.Spec.Flow.t(), t(), FlowRunner.Context.t()} | {:error, String.t()}
Evaluate the block we have transitioned to and return updated container, flow, block and context
@callback evaluate_outgoing( FlowRunner.Spec.Container.t(), FlowRunner.Spec.Flow.t(), t(), FlowRunner.Context.t(), user_input :: any() ) :: {:ok, user_input :: any()} | {:ok, user_input :: any(), opts :: Keyword.t()} | {:invalid, reason :: String.t()}
On leaving a block give the block an opportunity to evaluate the inputs received. This allows the block to fulfill tasks such as validation.
Return one of:
{:ok, user_input}— default. The validated input is stored incontext.vars[block.name](andcontext.vars["block"]["value"]) andwaiting_for_user_inputis cleared. Appropriate for question-shaped blocks whose output is the user's reply.{:ok, user_input, opts}— same as above plus a keyword list of options. Supported options:preserve_vars: true— do NOT overwritecontext.vars[block.name]with the user input, but still clearwaiting_for_user_input. Use this for blocks that set their own structured vars before pausing and must preserve that structure across the resume so downstream exits can read it.
{:invalid, reason}— the flow runner will exit through the block's default response.
Load the raw config received from the original JSON, validate it and return a map with atom keys with the correct configuration
Functions
Cast the received fields to their internal representation
@spec evaluate_default_exit(t()) :: {:error, String.t()} | {:ok, FlowRunner.Spec.Exit.t()}
@spec evaluate_exits(t(), FlowRunner.Context.t()) :: {:ok, FlowRunner.Spec.Exit.t()} | {:error, String.t()}
@spec evaluate_outgoing( FlowRunner.Spec.Container.t(), FlowRunner.Spec.Flow.t(), t(), FlowRunner.Context.t(), user_input :: any() ) :: {:ok, FlowRunner.Context.t(), t()} | {:invalid, reason :: String.t()}
@spec evaluate_user_input(t(), FlowRunner.Context.t(), iodata()) :: {:ok, FlowRunner.Context.t()} | {:error, String.t()}
@spec evaluate_user_input(t(), FlowRunner.Context.t(), iodata(), Keyword.t()) :: {:ok, FlowRunner.Context.t()} | {:error, String.t()}
@spec fetch_default_block(t(), FlowRunner.Spec.Flow.t(), FlowRunner.Context.t()) :: {:error, String.t()} | {:ok, FlowRunner.Context.t(), t() | nil}
@spec fetch_next_block(t(), FlowRunner.Spec.Flow.t(), FlowRunner.Context.t()) :: {:error, String.t()} | {:ok, FlowRunner.Context.t(), t()}
Load the map or list of maps into Elixir.FlowRunner.Spec.Block structs.
Validate a Elixir.FlowRunner.Spec.Block struct using Vex.validate