telega/flow/action
Pure control functions that construct FlowAction values.
Values
pub fn back(
ctx: bot.Context(session, error, dependencies),
instance: types.FlowInstance,
) -> Result(
#(
bot.Context(session, error, dependencies),
types.FlowAction(step_type),
types.FlowInstance,
),
error,
)
Go back to the previous step the user actually visited.
Routing steps — the ones a conditional transition starts from — are skipped: stopping on one would immediately route forward again.
pub fn cancel(
ctx: bot.Context(session, error, dependencies),
instance: types.FlowInstance,
) -> Result(
#(
bot.Context(session, error, dependencies),
types.FlowAction(step_type),
types.FlowInstance,
),
error,
)
Cancel the flow
pub fn complete(
ctx: bot.Context(session, error, dependencies),
instance: types.FlowInstance,
) -> Result(
#(
bot.Context(session, error, dependencies),
types.FlowAction(step_type),
types.FlowInstance,
),
error,
)
Complete the flow
pub fn enter_subflow(
ctx: bot.Context(session, error, dependencies),
instance: types.FlowInstance,
subflow_name subflow_name: String,
data data: dict.Dict(String, String),
) -> Result(
#(
bot.Context(session, error, dependencies),
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, dependencies),
instance: types.FlowInstance,
result result: option.Option(dict.Dict(String, String)),
) -> Result(
#(
bot.Context(session, error, dependencies),
types.FlowAction(step_type),
types.FlowInstance,
),
error,
)
Exit with result
pub fn goto(
ctx: bot.Context(session, error, dependencies),
instance: types.FlowInstance,
step step: step_type,
) -> Result(
#(
bot.Context(session, error, dependencies),
types.FlowAction(step_type),
types.FlowInstance,
),
error,
)
Hard reset to step: clears step data and erases history and the flow
stack, so back has nothing to return to afterwards.
This is rarely what a “go to this step” reads like — reset_to is the same
function under a name that says so. To move between steps while keeping the
history, return Jump instead.
pub fn next(
ctx: bot.Context(session, error, dependencies),
instance: types.FlowInstance,
step step: step_type,
) -> Result(
#(
bot.Context(session, error, dependencies),
types.FlowAction(step_type),
types.FlowInstance,
),
error,
)
Next navigation
pub fn reset_to(
ctx: bot.Context(session, error, dependencies),
instance: types.FlowInstance,
step step: step_type,
) -> Result(
#(
bot.Context(session, error, dependencies),
types.FlowAction(step_type),
types.FlowInstance,
),
error,
)
Hard reset to step — the explicit spelling of goto.
Step data, history and the flow stack are all cleared.
pub fn return_from_subflow(
ctx: bot.Context(session, error, dependencies),
instance: types.FlowInstance,
result result: dict.Dict(String, String),
) -> Result(
#(
bot.Context(session, error, dependencies),
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, dependencies),
instance: types.FlowInstance,
result: Result(a, any_error),
continue: fn(a) -> Result(
#(
bot.Context(session, error, dependencies),
types.FlowAction(step_type),
types.FlowInstance,
),
error,
),
) -> Result(
#(
bot.Context(session, error, dependencies),
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, dependencies),
instance: types.FlowInstance,
result: Result(a, err),
to_message: fn(err) -> String,
continue: fn(a) -> Result(
#(
bot.Context(session, error, dependencies),
types.FlowAction(step_type),
types.FlowInstance,
),
error,
),
) -> Result(
#(
bot.Context(session, error, dependencies),
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, dependencies),
instance: types.FlowInstance,
step step: String,
) -> Result(
#(
bot.Context(session, error, dependencies),
types.FlowAction(step_type),
types.FlowInstance,
),
error,
)
Next navigation with string step (for dynamic navigation)
pub fn wait(
ctx: bot.Context(session, error, dependencies),
instance: types.FlowInstance,
) -> Result(
#(
bot.Context(session, error, dependencies),
types.FlowAction(step_type),
types.FlowInstance,
),
error,
)
Wait for user input
pub fn wait_callback(
ctx: bot.Context(session, error, dependencies),
instance: types.FlowInstance,
) -> Result(
#(
bot.Context(session, error, dependencies),
types.FlowAction(step_type),
types.FlowInstance,
),
error,
)
Wait for callback
pub fn wait_callback_with_timeout(
ctx: bot.Context(session, error, dependencies),
instance: types.FlowInstance,
timeout_ms timeout_ms: Int,
) -> Result(
#(
bot.Context(session, error, dependencies),
types.FlowAction(step_type),
types.FlowInstance,
),
error,
)
Wait for callback with timeout
pub fn wait_with_timeout(
ctx: bot.Context(session, error, dependencies),
instance: types.FlowInstance,
timeout_ms timeout_ms: Int,
) -> Result(
#(
bot.Context(session, error, dependencies),
types.FlowAction(step_type),
types.FlowInstance,
),
error,
)
Wait for user input with timeout