public async Task PhoneNumberPrompt_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 PhoneNumberPrompt(Culture.English, async(ctx, result) => result.Value.StartsWith("123"));
                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}");
                    }
                }
            })
            .Send("hello")
            .AssertReply("Gimme:")
            .Send("888-123-4567")
            .AssertReply("null")
            .Send("123-123-4567")
            .AssertReply("123-123-4567")
            .StartTest();
        }
Exemplo n.º 2
0
        public async Task PhoneNumber_Prompt()
        {
            var conversationState = new ConversationState(new MemoryStorage());
            var dialogState       = conversationState.CreateProperty <DialogState>("dialogState");

            var adapter = new TestAdapter()
                          .Use(new AutoSaveStateMiddleware(conversationState));

            // Create new DialogSet.
            var dialogs = new DialogSet(dialogState);

            // Create and add number prompt to DialogSet.
            var numberPrompt = new PhoneNumberPrompt(nameof(PhoneNumberPrompt), defaultLocale: Culture.English);

            dialogs.Add(numberPrompt);

            await new TestFlow(adapter, async(turnContext, cancellationToken) =>
            {
                var dc = await dialogs.CreateContextAsync(turnContext, cancellationToken);

                var results = await dc.ContinueDialogAsync(cancellationToken);
                if (!turnContext.Responded && results.Status == DialogTurnStatus.Empty && results.Status != DialogTurnStatus.Complete)
                {
                    var options = new PromptOptions {
                        Prompt = new Activity {
                            Type = ActivityTypes.Message, Text = "Hey send your phone number"
                        }
                    };
                    await dc.PromptAsync(nameof(PhoneNumberPrompt), options, cancellationToken);
                }
                else if (results.Status == DialogTurnStatus.Complete)
                {
                    var phoneResult = (string)results.Result;

                    if (phoneResult != null)
                    {
                        await turnContext.SendActivityAsync(MessageFactory.Text($"Bot received phone number: {phoneResult}"), cancellationToken);
                    }
                    else
                    {
                        await turnContext.SendActivityAsync(MessageFactory.Text($"Nothing recognized"), cancellationToken);
                    }
                }
            })
            .Send("hello")
            .AssertReply("Hey send your phone number")
            .Send("yes sure , my number is +9112345678")
            .AssertReply("Bot received phone number: +9112345678")
            .StartTestAsync();
        }
Exemplo n.º 3
0
        public async Task PhoneNumberPrompt_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 PhoneNumberPrompt(Culture.English, async(ctx, result) =>
                {
                    if (!result.Value.StartsWith("123"))
                    {
                        result.Status = PromptStatus.OutOfRange;
                    }
                });
                if (!state.InPrompt)
                {
                    state.InPrompt = true;
                    await numberPrompt.Prompt(context, "Gimme:");
                }
                else
                {
                    var phoneResult = await numberPrompt.Recognize(context);
                    if (phoneResult.Succeeded())
                    {
                        await context.SendActivity($"{phoneResult.Value}");
                    }
                    else
                    {
                        await context.SendActivity(phoneResult.Status.ToString());
                    }
                }
            })
            .Send("hello")
            .AssertReply("Gimme:")
            .Send("888-123-4567")
            .AssertReply(PromptStatus.OutOfRange.ToString())
            .Send("123-123-4567")
            .AssertReply("123-123-4567")
            .StartTest();
        }
Exemplo n.º 4
0
        public async Task PhoneNumberPrompt_Test()
        {
            TestAdapter adapter = new TestAdapter()
                                  .Use(new ConversationState <TestState>(new MemoryStorage()));

            await new TestFlow(adapter, async(context) =>
            {
                var state      = ConversationState <TestState> .Get(context);
                var testPrompt = new PhoneNumberPrompt(Culture.English);
                if (!state.InPrompt)
                {
                    state.InPrompt = true;
                    await testPrompt.Prompt(context, "Gimme:");
                }
                else
                {
                    var phoneResult = await testPrompt.Recognize(context);
                    if (phoneResult.Succeeded())
                    {
                        Assert.IsNotNull(phoneResult.Text);
                        Assert.IsNotNull(phoneResult.Value);
                        await context.SendActivity($"{phoneResult.Value}");
                    }
                    else
                    {
                        await context.SendActivity(phoneResult.Status.ToString());
                    }
                }
            })
            .Send("hello")
            .AssertReply("Gimme:")
            .Send("test test test")
            .AssertReply(PromptStatus.NotRecognized.ToString())
            .Send("123 123123sdfsdf 123 1asdf23123 123 ")
            .AssertReply(PromptStatus.NotRecognized.ToString())
            .Send("123-456-7890")
            .AssertReply("123-456-7890")
            .StartTest();
        }