コード例 #1
0
        private async Task AskAboutFeaturePhonesAsync(IDialogContext context)
        {
            Activity         activity = (Activity)context.Activity;
            var              reply    = activity.CreateReply("Are you looking for a classic phone or a smart phone?");
            SuggestedActions buttons;

            // turn on flag
            askingAboutFeaturePhones = true;
            buttons = new SuggestedActions()
            {
                Actions = new List <CardAction>()
                {
                    new CardAction()
                    {
                        Title = "Classic Phone", Type = ActionTypes.ImBack, Value = "I'm looking for a classic phone"
                    },
                    new CardAction()
                    {
                        Title = "SmartPhone", Type = ActionTypes.ImBack, Value = "I'm looking for a smart phone"
                    },
                    new CardAction()
                    {
                        Title = "It doesn't really matter to me", Type = ActionTypes.ImBack, Value = "It doesn't matter"
                    }
                }
            };
            reply.SuggestedActions = buttons;
            await Miscellany.InsertDelayAsync(context);

            await context.PostAsync(reply);
        }
コード例 #2
0
        public async Task None(IDialogContext context, LuisResult result)
        {
            string typosWarning = TyposInformation(result);
            bool   typos        = typosWarning != null;
            double score        = ObtainTopIntentScore(result);

            if (justCheck4Errors)
            {
                CheckSpelling(context, result);
                return;
            }

            EDegreeOfCertain degreeOfCertain = GetDegreeOfCertain(result);

            if (typos)
            {
                await context.PostAsync(typosWarning);

                initialPhrase = result.AlteredQuery;
            }
            else
            {
                initialPhrase = result.Query;
            }
            await this.PostDebugInfoAsync(context, result, "No intention");

            await Miscellany.InsertDelayAsync(context);

            await context.PostAsync($"I'm sorry. I didn’t understand how I can help you. I can help you to **upgrade your phone**, to **change your plan** or **both**. I’ll be here whenever you type something new and we can start again.");

            context.Done(Tuple.Create(initialPhrase, EIntent.None));
        }
コード例 #3
0
        public async Task Morning(IDialogContext context, LuisResult result)
        {
            string utterance, response;

            if (result.AlteredQuery == null)
            {
                utterance = result.Query;
            }
            else
            {
                utterance = result.AlteredQuery;
            }
            utterance = utterance.ToLower();
            if (utterance.Contains("morning"))
            {
                response = "Good Morning!";
            }
            else if (utterance.Contains("evening"))
            {
                response = "Good Evening!";
            }
            else if (utterance.Contains("afternoon"))
            {
                response = "Good Afternoon!";
            }
            else
            {
                response = "Hello!";
            }
            await Miscellany.InsertDelayAsync(context);

            await context.PostAsync(response);

            await WriteGenericReplyAsync(context);
        }
コード例 #4
0
        public async Task Cheap(IDialogContext context, LuisResult result)
        {
            await ShowDebugInfoAsync(context, result);

            string chosenPlan;

            if (context.ConversationData.TryGetValue("ChosenPlanName", out chosenPlan))
            {
                await Miscellany.InsertDelayAsync(context);

                await context.PostAsync("I understand that for you price is important.");

                desiredFeature = EIntents.Cheap;
                await ProcessNeedOrFeatureAsync(context, result);
            }
            else
            {
                await Miscellany.InsertDelayAsync(context);

                await context.PostAsync("I understand that price is an important thing for you, but this will depend on what plan you take it with.  Lets work the plan out first then and come back to the phone.");

                desiredFeature = EIntents.Cheap;
                res            = result;
                context.Call(new PlanNode(), ProcessAfterPlanAsync);
            }
        }
コード例 #5
0
        private async Task ProcessBrandChoice(IDialogContext context, IAwaitable <object> awaitable)
        {
            Activity reply, ans = (Activity)(await awaitable);
            string   brand = ans.Text;


            if ((brand.Length > 7) && (brand.StartsWith("I want ")))
            {
                brand = brand.Substring(7).ToLower();
            }
            if (handSetsBag.IsBrandUnavailable(brand))
            {
                reply = ans.CreateReply("I'm sorry, unfortunately we do not have that brand available, would it be possible to pick another one?");
                Miscellany.ComposeBrandsCarousel(reply, handSetsBag.GetAllBrands().Keys, handSetsBag);
                await Miscellany.InsertDelayAsync(context);

                await context.PostAsync(reply);
            }
            else if (!handSetsBag.GetAllBrands().Keys.Contains(brand))
            {
                reply = ans.CreateReply("I'm sorry, unfortunately I don't know that brand, would it be possible to pick another one?");
                Miscellany.ComposeBrandsCarousel(reply, handSetsBag.GetAllBrands().Keys, handSetsBag);
                await Miscellany.InsertDelayAsync(context);

                await context.PostAsync(reply);
            }
            else
            {
                decoder.StrKeyWords = new List <string> {
                    brand.ToLower()
                };
                context.Wait(MessageReceived);
                await DecodeAndProcessIntentAsync(context);
            }
        }
コード例 #6
0
        private async Task AskBrandAndModelAsync(IDialogContext context)
        {
            StringBuilder builder        = new StringBuilder();
            var           reply          = ((Activity)context.Activity).CreateReply();
            int           numberOfModels = availableModelsCount;

            try
            {
                brands = GetAllBrands();

                reply.Text = $"You can choose from {numberOfModels} models from Apple, Samsung, Nokia and other leading brands. Click or type the brands below from this list";
                if (debugMessages)
                {
                    await context.PostAsync("DEBUG : Calling ComposeBrandsCarousel()");
                }
                Miscellany.ComposeBrandsCarousel(reply, brands.Keys, handSets);
                // ComposeBrandsCarousel(reply);
            }
            catch (Exception xception)
            {
                await context.PostAsync("xception message = " + xception.Message);
            }
            await Miscellany.InsertDelayAsync(context);

            await context.PostAsync(reply);

            context.Wait(BrandChoiceMadeAskModelAsync);
        }
コード例 #7
0
        private async Task CongratulateSubsAsync(IDialogContext context)
        {
            string congratulationsMsg = Miscellany.GetCorrectCongratsMessage(context, handSets.GetModelFeatures(chosenModel));

            await Miscellany.InsertDelayAsync(context);

            await context.PostAsync(congratulationsMsg);

            if (congratulationsMsg.StartsWith("Exce"))
            {
                await Miscellany.InsertDelayAsync(context);

                await context.PostAsync("The next step is to work out what plan is the best for you");
            }
            context.ConversationData.SetValue("SelectedPhone", chosenModel);
            //Ryans flow kicks in
            await Task.Delay(3000);

            if (CommonDialog.debugMessages)
            {
                await context.PostAsync("DEBUG : I'm going to call Ryan's node");
            }
            try
            {
                context.Call(new PlanNode(), PlanFlowDone);
            }
            catch (Exception xception)
            {
                await context.PostAsync("Error...xception message = " + xception.ToString());
            }
        }
コード例 #8
0
        public async Task HowAreYou(IDialogContext context, LuisResult result)
        {
            await Miscellany.InsertDelayAsync(context);

            await context.PostAsync("I'm fine, thank you.");

            await WriteGenericReplyAsync(context);
        }
コード例 #9
0
        private async Task MessageReceivedWithDecisionAsync(IDialogContext context, IAwaitable <IMessageActivity> awaitable)
        {
            IMessageActivity messageActivity = await awaitable;
            string           response = messageActivity.Text.TrimStart(' ');
            bool             knowsWhatHeWants = !(response.ToLower().StartsWith("no") && ((response.Length == 2) || !char.IsLetter(response[2])));
            List <string>    wantedBrands, wantedModels;
            int totalPhones = 3;

            try
            {
                totalPhones = GetModelCount();
            }
            catch (Exception xception)
            {
                await context.PostAsync("Error...xception message = " + xception.Message);
            }

            if (knowsWhatHeWants)
            {
                context.ConversationData.RemoveValue(BotConstants.LAST_FEATURE_KEY);
                context.ConversationData.RemoveValue(BotConstants.LAST_NEED_KEY);
                phraseFromSubs = response;
                if (debugMessages)
                {
                    await context.PostAsync("DEBUG : Response received " + response);
                }
                if (IndicatedModelsAndOrBrands(out wantedBrands, out wantedModels))
                {
                    await ProcessSelectedBrandsAndModels(context, wantedBrands, wantedModels, false);
                }
                else
                {
                    await Miscellany.InsertDelayAsync(context);

                    await context.PostAsync("Great to know. What model do you like the most?");

                    context.Call(new NodeLUISBegin(true), BrandAndModelReceivedAsync);
                }
            }
            else
            {
                if (debugMessages)
                {
                    await context.PostAsync("DEBUG : string representation : " + handSets.BuildStrRepFull());
                }

                /*    context.ConversationData.RemoveValue(BotConstants.LAST_FEATURE_KEY);
                 *  context.ConversationData.RemoveValue(BotConstants.LAST_NEED_KEY);
                 *  await DisplayTopSalesCarouselAsync(context);
                 *  firstTime = false;
                 *  context.Wait(PickOrRecommendOptionReceivedAsync);*/
                await AskPickOrRecommendOption(context);
            }
        }
コード例 #10
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;
        }
コード例 #11
0
        /*
         * - it's just that brand
         * > it's just that brand, but newer than current phone (deprecated)
         * : it's the brand and model node, he wants to explicitly pick the brand and then model
         * ~ it's everything that is not that brand
         *
         */
        private async Task FinalSelectionReceivedAsync(IDialogContext context, IAwaitable <object> awaitable)
        {
            string        selection = (string)(await awaitable);
            List <string> models2Exclude, remainingModels;

            if (debugMessages)
            {
                await context.PostAsync("DEBUG: Final selection received : " + selection);
            }
            switch (selection[0])
            {
            case LessThan5Node.SOME_OTHER_BRAND:
                isUnsure = false;
                await RecommendPhoneAsync(context, "!" + selection.Substring(1));

                break;

            case LessThan5Node.STICK_WITH_BRAND:
                isUnsure = false;
                await RecommendPhoneAsync(context, selection.Substring(1));

                break;

            case LessThan5Node.NONE_OF_THESE_MODELS:         // Start again from LessThan5Node
                await AskPickOrRecommendOption(context);

                break;
                models2Exclude = new List <string>(selection.Substring(1).Split(LessThan5Node.NONE_OF_THESE_MODELS));
                if (models2Exclude.Count == GetAllModels().Count)
                {
                    await Miscellany.InsertDelayAsync(context);

                    await context.PostAsync("Let's retry and find a phone that is suitable for your needs");

                    models2Exclude.Clear();
                }
                if (LuisCalled)
                {
                    context.Call(new BrandModelNode(models2Exclude), FinalSelectionReceivedAsync);
                }
                else
                {
                    remainingModels = new List <string>(GetAllModels().Except(models2Exclude));
                    await CallLuisPhoneNodeAsync(remainingModels, context);
                }
                break;

            default:
                context.Call(new ColorsNode(selection), MessageReceivedAsync);
                break;
            }
        }
コード例 #12
0
        private async Task BrandAndModelReceivedAsync(IDialogContext context, IAwaitable <object> awaitable)
        {
            List <string> brandsWanted = null,
                          modelsWanted = null;
            StringBuilder                         stringBuilder = new StringBuilder("Brands : ");
            Dictionary <string, bool>             brandsSet     = null;
            Dictionary <string, bool>             modelsSet;
            Tuple <string, NodeLUISBegin.EIntent> result = (Tuple <string, NodeLUISBegin.EIntent>)(await awaitable);
            string fullSentence;

            if (debugMessages)
            {
                await context.PostAsync("Beginning of BrandAndModelReceivedAsync()");
            }

            if (result.Item2 != NodeLUISBegin.EIntent.None)
            {
                string[] temp = result.Item1.Split(':');

                fullSentence = temp[1];
                await Miscellany.InsertDelayAsync(context);

                await context.PostAsync($"You typed \"{temp[0]}\", did you mean \"{Miscellany.QueryCompare(temp[0],fullSentence)}\"?");
            }
            else
            {
                fullSentence = result.Item1;
            }
            try
            {
                brandsSet = GetAllBrands();
            }
            catch (Exception xception)
            {
                await context.PostAsync("Error... xception message = " + xception.Message);
            }
            modelsSet = GetBrandModels(null);
            try
            {
                brandsWanted = FindBrandOccurrences(fullSentence, brandsSet);
                modelsWanted = FindModelOccurrences(fullSentence, modelsSet);
            }
            catch (Exception xception)
            {
                await context.PostAsync($"Exception message = {xception.Message}");
            }

            await ProcessSelectedBrandsAndModels(context, brandsWanted, modelsWanted, true);
        }
コード例 #13
0
        private async Task AskToRephraseAsync(IDialogContext context, LuisResult result)
        {
            if (numberOfTries >= MAX_TRIES)
            {
                await Miscellany.InsertDelayAsync(context);

                await context.PostAsync("I'm sorry, I'm afraid I can't understand what you want to do. Would you like to talk to a human?");

                numberOfTries = 1; // reset it
                context.Done(0);
                return;
            }
            if (numberOfTries++ == 1)
            {
                await Miscellany.InsertDelayAsync(context);

                await context.PostAsync("Sorry, I couldn't understand what you would like to do. ");

                await Miscellany.InsertDelayAsync(context);

                await context.PostAsync("Would it be possible to rephrase?");

                await Miscellany.InsertDelayAsync(context);

                await context.PostAsync("I'm here to help you upgrade a phone, plan or both. Which one do you want to choose?");

                context.Wait(this.MessageReceived);
            }
            else
            {
                numberOfTries++;
                await Miscellany.InsertDelayAsync(context);

                await context.PostAsync("I still didn't get it");

                await Miscellany.InsertDelayAsync(context);

                await context.PostAsync("Can you please rephrase it?");

                await Miscellany.InsertDelayAsync(context);

                await context.PostAsync("I'm here to help you upgrade a phone, plan or both. Which one do you want to choose?");

                context.Wait(this.MessageReceived);
            }
        }
コード例 #14
0
        private async Task MainEntryPoint(IDialogContext context)
        {
            DateTime time = DateTime.Now;
            int      hour = time.Hour;
            string   salutation, subsName;
            TimeZone tz = TimeZone.CurrentTimeZone;

            context.ConversationData.TryGetValue("SubsName", out subsName);
            await context.PostAsync($"Welcome to the MC upgrade BOT demo where you are now the customer named {subsName} and can interact with the bot as that customer.");

            if (CommonDialog.debugMessages)
            {
                await context.PostAsync("DEBUG : Beginning of program");

                await context.PostAsync("DEBUG : My timezone is " + tz.StandardName.ToString());
            }
            await Miscellany.InsertDelayAsync(context);

            if ((hour > 5) && (hour < 12))
            {
                salutation = "Good morning, ";
            }
            else if (hour < 19)
            {
                salutation = "Good afternoon, ";
            }
            else
            {
                salutation = "Good evening, ";
            }
            await context.PostAsync(salutation + subsName);

            await Miscellany.InsertDelayAsync(context);

            await context.PostAsync("As you are about to end your contract we are delighted to announce you are eligible for a handset upgrade or you may want to keep your phone and choose a new plan from one of our great deals.");

            await Miscellany.InsertDelayAsync(context);

            await context.PostAsync("How can I help you today?");

            context.Call(new NodeLUISBegin(), DoneInitiaLuisAsync);
        }
コード例 #15
0
        private async Task ConfirmationReceivedAsync(IDialogContext context, IAwaitable <object> awaitable)
        {
            string ans = ((Activity)(await awaitable)).Text;

            if (Miscellany.IsANo(ans))
            {
                await Miscellany.InsertDelayAsync(context);

                await context.PostAsync("Fine, could you please rephrase what you'd like to do, please?");

                await Miscellany.InsertDelayAsync(context);

                await context.PostAsync("I'm here to help you upgrade a phone, plan or both. Which one do you want to choose?");

                context.Wait(MessageReceived);
            }
            else
            {
                await ProcessLuisResultsAsync(context, this.luisResultCopy);
            }
        }
コード例 #16
0
        private async Task DoneInitiaLuisAsync(IDialogContext context, IAwaitable <object> result)
        {
            var ret = await result;
            Tuple <string, NodeLUISBegin.EIntent> luisOutput = ret as Tuple <string, NodeLUISBegin.EIntent>;

            if (CommonDialog.debugMessages)
            {
                await context.PostAsync("DEBUG : NodeLuisBegin returned : " + ret.ToString());
            }
            if (((Tuple <string, NodeLUISBegin.EIntent>)ret).Item2 == NodeLUISBegin.EIntent.HandSet)
            {
                context.ConversationData.SetValue(BotConstants.FLOW_TYPE_KEY, BotConstants.EQUIPMENT_FLOW_TYPE);
                context.Call(new NodePhoneFlow(((Tuple <string, NodeLUISBegin.EIntent>)ret).Item1), PhoneFlowDone);
            }
            else if (((Tuple <string, NodeLUISBegin.EIntent>)ret).Item2 == NodeLUISBegin.EIntent.Plan)
            {
                context.ConversationData.SetValue(BotConstants.FLOW_TYPE_KEY, BotConstants.PLAN_FLOW_TYPE);
                await Miscellany.InsertDelayAsync(context);

                await context.PostAsync("Sure.  I can help you to choose a new plan.");

                context.Call(new PlanNode(), PlanFlowDone);
            }
            else if (luisOutput.Item2 == NodeLUISBegin.EIntent.Both)
            {
                context.ConversationData.SetValue(BotConstants.FLOW_TYPE_KEY, BotConstants.BOTH_FLOW_TYPE);
                if (CommonDialog.debugMessages)
                {
                    await context.PostAsync("DEBUG : Both intent detected");
                }
                context.Call(new NodePhoneFlow(((Tuple <string, NodeLUISBegin.EIntent>)ret).Item1), PhoneFlowDone);
            }
            else
            {
                context.Wait(Restarting);
            }
        }
コード例 #17
0
        private async Task DisplayMultiPhoneCarouselAnsyc(IDialogContext context, List <String> models)
        {
            string        reviewsUrl;
            var           reply = ((Activity)context.Activity).CreateReply();
            HeroCard      heroCard;
            int           x = modelList.Count;
            List <string> brands;
            List <Tuple <HeroCard, HandSetFeatures> > heroCards = new List <Tuple <HeroCard, HandSetFeatures> >();

            if (firstTime)
            {
                if (!answerWasFeature)
                {
                    if (context.ConversationData.TryGetValue <List <string> >(BotConstants.SELECTED_BRANDS_KEY, out brands) && (brands.Count == 1) && (brands[0] == BotConstants.SHOW_ME_ALL))
                    {
                        await Miscellany.InsertDelayAsync(context);

                        await context.PostAsync($"Great, here are our {x} models to choose from. Click \"Plan Prices\" if you want to see the Phone Price on the different plans");

                        await Miscellany.InsertDelayAsync(context);

                        await context.PostAsync("If you want to learn more about features and reviews, please selecet \"Specifications\" ir \"Expert reviews\" or if you want to look at some other options, please type \"Start again\"");
                    }
                    else
                    {
                        await Miscellany.InsertDelayAsync(context);

                        await context.PostAsync($"Great, {needIntent} , Here are our TOP {x} models to choose from. Or let's look at some other options, please type \"Start again\"");
                    }
                }
                else
                {
                    if (context.ConversationData.TryGetValue <List <string> >(BotConstants.SELECTED_BRANDS_KEY, out brands))
                    {
                        await Miscellany.InsertDelayAsync(context);

                        if ((brands.Count == 1) && (brands[0] == BotConstants.SHOW_ME_ALL))
                        {
                            await context.PostAsync($"Great, here are our {x} models to choose from. Click \"Plan Prices\" if you want to see the Phone Price on the different plans");
                        }
                        else
                        {
                            await context.PostAsync($"Great, here are the {Miscellany.BuildBrandString(brands)} models that currently I have to choose from");
                        }
                    }
                    else
                    {
                        await Miscellany.InsertDelayAsync(context);

                        await context.PostAsync($"Great, here are the TOP {x} models {(featureIntent != null ? "for " + featureIntent : "")} to choose from.");
                    }
                    await Miscellany.InsertDelayAsync(context);

                    await context.PostAsync("Or let's work out some other options if you are not happy with these ones, please type \"Start again\"");
                }
                firstTime = false;
            }
            reply.AttachmentLayout = "carousel";
            foreach (var model in models)
            {
                heroCard = new HeroCard()
                {
                    Title    = Miscellany.Capitalize(GetModelBrand(model)),
                    Subtitle = Miscellany.Capitalize(model),
                    Text     = "",
                    Images   = new List <CardImage>()
                    {
                        new CardImage(GetEquipmentImageURL(model, true, context), "img/jpeg")
                    },
                    Buttons = new List <CardAction>()
                    {
                        new CardAction()
                        {
                            Title = "Pick Me!", Type = ActionTypes.ImBack, Value = "I want " + Miscellany.Capitalize(model)
                        },
                        new CardAction()
                        {
                            Title = "Plan Prices", Type = ActionTypes.ImBack, Value = "Plan Prices for " + Miscellany.Capitalize(model)
                        },
                        new CardAction()
                        {
                            Title = "Specifications", Type = ActionTypes.OpenUrl, Value = GetModelSpecsUrl(model)
                        }
                    }
                };

                if ((reviewsUrl = GetModelReviewsUrl(model)) != null)
                {
                    heroCard.Buttons.Add(new CardAction()
                    {
                        Title = "Expert Reviews", Type = ActionTypes.OpenUrl, Value = reviewsUrl
                    });
                }
                heroCards.Add(new Tuple <HeroCard, HandSetFeatures>(heroCard, handSets.GetModelFeatures(model)));
            }
            Miscellany.SortCarousel(heroCards);
            for (int n = 0; n < heroCards.Count; ++n)
            {
                reply.Attachments.Add(heroCards[n].Item1.ToAttachment());
            }
            await context.PostAsync(reply);

            context.Wait(CarouselSelectionButtonReceivedAsync);
        }
コード例 #18
0
        public async Task ProcessLuisNeedsResult(IDialogContext context, IAwaitable <object> awaitable)
        {
            Tuple <NodeLuisSubsNeeds.ENeeds, double> result = (Tuple <NodeLuisSubsNeeds.ENeeds, double>) await awaitable;
            StringBuilder sb         = new StringBuilder();
            double        needsScore = result.Item2;

            NodeLuisSubsNeeds.ENeeds needsIntent = result.Item1;
            int handSetsLeft, handSetsNow = decoder.CurrentNumberofHandsetsLeft();

            if (CommonDialog.debugMessages)
            {
                await context.PostAsync("DEBUG : Beginning of the method ProcessLuisNeedResult()");
            }
            if (needsScore > desiredFeatureScore)  // WE have a need
            {
                if (CommonDialog.debugMessages)
                {
                    await context.PostAsync("DEBUG : It's a need, namely " + needsIntent.ToString());
                }
                context.ConversationData.SetValue <NodeLuisSubsNeeds.ENeeds>(BotConstants.LAST_NEED_KEY, needsIntent);
                decoder.LastOneWasNeed    = true;
                decoder.FeatureOrNeedDesc = NodeLuisSubsNeeds.GetNeedIntentDesc(result.Item1);
                if (CommonDialog.debugMessages)
                {
                    await context.PostAsync("DEBUG : I'm going to obtain the top");
                }
                handSetsLeft = needsScores.GetTopFive(needsIntent);
                if (CommonDialog.debugMessages)
                {
                    await context.PostAsync("DEBUG : I've already obtained the top 5");
                }
                await UpdateUserAsync(context, handSetsLeft, handSetsNow);
            }
            else
            {
                try
                {
                    if (desiredFeature == EIntents.None)
                    {
                        await context.PostAsync("I'm sorry, I'm afraid I didn't understand that, could you please rephrase?");

                        return;
                    }
                    if (CommonDialog.debugMessages)
                    {
                        await context.PostAsync("DEBUG : I'm goin to set frequency");
                    }
                    topButtons.SetNewFreq(desiredFeature, sb);
                    if (CommonDialog.debugMessages)
                    {
                        await context.PostAsync("DEBUG : New Frequency set, getting into the switch to switch to correct one (no pun intented)");
                    }
                    context.ConversationData.SetValue(BotConstants.LAST_FEATURE_KEY, desiredFeature);
                    switch (desiredFeature)
                    {
                    case EIntents.Small:
                        if (!ExtractPhoneSizeInfo(res))
                        {
                            PromptDialog.Choice(context, ProcessSizeChoice, new List <string>()
                            {
                                "BIGGER", "SMALLER", "THE SAME"
                            }, "Are you looking for a phone with a similar size as your existing model or something bigger or smaller?", "Not understood, please try again", 3);
                        }
                        break;

                    case EIntents.Camera:
                        if (!GetCameraCompositeEntityData(res))      // The desired megapixels aren't present, so in this particular case we'll send it to fuzzy engine
                        {
                            if (CommonDialog.debugMessages)
                            {
                                await context.PostAsync("DEBUG : Camera intent : No data detected");
                            }
                            decoder.ExcludeThis(EIntents.Camera);
                            decoder.SetSizeRequirements(-1, true);
                            handSetsLeft = needsScores.GetTopFive(NodeLuisSubsNeeds.ENeeds.Camera);
                            await UpdateUserAsync(context, handSetsLeft, handSetsNow);
                        }
                        else
                        {
                            if (CommonDialog.debugMessages)
                            {
                                await context.PostAsync("DEBUG : Camera intent : Data detected");
                            }
                            await DecodeAndProcessIntentAsync(context);
                        }
                        break;

                    case EIntents.OS:
                        if (!GetOSData(res))
                        {
                            if (CommonDialog.debugMessages)
                            {
                                await context.PostAsync("Handling OS intent");
                            }
                            PromptDialog.Choice(context, ProcessEnumeratedChoice, handSetsBag.GetBagOSes(), "Could you please indicate your favourite Operating System?", "Not understood, please try again", 3);
                        }
                        else
                        {
                            await DecodeAndProcessIntentAsync(context);
                        }
                        break;

                    case EIntents.Color:
                        if (!GetPreferredColors(res))
                        {
                            PromptDialog.Choice(context, ProcessEnumeratedChoice, handSetsBag.GetBagColors(), "Could you please indicate your favourite Color?", "Not understood, please try again", 3);
                        }
                        else
                        {
                            await DecodeAndProcessIntentAsync(context);
                        }
                        break;

                    case EIntents.Brand:
                        if (!GetSpecificBrands(res))
                        {
                            List <string> brands = handSetsBag.GetBagBrands();
                            Activity      reply  = (Activity)context.MakeMessage();

                            reply.Text = "Could you please indicate your favourite brand?";
                            await Miscellany.InsertDelayAsync(context);

                            Miscellany.ComposeBrandsCarousel(reply, brands, handSetsBag);
                            await context.PostAsync(reply);

                            context.Wait(ProcessBrandChoice);
                        }
                        else
                        {
                            await DecodeAndProcessIntentAsync(context);
                        }
                        break;

                    default:
                        await DecodeAndProcessIntentAsync(context);

                        break;
                    }
                }
                catch (ArgumentException)
                {
                    await context.PostAsync("Argument xception");
                }
                catch (Exception xception)
                {
                    await context.PostAsync($"Error...Exception Message = {xception.Message}");
                }
            }
        }
コード例 #19
0
        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);
            }
        }
コード例 #20
0
        private async Task DisplaySinglePhoneCardAsync(IDialogContext context, string model)
        {
            string   equipmentURL, reviewsUrl;
            var      reply = ((Activity)context.Activity).CreateReply();
            HeroCard heroCard;

            this.selectedModel = model;
            if (!weAreOnBranch7)
            {
                await Miscellany.InsertDelayAsync(context);

                await context.PostAsync("Great. Let's have a look at that phone now.");
            }
            else
            {
                await Miscellany.InsertDelayAsync(context);

                await context.PostAsync("Great. Based on what you told me, I've narrowed it down to this recommended model");
            }
            equipmentURL = GetEquipmentImageURL(model, true, context);
            heroCard     = new HeroCard()
            {
                Title    = Miscellany.Capitalize(GetModelBrand(model)),
                Subtitle = Miscellany.Capitalize(model),
                Text     = weAreOnBranch7 ? "Select from one of the buttons below" : "Click one of the buttons to continue.",
                Images   = new List <CardImage> {
                    new CardImage(equipmentURL, "img/jpeg")
                },
                Buttons = new List <CardAction>()
                {
                    new CardAction()
                    {
                        Title = weAreOnBranch7 ? "Yes - great choice" : "Yes - that's the phone I like", Type = ActionTypes.ImBack, Value = "I want " + Miscellany.Capitalize(model)
                    },
                    new CardAction()
                    {
                        Title = weAreOnBranch7 ? "No. That's not quite right" : "No. I am after a different model", Type = ActionTypes.ImBack, Value = "No. I am after a different model"
                    },
                    new CardAction()
                    {
                        Title = "Phone Price per Plan", Type = ActionTypes.ImBack, Value = "Plan Prices for " + Miscellany.Capitalize(model)
                    },
                    new CardAction()
                    {
                        Title = "Specifications", Type = ActionTypes.OpenUrl, Value = GetModelSpecsUrl(model)
                    }
                }
            };
            reviewsUrl = GetModelReviewsUrl(model);
            if (reviewsUrl != null)
            {
                heroCard.Buttons.Add(new CardAction()
                {
                    Title = "Expert Reviews", Type = ActionTypes.OpenUrl, Value = reviewsUrl
                });
            }
            reply.Attachments.Add(heroCard.ToAttachment());

            await context.PostAsync(reply);

            context.Wait(SelectionButtonReceivedAsync);
        }
コード例 #21
0
        private async Task DisplayTopSalesCarouselAsync(IDialogContext context)
        {
            int               x;
            string            reviewsUrl;
            List <string>     topSellers;
            Activity          reply  = ((Activity)context.Activity).CreateReply();
            Activity          reply2 = ((Activity)context.Activity).CreateReply();
            HeroCard          heroCard;
            List <CardAction> buttons;

            topSellers = GetTop5Sellers();
            x          = topSellers.Count;
            reply.Text = "";
            foreach (var model in topSellers)
            {
                try
                {
                    heroCard = new HeroCard()
                    {
                        Title    = Miscellany.Capitalize(GetModelBrand(model)),
                        Subtitle = Miscellany.Capitalize(model),
                        Text     = "",
                        Images   = new List <CardImage>()
                        {
                            new CardImage(GetEquipmentImageURL(model, true, context), "img/jpeg")
                        },
                        Buttons = new List <CardAction>()
                        {
                            new CardAction()
                            {
                                Title = "Pick Me!", Type = ActionTypes.ImBack, Value = "I want " + Miscellany.Capitalize(model)        /*model*/
                            },
                            new CardAction()
                            {
                                Title = "Plan Prices", Type = ActionTypes.ImBack, Value = "Plan Prices for " + Miscellany.Capitalize(model)         /*model*/
                            },
                            new CardAction()
                            {
                                Title = "Specifications", Type = ActionTypes.OpenUrl, Value = GetModelSpecsUrl(model)
                            }
                        }
                    };
                }
                catch (Exception xception)
                {
                    if (CommonDialog.debugMessages)
                    {
                        await context.PostAsync("Error...xception message = " + xception.ToString());
                    }
                    heroCard = null;
                }
                if ((reviewsUrl = GetModelReviewsUrl(model)) != null)
                {
                    heroCard.Buttons.Add(new CardAction()
                    {
                        Title = "Reviews", Type = ActionTypes.OpenUrl, Value = reviewsUrl
                    });
                }
                reply.Attachments.Add(heroCard.ToAttachment());
            }
            reply.AttachmentLayout = "carousel";
            await Miscellany.InsertDelayAsync(context);

            await context.PostAsync("Here are our latest TOP 5 sellers to choose from, select if you see anything you like");

            await Miscellany.InsertDelayAsync(context);

            await Miscellany.InsertDelayAsync(context);

            await context.PostAsync(reply);

            buttons = new List <CardAction>()
            {
                new CardAction()
                {
                    Title = "I'll decide by myself", Type = ActionTypes.ImBack, Value = "I'll pick"
                },
                new CardAction()
                {
                    Title = "Help me work it out, based on what's important for me", Type = ActionTypes.ImBack, Value = "Help me work it out"
                }
            };
            reply2.SuggestedActions = new SuggestedActions(actions: buttons);
            reply2.Text             = "If you dont find anything you like, Let’s work some other options";
            await Miscellany.InsertDelayAsync(context);

            await context.PostAsync(reply2);
        }
コード例 #22
0
        private async Task CheckUserAnswerAsync(IDialogContext context, IAwaitable <IMessageActivity> result)
        {
            var  ans = (await result);
            var  text = ans.Text;
            bool LUISUpdated, luisTrained, firstTime = true;
            Tuple <string, EIntent> tuple;
            string          retVal = "";
            ITypingActivity typingActivity;
            var             connector = new ConnectorClient(new Uri(((Activity)ans).ServiceUrl));
            int             counter = 0, maxTimes = 8;

            if (CommonDialog.debugMessages)
            {
                await context.PostAsync("DEBUG : Beginning of method CheckUserAnswerAsync()");
            }
            if (humanFriendlyIntent.TryGetValue(text, out tuple))
            {
                try
                {
                    if (CommonDialog.debugMessages)
                    {
                        await context.PostAsync("Checking if we saw utterance enough times, the non-unnderstood utterance is " + nonUnderstoodUtterance);
                    }
                    LUISUpdated = await updater.UpdateUtteranceAsync(text, nonUnderstoodUtterance);

                    if (LUISUpdated)
                    {
                        if (CommonDialog.debugMessages)
                        {
                            await context.PostAsync("We did, utterance added to LUIS and order for training sent");
                        }
                        if (CommonDialog.debugMessages)
                        {
                            await context.PostAsync("DEBUG : Debug Messages : " + updater.debug);
                        }
                        if (CommonDialog.debugMessages)
                        {
                            await context.PostAsync("DEBUG: Training status = " + (await updater.CheckTrainStatus()));
                        }
                        do
                        {
                            if (luisTrained = await updater.CheckTrainStatus())
                            {
                                break;
                            }
                            if (!firstTime)
                            {
                                typingActivity      = ((Activity)ans).CreateReply();
                                typingActivity.Type = ActivityTypes.Typing;
                                await connector.Conversations.SendToConversationAsync((Activity)typingActivity);
                            }
                            else
                            {
                                firstTime = false;
                            }
                            Thread.Sleep(2500);
                            if (CommonDialog.debugMessages)
                            {
                                await context.PostAsync("DEBUG: Checking Training status = " + (await updater.CheckTrainStatus()));
                            }

                            if (CommonDialog.debugMessages)
                            {
                                await context.PostAsync("DEBUG: Training status = " + (await updater.CheckTrainStatus()));
                            }
                        }while ((counter < maxTimes) && !luisTrained);

                        retVal = await updater.PublishLuisAsync();

                        if (CommonDialog.debugMessages)
                        {
                            await context.PostAsync("DEBUG : Publish POST returned : " + retVal);
                        }
                        if (CommonDialog.debugMessages)
                        {
                            await context.PostAsync("DEBUG: Debug mesages = " + updater.debug);
                        }
                    }
                }
                catch (Exception xception)
                {
                    await context.PostAsync("Error...could not add utterance to LUIS, xception message = " + xception.Message);
                }
                if (CommonDialog.debugMessages)
                {
                    await context.PostAsync("DEBUG : End of Method CheckUserAnswerAsync()");
                }
                context.Done(Tuple.Create(initialPhrase, tuple.Item2));
            }
            else
            {
                await Miscellany.InsertDelayAsync(context);

                await context.PostAsync("OK, I didn't get that, could you please rephrase it for me?");

                await Miscellany.InsertDelayAsync(context);

                await context.PostAsync("I'm here to help you upgrade a phone, plan or both. Which one do you want to choose?");

                ++numberOfTries;
                context.Wait(this.MessageReceived);
            }
        }
コード例 #23
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());
                }
            }
        }
コード例 #24
0
        public override async Task StartAsync(IDialogContext context)
        {
            List <string>    brandsWanted, modelsWanted;
            string           flowType;
            Activity         reply, lastMsg = (Activity)context.Activity;
            SuggestedActions suggestedActions = new SuggestedActions
            {
                Actions = new List <CardAction>()
                {
                    new CardAction()
                    {
                        Title = "Yes, I know what I want", Type = ActionTypes.ImBack, Value = "Yes"
                    },
                    new CardAction()
                    {
                        Title = "No, I haven't made up my mind", Type = ActionTypes.ImBack, Value = "No"
                    }
                }
            };

            try
            {
                if (IndicatedModelsAndOrBrands(out brandsWanted, out modelsWanted))
                {
                    await Miscellany.InsertDelayAsync(context);

                    await context.PostAsync("Yes, I can help you with that.");
                    await ProcessSelectedBrandsAndModels(context, brandsWanted, modelsWanted, false);
                }
                else
                {
                    if (context.ConversationData.TryGetValue(BotConstants.FLOW_TYPE_KEY, out flowType))
                    {
                        await Miscellany.InsertDelayAsync(context);

                        if (flowType == BotConstants.BOTH_FLOW_TYPE)
                        {
                            await context.PostAsync("Sure. Let's start by choosing a new phone");
                        }
                        else if (flowType == BotConstants.EQUIPMENT_FLOW_TYPE)
                        {
                            await context.PostAsync("Sure. I can help you to choose a new phone.");
                        }
                        else if (flowType == BotConstants.PLAN_FLOW_TYPE)
                        {
                            await context.PostAsync("Fantastic. Let's choose a new phone for you then.");
                        }
                        else
                        {
                            throw new Exception("Error...NodePhoneFlow::StartAsync() unknown flow key value : " + flowType);
                        }
                    }
                    else
                    {
                        throw new Exception("Error...phone flow entered without flow key being assigned a value");
                    }
                    reply = lastMsg.CreateReply("Have you decided already what you want or would you like some support in choosing what's the right phone for you?");
                    reply.SuggestedActions = suggestedActions;
                    await Miscellany.InsertDelayAsync(context);

                    await context.PostAsync(reply);

                    context.Wait(MessageReceivedWithDecisionAsync);
                }
            }
            catch (Exception xception)
            {
                await context.PostAsync(xception.Message);
            }
        }
コード例 #25
0
ファイル: PlanNode.cs プロジェクト: Bairdsy/TelcoRetentionBot
        protected async Task ShowPlanCarouselAsync(IDialogContext context)
        {
            int  subsno;
            bool containsSIMO = false;

            var reply = context.MakeMessage();

            reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
            reply.Attachments      = new List <Attachment>();

            var CardList = new List <HeroCard>();

            context.ConversationData.TryGetValue("SubsNumber", out subsno);

            var collection = _database.GetCollection <BsonDocument>("offer_messages");
            var filter     = Builders <BsonDocument> .Filter.Eq("Anon Subsno", subsno);

            var sort = Builders <BsonDocument> .Sort.Ascending("Inbound Eligibility").Ascending("Value Rank");

            int count = 0;

            using (var cursor = await collection.FindAsync(filter, new FindOptions <BsonDocument, BsonDocument>()
            {
                Sort = sort
            }))
            {
                while (await cursor.MoveNextAsync())
                {
                    var batch = cursor.Current;
                    foreach (var document in batch)
                    {
                        string Name      = (string)document.GetElement("Offer Name").Value;
                        string Image     = (string)document.GetElement("Image Name").Value;
                        string Highlight = (string)document.GetElement("Plan Highlight").Value;
                        string Warning   = (string)document.GetElement("Plan Warning").Value;
                        string Message   = (string)document.GetElement("Plan Choice Message").Value;

                        string Code = (string)document.GetElement("Result Type Code").Value;

                        //await context.PostAsync($"DEBUG: Document [{Name}][{Image}][{Code}]");
                        if (Name.Contains("SIM"))
                        {
                            containsSIMO = true;
                        }
                        if (count == 0)
                        {
                            Name = "*Recommended for you* - " + Name;
                        }
                        var Card = new HeroCard
                        {
                            Title    = Name,
                            Subtitle = Highlight,
                            Text     = Warning,
                            Images   = new List <CardImage> {
                                new CardImage("http://www.madcalm.com/wp-content/uploads/2018/07/" + Image + ".png")
                            },
                            Buttons = new List <CardAction> {
                                new CardAction(ActionTypes.PostBack, "Pick Me!", value: "Choose " + Code), new CardAction(ActionTypes.ImBack, "Show Analysis", value: "Analyse")
                            }
                        };
                        CardList.Add(Card);
                        count++;
                    }
                    await Miscellany.InsertDelayAsync(context);

                    string suffixStr = containsSIMO ? "Also SIMO Plans are included" : String.Empty;
                    await context.PostAsync($"I've ranked all of your options, starting with your Recommended Plan, {suffixStr}");
                }
            }

            foreach (HeroCard productCard in CardList)
            {
                reply.Attachments.Add(productCard.ToAttachment());
            }

            await context.PostAsync(reply);

            context.Wait(this.ChosenPlan);
        }
コード例 #26
0
        private async Task WriteGenericReplyAsync(IDialogContext context)
        {
            await Miscellany.InsertDelayAsync(context);

            await context.PostAsync("I am excited to help you to choose a **plan** or **phone** or **both**. Let me know what you are looking for?");
        }
コード例 #27
0
ファイル: PlanNode.cs プロジェクト: Bairdsy/TelcoRetentionBot
        public async Task StartAsync(IDialogContext context)
        {
            failCount = 0;
            if (CommonDialog.debugMessages)
            {
                await context.PostAsync($"DEBUG: entering node2");
            }

            string selectedPlan;

            if (context.ConversationData.TryGetValue("ChosenPlanName", out selectedPlan) && selectedPlan.ToUpper().Contains("BEYOU"))
            {
                if (CommonDialog.debugMessages)
                {
                    await context.PostAsync($"DEBUG: back in plan node but plan already selected");
                }
                context.Done(0);
            }
            else
            {
                if (context.ConversationData.TryGetValue("SubsNumber", out subsno))
                {
                    //await context.PostAsync($"DEBUG: Subs Number is {subsno}");
                    int subsnum = Int32.Parse(subsno);

                    await Miscellany.InsertDelayAsync(context, false);

                    _client   = new MongoClient("mongodb://*****:*****@telcoretentiondb.documents.azure.com:10255/?ssl=true&replicaSet=globaldb");
                    _database = _client.GetDatabase("madcalm");


                    //    await context.PostAsync($"I have analysed the way you use your phone and am matching that to the offers we have available to find the very best fit for you.");
                    var collection = _database.GetCollection <BsonDocument>("offer_messages");
                    var filter     = Builders <BsonDocument> .Filter.Eq("Anon Subsno", subsnum);

                    var sort = Builders <BsonDocument> .Sort.Ascending("Inbound Eligibility").Ascending("Value Rank");

                    string generic_msg;


                    using (var cursor = await collection.FindAsync(filter, new FindOptions <BsonDocument, BsonDocument>()
                    {
                        Sort = sort
                    }))
                    {
                        while (await cursor.MoveNextAsync())
                        {
                            var batch = cursor.Current;
                            foreach (var document in batch)
                            {
                                generic_msg = (string)document.GetElement("Generic Usage Message").Value;
                                await context.PostAsync($"**{generic_msg}**");

                                await Task.Delay(5000);

                                break;
                            }
                        }
                    }
                    await Miscellany.InsertDelayAsync(context);

                    await context.PostAsync("I have analysed the way you use your phone");

                    await Task.Delay(5000);  // 3000 b4

                    await this.ShowSummaryCardAsync(context);

                    await Task.Delay(3000);

                    await Miscellany.InsertDelayAsync(context);

                    await context.PostAsync("Based on your current use, i am matching that to the offers we have available to find the very best fit for you.");

                    var CardList = new List <HeroCard>();


                    await this.ShowPlanCarouselAsync(context);
                }
                else
                {
                    await context.PostAsync($"Hmmm.  Seems I couldnt get the subscriber number.");
                }
            }
        }
コード例 #28
0
        private async Task ProcessSelectedBrandsAndModels(IDialogContext context, List <string> wantedBrands, List <string> wantedModels, bool modelEnteredOnEnd)
        {
            StringBuilder sb;
            int           x;
            List <string> selectResult;

            sb = new StringBuilder("DEBUG : Brands indicated : ");
            foreach (string brand in wantedBrands)
            {
                sb.Append("-->" + brand + "\r\n");
            }
            if (debugMessages)
            {
                await context.PostAsync("DEBUG : brands identified : " + sb.ToString());
            }
            sb = new StringBuilder("DEBUG : Models indicated : ");
            foreach (string model in wantedModels)
            {
                sb.Append("-->" + model + "\r\n");
            }
            if (debugMessages)
            {
                await context.PostAsync("DEBUG : models identified  : " + sb.ToString());
            }

            selectResult = SelectWithFilter(wantedModels);

            sb = new StringBuilder("DEBUG : Models selected by filter: ");
            foreach (string model in selectResult)
            {
                sb.Append("-->" + model + "\r\n");
            }
            if (debugMessages)
            {
                await context.PostAsync("DEBUG : models selected with regex : " + sb.ToString());
            }

            AddUncoveredBrands(wantedBrands, selectResult);

            sb = new StringBuilder("DEBUG : Models selected including uncovered brands: ");
            foreach (string model in selectResult)
            {
                sb.Append("-->" + model + "\r\n");
            }
            if (debugMessages)
            {
                await context.PostAsync("DEBUG : models identified with uncovered brands : " + sb.ToString());
            }

            handSets.InitializeBag(selectResult);

            if (debugMessages)
            {
                await context.PostAsync("DEBUG : contents of bag : " + handSets.BuildStrRep());
            }
            if (selectResult.Count == 0)
            {
                await context.PostAsync("I didn’t understand you, Could you just type the specific model or brand so I can present it to you ? ");

                context.Call(new BrandModelNode(), FinalSelectionReceivedAsync);
            }
            else if ((x = handSets.BagCount()) <= BotConstants.MAX_CAROUSEL_CARDS)
            {
                if (x > 1)
                {
                    await Miscellany.InsertDelayAsync(context);

                    if (modelEnteredOnEnd)
                    {
                        await context.PostAsync($"Great choice!There are {x} different versions for you to choose from");
                    }
                    else
                    {
                        await context.PostAsync($"There are {x} different versions for you to choose from");
                    }
                }
                context.Call(new LessThan5Node(selectResult, false), FinalSelectionReceivedAsync);
            }
            else
            {
                await CallLuisPhoneNodeAsync(selectResult, context);
            }
        }