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";
        }
Exemple #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);
        }