protected async Task <DialogTurnResult> InitAllTasks(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken)) { var state = await Accessor.GetAsync(sc.Context); state.ListType = state.ListType ?? ListType.ToDo.ToString(); if (!state.ListTypeIds.ContainsKey(state.ListType)) { await sc.Context.SendActivityAsync(sc.Context.Activity.CreateReply(ToDoSharedResponses.SettingUpOneNoteMessage)); var service = await ServiceManager.InitAsync(state.MsGraphToken, state.ListTypeIds); state.AllTasks = await service.GetTasksAsync(state.ListType); state.ShowTaskPageIndex = 0; var rangeCount = Math.Min(state.PageSize, state.AllTasks.Count); state.Tasks = state.AllTasks.GetRange(0, rangeCount); } if (state.AllTasks.Count <= 0) { await sc.Context.SendActivityAsync(sc.Context.Activity.CreateReply(ToDoSharedResponses.NoTasksInList)); return(await sc.EndDialogAsync(true)); } else { return(await sc.NextAsync()); } }
public async Task <DialogTurnResult> MarkToDoTaskCompleted(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken)) { try { var state = await Accessor.GetAsync(sc.Context); state.LastListType = state.ListType; if (!state.ListTypeIds.ContainsKey(state.ListType)) { await sc.Context.SendActivityAsync(sc.Context.Activity.CreateReply(ToDoSharedResponses.SettingUpOneNoteMessage)); } var service = await ServiceManager.InitAsync(state.MsGraphToken, state.ListTypeIds); BotResponse botResponse; string taskTopicToBeMarked = null; if (state.MarkOrDeleteAllTasksFlag) { await service.MarkTasksCompletedAsync(state.ListType, state.AllTasks); botResponse = MarkToDoResponses.AfterAllToDoTasksCompleted; } else { taskTopicToBeMarked = state.AllTasks[state.TaskIndexes[0]].Topic; var tasksToBeMarked = new List <TaskItem>(); state.TaskIndexes.ForEach(i => tasksToBeMarked.Add(state.AllTasks[i])); await service.MarkTasksCompletedAsync(state.ListType, tasksToBeMarked); botResponse = MarkToDoResponses.AfterToDoTaskCompleted; } state.AllTasks = await service.GetTasksAsync(state.ListType); var allTasksCount = state.AllTasks.Count; var currentTaskIndex = state.ShowTaskPageIndex * state.PageSize; state.Tasks = state.AllTasks.GetRange(currentTaskIndex, Math.Min(state.PageSize, allTasksCount - currentTaskIndex)); var markToDoAttachment = ToAdaptiveCardForOtherFlows( state.Tasks, state.AllTasks.Count, taskTopicToBeMarked, botResponse, ToDoSharedResponses.ShowToDoTasks); var markToDoReply = sc.Context.Activity.CreateReply(); markToDoReply.Attachments.Add(markToDoAttachment); await sc.Context.SendActivityAsync(markToDoReply); return(await sc.EndDialogAsync(true)); } catch { await HandleDialogExceptions(sc); throw; } }
protected async Task <ITaskService> InitListTypeIds(WaterfallStepContext sc) { var state = await ToDoStateAccessor.GetAsync(sc.Context); if (!state.ListTypeIds.ContainsKey(state.ListType)) { var emailService = await MailService.InitAsync(state.MsGraphToken); var senderMailAddress = await emailService.GetSenderMailAddressAsync(); var recovered = await RecoverListTypeIdsAsync(sc, senderMailAddress); if (!recovered) { if (ServiceManager is OneNoteService) { await sc.Context.SendActivityAsync(sc.Context.Activity.CreateReply(ToDoSharedResponses.SettingUpOneNoteMessage)); } else { await sc.Context.SendActivityAsync(sc.Context.Activity.CreateReply(ToDoSharedResponses.SettingUpOutlookMessage)); } var service = await ServiceManager.InitAsync(state.MsGraphToken, state.ListTypeIds); var taskWebLink = await service.GetTaskWebLink(); var emailContent = string.Format(ToDoStrings.EmailContent, taskWebLink); await emailService.SendMessageAsync(emailContent, ToDoStrings.EmailSubject); if (ServiceManager is OneNoteService) { await sc.Context.SendActivityAsync(sc.Context.Activity.CreateReply(ToDoSharedResponses.AfterOneNoteSetupMessage)); } else { await sc.Context.SendActivityAsync(sc.Context.Activity.CreateReply(ToDoSharedResponses.AfterOutlookSetupMessage)); } await StoreListTypeIdsAsync(sc, senderMailAddress); return(service); } } return(await ServiceManager.InitAsync(state.MsGraphToken, state.ListTypeIds)); }
protected async Task<DialogTurnResult> InitAllTasks(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken)) { try { var state = await Accessor.GetAsync(sc.Context); state.ListType = state.ListType ?? ToDoStrings.ToDo; if (!state.ListTypeIds.ContainsKey(state.ListType)) { await sc.Context.SendActivityAsync(sc.Context.Activity.CreateReply(ToDoSharedResponses.SettingUpOneNoteMessage)); var service = await ServiceManager.InitAsync(state.MsGraphToken, state.ListTypeIds); state.AllTasks = await service.GetTasksAsync(state.ListType); state.ShowTaskPageIndex = 0; var rangeCount = Math.Min(state.PageSize, state.AllTasks.Count); state.Tasks = state.AllTasks.GetRange(0, rangeCount); } else if (state.ListType != state.LastListType) { // LastListType is used to switch between list types in DeleteToDoItemDialog and MarkToDoItemDialog. var service = await ServiceManager.InitAsync(state.MsGraphToken, state.ListTypeIds); state.AllTasks = await service.GetTasksAsync(state.ListType); state.ShowTaskPageIndex = 0; var rangeCount = Math.Min(state.PageSize, state.AllTasks.Count); state.Tasks = state.AllTasks.GetRange(0, rangeCount); } if (state.AllTasks.Count <= 0) { await sc.Context.SendActivityAsync(sc.Context.Activity.CreateReply(ToDoSharedResponses.NoTasksInList)); return await sc.EndDialogAsync(true); } else { return await sc.NextAsync(); } } catch (SkillException ex) { await HandleDialogExceptions(sc, ex); return new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs); } catch (Exception ex) { await HandleDialogExceptions(sc, ex); return new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs); } }
protected async Task <DialogTurnResult> AddToDoTask(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken)) { try { var state = await Accessor.GetAsync(sc.Context); state.ListType = state.ListType ?? ToDoStrings.ToDo; state.LastListType = state.ListType; if (!state.ListTypeIds.ContainsKey(state.ListType)) { await sc.Context.SendActivityAsync(sc.Context.Activity.CreateReply(ToDoSharedResponses.SettingUpOneNoteMessage)); } var service = await ServiceManager.InitAsync(state.MsGraphToken, state.ListTypeIds); await service.AddTaskAsync(state.ListType, state.TaskContent); state.AllTasks = await service.GetTasksAsync(state.ListType); state.ShowTaskPageIndex = 0; var rangeCount = Math.Min(state.PageSize, state.AllTasks.Count); state.Tasks = state.AllTasks.GetRange(0, rangeCount); var toDoListAttachment = ToAdaptiveCardForOtherFlows( state.Tasks, state.AllTasks.Count, state.TaskContent, ToDoSharedResponses.AfterToDoTaskAdded, ToDoSharedResponses.ShowToDoTasks); var toDoListReply = sc.Context.Activity.CreateReply(); toDoListReply.Attachments.Add(toDoListAttachment); await sc.Context.SendActivityAsync(toDoListReply); return(await sc.EndDialogAsync(true)); } catch { await HandleDialogExceptions(sc); throw; } }
public async Task <DialogTurnResult> ShowToDoTasks(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken)) { try { var state = await Accessor.GetAsync(sc.Context); state.ListType = state.ListType ?? ToDoStrings.ToDo; state.LastListType = state.ListType; if (!state.ListTypeIds.ContainsKey(state.ListType)) { await sc.Context.SendActivityAsync(sc.Context.Activity.CreateReply(ToDoSharedResponses.SettingUpOneNoteMessage)); } var topIntent = state.LuisResult?.TopIntent().intent; if (topIntent == ToDo.Intent.ShowToDo) { var service = await ServiceManager.InitAsync(state.MsGraphToken, state.ListTypeIds); state.AllTasks = await service.GetTasksAsync(state.ListType); } var allTasksCount = state.AllTasks.Count; var currentTaskIndex = state.ShowTaskPageIndex * state.PageSize; state.Tasks = state.AllTasks.GetRange(currentTaskIndex, Math.Min(state.PageSize, allTasksCount - currentTaskIndex)); var generalTopIntent = state.GeneralLuisResult?.TopIntent().intent; if (state.Tasks.Count <= 0) { return(await sc.NextAsync()); } else { Attachment toDoListAttachment = null; if (topIntent == ToDo.Intent.ShowToDo) { toDoListAttachment = ToAdaptiveCardForShowToDos( state.Tasks, Math.Min(state.Tasks.Count, state.ReadSize), state.AllTasks.Count); } else if (generalTopIntent == General.Intent.Next) { toDoListAttachment = ToAdaptiveCardForNextPage( state.Tasks, Math.Min(state.Tasks.Count, state.ReadSize)); } else if (generalTopIntent == General.Intent.Previous) { toDoListAttachment = ToAdaptiveCardForPreviousPage( state.Tasks, Math.Min(state.Tasks.Count, state.ReadSize)); } else if (generalTopIntent == General.Intent.ReadMore) { if (state.ReadTaskIndex == 0) { toDoListAttachment = ToAdaptiveCardForNextPage( state.Tasks, Math.Min(state.Tasks.Count, state.ReadSize)); } else { var remainingTasksCount = state.Tasks.Count - (state.ReadTaskIndex * state.ReadSize); toDoListAttachment = ToAdaptiveCardForReadMore( state.Tasks, state.ReadTaskIndex * state.ReadSize, Math.Min(remainingTasksCount, state.ReadSize), state.AllTasks.Count); } } var toDoListReply = sc.Context.Activity.CreateReply(); toDoListReply.Attachments.Add(toDoListAttachment); await sc.Context.SendActivityAsync(toDoListReply); if (topIntent == ToDo.Intent.ShowToDo && allTasksCount > (state.ShowTaskPageIndex + 1) * state.PageSize) { await sc.Context.SendActivityAsync(sc.Context.Activity.CreateReply(ShowToDoResponses.ShowingMoreTasks)); } return(await sc.EndDialogAsync(true)); } } catch { await HandleDialogExceptions(sc); throw; } }
public async Task <DialogTurnResult> DeleteToDoTask(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken)) { try { var state = await Accessor.GetAsync(sc.Context); if (state.DeleteTaskConfirmation) { if (!state.ListTypeIds.ContainsKey(state.ListType)) { await sc.Context.SendActivityAsync(sc.Context.Activity.CreateReply(ToDoSharedResponses.SettingUpOneNoteMessage)); } var service = await ServiceManager.InitAsync(state.MsGraphToken, state.ListTypeIds); string taskTopicToBeDeleted = null; if (state.MarkOrDeleteAllTasksFlag) { await service.DeleteTasksAsync(state.ListType, state.AllTasks); state.AllTasks = new List <TaskItem>(); state.Tasks = new List <TaskItem>(); state.ShowTaskPageIndex = 0; state.TaskIndexes = new List <int>(); } else { taskTopicToBeDeleted = state.AllTasks[state.TaskIndexes[0]].Topic; var tasksToBeDeleted = new List <TaskItem>(); state.TaskIndexes.ForEach(i => tasksToBeDeleted.Add(state.AllTasks[i])); await service.DeleteTasksAsync(state.ListType, tasksToBeDeleted); state.AllTasks = await service.GetTasksAsync(state.ListType); var allTasksCount = state.AllTasks.Count; var currentTaskIndex = state.ShowTaskPageIndex * state.PageSize; while (currentTaskIndex >= allTasksCount && currentTaskIndex >= state.PageSize) { currentTaskIndex -= state.PageSize; state.ShowTaskPageIndex--; } state.Tasks = state.AllTasks.GetRange(currentTaskIndex, Math.Min(state.PageSize, allTasksCount - currentTaskIndex)); } if (state.MarkOrDeleteAllTasksFlag) { await sc.Context.SendActivityAsync(sc.Context.Activity.CreateReply(DeleteToDoResponses.AfterAllTasksDeleted)); } else { if (state.Tasks.Count > 0) { var deletedToDoListAttachment = ToAdaptiveCardAttachmentForOtherFlows( state.Tasks, state.AllTasks.Count, taskTopicToBeDeleted, DeleteToDoResponses.AfterTaskDeleted, ToDoSharedResponses.ShowToDoTasks); var deletedToDoListReply = sc.Context.Activity.CreateReply(); deletedToDoListReply.Attachments.Add(deletedToDoListAttachment); await sc.Context.SendActivityAsync(deletedToDoListReply); } else { var token1 = new StringDictionary() { { "taskContent", taskTopicToBeDeleted } }; var response1 = GenerateResponseWithTokens(DeleteToDoResponses.AfterTaskDeleted, token1); var token2 = new StringDictionary() { { "taskCount", "0" } }; var response2 = GenerateResponseWithTokens(ToDoSharedResponses.ShowToDoTasks, token2); var response = response1 + " " + response2.Remove(response2.Length - 1) + "."; var botResponse = sc.Context.Activity.CreateReply(response); botResponse.Speak = response; await sc.Context.SendActivityAsync(botResponse); } } } else { await sc.Context.SendActivityAsync(sc.Context.Activity.CreateReply(ToDoSharedResponses.ActionEnded)); } return(await sc.EndDialogAsync(true)); } catch { await HandleDialogExceptions(sc); throw; } }