Bot Framework (v4) - How To Get State From Custom Prompt Validation
I'm implementing a custom prompt validation where I need to access my state to compare with the user's input. I did a lot of search and microsoft documentation and some samples too
Solution 1:
If the only reason AddressTextPrompt
extends TextPrompt
is so that you can do validation, then you should really just pass a validator in to a TextPrompt
.
In the Multi-Turn-Prompt Sample,
...it passes in the validator:
this.addDialog(newNumberPrompt(NUMBER_PROMPT, this.agePromptValidator));
...then performs the validation:
asyncagePromptValidator(promptContext) {
// This condition is our validation rule. You can also change the value at this point.return promptContext.recognized.succeeded && promptContext.recognized.value > 0 && promptContext.recognized.value < 150;
}
If the validator returns false
, then the retryPrompt
is fired. Otherwise, activity.Text
is passed to the next step like normal. For you, the validator might look something like:
asyncaddressValidator(promptContext) {
constuserState: State = awaitthis.userProfile.get(context);
// This condition is our validation rule. You can also change the value at this point.return promptContext.recognized.succeeded && promptContext.recognized.value === userState.user.address;
}
Post a Comment for "Bot Framework (v4) - How To Get State From Custom Prompt Validation"