Scenes are built on top of DialogFlow, DialogState, and Context::dialog_*
helpers.
DialogFlow declares the allowed ordered steps:
use teamtalk::DialogFlow;
let onboarding = DialogFlow::new("onboarding", "ask_name")
.step("ask_email")
.step("done");Helpers on DialogFlow:
contains_stepnext_stepprevious_stepis_start_stepis_terminal_step
These let handlers move through the declared flow instead of hardcoding string transitions everywhere.
Context exposes the scene lifecycle:
dialog_startdialog_start_statedialog_start_flowdialog_start_checkeddialog_restart_flowdialog_advancedialog_advance_checkeddialog_advance_nextdialog_pausedialog_resumedialog_canceldialog_finishdialog_stop
dialog_cancel, dialog_finish, and dialog_stop currently all end the active
scene. Use the name that best matches the handler intent.
Dialogs can carry a deadline through DialogState::with_timeout,
with_deadline_unix_ms, or Context::dialog_set_timeout.
Timeout behavior is controlled by DialogTimeoutPolicy:
DialogTimeoutPolicy::Clear: default; expired dialogs are removed.DialogTimeoutPolicy::Pause: expired dialogs become paused and stay available throughdialog_current_live().
Use:
DialogState::with_timeout_policyContext::dialog_set_timeout_policyContext::dialog_timeout_policy
dialog_current() returns only active, non-expired scenes. dialog_current_live()
returns a live scene even if it is paused.
There are two ways to keep extra scene data:
- dialog metadata inside
DialogState - dialog-scoped state in the
StateStore
Metadata helpers:
dialog_metadatadialog_metadata_parsedialog_set_metadatadialog_remove_metadata
Dialog-scoped store helpers:
dialog_state_keydialog_state_getdialog_state_parsedialog_state_setdialog_state_set_typeddialog_state_remove
Dialog-scoped state uses a session-aware key. Restarting the same flow creates a new dialog session id, so scratch values from the previous run do not collide with the current one.
Use this split consistently:
- dialog metadata for small state tied directly to the dialog record
- dialog-scoped store for larger scratch values or typed counters
- user/global state for durable bot data that must outlive the current scene