Teneo Developers

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 address can be implemented 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:

flow layout

Create a Sub-Flow

First we will create a new Sub-Flow.

  1. You can create a new Sub-Flow by clicking on the dropdown menu below 'Flow' and call it Get email address.
  2. In the 'Flow' tab, go to '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 by clicking the Plus icon followed up with 'Continue with' and 'Transaction'.
  4. Select the new transition and call it Email entered.
  5. Make sure it is set to 'Get input before continuing'.
  6. With the transition in the flow still marked, navigate to the Match section and a Match for 'TLML Syntax'.
  7. Add the Syntax Condition %EMAIL_ADDRESS.SCRIPT^{email=_USED_WORDS}.

Set up the Sub-Flow to re-prompt

  1. Name the output node Confirm email and give it an answer I have your email as ${email}, is that correct?.
  2. Select the 'Confirm email' output node and using the mousekey, drag and drop a transition back to the output 'Prompt for email'.
  3. Make sure the transition is set to 'Get input before continuing'.
  4. Call the transition Re-try and add the following examples:

example-inputs

1no
2nope
3nah
4
  1. Finally, add a Match by clicking on the 'Generate' button to automatically generate a Match requirment based on the Intent examples 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. Click on Plus icon above the 'Re-Try' Transition, followed up with 'Split Path' and 'Transaction'.
  2. Select the Output node and name it Email confirmed.
  3. Add the following answer: OK, thank you!
  4. Select the new transition and make sure it is set to 'Gets input before continuing'.
  5. Call the transition Confirmed and add the following examples:

    example-inputs

    1yeah
    2yup
    3yes
    4
    
  6. Finally, generate a Match. Click on the 'Generate' button under the 'Match' section to automatically generate a Match requirment based on the Intent 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 address in as many other flows as we want. In the next section, we will 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 the following positive Intent examples:

    example-inputs

    1Can i get your newsletter?
    2How can i subscribe to the newsletter?
    3How to get on your mailing list?
    4I want to subscribe to your mailing list
    5I'd like to subscribe to the newsletter
    6Please add me to your mailing list
    7Please put me on the mailing list
    8
    
  5. Click on the 'Generate' button in the Match section to automatically generate the best Match 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 would be happy to add you to our mailing list to receive our 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. Click on the Plus icon, below the output, 'Happy to add you to our mailing list.', followed up with 'Continue With' and 'Flow Link'.
  2. Name the transition Call sub-flow and make sure 'Get input before continuing' is unchecked.
  3. Select the 'Flow' node and call it Get email address.
  4. With the 'Get email address' node selected, make sure the sidebar area 'Flow Link' is visible. Click 'Browse' and select our Sub-flow 'Get email address' inside the 'Flows' folder.
  5. Retrieve the email address from the sub-flow: in the section 'From' where you see 'Get the value back' select email from the dropdown list.

Finish the flow

  1. Select the Plus icon below the 'Flow' node and add a new output node by hovering over 'Continue With', followed by 'Transaction Element Output'.
  2. Name the transition Return from sub-flow and make sure 'Get input before continuing' is unchecked.
  3. Call the output node Confirmation.
  4. Lastly, give the output an answer I'm adding your address ${email} to our mailing list. You should receive a confirmation mail shortly..
  5. Hit 'Save'.

That's it! You may now give it a go in tryout 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.