Example #1
0
        private async Task <DialogTurnResult> MenuPromptAsync(WaterfallStepContext sc, CancellationToken cancellationToken)
        {
            var convState = await StateAccessor.GetAsync(sc.Context, () => new HospitalitySkillState(), cancellationToken);

            convState.FoodList = new List <FoodRequestClass>();
            await GetFoodEntitiesAsync(sc.Context, cancellationToken);

            var menu = convState.LuisResult?.Entities?.Menu;

            // didn't order, prompt if 1 menu type not identified
            if (convState.FoodList.Count == 0 && string.IsNullOrWhiteSpace(menu?[0][0]) && menu?.Length != 1)
            {
                var prompt = TemplateManager.GenerateActivity(RoomServiceResponses.MenuPrompt);

                // TODO what does this for ?
                if (sc.Context.Activity.ChannelId == "google")
                {
                    prompt.Text  = prompt.Text.Replace("*", string.Empty);
                    prompt.Speak = prompt.Speak.Replace("*", string.Empty);
                    var listAttachment = new ListAttachment(
                        "Select an option below",
                        new List <OptionItem>()
                    {
                        new OptionItem()
                        {
                            Title = "Breakfast",
                            Image = new OptionItemImage()
                            {
                                AccessibilityText = "Item 1 image", Url = "http://cdn.cnn.com/cnnnext/dam/assets/190515173104-03-breakfast-around-the-world-avacado-toast.jpg"
                            },
                            OptionInfo = new OptionItemInfo()
                            {
                                Key = "Breakfast", Synonyms = new List <string>()
                                {
                                    "first"
                                }
                            }
                        },
                        new OptionItem()
                        {
                            Title = "Lunch",
                            Image = new OptionItemImage()
                            {
                                AccessibilityText = "Item 2 image", Url = "https://simply-delicious-food.com/wp-content/uploads/2018/07/mexican-lunch-bowls-3.jpg"
                            },
                            OptionInfo = new OptionItemInfo()
                            {
                                Key = "Lunch", Synonyms = new List <string>()
                                {
                                    "second"
                                }
                            }
                        },
                        new OptionItem()
                        {
                            Title = "Dinner",
                            Image = new OptionItemImage()
                            {
                                AccessibilityText = "Item 3 image", Url = "https://cafedelites.com/wp-content/uploads/2018/06/Garlic-Butter-Steak-Shrimp-Recipe-IMAGE-1.jpg"
                            },
                            OptionInfo = new OptionItemInfo()
                            {
                                Key = "Dinner", Synonyms = new List <string>()
                                {
                                    "third"
                                }
                            }
                        },
                        new OptionItem()
                        {
                            Title = "24 Hour Options",
                            Image = new OptionItemImage()
                            {
                                AccessibilityText = "Item 4 image", Url = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQvAkc_j44yfAhswKl9s5LKnwFL4MGAg4IwFM6lBVTs0W4o9fLB&s"
                            },
                            OptionInfo = new OptionItemInfo()
                            {
                                Key = "24 hour options", Synonyms = new List <string>()
                                {
                                    "fourth"
                                }
                            }
                        }
                    },
                        ListAttachmentStyle.Carousel);
                    prompt.Attachments.Add(listAttachment);
                }
                else
                {
                    var actions = new List <CardAction>()
                    {
                        new CardAction(type: ActionTypes.ImBack, title: "Breakfast", value: "Breakfast menu"),
                        new CardAction(type: ActionTypes.ImBack, title: "Lunch", value: "Lunch menu"),
                        new CardAction(type: ActionTypes.ImBack, title: "Dinner", value: "Dinner menu"),
                        new CardAction(type: ActionTypes.ImBack, title: "24 Hour", value: "24 hour menu")
                    };

                    // create hero card instead when channel does not support suggested actions
                    if (!Channel.SupportsSuggestedActions(sc.Context.Activity.ChannelId))
                    {
                        var hero = new HeroCard(buttons: actions);
                        prompt.Attachments.Add(hero.ToAttachment());
                    }
                    else
                    {
                        prompt.SuggestedActions = new SuggestedActions {
                            Actions = actions
                        };
                    }
                }

                return(await sc.PromptAsync(DialogIds.MenuPrompt, new PromptOptions()
                {
                    Prompt = prompt,
                    RetryPrompt = TemplateManager.GenerateActivity(RoomServiceResponses.ChooseOneMenu)
                }, cancellationToken));
            }

            return(await sc.NextAsync(cancellationToken: cancellationToken));
        }
Example #2
0
        private async Task <DialogTurnResult> ShowMenuCardAsync(WaterfallStepContext sc, CancellationToken cancellationToken)
        {
            var convState = await StateAccessor.GetAsync(sc.Context, () => new HospitalitySkillState(), cancellationToken);

            if (convState.FoodList.Count == 0)
            {
                Menu menu = HotelService.GetMenu(convState.LuisResult?.Entities?.Menu[0][0]);

                // get available items for requested menu
                List <Card> menuItems = new List <Card>();
                foreach (var item in menu.Items)
                {
                    var cardName = GetCardName(sc.Context, "MenuItemCard");

                    // workaround for webchat not supporting hidden items on cards
                    if (Channel.GetChannelId(sc.Context) == Channels.Webchat)
                    {
                        cardName += ".1.0";
                    }

                    menuItems.Add(new Card(cardName, item));
                }

                var prompt = TemplateManager.GenerateActivity(RoomServiceResponses.FoodOrder);
                if (sc.Context.Activity.ChannelId == "google")
                {
                    List <OptionItem> menuOptions = new List <OptionItem>();
                    foreach (MenuItem item in menu.Items)
                    {
                        var option = new OptionItem()
                        {
                            Title       = item.Name,
                            Description = item.Description + " " + item.Price,
                            OptionInfo  = new OptionItemInfo()
                            {
                                Key = item.Name, Synonyms = new List <string>()
                                {
                                }
                            }
                        };
                        menuOptions.Add(option);
                    }

                    var listAttachment = new ListAttachment(
                        menu.Type + ": " + menu.TimeAvailable,
                        menuOptions,
                        ListAttachmentStyle.List);
                    prompt.Attachments.Add(listAttachment);
                }
                else
                {
                    // show menu card
                    await sc.Context.SendActivityAsync(TemplateManager.GenerateActivity(null, new Card(GetCardName(sc.Context, "MenuCard"), menu), null, "items", menuItems), cancellationToken);
                }

                // prompt for order
                return(await sc.PromptAsync(DialogIds.FoodOrderPrompt, new PromptOptions()
                {
                    Prompt = prompt,
                    RetryPrompt = TemplateManager.GenerateActivity(RoomServiceResponses.RetryFoodOrder)
                }, cancellationToken));
            }

            return(await sc.NextAsync(cancellationToken: cancellationToken));
        }