Teneo Developers

Branch at the beginning of a flow

There may be cases where we, depending on the input, want to give out different answers. For cases like this, it's important to know how to branch at the beginning of a flow. In this case we want edit previously created flow User asks about coffees we offer to recognize coffee types when mentioned by the user.

User: What kinds of coffees do you serve?
Bot: We offer a variety of handcrafted coffee drinks - from espressos to macchiatos to flat whites and more.

User: Do you serve brewed coffee?
Bot: Yes, we do indeed serve brewed coffee in our stores!

Here you'll learn how to add a branch at the beginning of your flow and to specify different paths depending on what the user said:

  • if the user asks about coffee types we serve,
  • if the user asks if we serve a specific coffee type,

These are the steps you'll need to take:

  • Extend the flow structure:
  • Add a junction, and set it to be start-node
  • Add one new output node.
  • Link the junction to the output nodes
  • Populate the output and transition for the coffee type response

The final version of the flow will look like this:
final flow layout

Create a new variable

As a first step we need to create a new flow variable that will store the coffee type the user mentions.

  1. Open or create the 'User asks about coffees we offer' flow.
  2. Inside the flow, click on the Variables icon underneath the minimap.
  3. Add a variable and name it mentionedCoffee.
  4. Put "" in the 'Evaluation Script' field. This initializes the variable with the empty string.
  5. Click on 'Confirm'.

Add an After Match to the Intent Trigger

In order to store the coffee type we need to add an After Match to the Intent Trigger. This will take the coffee type from our previously created entity and store it inside the flow variable 'mentionedCoffee'.

  1. Click on the Plus icon under the trigger.
  2. Click on 'After Match' and select 'Entity'.
  3. Select COFFEES_SERVED by typing or pasting it in and selecting it from the dropdown.
  4. Choose 'Add Variable Mapping'.
  5. The first dropdown represents the source, in this case the value of the NLU variable of the entity 'COFFEES_SERVED' that we want to store. Select 'coffeeType' from the dropdown menu.
  6. The second dropdown represents the target, i.e. the name of the variable where the extracted value is to be stored. Select 'mentionedCoffee' from the dropdown menu.

Extend the flow structure

Follow these steps to re-draw the structure of the flow:

  1. Add a junction by clicking on the Plus icon above the output node.
  2. Hover over 'with 'Split Path' and select 'transaction element', 'Output'.

Populate the new output and transition to recognize Coffee types

We will add a different route for when the user mentions its coffee type:

  1. Using the Plus icon, add a Match for 'Flow Variable' above the newly created output.
  2. From the dropdown, make sure 'mentionedCoffee' is selected.
  3. Navigate to the new output node and name it We serve the coffee type!. Add the following answer text: Yes, we do indeed serve ${mentionedCoffee}!.
  4. Hit 'Save'.

Notice how the transitions switched places. This because Teneo automatically tries the transitions from left to right. As this node has a Match attached, it will get tested first. If the transitions do not automatically switch places for you, close and reopen the flow and you will be able to see the change.

Try it out!

Now go ahead, open the 'Tryout' panel and give it a go!

User: What kinds of coffees do you serve?
Bot: We offer a variety of handcrafted coffee drinks - from espressos to macchiatos to flat whites and more.

User: Do you serve brewed coffee?
Bot: Yes, we do indeed serve brewed coffee!