private static async Task HandleExcelAttachement(IDialogContext context, Activity activity, TokenResponse token, Attachment attachment) { if (attachment.ContentType == FileDownloadInfo.ContentType) { FileDownloadInfo downloadInfo = (attachment.Content as JObject).ToObject <FileDownloadInfo>(); var filePath = System.Web.Hosting.HostingEnvironment.MapPath("~/Files/"); if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } filePath += attachment.Name + DateTime.Now.Millisecond; // just to avoid name collision with other users. if (downloadInfo != null) { using (WebClient myWebClient = new WebClient()) { // Download the Web resource and save it into the current filesystem folder. myWebClient.DownloadFile(downloadInfo.DownloadUrl, filePath); } if (File.Exists(filePath)) { string emailId = await GetUserEmailId(activity); string domainName = emailId.Split('@').LastOrDefault(); var teamDetails = ExcelHelper.GetAddTeamDetails(filePath, domainName); if (teamDetails == null) { await context.PostAsync($"Attachment received but unfortunately we are not able to read your excel file. Please make sure that all the colums are correct."); } else { string lastAction; if (context.UserData.TryGetValue(LastAction, out lastAction)) { await context.PostAsync($"Attachment received. Working on getting your {teamDetails.Count} Teams ready."); GraphAPIHelper helper = new GraphAPIHelper(); if (lastAction == "create team") { await helper.ProcessCreateNewRequest(context, teamDetails, token.Token); } else { await helper.ProcessUpdateRequest(context, teamDetails, token.Token); } } else { await context.PostAsync($"Not able to process your file. Please restart the flow."); } await SendHelpMessage(context, activity); } File.Delete(filePath); } } } }
private async Task SendArchiveTeamCard(IDialogContext context, Activity activity) { var token = await context.GetUserTokenAsync(ConnectionName).ConfigureAwait(false); if (token != null && token.Token != null) { GraphAPIHelper helper = new GraphAPIHelper(); var allTeams = await helper.GetAllTeams(token.Token); var getAllNonArchivedTeams = await helper.GetAllNonArchivedTeams(token.Token, allTeams); var durations = new List <AdaptiveChoice>(); foreach (var team in getAllNonArchivedTeams) { durations.Add(new AdaptiveChoice() { Title = team.displayName, Value = team.id }); } var Card = new AdaptiveCard() { Body = new List <AdaptiveElement>() { new AdaptiveTextBlock() { Text = "Archive Team", Size = AdaptiveTextSize.Large, Weight = AdaptiveTextWeight.Bolder }, new AdaptiveTextBlock() { Text = "Please select teams to archive:" }, new AdaptiveChoiceSetInput() { Id = "id", Choices = durations, IsMultiSelect = true, Style = AdaptiveChoiceInputStyle.Compact, IsRequired = true } }, Actions = new List <AdaptiveAction>() { new AdaptiveSubmitAction() { Title = "Archive Team", } } }; var attachment = new Attachment() { ContentType = AdaptiveCard.ContentType, Content = Card }; Activity reply = activity.CreateReply(); reply.Attachments.Add(attachment); await context.PostAsync(reply); } else { await SendOAuthCardAsync(context, activity); } }
private async Task HandleActions(IDialogContext context, Activity activity) { string type = string.Empty; var details = JsonConvert.DeserializeObject <ResponseData>(activity.Value.ToString()); if (details.id == null) { await context.PostAsync("Please select at least one team to archive."); return; } var teamsToArchive = details.id.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); var token = await context.GetUserTokenAsync(ConnectionName).ConfigureAwait(false); if (token == null || token.Token == null) { await SendOAuthCardAsync(context, activity); return; } GraphAPIHelper helper = new GraphAPIHelper(); var successCount = 0; foreach (var teamId in teamsToArchive) { if (!await helper.ArchiveTeamAsync(token.Token, teamId)) { await context.PostAsync("Failed to archive team with teamId: " + teamId); } else { successCount++; } } ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl)); var reply = activity.CreateReply(); var Card = new AdaptiveCard() { Body = new List <AdaptiveElement>() { new AdaptiveTextBlock() { Text = "Archive Team", Size = AdaptiveTextSize.Large, Weight = AdaptiveTextWeight.Bolder }, new AdaptiveTextBlock() { Text = $"Archive complete. Successful count: {successCount}" }, } }; var attachment = new Attachment() { ContentType = AdaptiveCard.ContentType, Content = Card }; reply.Attachments.Add(attachment); await connector.Conversations.UpdateActivityAsync(activity.Conversation.Id, activity.ReplyToId, reply); // await context.Update(reply); }