Пример #1
0
        private async Task CallLuisPhoneNodeAsync(List <string> basket, IDialogContext context)
        {
            StringBuilder sb = new StringBuilder();  // Only works for debug
            IntentDecoder theDecoder;
            TopFeatures   topFeatures;
            Activity      reply = ((Activity)context.Activity).CreateReply("You can also at any stage ask for all phones and work through the different options on your own, just type \"Start Again\"");

            handSets.InitializeBag(basket);
            theDecoder  = new IntentDecoder(handSets, null, null, basket);
            topFeatures = new TopFeatures(theDecoder);
            if (debugMessages)
            {
                await context.PostAsync($"DEBUG : bag is beginning with {handSets.BagCount()}");
            }
            if (debugMessages)
            {
                await context.PostAsync("DEBUG : String Representation = " + handSets.BuildStrRep());
            }
            if (GetModelCount() == basket.Count)
            {
                await Miscellany.InsertDelayAsync(context);

                await context.PostAsync($"We have over {basket.Count} different models of phone to choose from.");

                await Miscellany.InsertDelayAsync(context);

                await context.PostAsync("As you are unsure what is your best model then let me know what is important to you and I'll select a few for you to choose from");

                await Miscellany.InsertDelayAsync(context);

                await context.PostAsync(" If you like a particular brand just say which ones.");

                await Miscellany.InsertDelayAsync(context);

                await context.PostAsync("Or you can choose features (like weight, battery life, camera...) or just tell me how you mostly use your phone (e.g. I like to play games on my iPhone, I regularly read books on my phone)");
            }
            else
            {
                await Miscellany.InsertDelayAsync(context);

                await context.PostAsync($"We have {basket.Count} phones which match your requirement.If you tell me what is important to you or how you use your phone then I can help you to pick the right one.");
            }
            reply.SuggestedActions = topFeatures.GetTop4Buttons(sb);
            if (debugMessages)
            {
                await context.PostAsync("DEBUG : Results " + sb.ToString());
            }
            await Miscellany.InsertDelayAsync(context);

            await context.PostAsync(reply);

            context.Call(new NodeLUISPhoneDialog(topFeatures, handSets, null, null, basket), LuisResponseHandlerAsync);
            LuisCalled = true;
        }
        private async Task UpdateUserAsync(IDialogContext context, int handSetsLeft, int handSetsB4)
        {
            StringBuilder sb = new StringBuilder("-->");
            string        acknowledgeMsg = decoder.LastOneWasNeed ? null : GetRightStringMsg(), aux;
            bool          removedSome = true;
            var           reply       = ((Activity)context.Activity).CreateReply("What else is important to refine it further?");

            if (CommonDialog.debugMessages)
            {
                await context.PostAsync($"DEBUG : Threshold = {decoder.Threshold}, desired intent = {desiredFeature}");

                await context.PostAsync("DEBUG : Ranking : \r\n");

                await context.PostAsync(sb.ToString() + "\r\n");
            }
            if (handSetsLeft == handSetsB4)
            {
                await Miscellany.InsertDelayAsync(context);

                await context.PostAsync("Unfortunately, that doesn't help in narrowing the list down");

                removedSome = false;
            }
            else if (handSetsLeft == 0)
            {
                await Miscellany.InsertDelayAsync(context);

                await context.PostAsync("I'm afraid that's a very high standard, I don't have any equipment that fulfills it.");

                removedSome  = false;
                handSetsLeft = handSetsB4;
            }
            if (handSetsLeft > BotConstants.MAX_CAROUSEL_CARDS)
            {
                if (CommonDialog.debugMessages)
                {
                    await context.PostAsync($"DEBUG : There are {handSetsLeft} on bag");
                }
                if (removedSome && (acknowledgeMsg != null))
                {
                    await Miscellany.InsertDelayAsync(context);

                    await context.PostAsync(acknowledgeMsg);
                }
                aux = removedSome ? "We have now" : "We still have";
                await Miscellany.InsertDelayAsync(context);

                await context.PostAsync($"{aux} {handSetsLeft} models that might be suitable for your needs. I could help short list further if you tell me what else is important for you");

                sb = new StringBuilder("");
                reply.SuggestedActions = topButtons.GetTop4Buttons(sb);
                await Miscellany.InsertDelayAsync(context);

                await context.PostAsync(reply);
            }
            else
            {
                if (CommonDialog.debugMessages)
                {
                    await context.PostAsync("We have just 5 left or fewer");
                }
                if (acknowledgeMsg != null)
                {
                    await Miscellany.InsertDelayAsync(context);

                    await context.PostAsync(acknowledgeMsg);
                }
                if ((!decoder.LastOneWasNeed) && (desiredFeature == EIntents.Brand))
                {
                    context.ConversationData.SetValue(BotConstants.SELECTED_BRANDS_KEY, decoder.StrKeyWords);
                }
                if (CommonDialog.debugMessages)
                {
                    await context.PostAsync($"DEBUG : Number of phones on bag : {handSetsBag.BagCount()}");
                }
                context.Done(decoder);
            }
        }
Пример #3
0
        private async Task RecommendPhoneAsync(IDialogContext context, string brand, DateTime?lowerThreshold = null)
        {
            int           count;
            TopFeatures   topFeatures;
            IntentDecoder theDecoder = new IntentDecoder(handSets, brand, lowerThreshold, null);

            StringBuilder sb = new StringBuilder("");   // For debugging purposes

            try
            {
                topFeatures = new TopFeatures(theDecoder);
                handSets.InitializeBag(brand, lowerThreshold);
                count = handSets.BagCount();
                if (count > BotConstants.MAX_CAROUSEL_CARDS)
                {
                    if (debugMessages)
                    {
                        if (debugMessages)
                        {
                            await context.PostAsync($"DEBUG : bag is beginning with {handSets.BagCount()}");
                        }
                    }
                    if (debugMessages)
                    {
                        await context.PostAsync("DEBUG : String Representation = " + handSets.BuildStrRep());
                    }
                    Activity message = (Activity)context.Activity;
                    Activity reply   = message.CreateReply(isUnsure ? "If you like a particular brand just say which one and I can display all the models available from that supplier in a carousel below" :
                                                           "Remember that you can always ask for all phones and work through the different options on your own,just enter \"Start Again\"");
                    reply.SuggestedActions = topFeatures.GetTop4Buttons(sb);
                    if (debugMessages)
                    {
                        await context.PostAsync("DEBUG : " + sb.ToString());
                    }
                    await Miscellany.InsertDelayAsync(context);

                    await context.PostAsync($"We have over { count} different models of phone to choose from. ");

                    if (isUnsure)
                    {
                        await Miscellany.InsertDelayAsync(context);

                        await context.PostAsync("As you are unsure what is your best model then let me know what is important to you and I'll select a few for you to choose from. If you like a particular brand just say which ones.");
                    }
                    await Miscellany.InsertDelayAsync(context);

                    await context.PostAsync("Or you can choose features (like weight, battery life, camera...) ");

                    await Miscellany.InsertDelayAsync(context);

                    await context.PostAsync("I can also recommend some models if you tell me how you mostly use your phone (e.g. I like to play games on my iPhone, I regularly read books on my phone)");

                    await Miscellany.InsertDelayAsync(context);

                    await context.PostAsync(reply);

                    context.Call(new NodeLUISPhoneDialog(topFeatures, handSets, brand, lowerThreshold, null), LuisResponseHandlerAsync);
                }
                else
                {
                    context.Call(new LessThan5Node(handSets.GetBagModels(), true), FinalSelectionReceivedAsync);
                }
            }
            catch (Exception xception)
            {
                if (debugMessages)
                {
                    await context.PostAsync("DEBUG : Message from the exception : " + xception.Message + "\r\nDEBUG : string builder : " + sb.ToString());
                }
            }
        }