Intent Validation is the process that the framework runs to determine if the conditions within the state Object are the right ones to resolve the matched Intent.
It does so by running a method called onValidation that is present within the Intent Class.
The method also returns a Boolean value and is run only for the matched Intent. If the method returns 'false', the Intent will not be resolved and the developer must handle the notification of the validation error to the user.
It should be pointed out that this method is optional. The framework will assume a 'true' response if the method is not present.
This is an example of the onValidation method:
//Intent How are you?
let howAreYou = new Intent("howAreYou");
howAreYou.onMatching = () => {
return state.messageFromUser === "how are you?";
};
howAreYou.onValidation = () => {
if (state.getField('previousGreeting') !== 'hello') {
state.addErrorToStack(1001, "You didn't say hello to me before!");
return false;
}
};
This method will match if the user message was "how are you?" However, it will respond with an error if the user didn't say "hello" beforehand.
Comments
0 comments
Please sign in to leave a comment.