Routing Nodes

When a node is completed (i.e. user has responded with a valid input to a prompt node, or a function node has done running), you need to provide your app with the next steps of the conversation (i.e. what to do and where to go next). This is what Routing Nodes are used for.

When to use routing nodes

Routing Nodes keep the routing logic between nodes. Use these nodes to direct and navigate the conversation. We can go to another node in the flow, redirect the conversation to a different flow or execute some logic before redirecting the conversation. This logic is defined usually under on_complete property, or in the other life-cycle hooks, depending on the specific node type (for example, on_select for a prompt choice node).

Simple routing node

Consider the following node, where we ask the users for their email:

get_email:
 type: prompt
 prompt_type: email
 on_complete:
     go_to: "get_phone"

Notice the go_to parameter under the on_complete property. This tells the flow manager to redirect the users onto the get_phone node when they respond with a valid input (i.e. valid email address in this case).

The node referred inon_complete.go_to (e.g. get_phone) and the referring node (e.g. get_email) must be part of the same Flow. If you want to invoke a node from another flow, use redirect instead.

Functions

Routing nodes allow you to invoke a function before directing the conversation to the next node. Use do property to invoke a function:

get_email:
 type: prompt
 prompt_type: email
 on_complete:
    do:
func_id: "myapp.save_email"
params:
email: "{email}"
go_to: "get_phone"

In the above example the function save_email will be invoked before moving onto get_email node.

Redirects

Use the redirect property to redirect the conversation onto another flow.

When redirecting the conversation onto a new flow, the conversation state is being cleared. If you need to make some parameters available in the state of the new flow, you can use redirect.params as shown in the example below.

get_email:
 type: prompt
 prompt_type: email
 on_complete:
    redirect:
go_to: "get_phone"
params:
email: "{email}"
name: "{state.name.text}"

Conditional routing

Sometimes you may want to branch the conversation flow based on the user input or other state variables. That's what Conditional Routing nodes are used for.

For example, you may have a state variable named is_superhero indicating whether or not your user is a superhero. In that case, you'd probably want to give them special treatment. This is how you can reflect this in your code:

get_email:
 type: prompt
 prompt_type: email
 on_complete:
- condition:
term:
"state.is_superhero": True
go_to: "welcome_superheroes"
- condition:
term:
"state.is_superhero": False
go_to: "welcome_normal_people"

Notice that you refer