Current section
Files
Jump to
Current section
Files
src/telega@flow@action.erl
-module(telega@flow@action).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/telega/flow/action.gleam").
-export([next/3, unsafe_next/3, goto/3, back/2, complete/2, cancel/2, wait/2, wait_callback/2, wait_with_timeout/3, wait_callback_with_timeout/3, exit/3, enter_subflow/4, return_from_subflow/3, 'try'/4, try_with_message/5]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(" Pure control functions that construct `FlowAction` values.\n").
-file("src/telega/flow/action.gleam", 14).
?DOC(" Next navigation\n").
-spec next(
telega@bot:context(BKTP, BKTQ, BKTR),
telega@flow@types:flow_instance(),
BKTV
) -> {ok,
{telega@bot:context(BKTP, BKTQ, BKTR),
telega@flow@types:flow_action(BKTV),
telega@flow@types:flow_instance()}} |
{error, BKTQ}.
next(Ctx, Instance, Step) ->
{ok, {Ctx, {next, Step}, Instance}}.
-file("src/telega/flow/action.gleam", 23).
?DOC(" Next navigation with string step (for dynamic navigation)\n").
-spec unsafe_next(
telega@bot:context(BKUA, BKUB, BKUC),
telega@flow@types:flow_instance(),
binary()
) -> {ok,
{telega@bot:context(BKUA, BKUB, BKUC),
telega@flow@types:flow_action(any()),
telega@flow@types:flow_instance()}} |
{error, BKUB}.
unsafe_next(Ctx, Instance, Step) ->
{ok, {Ctx, {next_string, Step}, Instance}}.
-file("src/telega/flow/action.gleam", 32).
?DOC(" Type-safe goto navigation (clears step data)\n").
-spec goto(
telega@bot:context(BKUL, BKUM, BKUN),
telega@flow@types:flow_instance(),
BKUR
) -> {ok,
{telega@bot:context(BKUL, BKUM, BKUN),
telega@flow@types:flow_action(BKUR),
telega@flow@types:flow_instance()}} |
{error, BKUM}.
goto(Ctx, Instance, Step) ->
{ok, {Ctx, {go_to, Step}, Instance}}.
-file("src/telega/flow/action.gleam", 41).
?DOC(" Go back to previous step\n").
-spec back(
telega@bot:context(BKUW, BKUX, BKUY),
telega@flow@types:flow_instance()
) -> {ok,
{telega@bot:context(BKUW, BKUX, BKUY),
telega@flow@types:flow_action(any()),
telega@flow@types:flow_instance()}} |
{error, BKUX}.
back(Ctx, Instance) ->
{ok, {Ctx, back, Instance}}.
-file("src/telega/flow/action.gleam", 49).
?DOC(" Complete the flow\n").
-spec complete(
telega@bot:context(BKVH, BKVI, BKVJ),
telega@flow@types:flow_instance()
) -> {ok,
{telega@bot:context(BKVH, BKVI, BKVJ),
telega@flow@types:flow_action(any()),
telega@flow@types:flow_instance()}} |
{error, BKVI}.
complete(Ctx, Instance) ->
{ok,
{Ctx,
{complete, erlang:element(3, erlang:element(6, Instance))},
Instance}}.
-file("src/telega/flow/action.gleam", 57).
?DOC(" Cancel the flow\n").
-spec cancel(
telega@bot:context(BKVS, BKVT, BKVU),
telega@flow@types:flow_instance()
) -> {ok,
{telega@bot:context(BKVS, BKVT, BKVU),
telega@flow@types:flow_action(any()),
telega@flow@types:flow_instance()}} |
{error, BKVT}.
cancel(Ctx, Instance) ->
{ok, {Ctx, cancel, Instance}}.
-file("src/telega/flow/action.gleam", 65).
?DOC(" Wait for user input\n").
-spec wait(
telega@bot:context(BKWD, BKWE, BKWF),
telega@flow@types:flow_instance()
) -> {ok,
{telega@bot:context(BKWD, BKWE, BKWF),
telega@flow@types:flow_action(any()),
telega@flow@types:flow_instance()}} |
{error, BKWE}.
wait(Ctx, Instance) ->
{ok, {Ctx, wait, Instance}}.
-file("src/telega/flow/action.gleam", 73).
?DOC(" Wait for callback\n").
-spec wait_callback(
telega@bot:context(BKWO, BKWP, BKWQ),
telega@flow@types:flow_instance()
) -> {ok,
{telega@bot:context(BKWO, BKWP, BKWQ),
telega@flow@types:flow_action(any()),
telega@flow@types:flow_instance()}} |
{error, BKWP}.
wait_callback(Ctx, Instance) ->
{ok, {Ctx, wait_callback, Instance}}.
-file("src/telega/flow/action.gleam", 81).
?DOC(" Wait for user input with timeout\n").
-spec wait_with_timeout(
telega@bot:context(BKWZ, BKXA, BKXB),
telega@flow@types:flow_instance(),
integer()
) -> {ok,
{telega@bot:context(BKWZ, BKXA, BKXB),
telega@flow@types:flow_action(any()),
telega@flow@types:flow_instance()}} |
{error, BKXA}.
wait_with_timeout(Ctx, Instance, Timeout_ms) ->
{ok, {Ctx, {wait_with_timeout, Timeout_ms}, Instance}}.
-file("src/telega/flow/action.gleam", 90).
?DOC(" Wait for callback with timeout\n").
-spec wait_callback_with_timeout(
telega@bot:context(BKXK, BKXL, BKXM),
telega@flow@types:flow_instance(),
integer()
) -> {ok,
{telega@bot:context(BKXK, BKXL, BKXM),
telega@flow@types:flow_action(any()),
telega@flow@types:flow_instance()}} |
{error, BKXL}.
wait_callback_with_timeout(Ctx, Instance, Timeout_ms) ->
{ok, {Ctx, {wait_callback_with_timeout, Timeout_ms}, Instance}}.
-file("src/telega/flow/action.gleam", 99).
?DOC(" Exit with result\n").
-spec exit(
telega@bot:context(BKXV, BKXW, BKXX),
telega@flow@types:flow_instance(),
gleam@option:option(gleam@dict:dict(binary(), binary()))
) -> {ok,
{telega@bot:context(BKXV, BKXW, BKXX),
telega@flow@types:flow_action(any()),
telega@flow@types:flow_instance()}} |
{error, BKXW}.
exit(Ctx, Instance, Result) ->
{ok, {Ctx, {exit, Result}, Instance}}.
-file("src/telega/flow/action.gleam", 112).
?DOC(
" Enter a subflow by name\n"
"\n"
" This pushes the current flow state onto the stack and starts the subflow.\n"
" When the subflow completes with `return_from_subflow`, execution returns\n"
" to the parent flow at the step specified in `add_subflow`.\n"
).
-spec enter_subflow(
telega@bot:context(BKYJ, BKYK, BKYL),
telega@flow@types:flow_instance(),
binary(),
gleam@dict:dict(binary(), binary())
) -> {ok,
{telega@bot:context(BKYJ, BKYK, BKYL),
telega@flow@types:flow_action(any()),
telega@flow@types:flow_instance()}} |
{error, BKYK}.
enter_subflow(Ctx, Instance, Subflow_name, Data) ->
{ok, {Ctx, {enter_subflow, Subflow_name, Data}, Instance}}.
-file("src/telega/flow/action.gleam", 125).
?DOC(
" Return from a subflow with result data\n"
"\n"
" This pops the parent flow from the stack and merges the result data\n"
" into the parent's state, then continues at the return step.\n"
).
-spec return_from_subflow(
telega@bot:context(BKYW, BKYX, BKYY),
telega@flow@types:flow_instance(),
gleam@dict:dict(binary(), binary())
) -> {ok,
{telega@bot:context(BKYW, BKYX, BKYY),
telega@flow@types:flow_action(any()),
telega@flow@types:flow_instance()}} |
{error, BKYX}.
return_from_subflow(Ctx, Instance, Result) ->
{ok, {Ctx, {return_from_subflow, Result}, Instance}}.
-file("src/telega/flow/action.gleam", 142).
?DOC(
" Try a result, cancelling the flow on error.\n"
"\n"
" Designed for `use` syntax to flatten nested error handling in flow steps:\n"
"\n"
" ```gleam\n"
" use _ <- action.try(ctx, instance, reply.with_text(ctx, \"Hello!\"))\n"
" use data <- action.try(ctx, instance, fetch_data())\n"
" action.complete(ctx, instance)\n"
" ```\n"
).
-spec 'try'(
telega@bot:context(BKZJ, BKZK, BKZL),
telega@flow@types:flow_instance(),
{ok, BKZP} | {error, any()},
fun((BKZP) -> {ok,
{telega@bot:context(BKZJ, BKZK, BKZL),
telega@flow@types:flow_action(BKZT),
telega@flow@types:flow_instance()}} |
{error, BKZK})
) -> {ok,
{telega@bot:context(BKZJ, BKZK, BKZL),
telega@flow@types:flow_action(BKZT),
telega@flow@types:flow_instance()}} |
{error, BKZK}.
'try'(Ctx, Instance, Result, Continue) ->
case Result of
{ok, Value} ->
Continue(Value);
{error, _} ->
cancel(Ctx, Instance)
end.
-file("src/telega/flow/action.gleam", 166).
?DOC(
" Try a result, sending an error message and cancelling the flow on error.\n"
"\n"
" The `to_message` function converts the error into a user-facing message\n"
" that is sent via `reply.with_text` before cancelling.\n"
"\n"
" ```gleam\n"
" use data <- action.try_with_message(ctx, instance,\n"
" extract_data(instance),\n"
" fn(err) { \"❌ Error: \" <> err },\n"
" )\n"
" action.complete(ctx, instance)\n"
" ```\n"
).
-spec try_with_message(
telega@bot:context(BLAC, BLAD, BLAE),
telega@flow@types:flow_instance(),
{ok, BLAI} | {error, BLAJ},
fun((BLAJ) -> binary()),
fun((BLAI) -> {ok,
{telega@bot:context(BLAC, BLAD, BLAE),
telega@flow@types:flow_action(BLAM),
telega@flow@types:flow_instance()}} |
{error, BLAD})
) -> {ok,
{telega@bot:context(BLAC, BLAD, BLAE),
telega@flow@types:flow_action(BLAM),
telega@flow@types:flow_instance()}} |
{error, BLAD}.
try_with_message(Ctx, Instance, Result, To_message, Continue) ->
case Result of
{ok, Value} ->
Continue(Value);
{error, Err} ->
_ = telega@reply:with_text(Ctx, To_message(Err)),
cancel(Ctx, Instance)
end.