Branching dialogs/forms based on response in MS Bot Framework

前端 未结 1 1566
抹茶落季
抹茶落季 2021-01-16 08:51

We\'re experimenting with the MS Bot Framework and haven\'t quite worked out how to do this scenario:

We have a LUIS Dialog (type ), which
相关标签:
1条回答
  • 2021-01-16 09:36

    The FormFlow route is a valid option. What is missing in your form flow is asking for the address/order number after the lookup option is selected.

    What you can do in that case is adding two more fields to the OrderStatusDialog class: OrderNumber and DeliveryAddress.

    Then you need to use the selected OrderStatusLookupOptions to activate/deactivate the next field.

    The code, from the top of my head, would be something like:

    [Serializable]
    public class OrderStatusDialog
    {
        public OrderStatusLookupOptions? LookupOption;
    
        public int OrderNumber;
    
        public string DeliveryAddress
    
        public static IForm<OrderStatusDialog> BuildForm()
        {
            return new FormBuilder<OrderStatusDialog>()
                .Message("In order to look up the status of a order, we will first need either the order number or your delivery address.")
                .Field(nameof(OrderStatusDialog.LookupOption))
                .Field(new FieldReflector<OrderStatusDialog>(nameof(OrderStatusDialog.OrderNumber))
                    .SetActive(state => state.LookupOption == OrderStatusLookupOptions.OrderNumber))
                .Field(new FieldReflector<OrderStatusDialog>(nameof(OrderStatusDialog.DeliveryAddress))
                    .SetActive(state => state.LookupOption == OrderStatusLookupOptions.Address))
                .Build();
        }
    }
    

    Then on your Callback method you will receive the form filled and you can do the DB lookup.

    Alternatively, you can just use PromptDialogs and guide the user through the same experience. Take a look to the MultiDialogs sample to see the different alternatives.

    I added a working sample on this here.

    0 讨论(0)
提交回复
热议问题