コード例 #1
0
        private async Task HandleRequestMenu(IDialogContext context, IAwaitable <string> result)
        {
            var whatToShow = await result;
            var data       = await LuisApi.MakeRequest(whatToShow);

            var    intentOfResult = data["topScoringIntent"]["intent"].Value <string>();
            string option         = whatToShow.ToLower();

            try
            {
                Boolean askToOrder = false;
                if (option.Contains("eat") || option.Contains("food"))
                {
                    askToOrder = true;
                    await printFoodMenu(context);
                }
                else if (option.Contains("drink") || option.Contains("beverage"))
                {
                    askToOrder = true;
                    await printDrinksMenu(context);
                }
                else if (option.Contains("both") || option.Contains("all"))
                {
                    askToOrder = true;
                    await printFoodMenu(context);
                    await printDrinksMenu(context);
                }
                else if (intentOfResult.Equals("quitRequest"))
                {
                    await printQuitMessage(context);
                }
                else
                {
                    PromptDialog.Text(context, HandleRequestMenu, "Sorry, I don't understand this yet! What would you like to know - Menu for food, Menu for Drinks or both ?");
                }
                if (askToOrder)
                {
                    await context.PostAsync("Let me know what you want to Order!");
                }
            }
            catch (Exception e)
            {
                await context.PostAsync("Argh something went wrong with menu :( Sorry about that.");
            }
        }
コード例 #2
0
        private async Task handleOrderConfirm(IDialogContext context, IAwaitable <string> result)
        {
            var    foods         = await result;
            String m1            = "Would you like to confirm this order?" + "\n";
            string messageDialog = m1;

            if (foods.Equals("no") || foods.Equals("nope"))
            {
                foreach (var item in listOfOrders)
                {
                    messageDialog += item.quantity + " " + item.type + " " + item.name + " $" + getPrice(null, item) + "\n";
                }

                messageDialog += "Your total comes up to $" + getPrice(listOfOrders, null);
                context.PrivateConversationData.SetValue("orderStatus", "preConfirm");
                PromptDialog.Text(context, handleFinalIntent, messageDialog);
                //await context.PostAsync(m1 + "\n" + messageDialog);
            }



            else
            {
                var data = await LuisApi.MakeRequest(foods);

                var intentOfResult = data["topScoringIntent"]["intent"].Value <string>();
                if (!data.Equals(null) && intentOfResult.Equals("order"))
                {
                    JArray entitiesArr     = (JArray)data["entities"];
                    JArray entitiesArrComp = (JArray)data["compositeEntities"];
                    List <EntityRecommendation> entities = entitiesArr.ToObject <List <EntityRecommendation> >();
                    List <CompositeEntity>      comp     = entitiesArrComp.ToObject <List <CompositeEntity> >();

                    //context.PrivateConversationData.SetValue("custom", true);
                    await ExtractEntities(context, entities, comp, false);

                    //await context.Forward(new RootLuisDialog(), this.ResumeAfterNewOrderDialog, message, CancellationToken.None);
                }
                else
                {
                    PromptDialog.Text(context, handleOrderConfirm, "What do you want to order?");
                }
            }
        }
コード例 #3
0
        private async Task ResumeAfterOrderFoodClarification(IDialogContext context, IAwaitable <string> result)
        {
            var foods = await result;
            var data  = await LuisApi.MakeRequest(foods);

            var    intentOfResult  = data["topScoringIntent"]["intent"].Value <string>();
            JArray entitiesArr     = (JArray)data["entities"];
            JArray entitiesArrComp = (JArray)data["compositeEntities"];
            List <EntityRecommendation> entities = entitiesArr.ToObject <List <EntityRecommendation> >();
            List <CompositeEntity>      comp     = null;

            if (entitiesArrComp != null)
            {
                string food = context.PrivateConversationData.GetValue <string>("food");
                comp = entitiesArrComp.ToObject <List <CompositeEntity> >();
                List <Orders> orders   = getTempOrder(comp, food);
                Boolean       typeFlag = false;
                foreach (Orders order in orders)
                {
                    if (FoodMenu.foodDict[food].Contains(order.type))
                    {
                        addToOrder(listOfOrders, food, order.type, order.quantity, false);
                        typeFlag = true;
                        await context.PostAsync($"Great! I'll add {order.type} {food} to your order");

                        PromptDialog.Text(context, handleOrderConfirm, "Do you want to order anything else from here? You can continue to order or exclude items.");
                    }
                }

                if (!typeFlag)
                {
                    PromptDialog.Text(context, ResumeAfterOrderFoodClarification, "I'm sorry I didn't catch you. You can select the ones we have available.");
                }
            }
            else
            {
                PromptDialog.Text(context, ResumeAfterOrderFoodClarification, "I'm sorry I didn't catch you. You can select the ones we have available.");
            }



            /*
             * Boolean flag = false;
             * flag = CheckTypeValidity(context, foods);
             * // get quantity with luis call
             * if (flag)
             * {
             *  //if (!data.Equals(null) && intentOfResult.Equals("order"))
             *
             *  JArray entitiesArr = (JArray)data["entities"];
             *  JArray entitiesArrComp = (JArray)data["compositeEntities"];
             *  List<EntityRecommendation> entities = entitiesArr.ToObject<List<EntityRecommendation>>();
             *  List<CompositeEntity> comp = entitiesArrComp.ToObject<List<CompositeEntity>>();
             *
             *  await ExtractEntities(context, entities, comp, false);
             *  //await context.Forward(new RootLuisDialog(), this.ResumeAfterNewOrderDialog, message, CancellationToken.None);
             *
             *
             *  //foodTypePrompted = getType(context, foods);
             *  //context.PrivateConversationData.SetValue("typeFound", "true");
             *  //await context.PostAsync($"Great! I'll add {foodTypePrompted} burger to your order");
             *
             *  //addToOrder(listOfOrders, "burger", foodTypePrompted, 1);
             *
             *  //PromptDialog.Text(context, handleFinalIntent, "Do you want to order anything else from here?");
             * }
             * else
             * {
             *  context.PrivateConversationData.SetValue("typeFound", "false");
             *  //await context.PostAsync("Did not match with nay food type");
             *  PromptDialog.Text(context, ResumeAfterOrderFoodClarification, "I'm sorry I didn't catch you. You can select the ones we have available.");
             * }
             * //context.Wait(MessageReceived);
             */
        }