private async Task <DialogTurnResult> ListIdeasPhase2Async(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var tokenResponse = (TokenResponse)stepContext.Result; if (tokenResponse?.Token == null) { await stepContext.Context.SendActivityAsync(MessageFactory.Text("Login was not successful please try again."), cancellationToken); return(await stepContext.EndDialogAsync(null, cancellationToken)); } var handler = new JwtSecurityTokenHandler(); var token = handler.ReadJwtToken(tokenResponse.Token); var tenantId = token.Claims.FirstOrDefault(i => i.Type == "tid").Value; var userProfile = await UserProfileAccessor.GetAsync(stepContext.Context); var team = userProfile.SelectedTeam; var listIdeasOptions = (ListIdeasOptions)stepContext.Options; var plannerService = new PlannerService(tokenResponse.Token); var ideaService = new IdeaService(tokenResponse.Token); var plan = await plannerService.GetTeamPlanAsync(team.Id, team.DisplayName); if (plan == null) { await stepContext.Context.SendActivityAsync(MessageFactory.Text("Could not found the plan."), cancellationToken); return(await stepContext.EndDialogAsync(null, cancellationToken)); } var bucketName = ideaService.GetBucketName(listIdeasOptions.Status); var ideas = await ideaService.GetAsync(plan.Id, bucketName, listIdeasOptions.From); var summary = ideas.Length > 0 ? $"Getting {ideas.Length} {(ideas.Length > 1 ? "ideas" : "idea")} from Microsoft Planner, please wait..." : "No idea was found."; await stepContext.Context.SendActivityAsync(summary); foreach (var bucket in IdeasPlan.Buckets.All) { var bucketIdeas = ideas.Where(i => StringComparer.InvariantCultureIgnoreCase.Equals(i.Bucket, bucket)).ToArray(); if (!bucketIdeas.Any()) { continue; } if (string.IsNullOrEmpty(bucketName)) { await stepContext.Context.SendActivityAsync($"{bucket} ({bucketIdeas.Length + " " + (bucket.Length > 1 ? "ideas" : "idea")})"); } int pageSize = 6; int pageCount = (bucketIdeas.Length + pageSize - 1) / pageSize; for (int page = 0; page < pageCount; page++) { var attachments = new List <Attachment>(); var pageIdeas = bucketIdeas.Skip(pageSize * page).Take(pageSize).ToArray(); foreach (var idea in pageIdeas) { await ideaService.GetDetailsAsync(idea); var url = ideaService.GetIdeaUrl(tenantId, team.Id, plan.Id, idea.Id); var owners = $"Owners: {string.Join(",", idea.Owners)}"; var text = $"Start Date<br/>{idea.StartDate?.DateTime.ToShortDateString()}"; if (!string.IsNullOrEmpty(idea.Description)) { text += $"<br/><br/>{idea.Description.Replace("\r\n", "<br/>").Replace("\n", "<br/>")}"; } var viewAction = new CardAction(ActionTypes.OpenUrl, "View", value: url); var heroCard = new HeroCard(idea.Title, owners, text, buttons: new List <CardAction> { viewAction }); attachments.Add(heroCard.ToAttachment()); } var message = MessageFactory.Carousel(attachments); await stepContext.Context.SendActivityAsync(message); } } return(await stepContext.EndDialogAsync(null, cancellationToken)); }