private async Task <DialogTurnResult> ProcessIfExampleIsRequiredDialog(WaterfallStepContext step, CancellationToken cancellationToken = default(CancellationToken)) { bool askForExample = await accessors.AskForExamplePreference.GetAsync(step.Context, () => { return(false); }); if (askForExample) { var message = $"i would like to see a sample about {step.ActiveDialog.State["question"]}"; //await step.Context.SendActivityAsync(message, cancellationToken: cancellationToken); step.Context.Activity.Text = message; using (LuisRouterHelper luisRouterHelper = new LuisRouterHelper(Startup.EnvironmentName, Startup.ContentRootPath)) { var apps = await luisRouterHelper.LuisDiscoveryAsync(step, luisRouterAccessor, step.Context.Activity.Text, Startup.ApplicationCode, Startup.EncryptionKey); if (apps.Count > 0) { LuisAppDetail app = apps.OrderByDescending(x => x.Score).FirstOrDefault(); var recognizerResult = await luisRouterAccessor.LuisServices[app.Name].RecognizeAsync(step.Context, cancellationToken); var topIntent = recognizerResult?.GetTopScoringIntent(); if (topIntent != null && topIntent.HasValue && topIntent.Value.score >= .90 && topIntent.Value.intent != "None") { step.Context.Activity.Text = topIntent.Value.intent; var qnaName = string.Empty; using (QnAMakerHelper qnaMakerHelper = new QnAMakerHelper(Startup.EnvironmentName, Startup.ContentRootPath)) { qnaName = qnaMakerHelper.GetConfiguration().Name; } var response = await qnaMakerAccessor.QnAMakerServices[qnaName].GetAnswersAsync(step.Context); if (response != null && response.Length > 0) { string responseType = string.Empty; responseType = FindResponseTypeMetadata(response[0].Metadata); await step.Context.SendCustomResponseAsync(response[0].Answer, responseType); } else { await accessors.AskForExamplePreference.SetAsync(step.Context, false); await accessors.ConversationState.SaveChangesAsync(step.Context, false, cancellationToken); message = $"I did not find information to show you"; await step.Context.SendCustomResponseAsync(message); } } else { await accessors.AskForExamplePreference.SetAsync(step.Context, false); await accessors.ConversationState.SaveChangesAsync(step.Context, false, cancellationToken); message = $"I did not find information to show you"; await step.Context.SendCustomResponseAsync(message); } } else { await accessors.AskForExamplePreference.SetAsync(step.Context, false); await accessors.ConversationState.SaveChangesAsync(step.Context, false, cancellationToken); message = $"I did not find information to show you"; await step.Context.SendCustomResponseAsync(message); } } } return(await step.NextAsync()); }
private async Task <DialogTurnResult> ProcessQuestionDialog(WaterfallStepContext step, CancellationToken cancellationToken = default(CancellationToken)) { var question = (string)step.Result; step.ActiveDialog.State["question"] = question; if (question == "/start") { await step.EndDialogAsync(); return(Dialog.EndOfTurn); } using (LuisRouterHelper luisRouterHelper = new LuisRouterHelper(Startup.EnvironmentName, Startup.ContentRootPath)) { var apps = await luisRouterHelper.LuisDiscoveryAsync(step, luisRouterAccessor, step.Context.Activity.Text, Startup.ApplicationCode, Startup.EncryptionKey); if (apps.Count > 0) { LuisAppDetail app = apps.OrderByDescending(x => x.Score).FirstOrDefault(); var recognizerResult = await luisRouterAccessor.LuisServices[app.Name].RecognizeAsync(step.Context, cancellationToken); var topIntent = recognizerResult?.GetTopScoringIntent(); if (topIntent != null && topIntent.HasValue && topIntent.Value.score >= .90 && topIntent.Value.intent != "None") { step.Context.Activity.Text = topIntent.Value.intent; var qnaName = string.Empty; using (QnAMakerHelper qnaMakerHelper = new QnAMakerHelper(Startup.EnvironmentName, Startup.ContentRootPath)) { qnaName = qnaMakerHelper.GetConfiguration().Name; } var response = await qnaMakerAccessor.QnAMakerServices[qnaName].GetAnswersAsync(step.Context); if (response != null && response.Length > 0) { string responseType = string.Empty; responseType = FindResponseTypeMetadata(response[0].Metadata); await step.Context.SendCustomResponseAsync(response[0].Answer, responseType); if (!string.IsNullOrEmpty(responseType)) { if (!topIntent.Value.intent.EndsWith("_Sample")) { List <Choice> choices = new List <Choice>(); choices.Add(new Choice { Value = $"Yes" }); choices.Add(new Choice { Value = $"No" }); var message = $"Would you like to see an example?"; await step.Context.SendCustomResponseAsync(message); PromptOptions options = new PromptOptions { Choices = choices }; return(await step.PromptAsync("AskForExampleValidator", options, cancellationToken : cancellationToken)); } } } else { await accessors.AskForExamplePreference.SetAsync(step.Context, false); await accessors.ConversationState.SaveChangesAsync(step.Context, false, cancellationToken); var message = $"I did not find information to show you"; await step.Context.SendCustomResponseAsync(message); } } else { await accessors.AskForExamplePreference.SetAsync(step.Context, false); await accessors.ConversationState.SaveChangesAsync(step.Context, false, cancellationToken); var message = $"I did not find information to show you"; await step.Context.SendCustomResponseAsync(message); } } else { await accessors.AskForExamplePreference.SetAsync(step.Context, false); await accessors.ConversationState.SaveChangesAsync(step.Context, false, cancellationToken); var message = $"I did not find information to show you"; await step.Context.SendCustomResponseAsync(message); } } return(await step.NextAsync()); }