public async Task WaterfallWithCallback() { var convoState = new ConversationState(new MemoryStorage()); var adapter = new TestAdapter() .Use(new AutoSaveStateMiddleware(convoState)); var dialogState = convoState.CreateProperty <DialogState>("dialogState"); var dialogs = new DialogSet(dialogState); var waterfallDialog = new WaterfallDialog("test", new WaterfallStep[] { async(step, cancellationToken) => { await step.Context.SendActivityAsync("step1"); return(Dialog.EndOfTurn); }, async(step, cancellationToken) => { await step.Context.SendActivityAsync("step2"); return(Dialog.EndOfTurn); }, async(step, cancellationToken) => { await step.Context.SendActivityAsync("step3"); return(Dialog.EndOfTurn); }, }); dialogs.Add(waterfallDialog); await new TestFlow(adapter, async(turnContext, cancellationToken) => { var dc = await dialogs.CreateContextAsync(turnContext, cancellationToken); await dc.ContinueDialogAsync(cancellationToken); if (!turnContext.Responded) { await dc.BeginDialogAsync("test", null, cancellationToken); } }) .Send("hello") .AssertReply("step1") .Send("hello") .AssertReply("step2") .Send("hello") .AssertReply("step3") .StartTestAsync(); }
private static TestFlow CreateTestFlow(WaterfallDialog waterfallDialog) { var convoState = new ConversationState(new MemoryStorage()); var dialogState = convoState.CreateProperty <DialogState>("dialogState"); var adapter = new TestAdapter() .Use(new AutoSaveStateMiddleware(convoState)); var testFlow = new TestFlow(adapter, async(turnContext, cancellationToken) => { var state = await dialogState.GetAsync(turnContext, () => new DialogState(), cancellationToken); var dialogs = new DialogSet(dialogState); dialogs.Add(new CancelledComponentDialog(waterfallDialog)); var dc = await dialogs.CreateContextAsync(turnContext, cancellationToken); var results = await dc.ContinueDialogAsync(cancellationToken); if (results.Status == DialogTurnStatus.Empty) { results = await dc.BeginDialogAsync("TestComponentDialog", null, cancellationToken); } if (results.Status == DialogTurnStatus.Cancelled) { await turnContext.SendActivityAsync(MessageFactory.Text($"Component dialog cancelled (result value is {results.Result?.ToString()})."), cancellationToken); } else if (results.Status == DialogTurnStatus.Complete) { var value = (int)results.Result; await turnContext.SendActivityAsync(MessageFactory.Text($"Bot received the number '{value}'."), cancellationToken); } }); return(testFlow); }
public async Task WaterfallWithCallback() { var convoState = new ConversationState(new MemoryStorage()); var adapter = new TestAdapter() .Use(new AutoSaveStateMiddleware(convoState)); var dialogState = convoState.CreateProperty <DialogState>("dialogState"); var dialogs = new DialogSet(dialogState); var telemetryClient = new Mock <IBotTelemetryClient>(); var waterfallDialog = new WaterfallDialog("test", NewWaterfall()); dialogs.Add(waterfallDialog); dialogs.TelemetryClient = telemetryClient.Object; await new TestFlow(adapter, async(turnContext, cancellationToken) => { var dc = await dialogs.CreateContextAsync(turnContext, cancellationToken); await dc.ContinueDialogAsync(cancellationToken); if (!turnContext.Responded) { await dc.BeginDialogAsync("test", null, cancellationToken); } }) .Send("hello") .AssertReply("step1") .Send("hello") .AssertReply("step2") .Send("hello") .AssertReply("step3") .StartTestAsync(); telemetryClient.Verify(m => m.TrackEvent(It.IsAny <string>(), It.IsAny <IDictionary <string, string> >(), It.IsAny <IDictionary <string, double> >()), Times.Exactly(4)); }
public Task WaterfallWithStepsNull() { var waterfall = new WaterfallDialog("test"); waterfall.AddStep(null); return(Task.CompletedTask); }
/// <summary> /// Initializes a new instance of the <see cref="QnAMakerActionBuilder"/> class. /// Dialog helper to generate dialogs. /// </summary> /// <param name="qnaMakerClient">QnA Maker client.</param> internal QnAMakerActionBuilder(IQnAMakerClient qnaMakerClient) { _qnaMakerDialog = new WaterfallDialog(QnAMakerDialogName) .AddStep(CallGenerateAnswerAsync) .AddStep(CallTrain) .AddStep(CheckForMultiTurnPrompt) .AddStep(DisplayQnAResult); _qnaMakerClient = qnaMakerClient ?? throw new ArgumentNullException(nameof(qnaMakerClient)); }
public void CodeModel_NameFor_Dialog_Item() { ICodeModel codeModel = new CodeModel(); var item = new WaterfallDialog("dialog-id"); var returnedValue = codeModel.NameFor(item); Assert.Equal(item.Id, returnedValue); }
/// <summary> /// Dialog helper to generate dialogs /// </summary> /// <param name="services">Bot Services</param> public DialogHelper(IBotServices services) { QnAMakerActiveLearningDialog = new WaterfallDialog(ActiveLearningDialogName) .AddStep(CallGenerateAnswer) .AddStep(FilterLowVariationScoreList) .AddStep(CallTrain) .AddStep(DisplayQnAResult); _services = services; }
public SurveyDialog Build() { WaterfallStep[] waterfall = this.Dialogs.Select(this.CreateWaterfallStep).ToArray(); var dialog = new WaterfallDialog(this.Id, waterfall); this.AddDialog(dialog); return(this); }
public void WaterfallWithStepsNull() { var telemetryClient = new Mock <IBotTelemetryClient>(); var waterfall = new WaterfallDialog("test") { TelemetryClient = telemetryClient.Object }; waterfall.AddStep(null); }
public void WaterfallWithActionsNull() { Assert.Throws <ArgumentNullException>(() => { var telemetryClient = new Mock <IBotTelemetryClient>(); var waterfall = new WaterfallDialog("test") { TelemetryClient = telemetryClient.Object }; waterfall.AddStep(null); }); }
public Dialog Configure(DialogSet dialogSet) { RegisterPrompts(dialogSet); var steps = new WaterfallStep[] { ConfirmStartAsync, NextStepAsync, }; var waterfallDialog = new WaterfallDialog(DialogId, steps); return(waterfallDialog); }
public async Task CancelDialogOnFirstStepTest() { var steps = new WaterfallStep[] { CancelledWaterfallStep, }; var waterfallDialog = new WaterfallDialog("test-waterfall", steps); var testFlow = CreateTestFlow(waterfallDialog); await testFlow .Send("hello") .AssertReply("Component dialog cancelled (result value is 42).") .StartTestAsync(); }
private void AddMarsRoverDataDialog(DialogSet dialogSet) { var waterfallSteps = new WaterfallStep[] { ChoiceConfirmationDialogAsync, GetEarthDateInputAsync, GetNumberOfPicturesToDisplayAsync, DisplayDataAsync }; var dialog = new WaterfallDialog("DisplayMarsRoverData", waterfallSteps); dialogSet.Add(dialog); }
public SurveyStartDialog Build() { var steps = new WaterfallStep[] { this.StepAsync, this.FinishDialogAsync, }; var waterfall = new WaterfallDialog(this.Id, steps); this.AddDialog(waterfall); this.AddDialog(new ConfirmPrompt("confirm")); return(this); }
/// <summary> /// Build the dialog. /// </summary> /// <returns>A <see cref="SurveyEndDialog"/>.</returns> public SurveyEndDialog Build() { var steps = new WaterfallStep[] { this.StepAsync, this.SaveFeedbackAsync, this.EndDialogAsync, }; var waterfall = new WaterfallDialog(this.Id, steps); this.AddDialog(waterfall); return(this); }
public FreeTextDialog Build() { var steps = new WaterfallStep[] { this.AskQuestionAsync, this.SendResponseAsync, this.FinishDialogAsync, }; var waterfall = new WaterfallDialog(this.Id, steps); this.AddDialog(waterfall); this.AddDialog(new TextPrompt(FreeTextPrompt)); return(this); }
public async Task DialogManager_StateConfiguration() { // Arrange var dialog = new WaterfallDialog("test-dialog"); var memoryScope = new CustomMemoryScope(); var pathResolver = new CustomPathResolver(); var dialogManager = new DialogManager(dialog); dialogManager.StateConfiguration = new DialogStateManagerConfiguration(); dialogManager.StateConfiguration.MemoryScopes.Add(memoryScope); dialogManager.StateConfiguration.PathResolvers.Add(pathResolver); // The test dialog being used here happens to not send anything so we only need to mock the type. var adapterMock = new Mock <BotAdapter>(); // ChannelId and Conversation.Id are required for ConversationState and // ChannelId and From.Id are required for UserState. var activity = new Activity { ChannelId = "test-channel", Conversation = new ConversationAccount { Id = "test-conversation-id" }, From = new ChannelAccount { Id = "test-id" } }; // Act DialogStateManager actual; using (var turnContext = new TurnContext(adapterMock.Object, activity)) { turnContext.TurnState.Add(new ConversationState(new MemoryStorage())); await dialogManager.OnTurnAsync(turnContext); actual = turnContext.TurnState.Get <DialogStateManager>(); } // Assert Assert.Contains(memoryScope, actual.Configuration.MemoryScopes); Assert.Contains(pathResolver, actual.Configuration.PathResolvers); }
/// <summary> /// Dialog helper to generate dialogs /// </summary> /// <param name="services">Bot Services</param> public DialogHelper(IBotServices services) { QnAMakerActiveLearningDialog = new WaterfallDialog(ActiveLearningDialogName) .AddStep(CallGenerateAnswer) .AddStep(FilterLowVariationScoreList) .AddStep(CallTrain) .AddStep(DisplayQnAResult); _services = services; for (int i = 0; i < NrFeaturesLaptop; i++) { inputLaptops[i] = "0"; } for (int i = 0; i < NrFeaturesSmartphone; i++) { inputSmartphones[i] = "0"; } }
public Dialog Build() { //The WaterfallDialog is a type of dialog that can //have one or many steps that flow into eachother linearly. //The result of one Waterfall step will carry to the start //of the next one. //At any point, you are able to push or pop from the dialog stack. //Observe how the steps are applied here so that you can create //the steps necessary for placing an order. var steps = new WaterfallStep[] { MainMenuAsync }; var dialog = new WaterfallDialog(DialogNames.MAIN_MENU, steps); return(dialog); }
public StandupRootDialog(IIssueTrackingIntegrationService issueTrackingIntegrationService, SettingProvider settingProvider) : base(nameof(StandupRootDialog)) { _issueTrackingIntegrationService = issueTrackingIntegrationService; var dialog = new WaterfallDialog("standup", new WaterfallStep[] { StartDialogAsync, FinishDialogAsync }); AddDialog(dialog); AddDialog(new TicketReviewDialog(settingProvider)); AddDialog(new UserReviewDialog(_issueTrackingIntegrationService, settingProvider)); AddDialog(new TeamReviewDialog(_issueTrackingIntegrationService, settingProvider)); AddDialog(new TextPrompt(nameof(TextPrompt))); InitialDialogId = "standup"; }
public StandupDialog(UserState userState) : base(nameof(StandupDialog)) { _userStateAccessor = userState.CreateProperty <JObject>("result"); var slots = new List <SlotDetails> { new SlotDetails("doneStuff", "text", "What did you do?"), new SlotDetails("plans", "text", "What are you going to do?"), }; var dialog = new WaterfallDialog("standup", new WaterfallStep[] { StartDialogAsync, ProcessResultsAsync }); AddDialog(dialog); AddDialog(new SlotFillingDialog("workStuff", slots)); AddDialog(new TextPrompt("text")); InitialDialogId = "standup"; }
public MultipleChoiceDialog Build() { var steps = new WaterfallStep[] { this.AskQuestionAsync, this.SendResponseToUserAsync, this.EndDialogAsync, }; var waterfall = new WaterfallDialog(this.Id, steps); this.AddDialog(waterfall); this.AddDialog(new ChoicePrompt(ChoicePrompt, state) { Style = ListStyle.None }); return(this); }
public Dialog Build() { //Step 12) Create a new waterfall dialog covering the full range of //steps to order a pizza: GetAddress, ConfirmAddress, BeginOrder, GetSize, GetToppings, //ConfirmOrder and finally CompleteOrder var steps = new WaterfallStep[] { GetAddressAsync, ConfirmAddressAsync, BeginOrderAsync, GetSizeAsync, GetToppingsAsync, ConfirmOrderAsync, CompleteOrderAsync }; var dialog = new WaterfallDialog(DialogNames.PIZZA_ORDER, steps); return(dialog); }
public Dialog Configure(DialogSet dialogSet) { RegisterPrompts(dialogSet); var steps = new WaterfallStep[] { ConfirmStartAsync, PromptForAgeAsync, PromptForBiologicalSexAsync, PromptForCancerHistoryAsync, PromptForPsychCareHistoryAsync, PromptForPhysicalTherapyHistoryAsync, PromptForCognitiveBehavioralTherapyHistoryAsync, PromptForPreviousBackSurgeryHistoryAsync, PromptForFeverHistoryAsync, PromptForFecalIncontinenceHistoryAsync, PromptForOpioidUseAsync, PromptForLevelOfPainAsync, PromptForRaceStepAsync, SummaryAsync, }; var waterfallDialog = new WaterfallDialog(DialogId, steps); return(waterfallDialog); }
public void CodeModel_PointsFor() { ICodeModel codeModel = new CodeModel(); var item = new WaterfallDialog("dialog-id"); var activity = MessageFactory.Text("hi"); var context = new TurnContext(new TestAdapter(), activity); var dialogs = new DialogSet(); dialogs.Add(item); var dc = new DialogContext(dialogs, context, new DialogState()); var instance = new DialogInstance { Id = "dialog-id" }; dc.Stack.Add(instance); var codePoints = codeModel.PointsFor(dc, item, "more"); Assert.Equal(item, codePoints[0].Item); }
public async Task WaterfallWithStepsNull() { var waterfall = new WaterfallDialog("test"); waterfall.AddStep(null); }
public async Task ProtocolMessages_AreConsistent() { WaterfallStep MakeStep(string text, DialogTurnResult result = null) => async(stepContext, cancellationToken) => { await stepContext.Context.SendActivityAsync(MessageFactory.Text(text), cancellationToken); return(result ?? Dialog.EndOfTurn); }; var dialog = new WaterfallDialog( nameof(ProtocolMessages_AreConsistent), new[] { MakeStep("hello"), MakeStep("world") }); var trace = new List <MockTransport.Event>(); var transport = new MockTransport(trace); var debugger = MakeDebugger(transport); using (new ActiveObject(((IDebugTransport)transport).Accept)) { var storage = new MemoryStorage(); var userState = new UserState(storage); var conversationState = new ConversationState(storage); var adapter = new TestAdapter() .Use(debugger) .UseStorage(storage) .UseBotState(userState, conversationState); var dialogManager = new DialogManager(dialog); await new TestFlow((TestAdapter)adapter, async(turnContext, cancellationToken) => { await dialogManager.OnTurnAsync(turnContext, cancellationToken).ConfigureAwait(false); }) .Send("one") .AssertReply("hello") .Send("two") .AssertReply("world") .StartTestAsync(); } var pathJson = TraceOracle.MakePath(nameof(ProtocolMessages_AreConsistent)); var sorted = TraceOracle.TopologicalSort(trace, source => { var targets = from target in trace let score // responses come after requests = source.Client != target.Client && source.Seq == target.RequestSeq ? 2 // consistent within client xor server : source.Client == target.Client && source.Seq < target.Seq ? 1 // unrelated so remove : 0 where score != 0 orderby score descending, target.Order ascending select target; return(targets.ToArray()); }); var tokens = sorted.Select(JToken.FromObject).Select(TraceOracle.Normalize).ToArray(); await TraceOracle.ValidateAsync(pathJson, tokens, _output).ConfigureAwait(false); }