Use a Sub-Flow

Some flows may be re-used as parts of other flows. In Teneo, you can use sub-flows to do so. For example, requesting the user's email adress can be realised as a sub-flow that can then be used in larger flows. In the following, we will build both, the sub-flow and a flow that makes use of it.

This is how a conversation should look:

User: I'd like to subscribe to your newsletter
Bot: I'm happy to add you as a recipient of our free newsletter. Please enter your email address.

User: teneo@example.com
Bot: I have your email as teneo@example.com. Is that correct?

User: no
Bot: Please enter your email address.

User: teneo@example.com
Bot: Is your email address teneo@example.com correct? Please confirm.

User: yes
Bot: OK, thank you! I'm adding your address teneo@example.com to our mailing list. You will receive a confirmation mail shortly.

We will implement the conversation in two steps:

  1. Build the Sub-Flow.
  2. Build the main flow.

Build the Sub-Flow

Our Sub flow to retrieve the user's email will ask the user to enter an email address, confirm with the user that the email was correct, and if correct, return the mail. If not correct, the user will be re-prompted. This continues until a correct email was entered. The final Sub flow will look as follows: Subflow to query and return email

Create a Sub-Flow

First we will create a new flow and turn it into a sub-flow.

  1. Create a new Sub-Flow by pressing the dropdown menu located under 'Flow' and call it Get email address.
  2. In the 'Flow' tab, under 'Variables', Add a flow variable called email and initialize it to empty string "".
  3. Click the arrow to return to the 'Home' tab.

Add a prompt for e-mail

  1. Select the output node and name it Prompt for email.
  2. Give it the output Please enter your email address.
  3. With the output still selected, add a new output node to follow it.
  4. Select the new transition and call it Email entered.
  5. Make sure it is set to 'Conditional' and 'Gets input before continuing'.
  6. With the transition in the flow still marked, scroll down to 'Match Requirements' and add a requirement for 'Condition'.
  7. Add the condition %EMAIL_ADDRESS.SCRIPT^{email=_USED_WORDS}.

Set up the sub-flow to re-prompt

  1. Name the output node Confirm email.
  2. Select the second output and give it an answer I have your email as ${email} is that correct?.
  3. Select the 'Confirm email' output node and using the mousekey, drag and drop a transition back to the output 'Prompt for email'.
  4. Make sure the transition is set to 'Conditional' and 'Gets input before continuing'.
  5. Call the transition Re-try and add the following examples:
    no
    nope
    nah
  6. Finally, add a match requirement. Click on the 'Generate' button under the 'Match Requirements' section, this will automatically generate a match requirment based on the example specification. In this case the language object NO.PHR. This will send your flow back to the begining if the email stored is wrong.

Set up a positive confirmation of the email

  1. Select the output node 'Confirm email'.
  2. Add a new output node to follow it.
  3. Give the new output node a response OK, thank you! and rename the node Thank user.
  4. Select the transition and make sure it is set to 'Conditional' and 'Gets input before continuing'.
  5. Call the transition Confirmed and add the following examples:
    yeah
    yup
    yes
  6. Finally, add a match requirement. Click on the 'Generate' button under the 'Match Requirements' section, this will automatically generate a match requirment based on the example specification. In this case the language object YES.PHR. This will let you proceed if the email stored is correct.
  7. Click save.

That's it! We can now use this sub flow that requests the user's email adress in as many other flows as we want. In the next section we show you how exactly to do that.

Build the main flow

At this point we have a sub-flow that is not being used anywhere. Since it doesn't have a trigger, Teneo will never select it. In this section we will build a flow to trigger if users request to be added to the Longberry Baristas mailing list. Later this flow will make use of the Sub flow 'Get email address' that we created above. But for now we will just build the question and answer. We'll add the Sub flow link later.

Create the new flow

  1. Create a flow and name it User wants to subscribe to the mailing list.
  2. In the 'Flow' tab under 'Variables', add a flow variable called email and initialize it to empty string "".
  3. Click the arrow to return to the home page.
  4. Select the trigger, call it Subscribe to the mailing list and add positive learning examples:
    Can i get your newsletter?
    How can i subscribe to the newsletter?
    How to get on your mailing list?
    I want to subscribe to your mailing list
    I'd like to subscribe to the newsletter
    Please add me to your mailing list
    Please put me on the mailing list
  5. Click on the 'Generate' button under 'Match Requirements' section, this will automatically generate the best match requirment based on the example specification.
  6. Call the output node Happy to add you to our mailing list.
  7. Select the output node and add an answer I'm happy to add you to receive our completely free newsletter..

Add a call to the Sub-Flow

Now we want to pass control to the sub-flow and let it do all the work of prompting the user for an email address.

  1. Select the 'Happy to add you to our mailing list.' output node and add a 'Flow' node leaving it.
  2. Call the 'Flow' node Get email address.
  3. With the 'Get email address' node selected, make sure the sidebar area 'Flow Link' is visible.
  4. Click 'Browse' and select our subflow 'Get email address'.
  5. Retrieve the email address from the subflow: in the section 'From' where you see 'Get the value back' select email from the dropdown list.
  6. Name the transition Call sub-flow and make sure it is 'Unconditional' and set to 'Continues without input'.

Finish the flow

  1. Select the sub-flow node and add a new output node.
  2. Call the output node Confirmation.
  3. Give the output an answer I'm adding your address ${email} to our mailing list. You should receive a confirmation mail shortly..
  4. Call the transition Return from sub-flow and make sure it is 'Unconditional' and set to 'Continues without input'.
  5. Hit 'Save'.

That's it! You may now give it a go in try out and replicate the conversation below. Note that the answer parts from the sub flow are italic for illustrative purposes. In practice, they will not be distinguishable from the answers of the main flow:

User: I want to subscribe to your newsletter!
Bot: I'm happy to add you to receive our completely free newsletter. Please enter your email address.
User: teneo@example.com
Bot: I have your email as teneo@example.com, is that correct?
User: Yes.
Bot: OK, thank you! I'm adding your address teneo@example.com to our mailing list. You should receive a confirmation mail shortly.

Note that if the name of the sub flow should change at some point, all existing connections between main flows and this sub-flow will automatically be updated by Teneo.

What's next?

We're finally done with the Flows chapter. Next in line is conversations.

Was this page helpful?