Attributes in Flow XO

Attributes are a powerful feature in Flow XO. You can use attributes to store information, then access it later. Attributes are useful if you want your chatbot to do things like remember who the user is, complete an order, tabulate a response, or just give a personal greeting.

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

Attributes gather data, either actively, from direct user input, or passively, like counting how many time a user has accessed a flow. Your chatbot can use the same attributes across multiple flows.

For example, you might have a chatbot that recommends a song based on the user’s preferred genre and mood. When the user comes back for more, your chatbot will have this information on hand, and can make more recommendations. Or, the user can change their preferences if they want to hear something different.

Attribute Basics

Each attribute in your flow has a name and a value. One way to use attributes is to set the name, and later ask the user for a value. Your chatbot will store this as a name: value pair. For example:

  • genre: heavy metal
  • mood: happy

In the above example, the attribute names in your flow are genre and mood. The user-input values are heavy metal, and happy.

You can use this data in your flow to greet the user, then recommend a song.

Set an Attribute

Use Set an Attribute to establish an attribute name and assign a value. The value is the output from an action in your flow. This can be either active or passive data from the user.

Here’s how to set this up in Flow XO:

  1. In your flow, ask for the user’s preferred genre, and mood. For each of these actions, select Bot → Ask a Question.
  2. Now store each piece of data in an attribute. To do this, add a new action in your flow, and select Attributes in the Choose a Service window.
  3. Select Set an Attribute for your action and click Next.

Now add your attributes in the Settings window.

  1. Click + Add to add a new attribute.
  2. In the Name field, enter the name you want to give to the attribute, like “genre”.
  3. In the Value field, enter the output that you want to use as the attribute value. For example, the value for genre should be the answer to your question, “What genre do you like?” So, the Value field might look like “{{what_genre_do_you_like.parsed_answer}}”.
  4. Follow the same steps to set the attribute for mood.

The Attributes list should look something like this:

Click Next to continue.

When the user runs your chatbot, it will log the attribute values at this point in the flow. Your chatbot logs input data that is sent from the user to the bot. The log for attributes looks like this:

After you set an attribute, you can retrieve the information to use it in your flow.

Use an Attribute in a Flow

Once you have set an attribute, you can use it anywhere in your flow. You chatbot will use the attribute values logged in the input data .

At this point, we have stored the genre and mood. If you want use these values in a message, you can set up an action like this:

  1. In your flow, add a Bot to Send a Message.
  2. Start typing your message.
  3. In the place you want to display the genre, type {{. Then select Attributes { } in the drop-down.

Type the exact attribute name that you want to retrieve and press Enter. In this case, type “genre”, to mach the attribute that you created earlier:

Follow the same process to retrieve the mood attribute. The completed message will look something like this:

Your chatbot will replace “{{music_recommendations.attributes__genre}}” with the value stored in the genre attribute. It will do the same for mood.

So, if your user enters “heavy metal” and “happy”, your chatbot will send the message:

“You like heavy metal and you’re feeling happy. Here’s a song I think you’ll like!”

Update an Attribute

To update an attribute with a new value, use Set Attribute again.

A user may want to change the genre or mood the next time they visit your chatbot. If so, you can Set an Attribute again to update those values. The new value will overwrite the previous value.

  • Make sure to match the name of the attribute you are overwriting. For instance, to overwrite the value for mood, you must use the same attribute name, mood.
  • To completely reset an attribute, leave the Value empty.

Using Filters with Attributes

Another good way to use attributes is to filter an action in your flow based on an attribute value.

For example, you can have your chatbot send one message if the user is happy, but a different message if the user is sad. You can do this with a filter that checks the mood attribute you set earlier.

First, create a message that your chatbot will only send if the user’s mood is happy.

  1. Add an action in your flow. Use a Bot to Send a Message.
  2. Type your message for a happy user and click Next.
  3. On the Filters page, click + Add a Filter.
  4. Set the Value to your mood attribute.
  5. Set the Condition to Equals.
  6. Set the second Value to “happy”. You filter will look something like this:

This action will only run if the mood attribute has the value happy. To send a different message to a sad user, follow the same steps, but check for the value sad instead.

Increment an Attribute

You can increment the value of numeric attributes with +n or -n. This is useful for tracking patterns, like how many times a user has visited your chatbot or given a certain response.

Say the user also likes blues music. If your user has played one blues song, you’ll want to give them a different song the next time they pick the genre.

One way to change the song is by tracking how many times the user triggers your blues flow. Here’s how you can do this with attributes:

  1. Set up a new flow for the blues genre.
  2. Immediately after the trigger, add a new action and Set an Attribute.
  3. Give the attribute a logical Name, like blues.
  4. Set the Value to +1. Each time the user triggers this flow, the value for the blues attribute will increment by 1. By default, the starting value is 0.

Now that you’ve set up your incremental attribute, you need to tell your chatbot to log the value. To do this, use Get an Attribute.

Get an Attribute

Use Get an Attribute after you set an incremental attribute. This feature logs the new attribute value each time the counter goes up. It prevents your counter from resetting to 0.

Note: It’s usually unnecessary to use Get an Attribute because attributes are included in the data you receive when a message comes in to your bot.
You may still need to Get an Attribute if the attribute value may have changed during the flow (like when you increment a value).

To get an attribute:

  1. Add a new action in your flow.
  2. Select Attributes → Get an Attribute, and click Next.
  3. Type the exact attribute name that you want to log. In this case, blues:

Each time the user runs this flow, the value for blues will increment by one. Your chatbot will log each instance. So, if the user triggers this flow three times, the Value in your log will be “3”:

You can use this data in several ways. For example, you can search your external database, cycle songs listed in Google Sheets, or you can trigger new actions in your flow.

Conclusion

In Flow XO, attributes are an effective way to store and retrieve information. In this tutorial, you learned what attributes are, how to use them in your flow, and how attribute values persist across flows.

There are endless ways to use attributes in Flow XO. With attributes, users can change their responses so that you can provide service that meets changing requirements. You can track the frequency of a response and adjust output accordingly. You can also store attribute data outside your flow, like in Google Sheets.

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