The entity setter is a form of turn allowing the administrator or editor to build more complex and powerful chatbots without using API integrations. In this article, you'll learn what an entity setter does exactly and how to use it.
What does the entity setter do?
As the name mention, it is setting an entity. In the case of the bot, this means that is will use certain set of values. Entities can be either extracted from a user turn, or set by the bot to let the user make choices.
The main action from the entity setter is to assign a new value to an entity (existing or new).
Supported entity values are:
- none (an empty string, to clear the value)
- arbitrary string (exact name match)
- array (in JSON format)
- handlebar expression (double curly braces) to assign other entity's value
Multiple assignments get evaluated top to bottom and are chained, which means later ones can take their values from the previous.
Secondly, the entity setter can be used to assign specific formats. In case the format of an entity is extracted from any API, it could be that the information is not user friendly, with the entity setter, we can reshape the output to facilitate the interaction for the end-user.
Steps for entity setter
We will demonstrate possible scenarios. First. go to Turn editor > Action and select Entity Setter as the type of action. Fill in the fields as shown.
As the result of this node:
- entity number will first be set to 123 and then reset to an empty string
- same_as_number will be 123
- array will contain and array of two items - test and abc
Reformat entities
Entities extracted from external sources may have a format which are not user-friendly or so called 'human readable'. Therefore, it is possible to reformat the entities.
Entities can be formatted using default formats:
- Time 24:00
- Time 12:00 AM/PM
- Date DD-MM-YYYY
- Regex
Our default formats will convert the format as follow:
TIME
To effectively the time formats to convert the time to:
- Time 24:00
- Time 12:00 AM/PM
The source entity should contain the format: YYYY-MM-DDTHH:MM:SS
From this format, we will only extract the value: HH:MM
DATE
To effectively the time formats to convert the time to:
- Date DD-MM-YYYY
The source entity should contain the format: YYYY-MM-DD
From this format, we will only manipulate the ordering to display DD-MM-YYYY
How it works
When we are receiving time option such as below:
By applying the formatting Time - 24:00, the end- user is now interacting with a better format.
This will be the result for the end-user.