コード例 #1
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());
            }
        }
コード例 #2
0
        private bool ExtractPhoneSizeInfo(LuisResult result)
        {
            bool   desc      = false; // By default, ascending
            double threshold = -1;

            string[] tokens;
            int      index = 0;
            bool     additionalInfoDetected = false;

            double[] volume = new double[3];

            foreach (var cEntity in result.CompositeEntities)
            {
                if (cEntity.ParentType == "SizeComposite")
                {
                    foreach (var child in cEntity.Children)
                    {
                        switch (child.Type)
                        {
                        case "OrderByWay":
                            desc = ("small" != child.Value.ToLower() && ("smallest" != child.Value.ToLower()));
                            additionalInfoDetected = true;
                            break;

                        case "buildin.number":
                            if ((index < 3) && double.TryParse(child.Value, out volume[index]))
                            {
                                ++index;
                            }
                            break;

                        case "DimensionsRegEx":
                            if (index >= 3)
                            {
                                continue;     // We already have the info we need about the desired volume threshold
                            }
                            tokens = child.Value.ToLower().Split('x');
                            if (double.TryParse(tokens[0], out volume[0]) && double.TryParse(tokens[1], out volume[1]) && double.TryParse(tokens[2], out volume[2]))
                            {
                                index = 3;
                            }
                            break;

                        default:
                            break;
                        }
                    }
                    if (index == 3)  // OK, we have valid data
                    {
                        additionalInfoDetected = true;
                        threshold = Miscellany.Product(volume);
                    }
                }
            }
            if (additionalInfoDetected)
            {
                decoder.SetSizeRequirements(threshold, desc);
            }
            return(additionalInfoDetected);
        }
コード例 #3
0
ファイル: HandSets.cs プロジェクト: Bairdsy/TelcoRetentionBot
            public HandSetFeatures GetEquipmentFeatures(string model)
            {
                HandSetFeatures features;

                if (models.TryGetValue(model, out features))
                {
                    return(features);
                }
                if (spaceLess.TryGetValue(Miscellany.RemoveSpaces(model), out features))
                {
                    return(features);
                }
                else
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (var m in models.Keys)
                    {
                        sb.Append(m.ToString() + m.Length + "\r\n");
                    }
                    foreach (var m2 in spaceLess.Keys)
                    {
                        sb.Append(m2.ToString() + m2.Length + "\r\n");
                    }
                    throw new Exception($"Error...could not find the {model} model in database, it has {model.Length} letters, database keys = " + sb);
                }
            }
コード例 #4
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);
        }
コード例 #5
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);
        }
コード例 #6
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);
        }
コード例 #7
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);
            }
        }
コード例 #8
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);
            }
        }
コード例 #9
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));
        }
コード例 #10
0
        private async Task ProcessSizeChoice(IDialogContext context, IAwaitable <string> awaitable)
        {
            string          ans = await awaitable;
            string          currentModel;
            HandSetFeatures phoneFeatures;
            int             handSetsLeft, handSetsNow = decoder.CurrentNumberofHandsetsLeft();

            context.ConversationData.TryGetValue("HandsetModelKey", out currentModel);
            currentModel  = "iphone 7 plus  256gb";
            phoneFeatures = handSetsBag.GetModelFeatures(currentModel);

            if (ans == "THE SAME")
            {
                needsScores.CurrentPhone = currentModel;
                decoder.ExcludeThis(EIntents.Small);
                decoder.SetSizeRequirements(0, false);
                handSetsLeft = needsScores.GetTopFive(NodeLuisSubsNeeds.ENeeds.PhoneSize);
                await UpdateUserAsync(context, handSetsLeft, handSetsNow);
            }
            else
            {
                if (ans == "SMALLER")
                {
                    decoder.SetSizeRequirements(Miscellany.Product(phoneFeatures.BodySize), false);
                }
                else
                {
                    decoder.SetSizeRequirements(Miscellany.Product(phoneFeatures.BodySize), true);
                }
                await DecodeAndProcessIntentAsync(context);
            }
        }
コード例 #11
0
        protected override async Task <string> PrepareAsync(IActivity activity, CancellationToken token)
        {
            var message = activity as IMessageActivity;

            if ((message != null) && !String.IsNullOrWhiteSpace(message.Text))
            {
                var msg       = Miscellany.RemoveSpaces(message.Text.ToLowerInvariant());
                var keyPhrase = Miscellany.RemoveSpaces(BotConstants.KEY_PHRASE.ToLowerInvariant());

                if (msg.StartsWith(keyPhrase))
                {
                    if (msg.EndsWith(BotConstants.PASSWORD1.ToLowerInvariant()) || msg.EndsWith(BotConstants.PASSWORD2.ToLowerInvariant()))
                    {
                        turnOn = false;
                    }
                    else
                    {
                        turnOn = /* CommonDialog.debugMessages =*/ true;
                    }
                }
                else
                {
                    turnOn = null;
                }
            }

            if (turnOn != null)
            {
                return(message.Text);
            }
            else
            {
                return(null);
            }
        }
コード例 #12
0
        public async Task HowAreYou(IDialogContext context, LuisResult result)
        {
            await Miscellany.InsertDelayAsync(context);

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

            await WriteGenericReplyAsync(context);
        }
コード例 #13
0
        private string TyposInformation(LuisResult result)
        {
            string correctedQuery;

            if (result.AlteredQuery == null)
            {
                return(null);
            }
            correctedQuery = Miscellany.QueryCompare(result.Query, result.AlteredQuery);
            return($"You typed \"{result.Query}\", did you mean \"{correctedQuery}\"?");
        }
コード例 #14
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);
            }
        }
コード例 #15
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;
        }
コード例 #16
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;
            }
        }
コード例 #17
0
        private string IdentifyModel(string input)
        {
            string temp = Miscellany.RemoveSpaces(input.ToLower());

            foreach (var model in brandModels)
            {
                if (temp.Contains(Miscellany.RemoveSpaces(model.ToLower())))
                {
                    return(model);
                }
            }
            return(null);
        }
コード例 #18
0
        private void  ComposeModelCarousel(string brand, List <string> modelsVector, Activity reply, IDialogContext context)
        {
            HeroCard heroCard;
            string   reviewsUrl;
            List <Tuple <HeroCard, HandSetFeatures> > heroCards = new List <Tuple <HeroCard, HandSetFeatures> >();

            foreach (var model in modelsVector)
            {
                reviewsUrl = GetModelReviewsUrl(model);
                heroCard   = new HeroCard()
                {
                    Title    = Miscellany.Capitalize(model),
                    Subtitle = "",
                    Text     = "From " + Miscellany.Capitalize(brand),
                    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 a " + Miscellany.Capitalize(model)
                        },
                        new CardAction()
                        {
                            Title = "Plan Prices", Type = ActionTypes.ImBack, Value = "Show me Plan Prices for " + Miscellany.Capitalize(model)
                        },
                        new CardAction()
                        {
                            Title = "Specifications", Type = ActionTypes.OpenUrl, Value = GetModelSpecsUrl(model)
                        },
                    },
                };
                if (reviewsUrl != null)
                {
                    heroCard.Buttons.Add(new CardAction()
                    {
                        Title = "Reviews", Type = ActionTypes.OpenUrl, Value = GetModelReviewsUrl(model)
                    });
                }
                heroCards.Add(new Tuple <HeroCard, HandSetFeatures>(heroCard, handSets.GetModelFeatures(model)));
            }
            Miscellany.SortCarousel(heroCards);
            for (int x = 0; x < heroCards.Count; ++x)
            {
                reply.Attachments.Add(heroCards[x].Item1.ToAttachment());
            }

            reply.AttachmentLayout = "carousel";
        }
コード例 #19
0
ファイル: HandSets.cs プロジェクト: Bairdsy/TelcoRetentionBot
            public void Add(HandSetFeatures newModel)
            {
                HandSetFeatures old;

                if (!models.TryGetValue(newModel.Model, out old))
                {
                    models.Add(newModel.Model, newModel);
                    spaceLess.Add(Miscellany.RemoveSpaces(newModel.Model), newModel);
                }
                else
                {
                    newModel.CopyTo(old);
                }
            }
コード例 #20
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);
        }
コード例 #21
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);
            }
        }
コード例 #22
0
ファイル: HandSets.cs プロジェクト: Bairdsy/TelcoRetentionBot
            public string GetSpecificModelBrand(string model)
            {
                HandSetFeatures features;

                if (models.TryGetValue(model, out features))
                {
                    return(features.Brand);
                }
                //return models[model].Brand;
                if (spaceLess.TryGetValue(Miscellany.RemoveSpaces(model), out features))
                {
                    return(features.Brand);
                }
                else
                {
                    throw new Exception($"Error....I don't have the {model} model in my database");
                }
            }
コード例 #23
0
        private async Task SelectionButtonReceivedAsync(IDialogContext context, IAwaitable <object> awaitable)
        {
            IMessageActivity messageActivity = (IMessageActivity)(await awaitable);
            string           model, buttonPressed;
            List <string>    options;


            buttonPressed = messageActivity.Text;

            if (buttonPressed.StartsWith("I want "))
            {
                selectedModel = model = buttonPressed.Substring(7).ToLower();
                context.Done(model);
            }
            else if (buttonPressed.StartsWith("Plan Prices for "))
            {
                model = buttonPressed.Substring(16);
                await PlanPricesButtonHandlerAsync(context, model);
            }
            else if (buttonPressed.StartsWith("No"))
            {
                string brandLower;
                string brand          = Miscellany.Capitalize(brandLower = GetModelBrand(this.selectedModel));
                int    numberOfModels = GetBrandModels(brandLower).Count;

                if (numberOfModels > 1)
                {
                    options = new List <string>()
                    {
                        $"Yes, I want to stay with {brand}", "No"
                    };
                    PromptDialog.Choice(context,
                                        WrongRecoverOptionReceivedAsync,
                                        options,
                                        $"Do you still want to look at {brand} range or look at other phones?",
                                        "Not understood, please try again",
                                        4);
                }
                else  // If it is just one, there is really no point in asking if he wants to stick with the same brand...
                {
                    context.Done(SOME_OTHER_BRAND + brandLower);
                }
            }
        }
コード例 #24
0
        public override async Task StartAsync(IDialogContext context)
        {
            List <string> colors = null, capitalColors;
            string        modelCapitalized = Miscellany.Capitalize(chosenModel);

            if (debugMessages)
            {
                await context.PostAsync($"DEBUG : StartAsync() method in ColorsNode object, I received {chosenModel} model to present");
            }
            try
            {
                colors = GetColors(chosenModel);
            }
            catch (Exception xception)
            {
                await context.PostAsync($"Error...xception message = {xception.Message}, full xception = {xception.ToString()}");

                throw;
            }
            if (debugMessages)
            {
                await context.PostAsync($"I got {colors.Count} colors");
            }

            capitalColors = new List <string>();
            foreach (var color in colors)
            {
                capitalColors.Add(Miscellany.Capitalize(color));
            }
            if (colors.Count != 1)
            {
                PromptDialog.Choice(context,
                                    ColorSelectionReceivedAsync,
                                    capitalColors,
                                    $"OK. There are a few different options for you to pick for {modelCapitalized} from below:",
                                    "Sorry, not a valid option",
                                    4);
            }
            else
            {
                await CongratulateSubsAsync(context);
            }
        }
コード例 #25
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);
        }
コード例 #26
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);
            }
        }
コード例 #27
0
        private void ComposeBrandsCarousel(Activity reply)
        {
            HeroCard      card;
            int           len;
            List <string> brandModels;
            List <string> listOfBrands = new List <string>(brands.Keys);

            listOfBrands.Sort();
            len = listOfBrands.Count;
            for (int n = 0; n < len; ++n)
            {
                var brand = listOfBrands[n];
                brandModels = new List <string>(GetBrandModels(brand).Keys);
                if ((xclude != null) && // Avoid passing null to Except()
                    (brandModels.Except(xclude).Count() == 0))
                {
                    continue;
                }
                card = new HeroCard()
                {
                    Title    = Miscellany.Capitalize(brand),
                    Subtitle = Miscellany.Capitalize(brand),
                    Text     = "",
                    Images   = new List <CardImage>()
                    {
                        new CardImage(handSets.GetBrandLogo(brand), "img/jpeg")
                    },
                    Buttons = new List <CardAction>()
                    {
                        new CardAction()
                        {
                            Title = "Pick Me!", Type = ActionTypes.ImBack, Value = "I want " + brand
                        },
                    }
                };
                reply.Attachments.Add(card.ToAttachment());
            }
            reply.AttachmentLayout = "carousel";
        }
コード例 #28
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);
            }
        }
コード例 #29
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.");
                }
            }
        }
コード例 #30
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);
        }