Skip to main content

Sub-Flows

With Sub-Flows, you can reuse pieces of logic in main Flows and, consequently, save time and memory in your solution. Unlike regular Flows, Sub-Flows are not triggered by user inputs nor script expressions; they are activated using Flow Links in a regular Flow.

The sections on this page provide information about the various aspects of Sub-Flows:

Concept

Sub-Flows are a type of Flow used for recurring topics in a solution, like asking for the user's date of birth. In that case, one single Sub-Flow for can be used and this Sub-Flow can then be called by any Flow that needs the user's date of birth. It should be noted that the Sub-Flow cannot be triggered by anything else except for Flow Links which are defined by the developer in a parent Flow.

Unlike regular Flows, Sub-Flows are not triggered by a user input. In fact, Sub-Flows do not have triggers at all. Sub-Flows can only be activated when linked to from other Flows.

linking_subflow

When a Flow Link points to a Sub-Flow, the currently active Flow will stay active after the Sub-Flow is executed. In other words, the regular Flow is executed up to the Flow Link, then the Sub-Flow runs and, when completed, the control returns to the regular Flow to continue execution.

tip

You can link multiple Sub-Flows or regular Flows to any Sub-Flow or regular Flow.

warning

If an output in the Sub-Flow uses a revisitability limit and that limit is exceeded, the Sub-Flow and all calling flows are dropped.

Sub-Flows and Variables

When linking to a Sub-Flow, you can specify which Flow Variables can be transferred back and forth. These variables are useful for storing Flow-specific information and can be reused in the main Flow and Sub-Flow. For example, you may want to get a user's email address in a Sub-Flow and then send it back to the parent Flow for further processing.

In the example below, a Flow Link connects a Sub-Flow to a parent Flow and gets a user's email. This can then be added to a mailing list in the parent Flow.

call_to_sub_flow

How To

Create a Sub-Flow

To create a Sub-Flow in Studio Web, follow the below steps:

  1. Optionally, navigate to the folder where the Flow should be created.
  2. In the lower, right corner of the browser window, click the Create (New Document) button and select Create New Flow.
  3. The Create New Flow opens, click the Flow field and select Sub-Flow.
  4. Now, give the Sub-Flow a name and, optionally, add a description.
  5. Click Add Variable to add any Flow Variables if needed.
  6. Lastly, click Create.

The new Sub-Flow is automatically opened in edit mode and contains a Bot Output as a placeholder for development of the new Sub-Flow.

Change Flow to a Sub-Flow

note

This section currently only applies to Teneo Studio Desktop.

turn-flow-into-sub-flow

To change a regular Flow to a Sub-Flow, with the Flow open, simply click the Sub-Flow button in the top ribbon of the Flow; this will convert the Trigger node into a Sub-Flow node.

In the open Flow, follow the below steps to add a Flow Link:

  1. Click the Plus icon, and depending on the icon's location in the Flow graph and the desired behavior, select one of the following options:
    • Continue With > a Flow Link to pass the dialogue to another flow to add a Flow Link at this point in the Flow dialogue
    • Split Path > to a Flow Link to pass the dialogue to another flow to create a new path in the Flow dialogue containing the Flow Link
  2. Lastly, remember to Save the Flow to preserve the changes.

With the Flow open, follow the below steps to edit the Flow Link:

  1. In the Call Flow Link node, start writing the Flow name of the Flow you wish to link to.
  2. If Flow Variables are defined, click add variable mapping to:
    • Select the values to send To the target Flow.
    • Select the values to return From the target Flow.
  3. Remember to Save the Flow to preserve the changes.

In the open Flow, follow the below steps to delete a Call Flow Link:

  1. In the Call Flow Link node, click the Recycle Bin in the sidebar.
  2. Remember to Save the Flow to preserve the changes.

UI

IconDescriptionVisualizationRelated Pages
sub-flow-webOpens window for creating a Flow, Sub-Flow or Prompt Flow.sub-flow-web-visualizationFlows
Flow Variables
add-flow-link-webAdds Flow Link.flow-link-web-visualizationFlow Links
split-pathAdds Flow Link.split_path_web_visualizationFlow Links
call_sub_flow_webAdds Flow Link properties.call_sub_flow_visualization_webFlow Links
Flow Variables
note

A Flow Link is also called a call to a Flow in Teneo Studio Web.

Practical Examples

Linking to a Sub-Flow

Requesting someone's email address is a great example of a Sub-Flow, as it can be useful in various types of main Flows.

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 email. 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:

get_email_address_flow

First we will create a new Sub-Flow.

  1. You can create a new Sub-Flow by clicking on the Create button and selecting 'Sub Flow' from the dropdown menu.
  2. Name the Sub-Flow Get email address.
  3. Add a variable and name it email. Initialize it to empty string " " and click on 'Add'.
  4. Click on 'Create' to create your flow.

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. Add a new output node to follow it by clicking the Plus icon followed by 'Continue with' and 'Transaction'.
  4. Name the new transition Email entered.
  5. Click the Plus icon underneath the transition, followed by 'Match' and 'TLML Syntax'.
  6. Add the Syntax Condition %EMAIL_ADDRESS.SCRIPT^{email=_USED_WORDS}.

Set Up the Sub-Flow to Re-prompt

  1. Locate the Output node. Name it Confirm email and give it the answer I have your email as ${userEmail}, is that correct?.
  2. Navigate to the bottom of the 'Confirm email' output node and using the mousekey, drag and drop a transition back to the output 'Prompt for email'.
  3. Click on the Plus icon on the newly created transition between 'Confirm email' and 'Prompt for email'. Select 'Continue with' and 'transaction element' followed by 'Response'.
  4. Now click on the same Plus icon again, this time selecting 'Match' and 'Language object'.
  5. Paste in the following: NO.PHR. This will cover various versions of the word "no".

Set Up a Positive Confirmation of the Email

  1. Click on the Plus icon above the Match containing the NO.PHR language object. Select 'Split Path' and 'Transaction'.
  2. Select the Output node at the end of this path and name it Email confirmed.
  3. Add the following answer: OK, thank you! I'm adding your address ${userEmail}. You will receive a confirmation mail shortly.
  4. Name the User Intent above this output node Confirmed and add the following example inputs:

yeah

yup

yes

  1. Finally, generate a Match. Click on the Plus icon above the output node (the Plus icon will have a yellow 'TODO' message next to it) and select 'Match' and 'Generate' to automatically generate a Match requirement based on the Intent example specification. In this case we will generate language object YES.PHR. This will let you proceed if the email stored is correct.
  2. Save the Flow.

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 does not 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 a 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 will add the Sub-Flow link later.

  1. Create a Flow and name it User wants to subscribe to the mailing list.

  2. Add a Flow Variable called email and initialize it to empty string "" . Click 'Add' to add the variable.

  3. Click on 'Create' to create the Flow.

  4. Name the trigger Subscribe to the mailing list and add the following positive Intent 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 Plus icon below the trigger, followed by 'Match' and 'Generate' 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. In the output node, add the 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 followed by 'Continue With' and 'Flow Link'.
  2. Using the dropdown menu, locate our 'Get email address' Sub-Flow.
  3. Retrieve the email address from the Sub-Flow: in the section 'From', where you see 'Get the value back', select email from the dropdown lists.

Finish the Flow

  1. Select the Plus icon below the 'Flow' node and add a new output node by selecting 'Continue With', followed by 'Transaction Element Output'.
  2. Call the output node Confirmation.
  3. Lastly, give the output an answer I'm adding your address ${email} to our mailing list. You should receive a confirmation mail shortly..
  4. Hit 'Save'.

You should now be able to replicate the conversation below in Tryout. 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

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.