Validation Procedure property

Official Content
This documentation is valid for:
Procedure object used to validate the User Input.

Description

The Validation Procedure is available for any Chatbot User Input and is triggered as soon the enters data for that user input.

It's helpful to validate the entry of the user and ask him to enter another value in case 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 sent. Although the user enters a valid country, he can fail entering a country where that promotion applies. There, the chatbot can inform the user to enter the information again (giving a hint of what are the valid countries for the promotion).

The user input may have other validations (such as match With Entity property), or even, the data type 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 a vaild date format).
That validations are combined with the Validation Procedure:

  • The data is requested
  • The AI Provider validates if it matchs with the entity (match With Entity property and/or the data type)
  • If not matchs, it asks for entering it again (here the Try Limit property is used to determine the number of times the user is asked to re-try).
  • If it matchs, 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:

parn(in:&UserInput,out:&Error,out:&CustomResponse);

where

  • &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 parameters that contains the message to be displayed when the user fails.

Note: The name of the parameters can be any, except the data types, which have to be the expected. 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.

Temporary Limitation

The Try Limit property does not apply for the validation procedure yet. There isn't an automatic mecanism to count the failed attempts. You can have an internal counter for the limit of attempts, which can be implemented using the Context API.

Samples

Consider the Citizen Service Chatbot sample where several complaints can be sent to the citizen service, related to sanitation, traffic, etc.

In this sample, we have a Flow named "StatusClaim" where the user can enter his Identification and the Complaint Id (which is a number that he was given a time before when he made a complaint). Given that information, the chatbot answers the status of the complaint (it can be pending to be solved, or solved).

So we define the following Flow, where the ComplaintId user input has the Validation Procedure property set to "ValidateComplaint", which is a procedure of the KB.

 

image_2019324113454_1_png

 

The "ValidateComplaint" procedure is as follows:

parm(in:&ComplaintId,out:&Error,out:&ResponseforFailure);
Chatbot.Context.GetUserContextValue(!"CitizenAdv",GetUserId(),!"UserIdentification",&ParameterValue)
for each Complaint
    where ComplaintId = &ComplaintId
    where UserIdentification.Trim().ToLower() = &ParameterValue.Trim().ToLower()
    
    &Error              = FALSE
    exit
when none
    &Error              = TRUE
    &ResponseforFailure = format(!"%1 isn't a valid complaint Id. Try again please.",&ComplaintId.ToString())
endfor

Note that we use the Chatbots Context API to get the UserIdentification (which is in the Chatbot Context) to use it as another parameter to know if the complain Id given is valid (if it belongs to the user).

Availability

This property is available since GeneXus 16 upgrade 3.

Scope

Objects: Conversational Flows Instance

Was this page helpful?
What Is This?
Your feedback about this content is important. Let us know what you think.