示例#1
0
        /// <summary>
        /// Prompt for the Food type if not already provided on the initial utterance.
        /// </summary>
        /// <param name="sc">Waterfall Step Context.</param>
        /// <param name="cancellationToken">Cancellation Token.</param>
        /// <returns>Dialog Turn Result.</returns>
        private async Task <DialogTurnResult> AskForFoodTypeAsync(WaterfallStepContext sc, CancellationToken cancellationToken)
        {
            var state = await ConversationStateAccessor.GetAsync(sc.Context, cancellationToken : cancellationToken);

            var reservation = state.Booking;

            // If we already have a Cuisine provided we skip to next step
            if (reservation.Category != null)
            {
                return(await sc.NextAsync(sc.Values, cancellationToken));
            }

            // Fixed test data provided at this time
            var foodTypes = SeedReservationSampleData
                            .GetListOfDefaultFoodTypes()
                            .Select(
                r => new FoodTypeInfo
            {
                TypeName = r.Category,
                ImageUrl = BotImageForFoodType(r.Category)
            }).ToList();

            var tokens = new Dictionary <string, object>
            {
                { "FoodTypeList", foodTypes.ToSpeechString(TemplateManager.GetString(BotStrings.Or), f => f.TypeName) }
            };

            state.Cuisine = foodTypes;

            var cards   = new List <Card>();
            var options = new PromptOptions()
            {
                Choices = new List <Choice>(),
            };

            foreach (var foodType in foodTypes)
            {
                cards.Add(new Card(
                              GetDivergedCardName(sc.Context, "CuisineChoiceCard"),
                              new CuisineChoiceCardData
                {
                    ImageUrl   = foodType.ImageUrl,
                    ImageSize  = AdaptiveImageSize.Stretch,
                    ImageAlign = AdaptiveHorizontalAlignment.Stretch,
                    Cuisine    = foodType.TypeName,
                }));

                options.Choices.Add(new Choice(foodType.TypeName));
            }

            var replyMessage = TemplateManager.GenerateActivity(
                RestaurantBookingSharedResponses.BookRestaurantFoodSelectionPrompt,
                cards,
                tokens);

            // Prompt for restaurant choice
            return(await sc.PromptAsync(Actions.AskForFoodType, new PromptOptions { Prompt = replyMessage, Choices = options.Choices }, cancellationToken));
        }
示例#2
0
        /// <summary>
        /// Prompt for the Food type if not already provided on the initial utterance.
        /// </summary>
        /// <param name="sc">Waterfall Step Context.</param>
        /// <param name="cancellationToken">Cancellation Token.</param>
        /// <returns>Dialog Turn Result.</returns>
        private async Task <DialogTurnResult> AskForFoodType(WaterfallStepContext sc, CancellationToken cancellationToken)
        {
            var state = await Accessor.GetAsync(sc.Context);

            var reservation = state.Booking;

            // If we already have a Cuisine provided we skip to next step
            if (reservation.Category != null)
            {
                return(await sc.NextAsync(sc.Values, cancellationToken));
            }

            // Fixed test data provided at this time
            var foodTypes = SeedReservationSampleData
                            .GetListOfDefaultFoodTypes()
                            .Select(
                r => new FoodTypeInfo
            {
                TypeName = r.Category,
                ImageUrl = BotImageForFoodType(r.Category)
            }).ToList();

            var tokens = new StringDictionary
            {
                { "FoodTypeList", foodTypes.ToSpeechString(BotStrings.Or, f => f.TypeName) }
            };

            state.Cuisine = foodTypes;

            // Create a card for each restaurant
            var cardsData = new List <TitleImageTextButtonCardData>();

            foodTypes.ForEach(ft => cardsData.Add(
                                  new TitleImageTextButtonCardData
            {
                ImageUrl         = ft.ImageUrl,
                ImageSize        = AdaptiveImageSize.Stretch,
                ImageAlign       = AdaptiveHorizontalAlignment.Stretch,
                ButtonTitle      = ft.TypeName,
                SelectedItemData = ft.TypeName
            }));

            var reply = sc.Context.Activity.CreateAdaptiveCardGroupReply(
                RestaurantBookingSharedResponses.BookRestaurantFoodSelectionPrompt,
                @"Dialogs\RestaurantBooking\Resources\Cards\TitleImageTextButton.json",
                AttachmentLayoutTypes.Carousel, cardsData, ResponseBuilder, tokens);

            // Prompt for restaurant choice
            return(await sc.PromptAsync(Actions.AskForFoodType, new PromptOptions { Prompt = reply }, cancellationToken));
        }