| Procedure object used to validate the User Input.
The Validation Procedure is available for any Chatbot User Input and is triggered as soon the user enters data for that user input.
It is useful to validate the user's entry and ask him/her to enter another value if it's not valid (for the model). For instance, you can ask the user to enter the country where a promotion is going to be available. Although the user enters a valid country, it may not be the country where that promotion applies. There, the chatbot can ask the user to enter the information again (giving a hint of the valid countries for the promotion).
The user input may have other validations (such as match With Entity property), or even the data type - which is always checked for the user input (e.g. if it's a date, the AI Provider sends an error if the user enters data which isn't in a valid date format).
Those validations are combined with the Validation Procedure:
- The data is requested
- The AI Provider validates if it matches the entity (match With Entity property and/or the data type)
- If it doesn't match, it asks the user to enter it again (here the Try Limit property is used to determine the number of times the user is asked to re-try).
- If it matches, the data is assigned to the parameter
- The Validation Procedure is run
- If it is not valid (the validation procedure returns &Error = TRUE), it goes back (implicitly clears the parameter at the context) and the user is asked to enter it again
- The data is requested again.
The Validation Procedure must have a signature like the following:
- &UserInput is the Chatbot User Input (the parameter must be of the same data type of the User Input).
- &Error is Boolean
- &CustomResponse is a string parameter that contains the message to be displayed when the user fails to enter correct data.
Note: The parameter names can be anything, except the data types, which have to be the expected ones. Otherwise, you'll get an error like the following:
error: Unexpected Data Type. The Data Type of the x parameter must be the same as the User Input Data Type NUMERIC.
The Try Limit property does not apply to the validation procedure yet. There isn't an automatic mechanism to count the failed attempts. You can have an internal counter for the maximum number of attempts, which can be implemented using the Context API.
Consider the Citizen Service Chatbot sample where several complaints can be sent to citizen services in relation to sanitation, traffic, etc.
In this sample, we have a Flow called "StatusClaim" where the user can enter his Identification and the Complaint Id (a number he was given when he made the complaint). Given that information, the chatbot answers the status of the complaint (it can be pending to be solved, or solved).
So the following Flow is defined, where the ComplaintId user input has the Validation Procedure property set to "ValidateComplaint," which is a procedure of the KB.
The "ValidateComplaint" procedure is as follows:
for each Complaint
where ComplaintId = &ComplaintId
where UserIdentification.Trim().ToLower() = &ParameterValue.Trim().ToLower()
&Error = FALSE
&Error = TRUE
&ResponseforFailure = format(!"%1 isn't a valid complaint Id. Try again please.",&ComplaintId.ToString())
Note that we use the Chatbots Context API to get the UserIdentification (which is in the Chatbot Context) to be used as another parameter to find out if the complaint Id provided is valid (if it belongs to the user).
This property is available since GeneXus 16 upgrade 3.
Objects: Conversational Flows Instance