From edfad69e8c50438b1bedd6e5a4f028e97f245a3c Mon Sep 17 00:00:00 2001 From: lauren-mills Date: Wed, 1 May 2019 15:38:49 -0700 Subject: [PATCH] updated va to sdk 4.4 (#1214) --- .../BotTestBase.cs | 5 +- .../Mocks/MockLuisRecognizer.cs | 18 +- .../Mocks/MockQnAMaker.cs | 13 +- .../Utilities/GeneralTestUtil.cs | 4 +- .../VirtualAssistantSample.Tests.csproj | 2 +- .../Adapters/DefaultAdapter.cs | 1 - .../Dialogs/MainDialog.cs | 5 +- .../Services/BotServices.cs | 7 +- .../VirtualAssistantSample.csproj | 28 +- .../csharp/Template/VA.Tests/BotTestBase.cs | 17 +- .../VA.Tests/Mocks/MockLuisRecognizer.cs | 18 +- .../Template/VA.Tests/Mocks/MockQnAMaker.cs | 13 +- .../VA.Tests/Utilities/GeneralTestUtil.cs | 4 +- .../csharp/Template/VA.Tests/VA.Tests.csproj | 2 +- .../Template/VA/Adapters/DefaultAdapter.cs | 1 - .../csharp/Template/VA/Dialogs/MainDialog.cs | 416 +++++++++--------- .../Template/VA/Services/BotServices.cs | 7 +- .../csharp/Template/VA/VA.csproj | 28 +- 18 files changed, 314 insertions(+), 275 deletions(-) diff --git a/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample.Tests/BotTestBase.cs b/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample.Tests/BotTestBase.cs index 69368bd44a..dfa0830056 100644 --- a/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample.Tests/BotTestBase.cs +++ b/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample.Tests/BotTestBase.cs @@ -10,9 +10,10 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Bot.Connector.Authentication; using Microsoft.Bot.Builder.Solutions; -using Microsoft.Bot.Builder.Solutions.Telemetry; using Microsoft.Bot.Builder.Solutions.Testing; using Microsoft.Bot.Builder.Skills; +using Microsoft.Bot.Builder.AI.QnA; +using Microsoft.Bot.Builder.AI.Luis; namespace VirtualAssistantSample.Tests { @@ -32,7 +33,7 @@ public virtual void Initialize() { "en", new CognitiveModelSet { DispatchService = DispatchTestUtil.CreateRecognizer(), - LuisServices = new Dictionary + LuisServices = new Dictionary { { "general", GeneralTestUtil.CreateRecognizer() } }, diff --git a/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample.Tests/Mocks/MockLuisRecognizer.cs b/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample.Tests/Mocks/MockLuisRecognizer.cs index 61ab133e37..207f5ef598 100644 --- a/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample.Tests/Mocks/MockLuisRecognizer.cs +++ b/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample.Tests/Mocks/MockLuisRecognizer.cs @@ -4,11 +4,11 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using Microsoft.Bot.Builder.Solutions.Telemetry; +using Microsoft.Bot.Builder.AI.Luis; namespace VirtualAssistantSample.Tests.Mocks { - public class MockLuisRecognizer : ITelemetryLuisRecognizer + public class MockLuisRecognizer : ITelemetryRecognizer { public MockLuisRecognizer(IRecognizerConvert defaultIntent) { @@ -20,7 +20,9 @@ public MockLuisRecognizer(IRecognizerConvert defaultIntent) private IRecognizerConvert DefaultIntent { get; set; } - public bool LogPersonalInformation => throw new NotImplementedException(); + public bool LogPersonalInformation { get; set; } = false; + + public IBotTelemetryClient TelemetryClient { get; set; } = new NullBotTelemetryClient(); public void RegisterUtterances(Dictionary utterances) { @@ -52,5 +54,15 @@ public Task RecognizeAsync(ITurnContext turnContext, CancellationToken can var mockResult = TestUtterances.GetValueOrDefault(text, DefaultIntent); return Task.FromResult((T)mockResult); } + + public Task RecognizeAsync(ITurnContext turnContext, Dictionary telemetryProperties, Dictionary telemetryMetrics, CancellationToken cancellationToken = default(CancellationToken)) + { + throw new NotImplementedException(); + } + + public Task RecognizeAsync(ITurnContext turnContext, Dictionary telemetryProperties, Dictionary telemetryMetrics, CancellationToken cancellationToken = default(CancellationToken)) where T : IRecognizerConvert, new() + { + throw new NotImplementedException(); + } } } \ No newline at end of file diff --git a/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample.Tests/Mocks/MockQnAMaker.cs b/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample.Tests/Mocks/MockQnAMaker.cs index 52f521d912..4ddc273eae 100644 --- a/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample.Tests/Mocks/MockQnAMaker.cs +++ b/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample.Tests/Mocks/MockQnAMaker.cs @@ -1,6 +1,5 @@ using Microsoft.Bot.Builder; using Microsoft.Bot.Builder.AI.QnA; -using Microsoft.Bot.Builder.Solutions.Telemetry; using System; using System.Collections.Generic; using System.Threading.Tasks; @@ -19,7 +18,9 @@ public MockQnAMaker(QueryResult[] defaultAnswer) private QueryResult[] DefaultAnswer { get; set; } - public bool LogPersonalInformation => throw new NotImplementedException(); + public bool LogPersonalInformation { get; set; } = false; + + public IBotTelemetryClient TelemetryClient { get; set; } = new NullBotTelemetryClient(); public void RegisterAnswers(Dictionary utterances) { @@ -36,5 +37,13 @@ public Task GetAnswersAsync(ITurnContext context, QnAMakerOptions var mockResult = TestAnswers.GetValueOrDefault(text, DefaultAnswer); return Task.FromResult(mockResult); } + + public Task GetAnswersAsync(ITurnContext turnContext, QnAMakerOptions options, Dictionary telemetryProperties, Dictionary telemetryMetrics = null) + { + var text = turnContext.Activity.Text; + + var mockResult = TestAnswers.GetValueOrDefault(text, DefaultAnswer); + return Task.FromResult(mockResult); + } } } \ No newline at end of file diff --git a/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample.Tests/Utilities/GeneralTestUtil.cs b/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample.Tests/Utilities/GeneralTestUtil.cs index 2f3c91bb13..4aa87c850f 100644 --- a/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample.Tests/Utilities/GeneralTestUtil.cs +++ b/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample.Tests/Utilities/GeneralTestUtil.cs @@ -8,7 +8,7 @@ namespace VirtualAssistantSample.Tests.Utilities { public class GeneralTestUtil { - private static Dictionary _utterances = new Dictionary + private static readonly Dictionary _utterances = new Dictionary { { GeneralUtterances.Cancel, CreateIntent(GeneralUtterances.Cancel, GeneralLuis.Intent.Cancel) }, { GeneralUtterances.Escalate, CreateIntent(GeneralUtterances.Escalate, GeneralLuis.Intent.Escalate) }, @@ -25,7 +25,7 @@ public class GeneralTestUtil { GeneralUtterances.Stop, CreateIntent(GeneralUtterances.Stop, GeneralLuis.Intent.Stop) }, }; - public static IRecognizer CreateRecognizer() + public static MockLuisRecognizer CreateRecognizer() { var recognizer = new MockLuisRecognizer(defaultIntent: CreateIntent(string.Empty, GeneralLuis.Intent.None)); recognizer.RegisterUtterances(_utterances); diff --git a/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample.Tests/VirtualAssistantSample.Tests.csproj b/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample.Tests/VirtualAssistantSample.Tests.csproj index a31513795d..6d3fc221cb 100644 --- a/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample.Tests/VirtualAssistantSample.Tests.csproj +++ b/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample.Tests/VirtualAssistantSample.Tests.csproj @@ -9,7 +9,7 @@ - + diff --git a/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample/Adapters/DefaultAdapter.cs b/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample/Adapters/DefaultAdapter.cs index 3cfb97ca15..ed2e859b7d 100644 --- a/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample/Adapters/DefaultAdapter.cs +++ b/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample/Adapters/DefaultAdapter.cs @@ -5,7 +5,6 @@ using Microsoft.Bot.Builder.Azure; using Microsoft.Bot.Builder.Integration.AspNet.Core; using Microsoft.Bot.Builder.Solutions.Middleware; -using Microsoft.Bot.Builder.Solutions.Telemetry; using Microsoft.Bot.Connector.Authentication; using Microsoft.Bot.Schema; using VirtualAssistantSample.Responses.Main; diff --git a/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample/Dialogs/MainDialog.cs b/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample/Dialogs/MainDialog.cs index 14927dcbf0..e5a807433c 100644 --- a/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample/Dialogs/MainDialog.cs +++ b/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample/Dialogs/MainDialog.cs @@ -15,7 +15,6 @@ using Microsoft.Bot.Builder.Solutions.Dialogs; using Microsoft.Bot.Schema; using Newtonsoft.Json.Linq; -using VirtualAssistantSample.Models; using VirtualAssistantSample.Responses.Cancel; using VirtualAssistantSample.Responses.Main; using VirtualAssistantSample.Services; @@ -129,7 +128,7 @@ public MainDialog( } else { - var answers = await qnaService.GetAnswersAsync(dc.Context); + var answers = await qnaService.GetAnswersAsync(dc.Context, null, null); if (answers != null && answers.Count() > 0) { @@ -151,7 +150,7 @@ public MainDialog( } else { - var answers = await qnaService.GetAnswersAsync(dc.Context); + var answers = await qnaService.GetAnswersAsync(dc.Context, null, null); if (answers != null && answers.Count() > 0) { diff --git a/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample/Services/BotServices.cs b/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample/Services/BotServices.cs index f7996e6418..858eca7bcf 100644 --- a/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample/Services/BotServices.cs +++ b/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample/Services/BotServices.cs @@ -5,7 +5,6 @@ using Microsoft.Bot.Builder.AI.Luis; using Microsoft.Bot.Builder.AI.QnA; using Microsoft.Bot.Builder.Solutions; -using Microsoft.Bot.Builder.Solutions.Telemetry; namespace VirtualAssistantSample.Services { @@ -24,14 +23,14 @@ public BotServices(BotSettings settings) var config = pair.Value; var dispatchApp = new LuisApplication(config.DispatchModel.AppId, config.DispatchModel.SubscriptionKey, config.DispatchModel.GetEndpoint()); - set.DispatchService = new TelemetryLuisRecognizer(dispatchApp); + set.DispatchService = new LuisRecognizer(dispatchApp); if (config.LanguageModels != null) { foreach (var model in config.LanguageModels) { var luisApp = new LuisApplication(model.AppId, model.SubscriptionKey, model.GetEndpoint()); - set.LuisServices.Add(model.Id, new TelemetryLuisRecognizer(luisApp)); + set.LuisServices.Add(model.Id, new LuisRecognizer(luisApp)); } } @@ -43,7 +42,7 @@ public BotServices(BotSettings settings) EndpointKey = kb.EndpointKey, Host = kb.Hostname, }; - var qnaMaker = new TelemetryQnAMaker(qnaEndpoint); + var qnaMaker = new QnAMaker(qnaEndpoint); set.QnAServices.Add(kb.Id, qnaMaker); } diff --git a/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample/VirtualAssistantSample.csproj b/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample/VirtualAssistantSample.csproj index 1be394bc79..3c9701d63f 100644 --- a/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample/VirtualAssistantSample.csproj +++ b/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample/VirtualAssistantSample.csproj @@ -13,20 +13,20 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/templates/Virtual-Assistant-Template/csharp/Template/VA.Tests/BotTestBase.cs b/templates/Virtual-Assistant-Template/csharp/Template/VA.Tests/BotTestBase.cs index 6bc4a83cff..db76032227 100644 --- a/templates/Virtual-Assistant-Template/csharp/Template/VA.Tests/BotTestBase.cs +++ b/templates/Virtual-Assistant-Template/csharp/Template/VA.Tests/BotTestBase.cs @@ -1,18 +1,19 @@ using System.Collections.Generic; using System.Threading; -using $safeprojectname$.Utilities; using Microsoft.Bot.Builder; using Microsoft.Bot.Builder.Adapters; +using Microsoft.Bot.Builder.AI.QnA; +using Microsoft.Bot.Builder.AI.Luis; +using Microsoft.Bot.Builder.Skills; +using Microsoft.Bot.Builder.Solutions; +using Microsoft.Bot.Builder.Solutions.Testing; +using Microsoft.Bot.Connector.Authentication; +using Microsoft.Extensions.DependencyInjection; using Microsoft.VisualStudio.TestTools.UnitTesting; +using $safeprojectname$.Utilities; using $ext_safeprojectname$.Services; using $ext_safeprojectname$.Bots; using $ext_safeprojectname$.Dialogs; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Bot.Connector.Authentication; -using Microsoft.Bot.Builder.Solutions; -using Microsoft.Bot.Builder.Solutions.Telemetry; -using Microsoft.Bot.Builder.Solutions.Testing; -using Microsoft.Bot.Builder.Skills; namespace $safeprojectname$ { @@ -32,7 +33,7 @@ public virtual void Initialize() { "en", new CognitiveModelSet { DispatchService = DispatchTestUtil.CreateRecognizer(), - LuisServices = new Dictionary + LuisServices = new Dictionary { { "general", GeneralTestUtil.CreateRecognizer() } }, diff --git a/templates/Virtual-Assistant-Template/csharp/Template/VA.Tests/Mocks/MockLuisRecognizer.cs b/templates/Virtual-Assistant-Template/csharp/Template/VA.Tests/Mocks/MockLuisRecognizer.cs index 45c458b42a..72aeafc1b4 100644 --- a/templates/Virtual-Assistant-Template/csharp/Template/VA.Tests/Mocks/MockLuisRecognizer.cs +++ b/templates/Virtual-Assistant-Template/csharp/Template/VA.Tests/Mocks/MockLuisRecognizer.cs @@ -1,14 +1,14 @@ using Microsoft.Bot.Builder; +using Microsoft.Bot.Builder.AI.Luis; using Microsoft.Bot.Builder.Dialogs; using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using Microsoft.Bot.Builder.Solutions.Telemetry; namespace $safeprojectname$.Mocks { - public class MockLuisRecognizer : ITelemetryLuisRecognizer + public class MockLuisRecognizer : ITelemetryRecognizer { public MockLuisRecognizer(IRecognizerConvert defaultIntent) { @@ -20,7 +20,9 @@ public MockLuisRecognizer(IRecognizerConvert defaultIntent) private IRecognizerConvert DefaultIntent { get; set; } - public bool LogPersonalInformation => throw new NotImplementedException(); + public bool LogPersonalInformation { get; set; } = false; + + public IBotTelemetryClient TelemetryClient { get; set; } = new NullBotTelemetryClient(); public void RegisterUtterances(Dictionary utterances) { @@ -52,5 +54,15 @@ public Task RecognizeAsync(ITurnContext turnContext, CancellationToken can var mockResult = TestUtterances.GetValueOrDefault(text, DefaultIntent); return Task.FromResult((T)mockResult); } + + public Task RecognizeAsync(ITurnContext turnContext, Dictionary telemetryProperties, Dictionary telemetryMetrics, CancellationToken cancellationToken = default(CancellationToken)) + { + throw new NotImplementedException(); + } + + public Task RecognizeAsync(ITurnContext turnContext, Dictionary telemetryProperties, Dictionary telemetryMetrics, CancellationToken cancellationToken = default(CancellationToken)) where T : IRecognizerConvert, new() + { + throw new NotImplementedException(); + } } } \ No newline at end of file diff --git a/templates/Virtual-Assistant-Template/csharp/Template/VA.Tests/Mocks/MockQnAMaker.cs b/templates/Virtual-Assistant-Template/csharp/Template/VA.Tests/Mocks/MockQnAMaker.cs index 44d7f6dbc7..426beaef2f 100644 --- a/templates/Virtual-Assistant-Template/csharp/Template/VA.Tests/Mocks/MockQnAMaker.cs +++ b/templates/Virtual-Assistant-Template/csharp/Template/VA.Tests/Mocks/MockQnAMaker.cs @@ -1,6 +1,5 @@ using Microsoft.Bot.Builder; using Microsoft.Bot.Builder.AI.QnA; -using Microsoft.Bot.Builder.Solutions.Telemetry; using System; using System.Collections.Generic; using System.Threading.Tasks; @@ -19,7 +18,9 @@ public MockQnAMaker(QueryResult[] defaultAnswer) private QueryResult[] DefaultAnswer { get; set; } - public bool LogPersonalInformation => throw new NotImplementedException(); + public bool LogPersonalInformation { get; set; } = false; + + public IBotTelemetryClient TelemetryClient { get; set; } = new NullBotTelemetryClient(); public void RegisterAnswers(Dictionary utterances) { @@ -36,5 +37,13 @@ public Task GetAnswersAsync(ITurnContext context, QnAMakerOptions var mockResult = TestAnswers.GetValueOrDefault(text, DefaultAnswer); return Task.FromResult(mockResult); } + + public Task GetAnswersAsync(ITurnContext turnContext, QnAMakerOptions options, Dictionary telemetryProperties, Dictionary telemetryMetrics = null) + { + var text = turnContext.Activity.Text; + + var mockResult = TestAnswers.GetValueOrDefault(text, DefaultAnswer); + return Task.FromResult(mockResult); + } } } \ No newline at end of file diff --git a/templates/Virtual-Assistant-Template/csharp/Template/VA.Tests/Utilities/GeneralTestUtil.cs b/templates/Virtual-Assistant-Template/csharp/Template/VA.Tests/Utilities/GeneralTestUtil.cs index 1a6a9dc94f..4fbe5492a1 100644 --- a/templates/Virtual-Assistant-Template/csharp/Template/VA.Tests/Utilities/GeneralTestUtil.cs +++ b/templates/Virtual-Assistant-Template/csharp/Template/VA.Tests/Utilities/GeneralTestUtil.cs @@ -8,7 +8,7 @@ namespace $safeprojectname$.Utilities { public class GeneralTestUtil { - private static Dictionary _utterances = new Dictionary + private static readonly Dictionary _utterances = new Dictionary { { GeneralUtterances.Cancel, CreateIntent(GeneralUtterances.Cancel, GeneralLuis.Intent.Cancel) }, { GeneralUtterances.Escalate, CreateIntent(GeneralUtterances.Escalate, GeneralLuis.Intent.Escalate) }, @@ -25,7 +25,7 @@ public class GeneralTestUtil { GeneralUtterances.Stop, CreateIntent(GeneralUtterances.Stop, GeneralLuis.Intent.Stop) }, }; - public static IRecognizer CreateRecognizer() + public static MockLuisRecognizer CreateRecognizer() { var recognizer = new MockLuisRecognizer(defaultIntent: CreateIntent(string.Empty, GeneralLuis.Intent.None)); recognizer.RegisterUtterances(_utterances); diff --git a/templates/Virtual-Assistant-Template/csharp/Template/VA.Tests/VA.Tests.csproj b/templates/Virtual-Assistant-Template/csharp/Template/VA.Tests/VA.Tests.csproj index 2285bb92cd..7b8dc7a3f1 100644 --- a/templates/Virtual-Assistant-Template/csharp/Template/VA.Tests/VA.Tests.csproj +++ b/templates/Virtual-Assistant-Template/csharp/Template/VA.Tests/VA.Tests.csproj @@ -9,7 +9,7 @@ - + diff --git a/templates/Virtual-Assistant-Template/csharp/Template/VA/Adapters/DefaultAdapter.cs b/templates/Virtual-Assistant-Template/csharp/Template/VA/Adapters/DefaultAdapter.cs index 3a11086842..7472c67e65 100644 --- a/templates/Virtual-Assistant-Template/csharp/Template/VA/Adapters/DefaultAdapter.cs +++ b/templates/Virtual-Assistant-Template/csharp/Template/VA/Adapters/DefaultAdapter.cs @@ -5,7 +5,6 @@ using Microsoft.Bot.Builder.Azure; using Microsoft.Bot.Builder.Integration.AspNet.Core; using Microsoft.Bot.Builder.Solutions.Middleware; -using Microsoft.Bot.Builder.Solutions.Telemetry; using Microsoft.Bot.Connector.Authentication; using Microsoft.Bot.Schema; using $safeprojectname$.Responses.Main; diff --git a/templates/Virtual-Assistant-Template/csharp/Template/VA/Dialogs/MainDialog.cs b/templates/Virtual-Assistant-Template/csharp/Template/VA/Dialogs/MainDialog.cs index 5ec5902a9d..342ee4122d 100644 --- a/templates/Virtual-Assistant-Template/csharp/Template/VA/Dialogs/MainDialog.cs +++ b/templates/Virtual-Assistant-Template/csharp/Template/VA/Dialogs/MainDialog.cs @@ -22,113 +22,113 @@ namespace $safeprojectname$.Dialogs { public class MainDialog : RouterDialog -{ - private BotSettings _settings; - private BotServices _services; - private MainResponses _responder = new MainResponses(); - - public MainDialog( - BotSettings settings, - BotServices services, - OnboardingDialog onboardingDialog, - EscalateDialog escalateDialog, - CancelDialog cancelDialog, - List skillDialogs, - IBotTelemetryClient telemetryClient) - : base(nameof(MainDialog), telemetryClient) { - _settings = settings; - _services = services; - TelemetryClient = telemetryClient; - - AddDialog(onboardingDialog); - AddDialog(escalateDialog); - AddDialog(cancelDialog); - - foreach (var skillDialog in skillDialogs) + private BotSettings _settings; + private BotServices _services; + private MainResponses _responder = new MainResponses(); + + public MainDialog( + BotSettings settings, + BotServices services, + OnboardingDialog onboardingDialog, + EscalateDialog escalateDialog, + CancelDialog cancelDialog, + List skillDialogs, + IBotTelemetryClient telemetryClient) + : base(nameof(MainDialog), telemetryClient) { - AddDialog(skillDialog); - } - } + _settings = settings; + _services = services; + TelemetryClient = telemetryClient; - protected override async Task OnStartAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken)) - { - var view = new MainResponses(); - await view.ReplyWith(dc.Context, MainResponses.ResponseIds.NewUserGreeting); - } - - protected override async Task RouteAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken)) - { - // Get cognitive models for locale - var locale = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName; - var cognitiveModels = _services.CognitiveModelSets[locale]; + AddDialog(onboardingDialog); + AddDialog(escalateDialog); + AddDialog(cancelDialog); - // Check dispatch result - var dispatchResult = await cognitiveModels.DispatchService.RecognizeAsync(dc.Context, CancellationToken.None); - var intent = dispatchResult.TopIntent().intent; + foreach (var skillDialog in skillDialogs) + { + AddDialog(skillDialog); + } + } - // Identify if the dispatch intent matches any Action within a Skill if so, we pass to the appropriate SkillDialog to hand-off - var identifiedSkill = SkillRouter.IsSkill(_settings.Skills, intent.ToString()); + protected override async Task OnStartAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken)) + { + var view = new MainResponses(); + await view.ReplyWith(dc.Context, MainResponses.ResponseIds.NewUserGreeting); + } - if (identifiedSkill != null) + protected override async Task RouteAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken)) { - // We have identiifed a skill so initialize the skill connection with the target skill - await dc.BeginDialogAsync(identifiedSkill.Id); + // Get cognitive models for locale + var locale = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName; + var cognitiveModels = _services.CognitiveModelSets[locale]; - // Pass the activity we have - var result = await dc.ContinueDialogAsync(); + // Check dispatch result + var dispatchResult = await cognitiveModels.DispatchService.RecognizeAsync(dc.Context, CancellationToken.None); + var intent = dispatchResult.TopIntent().intent; - if (result.Status == DialogTurnStatus.Complete) - { - await CompleteAsync(dc); - } - } - else if (intent == DispatchLuis.Intent.l_general) - { - // If dispatch result is general luis model - cognitiveModels.LuisServices.TryGetValue("general", out var luisService); + // Identify if the dispatch intent matches any Action within a Skill if so, we pass to the appropriate SkillDialog to hand-off + var identifiedSkill = SkillRouter.IsSkill(_settings.Skills, intent.ToString()); - if (luisService == null) - { - throw new Exception("The general LUIS Model could not be found in your Bot Services configuration."); - } - else + if (identifiedSkill != null) { - var result = await luisService.RecognizeAsync(dc.Context, CancellationToken.None); + // We have identiifed a skill so initialize the skill connection with the target skill + await dc.BeginDialogAsync(identifiedSkill.Id); - var generalIntent = result?.TopIntent().intent; + // Pass the activity we have + var result = await dc.ContinueDialogAsync(); - // switch on general intents - switch (generalIntent) + if (result.Status == DialogTurnStatus.Complete) { - case GeneralLuis.Intent.Escalate: - { - // start escalate dialog - await dc.BeginDialogAsync(nameof(EscalateDialog)); - break; - } - - case GeneralLuis.Intent.None: - default: - { - // No intent was identified, send confused message - await _responder.ReplyWith(dc.Context, MainResponses.ResponseIds.Confused); - break; - } + await CompleteAsync(dc); } } - } - else if (intent == DispatchLuis.Intent.q_faq) - { - cognitiveModels.QnAServices.TryGetValue("faq", out var qnaService); - - if (qnaService == null) + else if (intent == DispatchLuis.Intent.l_general) { - throw new Exception("The specified QnA Maker Service could not be found in your Bot Services configuration."); + // If dispatch result is general luis model + cognitiveModels.LuisServices.TryGetValue("general", out var luisService); + + if (luisService == null) + { + throw new Exception("The general LUIS Model could not be found in your Bot Services configuration."); + } + else + { + var result = await luisService.RecognizeAsync(dc.Context, CancellationToken.None); + + var generalIntent = result?.TopIntent().intent; + + // switch on general intents + switch (generalIntent) + { + case GeneralLuis.Intent.Escalate: + { + // start escalate dialog + await dc.BeginDialogAsync(nameof(EscalateDialog)); + break; + } + + case GeneralLuis.Intent.None: + default: + { + // No intent was identified, send confused message + await _responder.ReplyWith(dc.Context, MainResponses.ResponseIds.Confused); + break; + } + } + } } - else + else if (intent == DispatchLuis.Intent.q_faq) { - var answers = await qnaService.GetAnswersAsync(dc.Context); + cognitiveModels.QnAServices.TryGetValue("faq", out var qnaService); + + if (qnaService == null) + { + throw new Exception("The specified QnA Maker Service could not be found in your Bot Services configuration."); + } + else + { + var answers = await qnaService.GetAnswersAsync(dc.Context, null, null); if (answers != null && answers.Count() > 0) { @@ -144,13 +144,13 @@ public MainDialog( { cognitiveModels.QnAServices.TryGetValue("chitchat", out var qnaService); - if (qnaService == null) - { - throw new Exception("The specified QnA Maker Service could not be found in your Bot Services configuration."); - } - else - { - var answers = await qnaService.GetAnswersAsync(dc.Context); + if (qnaService == null) + { + throw new Exception("The specified QnA Maker Service could not be found in your Bot Services configuration."); + } + else + { + var answers = await qnaService.GetAnswersAsync(dc.Context, null, null); if (answers != null && answers.Count() > 0) { @@ -169,152 +169,152 @@ public MainDialog( } } - protected override async Task OnEventAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken)) - { - // Check if there was an action submitted from intro card - var value = dc.Context.Activity.Value; - - if (value.GetType() == typeof(JObject)) + protected override async Task OnEventAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken)) { - var submit = JObject.Parse(value.ToString()); - if (value != null && (string)submit["action"] == "startOnboarding") + // Check if there was an action submitted from intro card + var value = dc.Context.Activity.Value; + + if (value.GetType() == typeof(JObject)) { - await dc.BeginDialogAsync(nameof(OnboardingDialog)); - return; + var submit = JObject.Parse(value.ToString()); + if (value != null && (string)submit["action"] == "startOnboarding") + { + await dc.BeginDialogAsync(nameof(OnboardingDialog)); + return; + } } - } - var forward = true; - var ev = dc.Context.Activity.AsEventActivity(); - if (!string.IsNullOrWhiteSpace(ev.Name)) - { - switch (ev.Name) + var forward = true; + var ev = dc.Context.Activity.AsEventActivity(); + if (!string.IsNullOrWhiteSpace(ev.Name)) { - case TokenEvents.TokenResponseEventName: - { - forward = true; - break; - } - default: - { - await dc.Context.SendActivityAsync(new Activity(type: ActivityTypes.Trace, text: $"Unknown Event {ev.Name} was received but not processed.")); - forward = false; - break; - } + switch (ev.Name) + { + case TokenEvents.TokenResponseEventName: + { + forward = true; + break; + } + default: + { + await dc.Context.SendActivityAsync(new Activity(type: ActivityTypes.Trace, text: $"Unknown Event {ev.Name} was received but not processed.")); + forward = false; + break; + } + } } - } - if (forward) - { - var result = await dc.ContinueDialogAsync(); - - if (result.Status == DialogTurnStatus.Complete) + if (forward) { - await CompleteAsync(dc); + var result = await dc.ContinueDialogAsync(); + + if (result.Status == DialogTurnStatus.Complete) + { + await CompleteAsync(dc); + } } } - } - protected override async Task CompleteAsync(DialogContext dc, DialogTurnResult result = null, CancellationToken cancellationToken = default(CancellationToken)) - { - // The active dialog's stack ended with a complete status - await _responder.ReplyWith(dc.Context, MainResponses.ResponseIds.Completed); - } - - protected override async Task OnInterruptDialogAsync(DialogContext dc, CancellationToken cancellationToken) - { - if (dc.Context.Activity.Type == ActivityTypes.Message && !string.IsNullOrWhiteSpace(dc.Context.Activity.Text)) + protected override async Task CompleteAsync(DialogContext dc, DialogTurnResult result = null, CancellationToken cancellationToken = default(CancellationToken)) { - // get current activity locale - var locale = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName; - var cognitiveModels = _services.CognitiveModelSets[locale]; + // The active dialog's stack ended with a complete status + await _responder.ReplyWith(dc.Context, MainResponses.ResponseIds.Completed); + } - // check luis intent - cognitiveModels.LuisServices.TryGetValue("general", out var luisService); - if (luisService == null) - { - throw new Exception("The general LUIS Model could not be found in your Bot Services configuration."); - } - else + protected override async Task OnInterruptDialogAsync(DialogContext dc, CancellationToken cancellationToken) + { + if (dc.Context.Activity.Type == ActivityTypes.Message && !string.IsNullOrWhiteSpace(dc.Context.Activity.Text)) { - var luisResult = await luisService.RecognizeAsync(dc.Context, cancellationToken); - var intent = luisResult.TopIntent().intent; + // get current activity locale + var locale = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName; + var cognitiveModels = _services.CognitiveModelSets[locale]; - if (luisResult.TopIntent().score > 0.5) + // check luis intent + cognitiveModels.LuisServices.TryGetValue("general", out var luisService); + if (luisService == null) + { + throw new Exception("The general LUIS Model could not be found in your Bot Services configuration."); + } + else { - switch (intent) + var luisResult = await luisService.RecognizeAsync(dc.Context, cancellationToken); + var intent = luisResult.TopIntent().intent; + + if (luisResult.TopIntent().score > 0.5) { - case GeneralLuis.Intent.Cancel: - { - return await OnCancel(dc); - } - case GeneralLuis.Intent.Help: - { - return await OnHelp(dc); - } - case GeneralLuis.Intent.Logout: - { - return await OnLogout(dc); - } + switch (intent) + { + case GeneralLuis.Intent.Cancel: + { + return await OnCancel(dc); + } + case GeneralLuis.Intent.Help: + { + return await OnHelp(dc); + } + case GeneralLuis.Intent.Logout: + { + return await OnLogout(dc); + } + } } } } - } - return InterruptionAction.NoAction; - } - - private async Task OnCancel(DialogContext dc) - { - if (dc.ActiveDialog != null && dc.ActiveDialog.Id != nameof(CancelDialog)) - { - // Don't start restart cancel dialog - await dc.BeginDialogAsync(nameof(CancelDialog)); - - // Signal that the dialog is waiting on user response - return InterruptionAction.StartedDialog; + return InterruptionAction.NoAction; } - var view = new CancelResponses(); - await view.ReplyWith(dc.Context, CancelResponses.ResponseIds.NothingToCancelMessage); + private async Task OnCancel(DialogContext dc) + { + if (dc.ActiveDialog != null && dc.ActiveDialog.Id != nameof(CancelDialog)) + { + // Don't start restart cancel dialog + await dc.BeginDialogAsync(nameof(CancelDialog)); - return InterruptionAction.StartedDialog; - } + // Signal that the dialog is waiting on user response + return InterruptionAction.StartedDialog; + } - private async Task OnHelp(DialogContext dc) - { - var view = new MainResponses(); - await view.ReplyWith(dc.Context, MainResponses.ResponseIds.Help); + var view = new CancelResponses(); + await view.ReplyWith(dc.Context, CancelResponses.ResponseIds.NothingToCancelMessage); - // Signal the conversation was interrupted and should immediately continue - return InterruptionAction.MessageSentToUser; - } + return InterruptionAction.StartedDialog; + } - private async Task OnLogout(DialogContext dc) - { - IUserTokenProvider tokenProvider; - var supported = dc.Context.Adapter is IUserTokenProvider; - if (!supported) + private async Task OnHelp(DialogContext dc) { - throw new InvalidOperationException("OAuthPrompt.SignOutUser(): not supported by the current adapter"); + var view = new MainResponses(); + await view.ReplyWith(dc.Context, MainResponses.ResponseIds.Help); + + // Signal the conversation was interrupted and should immediately continue + return InterruptionAction.MessageSentToUser; } - else + + private async Task OnLogout(DialogContext dc) { - tokenProvider = (IUserTokenProvider)dc.Context.Adapter; - } + IUserTokenProvider tokenProvider; + var supported = dc.Context.Adapter is IUserTokenProvider; + if (!supported) + { + throw new InvalidOperationException("OAuthPrompt.SignOutUser(): not supported by the current adapter"); + } + else + { + tokenProvider = (IUserTokenProvider)dc.Context.Adapter; + } - await dc.CancelAllDialogsAsync(); + await dc.CancelAllDialogsAsync(); - // Sign out user - var tokens = await tokenProvider.GetTokenStatusAsync(dc.Context, dc.Context.Activity.From.Id); - foreach (var token in tokens) - { - await tokenProvider.SignOutUserAsync(dc.Context, token.ConnectionName); - } + // Sign out user + var tokens = await tokenProvider.GetTokenStatusAsync(dc.Context, dc.Context.Activity.From.Id); + foreach (var token in tokens) + { + await tokenProvider.SignOutUserAsync(dc.Context, token.ConnectionName); + } - await dc.Context.SendActivityAsync(MainStrings.LOGOUT); + await dc.Context.SendActivityAsync(MainStrings.LOGOUT); - return InterruptionAction.StartedDialog; + return InterruptionAction.StartedDialog; + } } -} } \ No newline at end of file diff --git a/templates/Virtual-Assistant-Template/csharp/Template/VA/Services/BotServices.cs b/templates/Virtual-Assistant-Template/csharp/Template/VA/Services/BotServices.cs index edbc18aac7..1fd49d1376 100644 --- a/templates/Virtual-Assistant-Template/csharp/Template/VA/Services/BotServices.cs +++ b/templates/Virtual-Assistant-Template/csharp/Template/VA/Services/BotServices.cs @@ -5,7 +5,6 @@ using Microsoft.Bot.Builder.AI.Luis; using Microsoft.Bot.Builder.AI.QnA; using Microsoft.Bot.Builder.Solutions; -using Microsoft.Bot.Builder.Solutions.Telemetry; namespace $safeprojectname$.Services { @@ -24,14 +23,14 @@ public BotServices(BotSettings settings) var config = pair.Value; var dispatchApp = new LuisApplication(config.DispatchModel.AppId, config.DispatchModel.SubscriptionKey, config.DispatchModel.GetEndpoint()); - set.DispatchService = new TelemetryLuisRecognizer(dispatchApp); + set.DispatchService = new LuisRecognizer(dispatchApp); if (config.LanguageModels != null) { foreach (var model in config.LanguageModels) { var luisApp = new LuisApplication(model.AppId, model.SubscriptionKey, model.GetEndpoint()); - set.LuisServices.Add(model.Id, new TelemetryLuisRecognizer(luisApp)); + set.LuisServices.Add(model.Id, new LuisRecognizer(luisApp)); } } @@ -43,7 +42,7 @@ public BotServices(BotSettings settings) EndpointKey = kb.EndpointKey, Host = kb.Hostname, }; - var qnaMaker = new TelemetryQnAMaker(qnaEndpoint); + var qnaMaker = new QnAMaker(qnaEndpoint); set.QnAServices.Add(kb.Id, qnaMaker); } diff --git a/templates/Virtual-Assistant-Template/csharp/Template/VA/VA.csproj b/templates/Virtual-Assistant-Template/csharp/Template/VA/VA.csproj index f83812fa11..22838e82b6 100644 --- a/templates/Virtual-Assistant-Template/csharp/Template/VA/VA.csproj +++ b/templates/Virtual-Assistant-Template/csharp/Template/VA/VA.csproj @@ -13,20 +13,20 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + +