Navigating in a CSML Bot
Navigating within a flow
A flow is made of at least one step (called start), but can also contain as many steps as necessary. You should think of steps as individual, simple bits of logic, linked inside the same conversation topic (which is the flow).
To go from one step to the next, you can simply use the keyword goto (or goto step) followed by the name of the step.
To finish a flow (and close the conversation), add goto end.
start:
say "hi"
goto step otherstep // note: in the following examples, we will use the shorthand notation `goto otherstep`
otherstep:
say "I'm in otherstep"
goto endNavigating between flows
Similarly to navigating between steps of the same flow, you can go to the beginning of any other flow by using the goto flow keyword. This will trigger the start step of the target flow and close the current flow, so coming back to the first flow will actually go back to the beginning of that flow.
somestep:
goto flow anotherflowAdvanced navigation
Introduced in CSML v1.2
If you want to reach a specific step in a specific flow, you can use the @ notation:
goto step_name@flow_nameThis is the universal way of navigating between steps and flow. The above two methods are actually special cases of this notation:
When the
@flow_namepart is not specified, CSML interprets it as "in the current flow". Sogoto stepnameactually is shorthand notation forgoto stepname@current_flow, wherecurrent_flowis dynamically matched from the name of the current flow, and works accordingly.When the
step_namepart is not specified, CSML interprets it asstart. So as@means "flow",goto @flow_nameis the same asgoto start@flow_namewhich is also the same asgoto flow flow_name.
Examples
goto stepname // navigate to the step named stepname in the current flow
goto flow flowname // navigate to the start step in flow flowname
goto @flowname // navigate to the start step in flow flowname
goto stepname@flowname // navigate to step stepname in flow flownameDynamic step and flow names
Introduced in CSML v1.5
As you can see above, steps and flows use strings as identifiers, but they are expressed without double quotes "...". In order to navigate to dynamically set steps or flows, CSML adds a special syntax, similar to the dereference pointer concept in other languages.
To go to a variable step or flow, you can reference the variable name prefixed with a $ sign:
do mystep = "somestep"
do myflow = "someflow"
goto $mystep@$myflowAny of the syntaxes presented above are supported. For instance:
do buttons = [Button("Burgers"), Button("Vegetables")]
say Question(
"What is your favorite food?",
buttons = buttons
)
hold
do matched = event.match_array(buttons)
if (!matched) { /* handle case where input does not match anything */ }
do target = matched.title
goto flow $target
// depending on which button the user selected, this is equivalent to
// goto flow Burgers or goto flow VegetablesPlease note that dot notation (accessing child properties in an object or array, i.e a.b) is not supported in variable flow and step names.
Last updated
Was this helpful?