コード例 #1
0
        public async Task LengthCheckPromptTest(IBotContext context)
        {
            dynamic conversationState = ConversationState <StoreItem> .Get(context);

            TextPrompt askForName = new TextPrompt(MinLengthValidator);

            if (conversationState["topic"] != "textPromptTest")
            {
                conversationState["topic"] = "textPromptTest";
                await askForName.Prompt(context, "Your Name:");
            }
            else
            {
                var text = await askForName.Recognize(context);

                if (text != null)
                {
                    context.Reply("Passed");
                    context.Reply(text);
                }
                else
                {
                    context.Reply("Failed");
                }
            }
        }
コード例 #2
0
        public async Task Waterfall()
        {
            TestAdapter adapter = new TestAdapter()
                                  .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage()));

            await new TestFlow(adapter, async(turnContext) =>
            {
                var waterfall = new Waterfall(new WaterfallStep[]
                {
                    async(dc, args, next) => { await dc.Context.SendActivity("step1"); },
                    async(dc, args, next) => { await dc.Context.SendActivity("step2"); },
                    async(dc, args, next) => { await dc.Context.SendActivity("step3"); },
                });

                var state = ConversationState <Dictionary <string, object> > .Get(turnContext);

                var dialogCompletion = await waterfall.Continue(turnContext, state);
                if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                {
                    await waterfall.Begin(turnContext, state);
                }
            })
            .Send("hello")
            .AssertReply("step1")
            .Send("hello")
            .AssertReply("step2")
            .Send("hello")
            .AssertReply("step3")
            .StartTest();
        }
コード例 #3
0
        public async Task NumberPromptRetry()
        {
            TestAdapter adapter = new TestAdapter()
                                  .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage()));

            await new TestFlow(adapter, async(turnContext) =>
            {
                var state  = ConversationState <Dictionary <string, object> > .Get(turnContext);
                var prompt = new NumberPrompt <int>(Culture.English);

                var dialogCompletion = await prompt.Continue(turnContext, state);
                if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                {
                    await prompt.Begin(turnContext, state,
                                       new PromptOptions
                    {
                        PromptString      = "Enter a number.",
                        RetryPromptString = "You must enter a number."
                    });
                }
                else if (dialogCompletion.IsCompleted)
                {
                    var numberResult = (NumberResult <int>)dialogCompletion.Result;
                    await turnContext.SendActivity($"Bot received the number '{numberResult.Value}'.");
                }
            })
            .Send("hello")
            .AssertReply("Enter a number.")
            .Send("hello")
            .AssertReply("You must enter a number.")
            .Send("64")
            .AssertReply("Bot received the number '64'.")
            .StartTest();
        }
コード例 #4
0
ファイル: PictureBot.cs プロジェクト: rgknp/AIDayLabs
        /// <summary>
        /// Every Conversation turn for our bot calls this method.
        /// </summary>
        /// <param name="context">The current turn context.</param>
        public async Task OnTurn(ITurnContext context)
        {
            if (context.Activity.Type is ActivityTypes.Message)
            {
                // Get the user and conversation state from the turn context.
                var state = UserState <UserData> .Get(context);

                var conversationInfo = ConversationState <ConversationInfo> .Get(context);

                // Establish dialog state from the conversation state.
                var dc = _dialogs.CreateContext(context, conversationInfo);

                // Continue any current dialog.
                await dc.Continue();

                // Every turn sends a response, so if no response was sent,
                // then there no dialog is currently active.
                if (!context.Responded)
                {
                    // Greet them if we haven't already
                    if (state.Greeted == "not greeted")
                    {
                        await RootResponses.ReplyWithGreeting(context);

                        await RootResponses.ReplyWithHelp(context);

                        state.Greeted = "greeted";
                    }
                    else
                    {
                        await dc.Begin(RootDialog);
                    }
                }
            }
        }
コード例 #5
0
        public async Task OnTurn(ITurnContext turnContext)
        {
            try
            {
                switch (turnContext.Activity.Type)
                {
                case ActivityTypes.Message:
                    var state = ConversationState <Dictionary <string, object> > .Get(turnContext);

                    var dc = _dialogs.CreateContext(turnContext, state);

                    await dc.Continue();

                    if (!turnContext.Responded)
                    {
                        await dc.Begin("waterfall");
                    }
                    break;

                case ActivityTypes.ConversationUpdate:
                    foreach (var newMember in turnContext.Activity.MembersAdded)
                    {
                        if (newMember.Id != turnContext.Activity.Recipient.Id)
                        {
                            await turnContext.SendActivity("Hello and welcome to the waterfall and prompt bot.");
                        }
                    }
                    break;
                }
            }
            catch (Exception e)
            {
                await turnContext.SendActivity($"Exception: {e.Message}");
            }
        }
コード例 #6
0
        public async Task ShouldSendActivityBasedPromptWithSsml()
        {
            TestAdapter adapter = new TestAdapter()
                                  .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage()));

            await new TestFlow(adapter, async(turnContext) =>
            {
                var state  = ConversationState <Dictionary <string, object> > .Get(turnContext);
                var prompt = new ChoicePrompt(Culture.English);

                var dialogCompletion = await prompt.Continue(turnContext, state);
                if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                {
                    await prompt.Begin(turnContext, state,
                                       new ChoicePromptOptions
                    {
                        // TODO: the current model adds the Speak to the activity - that seem surprising (and unnecessary)
                        PromptActivity = MessageFactory.Text("test"),
                        Speak          = "spoken test"
                    });
                }
            })
            .Send("hello")
            .AssertReply(SpeakValidator("test", "spoken test"))
            .StartTest();
        }
コード例 #7
0
        public async Task ShouldSendPromptAsAnInlineList()
        {
            TestAdapter adapter = new TestAdapter()
                                  .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage()));

            await new TestFlow(adapter, async(turnContext) =>
            {
                var state    = ConversationState <Dictionary <string, object> > .Get(turnContext);
                var prompt   = new ChoicePrompt(Culture.English);
                prompt.Style = ListStyle.Inline;

                var dialogCompletion = await prompt.Continue(turnContext, state);
                if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                {
                    await prompt.Begin(turnContext, state,
                                       new ChoicePromptOptions
                    {
                        PromptString = "favorite color?",
                        Choices      = ChoiceFactory.ToChoices(colorChoices)
                    });
                }
            })
            .Send("hello")
            .AssertReply("favorite color? (1) red, (2) green, or (3) blue")
            .StartTest();
        }
コード例 #8
0
        public async Task BasicAttachmentPrompt()
        {
            TestAdapter adapter = new TestAdapter()
                                  .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage()));

            var attachment = new Attachment {
                Content = "some content", ContentType = "text/plain"
            };
            var activityWithAttachment = MessageFactory.Attachment(attachment);

            await new TestFlow(adapter, async(turnContext) =>
            {
                var state  = ConversationState <Dictionary <string, object> > .Get(turnContext);
                var prompt = new AttachmentPrompt();

                var dialogCompletion = await prompt.Continue(turnContext, state);
                if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                {
                    await prompt.Begin(turnContext, state, new PromptOptions {
                        PromptString = "please add an attachment."
                    });
                }
                else if (dialogCompletion.IsCompleted)
                {
                    var attachmentResult = (AttachmentResult)dialogCompletion.Result;
                    var reply            = (string)attachmentResult.Attachments.First().Content;
                    await turnContext.SendActivity(reply);
                }
            })
            .Send("hello")
            .AssertReply("please add an attachment.")
            .Send(activityWithAttachment)
            .AssertReply("some content")
            .StartTest();
        }
コード例 #9
0
        protected override async Task OnReceiveActivity(IBotContext context)
        {
            // --- Our receive handler simply inspects the persisted ITopic class and calls to it as appropriate ---

            bool handled = false;
            // Get the current ActiveTopic from my persisted conversation state
            var conversation = ConversationState <ConversationData> .Get(context);

            //var conversation = context.GetConversationState<ConversationData>();

            // if we don't have an active topic yet
            if (conversation.ActiveTopic == null)
            {
                // use the default topic
                conversation.ActiveTopic = new DefaultTopic();
                handled = await conversation.ActiveTopic.StartTopic(context);
            }
            else
            {
                // we do have an active topic, so call it
                handled = await conversation.ActiveTopic.ContinueTopic(context);
            }

            // if activeTopic's result is false and the activeTopic is NOT already the default topic
            if (handled == false && !(conversation.ActiveTopic is DefaultTopic))
            {
                // USe DefaultTopic as the active topic
                conversation.ActiveTopic = new DefaultTopic();
                handled = await conversation.ActiveTopic.ResumeTopic(context);
            }
        }
コード例 #10
0
        public async Task CurrencyPrompt_Validator()
        {
            TestAdapter adapter = new TestAdapter()
                                  .Use(new ConversationState <TestState>(new MemoryStorage()));

            await new TestFlow(adapter, async(context) =>
            {
                var state        = ConversationState <TestState> .Get(context);
                var numberPrompt = new CurrencyPrompt(Culture.English, async(ctx, result) => result.Value > 10);
                if (!state.InPrompt)
                {
                    state.InPrompt = true;
                    await numberPrompt.Prompt(context, "Gimme:");
                }
                else
                {
                    var result = await numberPrompt.Recognize(context);
                    if (result == null)
                    {
                        context.Reply("null");
                    }
                    else
                    {
                        context.Reply($"{result.Value} {result.Unit}");
                    }
                }
            })
            .Send("hello")
            .AssertReply("Gimme:")
            .Send(" I would like $1.00")
            .AssertReply("null")
            .Send(" I would like $45.50")
            .AssertReply("45.5 Dollar")
            .StartTest();
        }
コード例 #11
0
        public async Task OnTurn(ITurnContext context)
        {
            if (context.Activity.Type == ActivityTypes.Message)
            {
                // The type parameter PropertyBag inherits from
                // Dictionary<string,object>
                var state = ConversationState <Dictionary <string, object> > .Get(context);

                var dc = dialogs.CreateContext(context, state);
                await dc.Continue();

                // Additional logic can be added to enter each dialog depending on the message received
                string activityText = context.Activity.Text.ToLowerInvariant();

                if (!context.Responded)
                {
                    if (activityText.Contains("recommend") || activityText.Contains("movie"))
                    {
                        await dc.Begin("movieRecommendation");
                    }
                    else
                    {
                        await context.SendActivity($"You said '{context.Activity.Text}'; maybe you could ask me to recommend you movie?");
                    }
                }
            }
        }
コード例 #12
0
        public async Task OnTurn(ITurnContext turnContext)
        {
            var localContext = new V4ReferenceContext(turnContext);

            // Get the current ActiveTopic from my persisted conversation state
            var conversation = ConversationState <ConversationData> .Get(localContext);

            var handled = false;

            // if we don't have an active subject yet
            if (conversation.CurrentSubject == null)
            {
                // use the default topic
                conversation.CurrentSubject = new MainSubject();
                handled = await conversation.CurrentSubject.StartSubject(localContext);
            }
            else
            {
                // we do have an active subject, so call it
                handled = await conversation.CurrentSubject.ContinueSubject(localContext);
            }

            //// if activeTopic's result is false and the activeTopic is NOT already the default topic
            //if (handled == false && !(conversation.ActiveTopic is DefaultTopic))
            //{
            //    // Use DefaultTopic as the active topic
            //    conversation.CurrentSubject = new DefaultTopic();
            //    await conversation.CurrentSubject.ResumeTopic(localContext);
            //}
        }
コード例 #13
0
        public async Task OnTurn(ITurnContext context)
        {
            var state = ConversationState <Dictionary <string, object> > .Get(context);

            var prompt  = new TextPrompt();
            var options = new PromptOptions {
                PromptString = "Hello, I'm the demo bot. What is your name?"
            };

            switch (context.Activity.Type)
            {
            case ActivityTypes.ConversationUpdate:
                if (context.Activity.MembersAdded[0].Id != context.Activity.Recipient.Id)
                {
                    await prompt.Begin(context, state, options);
                }
                break;

            case ActivityTypes.Message:
                var dialogCompletion = await prompt.Continue(context, state);

                if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                {
                    await prompt.Begin(context, state, options);
                }
                else if (dialogCompletion.IsCompleted)
                {
                    var textResult = (Microsoft.Bot.Builder.Prompts.TextResult)dialogCompletion.Result;
                    await context.SendActivity($"Bot received the text '{textResult.Value}'.");
                }
                break;
            }
        }
コード例 #14
0
        public async Task MultipleResolutionsDateTimePrompt()
        {
            TestAdapter adapter = new TestAdapter()
                                  .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage()));

            await new TestFlow(adapter, async(turnContext) =>
            {
                var state  = ConversationState <Dictionary <string, object> > .Get(turnContext);
                var prompt = new DateTimePrompt(Culture.English);

                var dialogCompletion = await prompt.Continue(turnContext, state);
                if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                {
                    await prompt.Begin(turnContext, state, new PromptOptions {
                        PromptString = "What date would you like?"
                    });
                }
                else if (dialogCompletion.IsCompleted)
                {
                    var dateTimeResult   = (DateTimeResult)dialogCompletion.Result;
                    var timexExpressions = dateTimeResult.Resolution.Select(r => r.Timex).Distinct();
                    var reply            = string.Join(" ", timexExpressions);
                    await turnContext.SendActivityAsync(reply);
                }
            })
            .Send("hello")
            .AssertReply("What date would you like?")
            .Send("Wednesday 4 oclock")
            .AssertReply("XXXX-WXX-3T04 XXXX-WXX-3T16")
            .StartTestAsync();
        }
コード例 #15
0
        public async Task ShouldSendPromptWithoutAddingAListButAddingSsml()
        {
            TestAdapter adapter = new TestAdapter()
                                  .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage()));

            await new TestFlow(adapter, async(turnContext) =>
            {
                var state    = ConversationState <Dictionary <string, object> > .Get(turnContext);
                var prompt   = new ChoicePrompt(Culture.English);
                prompt.Style = ListStyle.None;

                var dialogCompletion = await prompt.Continue(turnContext, state);
                if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                {
                    await prompt.Begin(turnContext, state,
                                       new ChoicePromptOptions
                    {
                        PromptString = "favorite color?",
                        Speak        = "spoken prompt",
                        Choices      = ChoiceFactory.ToChoices(colorChoices)
                    });
                }
            })
            .Send("hello")
            .AssertReply(SpeakValidator("favorite color?", "spoken prompt"))
            .StartTest();
        }
コード例 #16
0
        public async Task BasicDateTimePrompt()
        {
            TestAdapter adapter = new TestAdapter()
                                  .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage()));

            await new TestFlow(adapter, async(turnContext) =>
            {
                var state  = ConversationState <Dictionary <string, object> > .Get(turnContext);
                var prompt = new DateTimePrompt(Culture.English);

                var dialogCompletion = await prompt.Continue(turnContext, state);
                if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                {
                    await prompt.Begin(turnContext, state, new PromptOptions {
                        PromptString = "What date would you like?"
                    });
                }
                else if (dialogCompletion.IsCompleted)
                {
                    var dateTimeResult = (DateTimeResult)dialogCompletion.Result;
                    var resolution     = dateTimeResult.Resolution.First();
                    var reply          = $"Timex:'{resolution.Timex}' Value:'{resolution.Value}'";
                    await turnContext.SendActivity(reply);
                }
            })
            .Send("hello")
            .AssertReply("What date would you like?")
            .Send("5th December 2018 at 9am")
            .AssertReply("Timex:'2018-12-05T09' Value:'2018-12-05 09:00:00'")
            .StartTest();
        }
コード例 #17
0
        public async Task ShouldSendActivityBasedPrompt()
        {
            TestAdapter adapter = new TestAdapter()
                                  .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage()));

            await new TestFlow(adapter, async(turnContext) =>
            {
                var state    = ConversationState <Dictionary <string, object> > .Get(turnContext);
                var prompt   = new ChoicePrompt(Culture.English);
                prompt.Style = ListStyle.None;

                var dialogCompletion = await prompt.Continue(turnContext, state);
                if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                {
                    await prompt.Begin(turnContext, state,
                                       new ChoicePromptOptions
                    {
                        PromptActivity = MessageFactory.Text("test"),
                        Choices        = ChoiceFactory.ToChoices(colorChoices)
                    });
                }
            })
            .Send("hello")
            .AssertReply("test")
            .StartTest();
        }
コード例 #18
0
        public async Task LengthCheckPromptTest(ITurnContext context)
        {
            dynamic conversationState = ConversationState <StoreItem> .Get(context);

            TextPrompt askForName = new TextPrompt(MinLengthValidator);

            if (conversationState["topic"] != "textPromptTest")
            {
                conversationState["topic"] = "textPromptTest";
                await askForName.Prompt(context, "Your Name:");
            }
            else
            {
                var textResult = await askForName.Recognize(context);

                if (textResult.Succeeded())
                {
                    await context.SendActivity(textResult.Value);
                }
                else
                {
                    await context.SendActivity(textResult.Status.ToString());
                }
            }
        }
コード例 #19
0
        public async Task ShouldRecognizeAChoice()
        {
            TestAdapter adapter = new TestAdapter()
                                  .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage()));

            await new TestFlow(adapter, async(turnContext) =>
            {
                var state    = ConversationState <Dictionary <string, object> > .Get(turnContext);
                var prompt   = new ChoicePrompt(Culture.English);
                prompt.Style = ListStyle.None;

                var dialogCompletion = await prompt.Continue(turnContext, state);
                if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                {
                    await prompt.Begin(turnContext, state,
                                       new ChoicePromptOptions
                    {
                        PromptString = "favorite color?",
                        Choices      = ChoiceFactory.ToChoices(colorChoices)
                    });
                }
                else if (dialogCompletion.IsCompleted)
                {
                    var choiceResult = (ChoiceResult)dialogCompletion.Result;
                    await turnContext.SendActivity($"{choiceResult.Value.Value}");
                }
            })
            .Send("hello")
            .AssertReply(StartsWithValidator("favorite color?"))
            .Send("red")
            .AssertReply("red")
            .StartTest();
        }
コード例 #20
0
        public async Task DateTimePrompt()
        {
            var activities = TranscriptUtilities.GetFromTestContext(TestContext);

            TestAdapter adapter = new TestAdapter()
                                  .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage()));

            await new TestFlow(adapter, async(turnContext) =>
            {
                var state  = ConversationState <Dictionary <string, object> > .Get(turnContext);
                var prompt = new DateTimePrompt(Culture.English);

                var dialogCompletion = await prompt.Continue(turnContext, state);
                if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                {
                    await prompt.Begin(turnContext, state, new PromptOptions {
                        PromptString = "What date would you like?", RetryPromptString = "Sorry, but that is not a date. What date would you like?"
                    });
                }
                else if (dialogCompletion.IsCompleted)
                {
                    var dateTimeResult = (DateTimeResult)dialogCompletion.Result;
                    var resolution     = dateTimeResult.Resolution.First();
                    var reply          = $"Timex:'{resolution.Timex}' Value:'{resolution.Value}'";
                    await turnContext.SendActivityAsync(reply);
                }
            })
            .Test(activities)
            .StartTestAsync();
        }
コード例 #21
0
        public async Task OnReceiveActivity(ITurnContext context)
        {
            // Get the current ActiveTopic from my persisted conversation state
            var conversation = ConversationState <ConversationData> .Get(context);

            var handled = false;

            // if we don't have an active topic yet
            if (conversation.ActiveTopic == null)
            {
                // use the default topic
                conversation.ActiveTopic = new DefaultTopic();
                handled = await conversation.ActiveTopic.StartTopic(context);
            }
            else
            {
                // we do have an active topic, so call it
                handled = await conversation.ActiveTopic.ContinueTopic(context);
            }

            // if activeTopic's result is false and the activeTopic is NOT already the default topic
            if (handled == false && !(conversation.ActiveTopic is DefaultTopic))
            {
                // Use DefaultTopic as the active topic
                conversation.ActiveTopic = new DefaultTopic();
                await conversation.ActiveTopic.ResumeTopic(context);
            }
        }
コード例 #22
0
        public async Task AttachmentPrompt()
        {
            var activities = TranscriptUtilities.GetFromTestContext(TestContext);

            TestAdapter adapter = new TestAdapter()
                                  .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage()));

            await new TestFlow(adapter, async(turnContext) =>
            {
                var state  = ConversationState <Dictionary <string, object> > .Get(turnContext);
                var prompt = new AttachmentPrompt();

                var dialogCompletion = await prompt.Continue(turnContext, state);
                if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                {
                    await prompt.Begin(turnContext, state, new PromptOptions {
                        PromptString = "please add an attachment."
                    });
                }
                else if (dialogCompletion.IsCompleted)
                {
                    var attachmentResult = (AttachmentResult)dialogCompletion.Result;
                    var reply            = (string)attachmentResult.Attachments.First().Content;
                    await turnContext.SendActivityAsync(reply);
                }
            })
            .Test(activities)
            .StartTestAsync();
        }
コード例 #23
0
        /// <summary>
        ///     Handles messages sent to the conversation
        /// </summary>
        /// <param name="context"> The context object for this turn </param>
        /// <returns>
        /// the <see cref="Task"/>
        /// </returns>
        private async Task HandleMessage(ITurnContext context)
        {
            var conversationState = ConversationState <Dictionary <string, object> > .Get(context);

            var dc = this.dialogs.CreateContext(context, conversationState);

            if (context.Activity.Text.ToLowerInvariant().Contains("stop"))
            {
                await dc.Context.SendActivity($"Feedback canceled");

                dc.EndAll();
            }
            else
            {
                await dc.Continue();

                if (!context.Responded)
                {
                    if (context.Activity.Text.ToLowerInvariant().Equals("geronimo"))
                    {
                        await dc.Begin("start");
                    }
                }
            }
        }
コード例 #24
0
        public async Task Waterfall()
        {
            var activities = TranscriptUtilities.GetFromTestContext(TestContext);

            TestAdapter adapter = new TestAdapter()
                                  .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage()));

            await new TestFlow(adapter, async(turnContext) =>
            {
                var waterfall = new Waterfall(new WaterfallStep[]
                {
                    async(dc, args, next) => { await dc.Context.SendActivityAsync("step1"); },
                    async(dc, args, next) => { await dc.Context.SendActivityAsync("step2"); },
                    async(dc, args, next) => { await dc.Context.SendActivityAsync("step3"); },
                });

                var state = ConversationState <Dictionary <string, object> > .Get(turnContext);

                var dialogCompletion = await waterfall.Continue(turnContext, state);
                if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                {
                    await waterfall.Begin(turnContext, state);
                }
            })
            .Test(activities)
            .StartTestAsync();
        }
コード例 #25
0
        public async Task TextPrompt()
        {
            TestAdapter adapter = new TestAdapter()
                                  .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage()));

            await new TestFlow(adapter, async(turnContext) =>
            {
                var state  = ConversationState <Dictionary <string, object> > .Get(turnContext);
                var prompt = new TextPrompt();

                var dialogCompletion = await prompt.Continue(turnContext, state);
                if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                {
                    await prompt.Begin(turnContext, state, new PromptOptions {
                        PromptString = "Enter some text."
                    });
                }
                else if (dialogCompletion.IsCompleted)
                {
                    var textResult = (TextResult)dialogCompletion.Result;
                    await turnContext.SendActivity($"Bot received the text '{textResult.Value}'.");
                }
            })
            .Send("hello")
            .AssertReply("Enter some text.")
            .Send("some text")
            .AssertReply("Bot received the text 'some text'.")
            .StartTest();
        }
コード例 #26
0
        public async Task WaterfallNested()
        {
            var activities = TranscriptUtilities.GetFromTestContext(TestContext);

            TestAdapter adapter = new TestAdapter()
                                  .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage()));

            await new TestFlow(adapter, async(turnContext) =>
            {
                var dialogs = new DialogSet();
                dialogs.Add("test-waterfall-a", Create_Waterfall3());
                dialogs.Add("test-waterfall-b", Create_Waterfall4());
                dialogs.Add("test-waterfall-c", Create_Waterfall5());

                var state = ConversationState <Dictionary <string, object> > .Get(turnContext);
                var dc    = dialogs.CreateContext(turnContext, state);

                await dc.Continue();

                if (!turnContext.Responded)
                {
                    await dc.Begin("test-waterfall-a");
                }
            })
            .Test(activities)
            .StartTestAsync();
        }
コード例 #27
0
        public async Task WaterfallNested()
        {
            TestAdapter adapter = new TestAdapter()
                                  .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage()));

            await new TestFlow(adapter, async(turnContext) =>
            {
                var dialogs = new DialogSet();
                dialogs.Add("test-waterfall-a", Create_Waterfall3());
                dialogs.Add("test-waterfall-b", Create_Waterfall4());
                dialogs.Add("test-waterfall-c", Create_Waterfall5());

                var state = ConversationState <Dictionary <string, object> > .Get(turnContext);
                var dc    = dialogs.CreateContext(turnContext, state);

                await dc.Continue();

                if (!turnContext.Responded)
                {
                    await dc.Begin("test-waterfall-a");
                }
            })
            .Send("hello")
            .AssertReply("step1")
            .AssertReply("step1.1")
            .Send("hello")
            .AssertReply("step1.2")
            .Send("hello")
            .AssertReply("step2")
            .AssertReply("step2.1")
            .Send("hello")
            .AssertReply("step2.2")
            .StartTest();
        }
コード例 #28
0
        public async Task NumberPrompt()
        {
            TestAdapter adapter = new TestAdapter()
                                  .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage()));

            await new TestFlow(adapter, async(turnContext) =>
            {
                var dialogs = new DialogSet();
                dialogs.Add("test-prompt", new NumberPrompt <int>(Culture.English));

                var state = ConversationState <Dictionary <string, object> > .Get(turnContext);
                var dc    = dialogs.CreateContext(turnContext, state);

                await dc.Continue();
                var dialogResult = dc.DialogResult;

                if (!dialogResult.Active)
                {
                    if (dialogResult.Result != null)
                    {
                        var numberResult = (NumberResult <int>)dialogResult.Result;
                        await turnContext.SendActivity($"Bot received the number '{numberResult.Value}'.");
                    }
                    else
                    {
                        await dc.Prompt("test-prompt", "Enter a number.");
                    }
                }
            })
            .Send("hello")
            .AssertReply("Enter a number.")
            .Send("42")
            .AssertReply("Bot received the number '42'.")
            .StartTest();
        }
コード例 #29
0
        public async Task ConfirmPrompt()
        {
            TestAdapter adapter = new TestAdapter()
                                  .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage()));

            await new TestFlow(adapter, async(turnContext) =>
            {
                var state  = ConversationState <Dictionary <string, object> > .Get(turnContext);
                var prompt = new ConfirmPrompt(Culture.English);

                var dialogCompletion = await prompt.Continue(turnContext, state);
                if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                {
                    await prompt.Begin(turnContext, state, new PromptOptions {
                        PromptString = "Please confirm."
                    });
                }
                else if (dialogCompletion.IsCompleted)
                {
                    if (((ConfirmResult)dialogCompletion.Result).Confirmation)
                    {
                        await turnContext.SendActivity("Confirmed.");
                    }
                    else
                    {
                        await turnContext.SendActivity("Not confirmed.");
                    }
                }
            })
            .Send("hello")
            .AssertReply("Please confirm. (1) Yes or (2) No")
            .Send("yes")
            .AssertReply("Confirmed.")
            .StartTest();
        }
コード例 #30
0
        public async Task ShouldNOTrecognizeOtherText()
        {
            var adapter = new TestAdapter()
                          .Use(new ConversationState <TestState>(new MemoryStorage()));

            await new TestFlow(adapter, async(context) =>
            {
                var state = ConversationState <TestState> .Get(context);

                var choicePrompt = new ChoicePrompt(Culture.English);
                if (!state.InPrompt)
                {
                    state.InPrompt = true;
                    await choicePrompt.Prompt(context, colorChoices, "favorite color?");
                }
                else
                {
                    var choiceResult = await choicePrompt.Recognize(context, colorChoices);
                    if (choiceResult.Succeeded())
                    {
                        await context.SendActivity(choiceResult.Value.Value.ToString());
                    }
                    else
                    {
                        await context.SendActivity(choiceResult.Status);
                    }
                }
            })
            .Send("hello")
            .AssertReply(StartsWithValidator("favorite color?"))
            .Send("what was that?")
            .AssertReply("NotRecognized")
            .StartTest();
        }