telega/flow/action

Pure control functions that construct FlowAction values.

Values

pub fn back(
  ctx: bot.Context(session, error),
  instance: types.FlowInstance,
) -> Result(
  #(
    bot.Context(session, error),
    types.FlowAction(step_type),
    types.FlowInstance,
  ),
  error,
)

Go back to previous step

pub fn cancel(
  ctx: bot.Context(session, error),
  instance: types.FlowInstance,
) -> Result(
  #(
    bot.Context(session, error),
    types.FlowAction(step_type),
    types.FlowInstance,
  ),
  error,
)

Cancel the flow

pub fn complete(
  ctx: bot.Context(session, error),
  instance: types.FlowInstance,
) -> Result(
  #(
    bot.Context(session, error),
    types.FlowAction(step_type),
    types.FlowInstance,
  ),
  error,
)

Complete the flow

pub fn enter_subflow(
  ctx: bot.Context(session, error),
  instance: types.FlowInstance,
  subflow_name subflow_name: String,
  data data: dict.Dict(String, String),
) -> Result(
  #(
    bot.Context(session, error),
    types.FlowAction(step_type),
    types.FlowInstance,
  ),
  error,
)

Enter a subflow by name

This pushes the current flow state onto the stack and starts the subflow. When the subflow completes with return_from_subflow, execution returns to the parent flow at the step specified in add_subflow.

pub fn exit(
  ctx: bot.Context(session, error),
  instance: types.FlowInstance,
  result result: option.Option(dict.Dict(String, String)),
) -> Result(
  #(
    bot.Context(session, error),
    types.FlowAction(step_type),
    types.FlowInstance,
  ),
  error,
)

Exit with result

pub fn goto(
  ctx: bot.Context(session, error),
  instance: types.FlowInstance,
  step step: step_type,
) -> Result(
  #(
    bot.Context(session, error),
    types.FlowAction(step_type),
    types.FlowInstance,
  ),
  error,
)

Type-safe goto navigation (clears step data)

pub fn next(
  ctx: bot.Context(session, error),
  instance: types.FlowInstance,
  step step: step_type,
) -> Result(
  #(
    bot.Context(session, error),
    types.FlowAction(step_type),
    types.FlowInstance,
  ),
  error,
)

Next navigation

pub fn return_from_subflow(
  ctx: bot.Context(session, error),
  instance: types.FlowInstance,
  result result: dict.Dict(String, String),
) -> Result(
  #(
    bot.Context(session, error),
    types.FlowAction(step_type),
    types.FlowInstance,
  ),
  error,
)

Return from a subflow with result data

This pops the parent flow from the stack and merges the result data into the parent’s state, then continues at the return step.

pub fn try(
  ctx: bot.Context(session, error),
  instance: types.FlowInstance,
  result: Result(a, any_error),
  continue: fn(a) -> Result(
    #(
      bot.Context(session, error),
      types.FlowAction(step_type),
      types.FlowInstance,
    ),
    error,
  ),
) -> Result(
  #(
    bot.Context(session, error),
    types.FlowAction(step_type),
    types.FlowInstance,
  ),
  error,
)

Try a result, cancelling the flow on error.

Designed for use syntax to flatten nested error handling in flow steps:

use _ <- action.try(ctx, instance, reply.with_text(ctx, "Hello!"))
use data <- action.try(ctx, instance, fetch_data())
action.complete(ctx, instance)
pub fn try_with_message(
  ctx: bot.Context(session, error),
  instance: types.FlowInstance,
  result: Result(a, err),
  to_message: fn(err) -> String,
  continue: fn(a) -> Result(
    #(
      bot.Context(session, error),
      types.FlowAction(step_type),
      types.FlowInstance,
    ),
    error,
  ),
) -> Result(
  #(
    bot.Context(session, error),
    types.FlowAction(step_type),
    types.FlowInstance,
  ),
  error,
)

Try a result, sending an error message and cancelling the flow on error.

The to_message function converts the error into a user-facing message that is sent via reply.with_text before cancelling.

use data <- action.try_with_message(ctx, instance,
  extract_data(instance),
  fn(err) { "❌ Error: " <> err },
)
action.complete(ctx, instance)
pub fn unsafe_next(
  ctx: bot.Context(session, error),
  instance: types.FlowInstance,
  step step: String,
) -> Result(
  #(
    bot.Context(session, error),
    types.FlowAction(step_type),
    types.FlowInstance,
  ),
  error,
)

Next navigation with string step (for dynamic navigation)

pub fn wait(
  ctx: bot.Context(session, error),
  instance: types.FlowInstance,
) -> Result(
  #(
    bot.Context(session, error),
    types.FlowAction(step_type),
    types.FlowInstance,
  ),
  error,
)

Wait for user input

pub fn wait_callback(
  ctx: bot.Context(session, error),
  instance: types.FlowInstance,
) -> Result(
  #(
    bot.Context(session, error),
    types.FlowAction(step_type),
    types.FlowInstance,
  ),
  error,
)

Wait for callback

pub fn wait_callback_with_timeout(
  ctx: bot.Context(session, error),
  instance: types.FlowInstance,
  timeout_ms timeout_ms: Int,
) -> Result(
  #(
    bot.Context(session, error),
    types.FlowAction(step_type),
    types.FlowInstance,
  ),
  error,
)

Wait for callback with timeout

pub fn wait_with_timeout(
  ctx: bot.Context(session, error),
  instance: types.FlowInstance,
  timeout_ms timeout_ms: Int,
) -> Result(
  #(
    bot.Context(session, error),
    types.FlowAction(step_type),
    types.FlowInstance,
  ),
  error,
)

Wait for user input with timeout

Search Document