Using Label and Goto a Label in Flow XO

Lydia Husser
Flow XO
Published in
8 min readApr 5, 2017

When you build a flow in Flow XO, you might want to repeat part of a flow, or even skip some of it, depending on the user’s response. You can do this with the Label and Goto a Label actions.

If you don’t already have a free Flow XO account, get yours now.

For instance, say you run a restaurant. Your patrons can use your bot to reserve a table, but you only want to take reservations up to one month in advance. So, you’ll want your bot to check the date the user gives you. If it is more than one month from now, your bot should go back and ask for a date again.

To follow along with this tutorial, install this Shared Flow in your Flow XO account.

Plan Your Flow

First, plan the framework for your flow. You want to ask the user for a date and check if the output is within a month from now. If it is not, your bot should go back to the top of the flow and repeat your original question. Before it does, you’ll want to tell the user why you’re asking again.

To go back to your original question, you’ll use the Flow actions Label and Goto a Label. These will tell your bot when it should go back, and where it should go back to. Your flow might look something like this:

  1. Trigger
  2. Label: This is where the loop starts.
  3. New Message: If the user gives a date later than 30 days from now, tell the user why you’re asking again. Your bot should only do this action if you’ve looped back from your Goto a Label action.
  4. Ask a Question: Ask the user for a date.
  5. Parse Date: Calculate what the date will be in 30 days, and store it.
  6. Goto a Label: This is where the loop ends. If the user’s date is more than 30 days from now, go back to 2. Label.
  7. New Message: Confirm the date with the user.

Now that you have an outline, you can start building your flow.

Build Your Flow

You’ll need to have date outputs in place before you can create filters for your Label and Goto a Label actions. This means that you’ll build your flow in the order that the user will see it. The order outlined above will be the result.

To begin:

  1. Create a trigger.
  2. In your flow, add an action. Select Bot → Ask a Question, then ask the user to give a date. Use the Date (dd/mm) or Date (mm/dd) validation to make sure the output is a valid date.
  3. Next, you’ll use the Flow XO Date & Time feature to calculate and parse the date 30 days from now.

Parse Date

You want to make sure the user has entered a date within one month. To do this, your bot needs to calculate what the date will be 30 days from now. Then it should store that date so you can use it later for comparison.

To do this, you’ll use the Parse Date action in your flow. This action will take your date input and store it as a standardized date.

  1. In your flow, add an action. Select Date & Time → Parse Date, then click Next.
  2. In the Settings window, type a Date/Time in a valid format. See Date & Time Handling in the Flow XO Help Center for acceptable date/time formats.

In this case, you want your bot to calculate what the date will be in 30 days. So, in the Date/Time field, type “in 30 days”. Here’s what this looks like:

Your bot will standardize and store the date output from this action.

Add a Label

At this point, your bot has a date from the user, and it knows what the date will be in 30 days. The next step is to compare these dates. If the date from the user is more than 30 days from now, your bot should loop back to your question. To do this you’ll use the actions Label and Goto a Label.

In Flow XO, the Label action creates a point that your bot can jump to. A bot can jump either forward or back within a flow.

In this case, you want your bot to jump back. Your bot should go to the point where you asked the user to input a date. To set this up:

  1. In your flow, add a new action above your Ask a Question action, where you asked the user to give a date.
  2. For your new action, select Flow → Label, then click Next.
  3. In the Settings window, type a Word or Phrase that you will be able to remember later.

The text you type in the Word or Phrase field identifies the unique label. Later, when you create a Goto a Label action, you’ll input the same word or phrase to tell your bot which label to jump to. In this case, you’ll call the label date.

Finish and save the label. Your flow should now look like this:

There are no filters on the Label action. Instead, you’ll add a filter to your Goto a Label action to tell your bot when to make this jump.

Goto a Label

In Flow XO, the Goto a Label action tells your bot what Label to jump to. It also tells your bot what conditions must be present to make the jump.

For this flow, you only want your bot to go back to your Label action if the user gives a date that is more than 30 days from now. To do this, you’ll create a Goto a Label action with a filter. You’ll also use metadata to track when the user activates the Goto a Label action.

To set this up in your flow:

  1. Add a new action below your Parse Date action. You’ll need the output from your Ask a Question and Parse Date actions.
  2. For your new action, select Flow → Goto a Label. Then click Next.
  3. In the Settings window, type the same Word or Phrase you used in the Label action earlier. This will tell your bot which Label to jump to when the user input meets filter conditions. Earlier, you used date, so use date again here:

Next, use the Metadata field to create an output for this action.

Goto a Label Metadata

In Flow XO, Metadata is optional information that your bot can store. When you put metadata on a Goto a Label action, it will carry over as an output for the Label action. You can use this output in other actions.

For this example, you’ll want to track whether the user has activated the Goto a Label action. Later, you’ll use this data to have your bot send a message that explains why you’re asking for a date again. Use Metadata to set up this output:

  1. Under Metadata, click + Add to add a new field.
  2. In the first column, give your metadata a name that you’ll be able to remember later.
  3. In the second column, give your metadata a simple value, like 1. For example:

In a later action, you’ll check whether this metadata field is empty. For now, click Next to add a filter to your Goto a Label action.

Goto a Label Filter

In this case, you only want your bot to jump back to your Label if the user gives a date that is more than 30 days from now. This means that you need a filter on your Goto a Label action that compares these dates. To create this filter:

  1. In the Filter window, enter the first Value. Use the output from your Ask a Question action, where you asked the user to give a date.
  2. You want to check if the date is greater than 30 days from now. So, set the Condition to is greater than.
  3. Enter the second Value. For this field, use the output from your Parse Date action. Remember, that is where your bot will calculate what the date will be 30 days from now.

Here’s what your Filter window should look like:

Your bot will only jump back to your Label if the user input meets these conditions. The Goto a Label action is now done. Click Next, then Save the action.

Send a Message

Next, tell the user why you’re asking for a date again. You only want your bot to do this after looping back to your Label. So, you’ll use a filter to check if the user activated the Goto a Label action. To do this:

  1. In your flow, add a new action. Place it below your Label action and above your Ask a Question action. This was where you asked the user to give a date.
  2. For your new action, select Bot → Send a Message. Then click Next.
  3. In the Message box, explain to the user that they need to give a date within the next 30 days. Click Next when you’re done.
  4. In the Filter window, create a filter. Tell your bot to only send this message if the user activated the Goto a Label action.

For the Value, tell your bot to look at the metadata output for your Label action. Remember that your bot will carry over metadata from the Goto Label action. To do this, type {{, find your Label, then select Metadata { }:

In the Metadata Key, type the name you gave to the metadata field in your Goto a Label action. In this case, you used asking_again, so type that in the Key:

Set the Condition to is not empty. If this metadata is not empty, it means the user activated the Goto Label action. When this happens, your bot should send this message. Your filter should look something like this:

You now have a complete Label and Goto a Label loop. To close your flow, you may want to confirm the date with the user. Your complete flow might look like this:

Conclusion

In this tutorial, you learned how to build a bot using Label and Goto Label actions. You also learned about Flow XO’s Date & Time feature, and a practical way to use Metadata. Flow XO has even more features that can help you build a responsive bot.

Want to find out more? We have full documentation for the Flow action and other features in Flow XO over at our Help Center, or get help & advice from other Flow XO users on the Community Site.

--

--