protected override async Task RouteAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken)) { var state = await _toDoStateAccessor.GetAsync(dc.Context, () => new ToDoSkillState()); // get current activity locale var locale = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName; var localeConfig = _services.LocaleConfigurations[locale]; // Initialize the PageSize and ReadSize parameters in state from configuration InitializeConfig(state); // If dispatch result is general luis model localeConfig.LuisServices.TryGetValue("todo", out var luisService); if (luisService == null) { throw new Exception("The specified LUIS Model could not be found in your Bot Services configuration."); } else { var result = await luisService.RecognizeAsync <ToDo>(dc.Context, CancellationToken.None); var intent = result?.TopIntent().intent; var generalTopIntent = state.GeneralLuisResult?.TopIntent().intent; var skillOptions = new ToDoSkillDialogOptions { SkillMode = _skillMode, }; // switch on general intents switch (intent) { case ToDo.Intent.AddToDo: { await dc.BeginDialogAsync(nameof(AddToDoItemDialog), skillOptions); break; } case ToDo.Intent.MarkToDo: { await dc.BeginDialogAsync(nameof(MarkToDoItemDialog), skillOptions); break; } case ToDo.Intent.DeleteToDo: { await dc.BeginDialogAsync(nameof(DeleteToDoItemDialog), skillOptions); break; } case ToDo.Intent.ShowToDo: { await dc.BeginDialogAsync(nameof(ShowToDoItemDialog), skillOptions); break; } case ToDo.Intent.None: { if (generalTopIntent == General.Intent.Next || generalTopIntent == General.Intent.Previous || generalTopIntent == General.Intent.ReadMore) { await dc.BeginDialogAsync(nameof(ShowToDoItemDialog), skillOptions); } else { // No intent was identified, send confused message await dc.Context.SendActivityAsync(dc.Context.Activity.CreateReply(ToDoMainResponses.DidntUnderstandMessage)); if (_skillMode) { await CompleteAsync(dc); } } break; } default: { // intent was identified but not yet implemented await dc.Context.SendActivityAsync(dc.Context.Activity.CreateReply(ToDoMainResponses.FeatureNotAvailable)); if (_skillMode) { await CompleteAsync(dc); } break; } } } }
/// <summary> /// Run every turn of the conversation. Handles orchestration of messages. /// </summary> /// <param name="dc">Current dialog context.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>Completed Task.</returns> protected override async Task RouteAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken)) { // Get the conversation state from the turn context var state = await this.toDoSkillAccessors.ToDoSkillState.GetAsync(dc.Context, () => new ToDoSkillState()); var dialogState = await this.toDoSkillAccessors.ConversationDialogState.GetAsync(dc.Context, () => new DialogState()); ToDo luisResult = null; if (this.skillMode && state.LuisResultPassedFromSkill != null) { luisResult = (ToDo)state.LuisResultPassedFromSkill; state.LuisResultPassedFromSkill = null; } else if (this.toDoSkillServices?.LuisRecognizer != null) { luisResult = await this.toDoSkillServices.LuisRecognizer.RecognizeAsync <ToDo>(dc.Context, cancellationToken); if (luisResult == null) { throw new Exception("ToDoSkill: Could not get Luis Recognizer result."); } } else { throw new Exception("ToDoSkill: Could not get Luis Recognizer result."); } state.LuisResult = luisResult; await ToDoHelper.DigestLuisResultAsync(dc.Context, this.toDoSkillAccessors); var skillOptions = new ToDoSkillDialogOptions { SkillMode = this.skillMode, }; var intent = luisResult?.TopIntent().intent; switch (intent) { case ToDo.Intent.Greeting: { await dc.BeginDialogAsync(GreetingDialog.Name, skillOptions); break; } case ToDo.Intent.ShowToDo: case ToDo.Intent.Previous: case ToDo.Intent.Next: { await dc.BeginDialogAsync(ShowToDoTasksDialog.Name, skillOptions); break; } case ToDo.Intent.AddToDo: { await dc.BeginDialogAsync(AddToDoTaskDialog.Name, skillOptions); break; } case ToDo.Intent.MarkToDo: { await dc.BeginDialogAsync(MarkToDoTaskDialog.Name, skillOptions); break; } case ToDo.Intent.DeleteToDo: { await dc.BeginDialogAsync(DeleteToDoTaskDialog.Name, skillOptions); break; } case ToDo.Intent.None: { await this.toDoSkillResponses.ReplyWith(dc.Context, ToDoSkillResponses.Confused); if (skillMode) { await CompleteAsync(dc); } break; } default: { await dc.Context.SendActivityAsync("This feature is not yet available in the To Do Skill. Please try asking something else."); if (skillMode) { await CompleteAsync(dc); } break; } } }