I need help, I am creating a bot that allows entering a date, I need to validate that the user has entered the corresponding date, otherwise it will come back and ask him to enter the date.
When I do this, it throws me an infinite loop when executing the bot in the emulator
public PruebaOpciones()
{
var waterfallStep = new WaterfallStep[]
{
SetPeriodo,
Confirmation,
FinalProcess
};
AddDialog(new WaterfallDialog(nameof(WaterfallDialog), waterfallStep));
AddDialog(new TextPrompt(nameof(TextPrompt)));
}
private async Task<DialogTurnResult> SetPeriodo(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
while (true)
{
string periodo = "Ingresa el mes que quieres consultar por favor.";
await stepContext.PromptAsync(
nameof(TextPrompt),
new PromptOptions
{
Prompt = MessageFactory.Text(periodo),
},
cancellationToken
);
periodo = periodo.ToLower();
int periodoLength = periodo.Length;
if (periodoLength == 1)
{
periodo = "0" + periodo;
break;
}
string[] periodoList = { "enero", "febrero", "marzo", "abril","mayo","junio","julio","agosto","septiembre","octubre",
"noviembre","diciembre","01", "02", "03", "04", "05","06","07","08","09","10","11","12"};
List<string> periodoRange = new List<string>(periodoList);
if (periodoRange.Contains(periodo))
{
break;
}
else
{
return await SetPeriodo(stepContext, cancellationToken);
}
}
return await stepContext.ContinueDialogAsync(cancellationToken: cancellationToken);
}
[1]: https://i.stack.imgur.com/CIb4s.png
How can I solve this issue and not throw me an infinite loop and only ask me once and if I enter wrong, come back and ask me?