Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Know the number of attempts inside a validation #1257

Closed
CKGrafico opened this issue Feb 20, 2019 · 3 comments · Fixed by microsoft/botbuilder-js#870 or microsoft/botbuilder-dotnet#1651
Assignees
Labels
customer-reported Issue is created by anyone that is not a collaborator in the repository. P1 Painful if we don't fix, won't block releasing

Comments

@CKGrafico
Copy link

Is your feature request related to a problem? Please describe.
Know the number of attempts in the same validation.

Describe the solution you'd like
PromptValidatorContext should have the number of attempts in the same validation.

Additional context

AddDialog(new TextPrompt(PromptKeys.UserCode, ValidateUserCode))
...

 private static async Task<bool> ValidateUserCode(PromptValidatorContext<string> promptContext, CancellationToken cancellationToken)
        {
            var value = promptContext.Recognized.Value?.Trim() ?? string.Empty;
            var regex = @"(CI)[0-9]*";
            var match = Regex.Match(value, regex, RegexOptions.IgnoreCase);

            if (match.Success)
            {
                promptContext.Recognized.Value = value;
                return true;
            }

            await promptContext.Context.SendActivityAsync(BotStrings.SharedValidateUserCode);
            return false;
        }

We have a code similar to this and we want to cancel the dialog after some attempts.
Example:

 private static async Task<bool> ValidateUserCode(PromptValidatorContext<string> promptContext, CancellationToken cancellationToken)
        {
            if (numberOfAttempts > 5) {
                // cancel everything
                promptContext.EndDialogAsync();
           }
            var value = promptContext.Recognized.Value?.Trim() ?? string.Empty;
            var regex = @"(CI)[0-9]*";
            var match = Regex.Match(value, regex, RegexOptions.IgnoreCase);

            if (match.Success)
            {
                promptContext.Recognized.Value = value;
                return true;
            }

            await promptContext.Context.SendActivityAsync(BotStrings.SharedValidateUserCode);
            return false;
        }
@asturm0
Copy link

asturm0 commented Jun 13, 2019

Hey guys,
I'm not sure if I'm missing something here, but I can't find a way to actually leave the validator and end the dialog. @CKGrafico, in you're example you suggest to use "promptContext.EndDialogAsync();" after 5 retries. Actually, the prompt context does not derive form the DialogContext, so the EndDialog method is not available. Is there any other way to get out of the custom validator? If not, what's the point of having an attempt counter? :-)

@asturm0
Copy link

asturm0 commented Jun 25, 2019

Could you give me a hint, @johnataylor ?

@asturm0
Copy link

asturm0 commented Jul 10, 2019

For anyone who stumbles over the same problem:
https://stackoverflow.com/questions/56790417/leaving-custom-prompt-validation-in-bot-framework-v4

@Kaiqb Kaiqb added the customer-reported Issue is created by anyone that is not a collaborator in the repository. label Jul 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-reported Issue is created by anyone that is not a collaborator in the repository. P1 Painful if we don't fix, won't block releasing
Projects
None yet
5 participants