I am using bot framework and I am trying to define a form dynamically using FormFlow. I have a problem with one specific field:
.Field(new FieldReflector<IssueFormModel>(nameof(IssueResultModel.ProductPlatform))
.SetType(typeof(string))
.SetDefine(async (issue, field) =>
{
if (issue.ProductName != null)
{
foreach (var platform in productsWithPlatforms[issue.ProductName])
{
field.AddDescription(platform, platform).AddTerms(platform, platform);
}
}
return await Task.FromResult(true);
})
.SetPrompt(new PromptAttribute("Which platform of {ProductName}{||}?"))
.SetAllowsMultiple(false)
.SetValidate(async (state, value) => await ValidateProductPlatform(value, state)))
The problem is that ProductPlatform depends on ProductName, therefore it is a string. This works fine, however, this way, the bot does not show the options of possible platforms (although there is {||} in SetPrompt).
When I set type to null SetType(null)
, the bot now shows possible platforms as buttons, however, it never goes to ValidateProductPlatform when user decides to type a wrong platform instead of clicking on the correct one (I guess the validation itself is done already on SetDefine level). The only reason I need to validate user input through ValidateProductPlatform is that I want to cancel the form after 3 unsuccessful attempts.
So, is there any way to achieve this?: User has options (as buttons) for ProductPlaftorm based on ProductName, but instead of clicking, they (might) type a wrong platform, and after 3 wrong attempts, the form ends.
PS: I saw Microsoft Bot : How to capture Too Many Attempts in Form Flow? but I am not able to use it since it appears as if SetValidate was ignored in my case (when SetType(null)
)