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"; }
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); } } }
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); } }
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"; }
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); }
private async Task BrandChoiceMadeAskModelAsync(IDialogContext context, IAwaitable <object> awaitable) { Activity messageActivity = (Activity)await awaitable; string brand = messageActivity.Text.StartsWith("I want ") ? messageActivity.Text.Substring(7) : messageActivity.Text; Dictionary <string, bool> tempHash; List <string> brandModelsList = new List <string>(); bool moreThanOne, unavailable; IEnumerable <string> vector; if (debugMessages) { await context.PostAsync("Beginning of BrandChoiceMadeAskModelAsync()"); } brand = brand.ToLower(); brandChosen = brand; tempHash = GetBrandModels(brand); if (debugMessages) { await context.PostAsync("Collecting models' hash"); } if (!(unavailable = IsBrandUnavailable(brand)) && (tempHash.Count() > 0)) { vector = xclude != null?tempHash.Keys.Except(xclude) : tempHash.Keys; foreach (string model in vector) { brandModelsList.Add(model); } brandModels = brandModelsList; moreThanOne = (brandModels.Count != 1); brand = Miscellany.Capitalize(brand); var reply = messageActivity.CreateReply(moreThanOne ? "Which model would you like to have? Please pick one" : $"This is the only model I have available from {brand}"); ComposeModelCarousel(brand, brandModelsList, reply, context); await context.PostAsync(reply); if (debugMessages) { await context.PostAsync("DEBUG : Exiting BrandChoiceMadeAskModelAsync(), brand is available on stock"); } context.Wait(ChoiceMadeAsync); } else if (unavailable) { int x = availableModelsCount; await context.PostAsync($"We currently do not have any {brand.ToUpper()} devices available, you can choose from up to {x} models from leading manufacturers including Apple, Samsung, Nokia and HTC. Type the brands below from this list"); if (debugMessages) { await context.PostAsync("DEBUG : Exiting BrandChoiceMadeAskModelAsync(), brand is not available on stock"); } context.Wait(BrandChoiceMadeAskModelAsync); } else { await context.PostAsync("Not understood, please pick or type the brand you like"); if (debugMessages) { await context.PostAsync("DEBUG : Exiting BrandChoiceMadeAskModelAsync(), brand is not available on stock"); } context.Wait(BrandChoiceMadeAskModelAsync); } }
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); }
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); }
public override async Task StartAsync(IDialogContext context) { failCount = 0; if (CommonDialog.debugMessages) { await context.PostAsync($"DEBUG: entering TermsNode"); } if (context.ConversationData.TryGetValue("SubsNumber", out subsno)) { await Task.Delay(2500); int subsnum = Int32.Parse(subsno); string planName, planImage, phoneName, resCode; var choiceList = new List <string>(); if (context.ConversationData.TryGetValue("ChosenPlanName", out planName)) { if (CommonDialog.debugMessages) { await context.PostAsync($"DEBUG: Chosen plan is {planName}"); } context.ConversationData.TryGetValue("ChosenPlanImage", out planImage); context.ConversationData.TryGetValue("ChosenPlanCode", out resCode); if (context.ConversationData.TryGetValue("SelectedPhone", out phoneName)) { if (CommonDialog.debugMessages) { await context.PostAsync($"DEBUG: selected phone is {phoneName}"); } await context.PostAsync($"Okay. The phone and plan you have chosen are shown below."); // They have a new plan and a new phone, so show both in a carousel var reply = context.MakeMessage(); reply.AttachmentLayout = AttachmentLayoutTypes.Carousel; reply.Attachments = new List <Attachment>(); var CardList = new List <HeroCard>(); var planCard = new HeroCard { Title = "Your selected plan", Subtitle = planName, Images = new List <CardImage> { new CardImage(planImage) }, // Buttons = new List<CardAction> { new CardAction(ActionTypes.PostBack, "Pick Me!", value: "Choose " + Code), new CardAction(ActionTypes.ImBack, "Show Analysis", value: "Analyse") } }; reply.Attachments.Add(planCard.ToAttachment()); var phoneCard = new HeroCard() { Title = Miscellany.Capitalize(GetModelBrand(phoneName)), Subtitle = Miscellany.Capitalize(phoneName), Text = "", Images = new List <CardImage>() { new CardImage(GetEquipmentImageURL(phoneName, true, context), "img/jpeg") }, }; reply.Attachments.Add(phoneCard.ToAttachment()); choiceList.Add("Yes - both are correct."); choiceList.Add("No - I want a different phone."); choiceList.Add("No - I want a different plan."); choiceList.Add("No - I have changed my mind."); await context.PostAsync(reply); } else { // New plan only await context.PostAsync($"Okay. Please confirm the plan you have chosen below."); // They have a new plan and a new phone, so show both in a carousel var reply = context.MakeMessage(); reply.AttachmentLayout = AttachmentLayoutTypes.Carousel; reply.Attachments = new List <Attachment>(); var CardList = new List <HeroCard>(); var planCard = new HeroCard { Title = "Your selected plan", Subtitle = planName, Images = new List <CardImage> { new CardImage(planImage) }, // Buttons = new List<CardAction> { new CardAction(ActionTypes.PostBack, "Pick Me!", value: "Choose " + Code), new CardAction(ActionTypes.ImBack, "Show Analysis", value: "Analyse") } }; reply.Attachments.Add(planCard.ToAttachment()); choiceList.Add("Yes - that is correct."); choiceList.Add("No - I want a different plan."); choiceList.Add("No - I want a phone as well."); choiceList.Add("No - I have changed my mind."); await context.PostAsync(reply); } } else { if (CommonDialog.debugMessages) { await context.PostAsync($"DEBUG: no Chosen Plan detected."); } if (context.ConversationData.TryGetValue("SelectedPhone", out phoneName)) { if (CommonDialog.debugMessages) { await context.PostAsync($"DEBUG: chosen phone is {phoneName}"); } // New phone only await context.PostAsync($"Okay. Please confirm the phone you have chosen below."); // They have a new plan and a new phone, so show both in a carousel var reply = context.MakeMessage(); reply.AttachmentLayout = AttachmentLayoutTypes.Carousel; reply.Attachments = new List <Attachment>(); var CardList = new List <HeroCard>(); var phoneCard = new HeroCard() { Title = Miscellany.Capitalize(GetModelBrand(phoneName)), Subtitle = Miscellany.Capitalize(phoneName), Text = "", Images = new List <CardImage>() { new CardImage(GetEquipmentImageURL(phoneName, true, context), "img/jpeg") }, }; reply.Attachments.Add(phoneCard.ToAttachment()); choiceList.Add("Yes - that is correct."); choiceList.Add("No - I want a different phone."); choiceList.Add("No - I want to change plan as well."); choiceList.Add("No - I have changed my mind."); await context.PostAsync(reply); } else { // Nothing await context.PostAsync("ERROR: End of flow with no phone or plan chosen."); context.Done(2); } } PromptDialog.Choice(context, this.ConfirmSale, choiceList, "Are these details for your order correct?", "Not a valid option", 3); } else { await context.PostAsync($"Hmmm. Seems I couldnt get the subscriber number."); context.Done(2); } }