private async Task SendApprovalRequest(IDialogContext context, IAwaitable <GetTokenResponse> tokenResponse) { var accessToken = await tokenResponse; var userId = context.ConversationData.GetValueOrDefault <string>("approvalRequestor"); var fileId = context.ConversationData.GetValueOrDefault <string>("selectedFile"); var approvers = context.ConversationData.GetValueOrDefault <string[]>("approvers"); ClearConversationData(context, "approvalRequestor", "selectedFile", "approvers"); if (accessToken == null || string.IsNullOrEmpty(accessToken.Token)) { await context.PostAsync(Apologize("I could not get an access token")); return; } if (string.IsNullOrEmpty(userId)) { await context.PostAsync(Apologize("I could not find a user ID in the conversation state")); return; } if (string.IsNullOrEmpty(fileId)) { await context.PostAsync(Apologize("I could not find a selected file ID in the conversation state")); return; } if (string.IsNullOrEmpty(fileId)) { await context.PostAsync(Apologize("I could not find list of approvers in the conversation state")); return; } try { await ApprovalRequestHelper.SendApprovalRequest(accessToken.Token, userId, fileId, approvers); } catch (Microsoft.Graph.ServiceException ex) { if (ex.Error.Code == "UnknownError" && ex.Message.Contains("Invalid Hostname")) { // Log that this happened await DatabaseHelper.AddGraphLog(new GraphLogEntry(ex, "retry-send-approval")); // retry await ApprovalRequestHelper.SendApprovalRequest(accessToken.Token, userId, fileId, approvers); } else { throw; } } await context.PostAsync(@"I've sent the request. You can check the status of your request by typing ""check status""."); }
private async Task ConfirmFile(IDialogContext context, IAwaitable <GetTokenResponse> tokenResponse) { var accessToken = await tokenResponse; var fileId = context.ConversationData.GetValueOrDefault <string>("selectedFile"); ClearConversationData(context, "selectedFile"); if (accessToken == null || string.IsNullOrEmpty(accessToken.Token)) { await context.PostAsync(Apologize("I could not get an access token")); return; } if (string.IsNullOrEmpty(fileId)) { await context.PostAsync(Apologize("I could not find a selected file ID in the conversation state")); return; } //await ShowTyping(context, activity); var reply = context.MakeMessage(); AdaptiveCard fileDetailCard = null; try { fileDetailCard = await GraphHelper.GetFileDetailCard(accessToken.Token, fileId); } catch (Microsoft.Graph.ServiceException ex) { if (ex.Error.Code == "UnknownError" && ex.Message.Contains("Invalid Hostname")) { // Log that this happened await DatabaseHelper.AddGraphLog(new GraphLogEntry(ex, "retry-get-file-detail")); // retry fileDetailCard = await GraphHelper.GetFileDetailCard(accessToken.Token, fileId); } else { throw; } } reply.Attachments = new List <Attachment>() { new Attachment() { ContentType = AdaptiveCard.ContentType, Content = fileDetailCard } }; await context.PostAsync(reply); }
private async Task PromptForFile(IDialogContext context, IAwaitable <GetTokenResponse> tokenResponse) { //await ShowTyping(context, activity); var accessToken = await tokenResponse; if (accessToken == null || string.IsNullOrEmpty(accessToken.Token)) { await context.PostAsync(Apologize("I could not get an access token")); return; } // Get a list of files to choose from AdaptiveCard pickerCard = null; try { pickerCard = await GraphHelper.GetFilePickerCardFromOneDrive(accessToken.Token); } catch (Microsoft.Graph.ServiceException ex) { if (ex.Error.Code == "UnknownError" && ex.Message.Contains("Invalid Hostname")) { // Log that this happened await DatabaseHelper.AddGraphLog(new GraphLogEntry(ex, "retry-get-file-picker")); // retry pickerCard = await GraphHelper.GetFilePickerCardFromOneDrive(accessToken.Token); } else { throw; } } if (pickerCard != null) { var reply = context.MakeMessage(); reply.Attachments = new List <Attachment>() { new Attachment() { ContentType = AdaptiveCard.ContentType, Content = pickerCard } }; await context.PostAsync(reply); } else { await context.PostAsync("I couldn't find any files in your OneDrive. Please add the file you want approved and try again."); } }