Search code examples
botsbotframeworkformbuilder

FormBuilder Code execution suddenly jumps to FormCompletion delegate


I have below code in Bot framework app. You can see in below code I have commented ValidateStartDate delegate, the reason behind it is that if I include delegate in formflow then after the delegate execution code jumps directly to BookingComplete delegate of "context.Call(Booking, BookingComplete);" i.e end of conversation.But ideally, it should execute rest of the fields from form builder. Note that here StartDate is of type String, and I am manually validating date part.Also, no visible exception occurs during code execution

public static IForm<ConferenceBooking> BuildForm()
{
     return new FormBuilder<ConferenceBooking>().Message("Tell me meeting details!")
    .Field(nameof(title))
    .Field(nameof(StartDate))//, validate: ValidateStartDate
    .Field(nameof(EntryTime), validate:ValidateCallTime)
    .Build();
}

Below is delegate part for StartDate

private static Task<ValidateResult> ValidateStartDate(ConferenceBooking state, object response)
{
var result = new ValidateResult();
DateTime startDt = Convert.ToDateTime(GetDate(Convert.ToString(response)));
if (startDt == null || startDt == DateTime.MinValue)
{
    result.IsValid = false;
    result.Feedback = "I could not understand this format.";
}
else if (startDt.Date < DateTime.Now.Date)
{
    result.IsValid = false;
    result.Feedback = "Sorry, back dated bookings are not allowed";
}
else
{
    result.IsValid = true;
    result.Value = startDt;
}
  return Task.FromResult(result);
}

Solution

  • I have also noticed this behavior before and this was always due to an exception. The FormBuilder appears to catch all exceptions and exits the form in the catch block. This is why you don't see any exceptions popping up. Try going over your code step by step or executing it from outside the form.