#Functional node

Understanding functional nodes

In the graph we have simple nodes, containing the messages fired by the chatbot and functional nodes. As per name, functional nodes contain functions, that is to say nodes containing some logic. With functions you can set built-in logic rules or execute API calls to your core systems and associate a chatbot behaviour according to every function’s output.

All functional nodes share the same principle: the flow of the conversation varies according to the previous user input. In other words, the functional node contains some logic to select the conversational path depending on the history of every user’s chat.

In order to create a functional node select the 🔹 icon from the controls toolbar at the left of the board and exactly as per simple nodes, click in any empty space in the board.

Every function has outputs represented through red edges. In a functional node, edges are predefined, therefore, when creating new ones the edge control panel will display a drop-down with the available options. For example, in the function below, we check an email address and are given valid and invalid outputs as options.

There are Standard Functions, which are provided directly by Spixii and Custom Functions, with possibility to enter custom logic. We can see some examples starting from Standard Functions.

Standard Functions

Most of the Standard Functions are validation functions. As an example, the simplest scenario is a function with two outputs: valid and not valid. When the input from the user is not valid, you can create an out-coming edge pointing to an error message. When the input is valid, the conversation can continue as per the “golden path” to the following conversational node.

Some of the Standard Function examples include:

Function is_date_in_range

The function is_date_in_range, checks whether the date selected by the user is inside or outside a desired range. As function outputs you have 4 scenarios: a date before the allowed range, a date after the allowed range, a date given doesn't have the format YYYY-MM-DD and the one within the allowed range. For each scenario, you can have a specific chatbot message or conversation flow.

The is_date_in_range function has 3 arguments:

Max date and Min date can be empty: the function simply won't validate the missing border. In the following example, the conversation will display to the user the message "In range" if and only if the date picked up is between the 1st and the 10th of January 2022.

⚠️Important note: It's a good practice implementing the right input validation from both the angles, the UI and the logic. In the example above, the calendar edge can be customised the two limit dates Max Date and Min Date.

This customisation allows users to proceed with the conversation if and only if they pick-up a date between the 1st and the 10th of January 2022. However, it's worthy increasing the robustness of the process by concatenating the is_date_in_range function.

In particular, by selecting the checkbox Dates out of limits can be selected, the dates out of the range will be clickable: this is useful to give to the user an explanation of the date limits. For example, in a claim notification process the date of the loss can't be in the future: the conversation designer may:

Function is_email

The function is_email, checks if the email entered by the user is aligned with ISO RCF 822 standard email address format. As outputs we have valid and not valid. As outputs we have valid and not valid. In the example below, the variable myEmail contains the text given by the user that has to be validated by the is_email function.

⚠️Important note: It's a good practice implementing the right input validation from both the angles, the UI and the logic. In the example above, the freetext edge can be customised with the Email input type.

This customisation allows users to proceed with the conversation if and only if they type a valid email address. However, it's worthy increasing the robustness of the process by concatenating the is_email function.

Function is_equal

The function is_equal, verify if two variables are equal. As outputs we have valid and not valid. This function takes 4 arguments:

In the following example, the is_equal function is used to check if the date picked up by the user is today or not. In the first case, the process will display the message "Selected today", otherwise it will display "Selected a day different from today".

FirstVariable is set to @, which means that the function takes the value given at the previous question. SecondVariable is set to @today, which means that its value is give by the value of the variable with name today. The other parameters are untouched.

Function is_null

The function is_null, checks if a variable is empty (not defined, defined as null or defined as an empty string). As outputs we have valid and not valid.

Function is_regex_valid

The function is_regex_valid, verify if a variable matches with a given regular expression. As outputs we have valid and not valid. Regular expressions are useful to apply some static validation on a user input. Let's assume in the following example that the policy Id format is 3 letters + a number of 5 digits. The regular expression ^[a-zA-Z]{3}\d{5}$ can validate immediately if a variable complies with the format.

Examples of accepted policy Ids are PLC12345 and ABC00000, meanwhile TooManyLetters12345 or ABC1234567890 will be rejected.

Custom Functions

With Custom Functions you can define a new function along with its outputs. Spixii CPA provides a powerful Function Manager to create and manage the function straight from the platform.

When creating a new functional node, the option Create new function is available from the sidebar. When clicking the button, the function control panel will allow you to specify name and description for the new function.

The Function Manager contains the following elements:

  1. The Source code panel, that allows you to enter or even import your code. Through the Python coding language, specific logic can be defined for the conversation flow.

  2. The Arguments panel,

  3. The Returns panel, where the outputs of the function are defined. Outputs correspond with edges outcoming from the functional node.

  4. The Function simulator panel, where the function can be tested while creating it with the help of the development logs to the right.