private string GetRightStringMsg()
        {
            string[]      alternatives;
            StringBuilder aux;
            int           len;

            IntentDecoder.FilterSettings filterSettings;

            if (acknowledgeMessages.TryGetValue(desiredFeature, out alternatives))
            {
                filterSettings = decoder.GetRequirements(desiredFeature);
                switch (desiredFeature)
                {
                case EIntents.Brand:
                    len = filterSettings.Enumerated.Count;
                    aux = len > 1 ? new StringBuilder("brands ") : new StringBuilder("brand ");
                    aux.Append(Miscellany.BuildBrandString(filterSettings.Enumerated));
                    return(string.Format(alternatives[0], aux.ToString()));

                case EIntents.OS:
                case EIntents.Color:
                    len = filterSettings.Enumerated.Count;
                    aux = new StringBuilder(filterSettings.Enumerated[0]);
                    if (len > 1)
                    {
                        for (int n = 1; n < (len - 1); ++n)
                        {
                            aux.Append($", {filterSettings.Enumerated[n]}");
                        }
                        aux.Append(EIntents.OS == desiredFeature ? " or" : " and");
                        aux.Append($" {filterSettings.Enumerated[len - 1]}.");
                    }
                    return(string.Format(alternatives[0], aux.ToString()));

                case EIntents.Small:
                    if (!filterSettings.FiltersSet || ((filterSettings.Threshold == -1) && filterSettings.Desc))
                    {
                        return(alternatives[1]);
                    }
                    else if (filterSettings.Threshold == -1)
                    {
                        return(alternatives[0]);
                    }
                    else if (filterSettings.Threshold == 0)
                    {
                        return(alternatives[4]);
                    }
                    else
                    {
                        return(string.Format(filterSettings.Desc ? alternatives[3] : alternatives[2], $"{filterSettings.Threshold} mm3."));
                    }

                case EIntents.Newest:
                    if (filterSettings.FiltersSet)
                    {
                        return(string.Format(alternatives[1], filterSettings.DateThreshold));
                    }
                    else
                    {
                        return(alternatives[0]);
                    }

                default:
                    if (filterSettings.FiltersSet)
                    {
                        return(string.Format(alternatives[1], (int)filterSettings.Threshold));
                    }
                    else
                    {
                        return(alternatives[0]);
                    }
                }
            }
            else
            {
                return(null);
            }
        }
示例#2
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);
        }