public async Task ShowsFirstMessageAndCallsAzureDialogDirectly() { // Arrange var feedbackOptions = new FeedbackOptions(); var mockTemplateManager = SimpleMockFactory.CreateMockTemplateManager("mock template message"); var mockDialog = new Mock <AzureDialog>(Configuration, _telemetryClient, mockTemplateManager.Object); mockDialog.Setup(x => x.BeginDialogAsync(It.IsAny <DialogContext>(), It.IsAny <object>(), It.IsAny <CancellationToken>())) .Returns(async(DialogContext dialogContext, object options, CancellationToken cancellationToken) => { dialogContext.Dialogs.Add(new TextPrompt("MockDialog")); return(await dialogContext.PromptAsync("MockDialog", new PromptOptions() { Prompt = MessageFactory.Text($"{nameof(AzureDialog)} mock invoked") }, cancellationToken)); }); var fileSearchDialog = new Mock <FileSearchDialog>(_telemetryClient, Configuration); var mainDialog = new MainDialog(_telemetryClient, feedbackOptions, _mockLogger.Object, mockTemplateManager.Object, _userState, mockDialog.Object, fileSearchDialog.Object); var testClient = new DialogTestClient(Channels.Test, mainDialog, middlewares: new[] { new XUnitDialogTestLogger(Output) }); // Act/Assert var reply = await testClient.SendActivityAsync <IMessageActivity>("hi"); Assert.Equal("mock template message", reply.Text); reply = await testClient.SendActivityAsync <IMessageActivity>("next"); Assert.Equal($"{nameof(AzureDialog)} mock invoked", reply.Text); }
public MainDialog( IServiceProvider serviceProvider) : base(nameof(MainDialog)) { _services = serviceProvider.GetService <BotServices>(); _templateManager = serviceProvider.GetService <LocaleTemplateManager>(); _skillsConfig = serviceProvider.GetService <SkillsConfiguration>(); _feedbackOptions = serviceProvider.GetService <FeedbackOptions>(); TelemetryClient = serviceProvider.GetService <IBotTelemetryClient>(); var userState = serviceProvider.GetService <UserState>(); _userProfileState = userState.CreateProperty <UserProfileState>(nameof(UserProfileState)); var conversationState = serviceProvider.GetService <ConversationState>(); _previousResponseAccessor = conversationState.CreateProperty <List <Activity> >(StateProperties.PreviousBotResponse); // Create state property to track the active skill. _activeSkillProperty = conversationState.CreateProperty <BotFrameworkSkill>(ActiveSkillPropertyName); _feedbackAccessor = conversationState.CreateProperty <FeedbackRecord>(nameof(FeedbackRecord)); var steps = new List <WaterfallStep>() { OnboardingStepAsync, IntroStepAsync, RouteStepAsync, FinalStepAsync, }; // Add FeedbackSteps if (_feedbackOptions.FeedbackEnabled) { steps.Add(RequestFeedback); steps.Add(RequestFeedbackComment); steps.Add(ProcessFeedback); AddDialog(new TextPrompt(DialogIds.FeedbackPrompt)); AddDialog(new TextPrompt(DialogIds.FeedbackCommentPrompt)); } steps.Add(FinalStepAsync); AddDialog(new WaterfallDialog(nameof(MainDialog), steps)); AddDialog(new TextPrompt(nameof(TextPrompt))); InitialDialogId = nameof(MainDialog); // Register dialogs _onboardingDialog = serviceProvider.GetService <OnboardingDialog>(); _switchSkillDialog = serviceProvider.GetService <SwitchSkillDialog>(); AddDialog(_onboardingDialog); AddDialog(_switchSkillDialog); // Register skill dialogs var skillDialogs = serviceProvider.GetServices <SkillDialog>(); foreach (var dialog in skillDialogs) { AddDialog(dialog); } }
public MainDialog(IBotTelemetryClient telemetryClient, FeedbackOptions feedbackOptions, ILogger <MainDialog> logger, TemplateManager templateManager, UserState userState, AzureDialog azureDialog, FileSearchDialog fileSearchDialog, AdenSolutionDialog adenSolutionDialog) : base(nameof(MainDialog)) { _logger = logger; _feedbackOptions = feedbackOptions; _templateManager = templateManager; _previousResponseAccessor = userState.CreateProperty <List <Activity> >(StateProperties.PreviousBotResponse); _feedbackAccessor = userState.CreateProperty <FeedbackRecord>(StateProperties.FeedbackRecord); TelemetryClient = telemetryClient; var steps = new List <WaterfallStep> { IntroStepAsync, RouteStepAsync }; // 启用反馈 if (_feedbackOptions.FeedbackEnabled) { steps.Add(ReqeustFeedback); steps.Add(RequestFeedbackComment); steps.Add(ProcessFeedback); AddDialog(new TextPrompt(DialogIds.FeedbackPrompt)); AddDialog(new TextPrompt(DialogIds.FeedbackCommentPrompt)); } steps.Add(FinalStepAsync); AddDialog(new WaterfallDialog(nameof(MainDialog), steps)); AddDialog(new TextPrompt(DialogIds.NextActionPrompt)); InitialDialogId = nameof(MainDialog); AddDialog(azureDialog); AddDialog(fileSearchDialog); AddDialog(adenSolutionDialog); }
public MainDialog( IServiceProvider serviceProvider, IBotTelemetryClient telemetryClient ) : base(nameof(MainDialog)) { _services = serviceProvider.GetService <BotServices>(); _settings = serviceProvider.GetService <BotSettings>(); _templateManager = serviceProvider.GetService <LocaleTemplateManager>(); _skillsConfig = serviceProvider.GetService <SkillsConfiguration>(); _feedbackOptions = serviceProvider.GetService <FeedbackOptions>(); TelemetryClient = telemetryClient; var userState = serviceProvider.GetService <UserState>(); _userProfileState = userState.CreateProperty <UserProfileState>(nameof(UserProfileState)); var conversationState = serviceProvider.GetService <ConversationState>(); _previousResponseAccessor = conversationState.CreateProperty <List <Activity> >(StateProperties.PreviousBotResponse); _feedbackAccessor = conversationState.CreateProperty <FeedbackRecord>(nameof(FeedbackRecord)); var steps = new List <WaterfallStep>() { OnboardingStepAsync, IntroStepAsync, RouteStepAsync, }; if (_feedbackOptions.FeedbackEnabled) { steps.Add(RequestFeedback); steps.Add(RequestFeedbackComment); steps.Add(ProcessFeedback); AddDialog(new TextPrompt(DialogIds.FeedbackPrompt)); AddDialog(new TextPrompt(DialogIds.FeedbackCommentPrompt)); } steps.Add(FinalStepAsync); AddDialog(new WaterfallDialog(nameof(MainDialog), steps)); AddDialog(new TextPrompt(DialogIds.NextActionPrompt)); InitialDialogId = nameof(MainDialog); // Register dialogs _onboardingDialog = serviceProvider.GetService <OnboardingDialog>(); _switchSkillDialog = serviceProvider.GetService <SwitchSkillDialog>(); AddDialog(_onboardingDialog); AddDialog(_switchSkillDialog); // Register a QnAMakerDialog for each registered knowledgebase and ensure localised responses are provided. var localizedServices = _services.GetCognitiveModels(); foreach (var knowledgebase in localizedServices.QnAConfiguration) { var qnaDialog = new QnAMakerDialog( knowledgeBaseId: knowledgebase.Value.KnowledgeBaseId, endpointKey: knowledgebase.Value.EndpointKey, hostName: knowledgebase.Value.Host, noAnswer: _templateManager.GenerateActivityForLocale("UnsupportedMessage"), activeLearningCardTitle: _templateManager.GenerateActivityForLocale("QnaMakerAdaptiveLearningCardTitle").Text, cardNoMatchText: _templateManager.GenerateActivityForLocale("QnaMakerNoMatchText").Text) { Id = knowledgebase.Key }; AddDialog(qnaDialog); } // Register skill dialogs var skillDialogs = serviceProvider.GetServices <SkillDialog>(); foreach (var dialog in skillDialogs) { AddDialog(dialog); } }