telega/flow/registry
FlowRegistry and router integration.
Types
Flow registry for centralized flow management
pub opaque type FlowRegistry(session, error, dependencies)
Values
pub fn apply_to_router(
router: router.Router(session, error, dependencies),
registry: FlowRegistry(session, error, dependencies),
) -> router.Router(session, error, dependencies)
Apply all registered flows to a router
pub fn call_flow(
ctx ctx: bot.Context(session, error, dependencies),
registry registry: FlowRegistry(session, error, dependencies),
name flow_name: String,
initial initial_data: dict.Dict(String, String),
) -> Result(bot.Context(session, error, dependencies), error)
Call a registered flow from any handler
pub fn cancel_flow_instance(
registry: FlowRegistry(session, error, dependencies),
flow_id flow_id: String,
) -> Result(Bool, error)
Cancel a specific flow instance by ID
pub fn cancel_user_flows(
registry: FlowRegistry(session, error, dependencies),
user_id user_id: Int,
chat_id chat_id: Int,
) -> Result(List(String), error)
Cancel all flows for a user in a chat
pub fn new_registry() -> FlowRegistry(
session,
error,
dependencies,
)
Create a new empty flow registry
pub fn register(
registry: FlowRegistry(session, error, dependencies),
trigger: types.FlowTrigger,
flow: types.Flow(step_type, session, error, dependencies),
) -> FlowRegistry(session, error, dependencies)
Add a flow to the registry with a trigger
pub fn register_callable(
registry: FlowRegistry(session, error, dependencies),
flow: types.Flow(step_type, session, error, dependencies),
) -> FlowRegistry(session, error, dependencies)
Register a flow without a trigger (for calling from handlers)
pub fn register_cancel_command(
registry: FlowRegistry(session, error, dependencies),
command: String,
) -> FlowRegistry(session, error, dependencies)
Register a cancel command that cancels all active flows for the user
pub fn register_cancel_command_with(
registry: FlowRegistry(session, error, dependencies),
command: String,
on_cancel: fn(
bot.Context(session, error, dependencies),
List(String),
) -> Result(bot.Context(session, error, dependencies), error),
) -> FlowRegistry(session, error, dependencies)
Register a cancel command with a custom callback
pub fn register_with_data(
registry: FlowRegistry(session, error, dependencies),
trigger: types.FlowTrigger,
flow: types.Flow(step_type, session, error, dependencies),
initial_data: dict.Dict(String, String),
) -> FlowRegistry(session, error, dependencies)
Add a flow to the registry with a trigger and initial data
pub fn to_handler(
flow flow: types.Flow(step_type, session, error, dependencies),
) -> fn(bot.Context(session, error, dependencies), update.Command) -> Result(
bot.Context(session, error, dependencies),
error,
)
Create a router handler that starts a flow
pub fn with_callback_filter(
registry: FlowRegistry(session, error, dependencies),
flow_name flow_name: String,
filter filter: fn(String) -> Bool,
) -> FlowRegistry(session, error, dependencies)
Restrict a registered flow’s callback auto-resume to payloads accepted by
filter. Auto-resume normally delivers a callback to the first waiting
flow regardless of payload; with a filter, a press that belongs to another
flow’s keyboard skips this one and reaches its real target. Used by the
dialog engine, whose payloads are self-identifying (dlg:<dialog_id>:...).
pub fn with_orphan_callback_handler(
registry: FlowRegistry(session, error, dependencies),
matches matches: fn(String) -> Bool,
handler handler: fn(
bot.Context(session, error, dependencies),
String,
) -> Result(bot.Context(session, error, dependencies), error),
) -> FlowRegistry(session, error, dependencies)
Handle callback payloads that no waiting flow consumed. Handlers are
tried in registration order; the first whose matches accepts the raw
payload runs. Used by dialogs to answer presses on messages of already
finished dialogs (otherwise the spinner hangs and the press is silently
swallowed by the registry’s catch-all route).