ChatBot offers several ways to collect information. The easiest way is to use the Question action. It automatically saves the user’s answer so you can use saved data in an ongoing conversation.
However, sometimes you do not need to ask a question and save it as an attribute. You just need to bring the attribute’s value to the story. That’s when the Set attribute action comes in handy.
Learn more about attributes in the following articles:
When to use the Set attribute action
Attributes let you collect common data such as a user’s name or email. Using default attributes, you can also gather more advanced information, including your user’s location or country.
In each of these situations, the Set attribute action can help. This action allows you to save, use, and modify an attribute if needed.
The Set attribute consists of two elements:
-
SET - choose the attribute’s name,
-
TO - provide value to the attribute.
How to use the Set attribute action in your Story
Choose the Set attribute block from the Actions and interactions menu and add it to your Story.
How does the Set attribute work with default attributes
After you add the action to your tree, you need to enter the attribute’s name and value.
When the user provides the correct keywords, your chatbot will recognize the phrases and correctly set the attribute’s value. The chatbot chooses the path based on the Confidence score.
-
Add the User input block after your Welcome message.
-
Click on the new block and provide the phrases.
-
Add the Set attribute action.
-
Set the Set attribute action to Language.
-
Provide English as the value. The chatbot can follow this path if the keywords are correct.
-
Place the second User input and provide the keywords.
-
Place the second action in your Story.
-
Set the attribute to Language and provide Polish as the value.
-
Provide the messages in both languages. Add the responses to the Bot responses block placed after the actions.
-
Test the Story in the Testing tool - the chat window provided in the visual builder.
Provide the phrase in Polish. The bot will choose the path that leads to the Polish options.
How to set the value of a custom attribute
You can add a custom attribute if you want to use more advanced information that doesn’t qualify as a default attribute. Add this attribute while setting the Set attribute action.
-
Click on the Set attribute block.
-
Click on the + Add custom attribute option at the bottom of the menu. This will open a pop-up window.
-
Provide the name of your custom attribute and save it.
-
The custom attribute is now visible in the menu with the default attributes.
-
Add the User input block. Click on it and add your newly created attribute. Use the brackets symbol. Your bot needs a place to collect the attribute.
-
You can use the custom attribute the same way as the default attributes.
-
Add a Bot response block to continue the chat.
The difference between Question and Set attribute actions
ChatBot allows you to collect information in several ways. The easiest way is to use attributes. You can collect them using the Question or Set attribute action.
While using the Set attribute action, you must create and collect the attributes in separate steps. In contrast, Question allows you to do it in just one step as you create and collect the attribute in the same place in the Story.
Like the Set attribute action, the attributes contained using the Question action can be saved, used, and modified throughout the Story. Also, it lets you ask multiple questions. Each answer is also saved automatically as an attribute.
The Set attribute action lets you keep only one attribute at a time. While the Question action is more efficient, sometimes you do not need to ask a question; you just need to set an attribute’s value in the story. In such cases, the Set attributes action is more beneficial.
Attributes in the Archives
After the chat, all of the attributes are available in the Archives. You can check them there and analyze the chat information.