예제 #1
0
        public async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> argument)
        {
            IMessageActivity activity = await argument;

            if (activity.Attachments != null && activity.Attachments.Count > 0)
            {
                await context.PostAsync("Ich habe attachments gefunden");

                byte[] bytes = await this.getContentFromAttachment(activity, activity.Attachments[0]);

                string url = await AzureFunctionAPI.SaveBlob(bytes);

                HeroCard heroCard = new HeroCard()
                {
                    Images = new List <CardImage>()
                    {
                        new CardImage(url, alt: url),
                    },
                    Text = url
                };
                IMessageActivity response = context.MakeMessage();
                response.Attachments = new List <Attachment>();
                response.Attachments.Add(heroCard.ToAttachment());

                await context.PostAsync(response);

                context.Done("Fertig");
                return;
            }
            string TextToLuis = activity.Text;

            this.luisResult = await LuisApi.GetLuisResult(TextToLuis);

            await this.HandleLuisMessage(context);
        }
예제 #2
0
        public async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> argument)
        {
            var message = await argument;

            var TextToLuis = (await argument).Text;

            luisResult = await LuisApi.GetLuisResult(TextToLuis);

            await this.HandleLuisMessage(context);
        }
예제 #3
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.");
            }
        }
예제 #4
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?");
                }
            }
        }
예제 #5
0
        private async Task <DialogTurnResult> ActStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            if (!_luisRecognizer.IsConfigured)
            {
                // LUIS is not configured, we just run the BookingDialog path with an empty BookingDetailsInstance.
                return(await stepContext.BeginDialogAsync(nameof(TextPrompt), new PromptOptions { Prompt = MessageFactory.Text("Luis not Configured") }, cancellationToken));
            }


            var Intent = await LuisApi.SendUserInputToLuis(stepContext.Result.ToString());

            switch (Intent)
            {
            case "Hello":


                var HelloMessageText = "Hello there";
                var getHelloMessage  = MessageFactory.Text(HelloMessageText, HelloMessageText, InputHints.IgnoringInput);
                await stepContext.Context.SendActivityAsync(getHelloMessage, cancellationToken);

                break;


            case "Goodbye":
                // We haven't implemented the GetWeatherDialog so we just display a TODO message.
                var ByeMessageText = "Goodbye there";
                var getByeMessage  = MessageFactory.Text(ByeMessageText, ByeMessageText, InputHints.IgnoringInput);
                await stepContext.Context.SendActivityAsync(getByeMessage, cancellationToken);

                break;

            case "Jokes":

                var joke = await JokesApi.GetJoke();

                var JokeMessageText = "Mmmm well..." + System.Environment.NewLine + joke;
                var getJokeMessage  = MessageFactory.Text(JokeMessageText, JokeMessageText, InputHints.IgnoringInput);
                await stepContext.Context.SendActivityAsync(getJokeMessage, cancellationToken);

                break;

            case "UserLaughs":
                Random rnd  = new Random();
                int    rndv = rnd.Next(1, 3);
                if (rndv == 1)
                {
                    var userLaughText       = "Yes, this was funny, I liked it too... 🤣🤣🤣🤣";
                    var getuserLaughMessage = MessageFactory.Text(userLaughText, userLaughText, InputHints.IgnoringInput);
                    await stepContext.Context.SendActivityAsync(getuserLaughMessage, cancellationToken);

                    break;
                }
                else
                {
                    var userLaughText       = "🤣🤣🤣🤣";
                    var getuserLaughMessage = MessageFactory.Text(userLaughText, userLaughText, InputHints.IgnoringInput);
                    await stepContext.Context.SendActivityAsync(getuserLaughMessage, cancellationToken);

                    break;
                }

            case "Recipes":
                return(await stepContext.BeginDialogAsync(nameof(RecipeDialog), null, cancellationToken));

            case "weather":
                return(await stepContext.BeginDialogAsync(nameof(WeatherDialog), null, cancellationToken));

            default:
                // Catch all for unhandled intents
                var didntUnderstandMessageText = $"Sorry, I didn't get that. Please try asking in a different way";
                var didntUnderstandMessage     = MessageFactory.Text(didntUnderstandMessageText, didntUnderstandMessageText, InputHints.IgnoringInput);
                await stepContext.Context.SendActivityAsync(didntUnderstandMessage, cancellationToken);

                break;
            }

            return(await stepContext.NextAsync(null, cancellationToken));
        }
예제 #6
0
 /// <summary>
 /// Setup before each unit test
 /// </summary>
 public void Init()
 {
     instance = new LuisApi();
 }
예제 #7
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);
             */
        }