I want to prompt further field based on its previous field result in Bot Framework App [duplicate]

不想你离开。 提交于 2019-12-24 15:00:25

问题


I have below formbuilder code in a class, I want to prompt user based on its response. if user response for field "ConfirmISTTimeZone" is "Yes" then it should prompt for the field "TimeZone" else it should directly prompt "Duration" How to do this?

var formflow = new FormBuilder<FlightBooking>().Message("Tell me Flight details!")
        .Field(nameof(Flightname))
        .Field(nameof(StartDate), validate: ValidateStartDate)
        .Field(nameof(ConfirmISTTimeZone), validate: ValidateResponseOfTimeZone)
        .Field(nameof(TimeZone), validate: ValidateTimeZone)
        .Field(nameof(Duration), validate: ValidateDuration)

回答1:


You can use the SetActivemethod for that on the FieldReflectorclass.

var formflow = new FormBuilder<FlightBooking>().Message("Tell me Flight details!")
        .Field(nameof(Flightname))
        .Field(nameof(StartDate), validate: ValidateStartDate)
        .Field(nameof(ConfirmISTTimeZone), validate: ValidateResponseOfTimeZone)
        .Field(new FieldReflector<FlightBooking>(nameof(TimeZone))
               .SetActive(CheckActiveMethod)
               .SetValidate(ValidateTimeZone))
        .Field(nameof(Duration), validate: ValidateDuration)

The CheckActiveMethod is just a method that takes the state and return either true, if the field is active and should be prompted, or false, if the field can be skipped.




回答2:


Another option is include 'active: ActiveTimeZone' in the Field of TimeZone

.Field(nameof(TimeZone), active: ActiveTimeZone, validate: ValidateTimeZone)

 private bool ActiveTimeZone(FlightBooking state)
    {
        bool setActive = true;
        if (!state.ConfirmISTTimeZone.Contains("Add ur condition here"))
            setActive = false;


        return setActive;

    }


来源:https://stackoverflow.com/questions/44126219/i-want-to-prompt-further-field-based-on-its-previous-field-result-in-bot-framewo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!