3

I am currently working on Bot framework technology, in one of my project I want to go back to the user conversation once I click the back button in FORM like this below figure. enter image description here

I know when user enter back in bot framework emulator it will go back immediately but I want above scenario.

How can I resolve the above scenario?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Pradeep
  • 5,101
  • 14
  • 68
  • 140
  • I'm not sure I understand what you are asking. Can you be more specfiic? – Lars Dec 02 '16 at 21:42
  • In the above image when I am click the back button it will not go to previous step conversation dialog. can you please tell me how can I go back to previous conversation once I click the back button. – Pradeep Dec 03 '16 at 04:23
  • So are you saying it worked in the emulator but not elsewhere? – Lars Dec 05 '16 at 23:38
  • Even Emulator also it's not working. – Pradeep Dec 06 '16 at 03:46

1 Answers1

0

If this is a FormDialog, you can add validation steps to each element in the form. In your case, you're probably using a bool "WantsToCreateAccount" or something to the likes of it?

In your FormBuilder code, you'd typically do as I've done here, on a simpler form:

public static IForm<UserData> BuildForm()
{
    return new FormBuilder<UserData>()
            .Message("Before we start, let me ask you a couple of questions")
            .AddRemainingFields()

            .Field(new FieldReflector<UserData>(nameof(IsCustomer))
                .SetValidate(async (state, value) => await ValidateIsCustomerFieldAsync(state, value)))

            .Field(new FieldReflector<UserData>(nameof(HasCustomerId))
                .SetValidate(async (state, value) => await ValidateHasCustomerIdFieldAsync(state, value)))

            .Build();
}

The SetValidate is the key here, where you can apply whatever logic you'd like after validation of that field, i.e.

private static Task<ValidateResult> ValidateHasCustomerIdFieldAsync(UserData state, object value)
{
    if( (SvarAlternativ) value == SvarAlternativ.Nej)
    {
        state.CustomerId = "Kund, har inte Id";
    }
    return Task.FromResult(new ValidateResult { IsValid = true, Value = value });
}

Note that a BOOLEAN value is tricky to do validation with because it's a value type that cannot be null, so the validator won't see if it has a "NoValue" or "false" state. Because of this, I just created an enum, where the zero value is the "NoValue" state set by the bot framework:

public enum SvarAlternativ
    {
        NoValue,
        Ja, 
        Nej
    }

Hope this helps you. Once inside the validation method, you can context.close or do whatever you need.

Pedro G. Dias
  • 3,162
  • 1
  • 18
  • 30