Ejemplo n.º 1
0
 public async Task ShouldSendPromptUsingSuggestedActions()
 {
     await new TestFlow(new TestAdapter(), async(context) =>
     {
         var choicePrompt   = new ChoicePrompt(Culture.English);
         choicePrompt.Style = ListStyle.SuggestedAction;
         await choicePrompt.Prompt(context, colorChoices, "favorite color?");
     })
     .Send("hello")
     .AssertReply(SuggestedActionsValidator("favorite color?",
                                            new SuggestedActions
     {
         Actions = new List <CardAction>
         {
             new CardAction {
                 Type = "imBack", Value = "red", Title = "red"
             },
             new CardAction {
                 Type = "imBack", Value = "green", Title = "green"
             },
             new CardAction {
                 Type = "imBack", Value = "blue", Title = "blue"
             },
         }
     }))
     .StartTest();
 }
        public async Task ShouldSendPrompt()
        {
            ConversationState convoState = new ConversationState(new MemoryStorage());
            var testProperty             = convoState.CreateProperty <Dictionary <string, object> >("test", () => new Dictionary <string, object>());

            TestAdapter adapter = new TestAdapter()
                                  .Use(convoState);

            await new TestFlow(adapter, async(turnContext) =>
            {
                var state  = await testProperty.GetAsync(turnContext);
                var prompt = new ChoicePrompt(Culture.English);

                var dialogCompletion = await prompt.ContinueAsync(turnContext, state);
                if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                {
                    await prompt.BeginAsync(turnContext, state,
                                            new ChoicePromptOptions
                    {
                        PromptString = "favorite color?",
                        Choices      = ChoiceFactory.ToChoices(colorChoices)
                    });
                }
            })
            .Send("hello")
            .AssertReply(StartsWithValidator("favorite color?"))
            .StartTestAsync();
        }
Ejemplo n.º 3
0
        public SubjectDialog(string dialogId, IOpenDataService openDataService, IEnumerable <WaterfallStep> steps = null) : base(dialogId)
        {
            _openDataService = openDataService;

            string fullPath = Path.Combine(new string[] { ".", ".", "Resources", "SubjectDialog.lg" });

            _lgEngine = Templates.ParseFile(fullPath);

            ChoicePrompt choicePrompt = new ChoicePrompt(nameof(ChoicePrompt));

            choicePrompt.ChoiceOptions = new ChoiceFactoryOptions {
                IncludeNumbers = false
            };
            //choicePrompt.RecognizerOptions = new FindChoicesOptions { AllowPartialMatches = true };
            AddDialog(choicePrompt);
            AddDialog(new TextPrompt(nameof(TextPrompt)));
            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[]
            {
                QuestionCenterStepAsync,
                QuestionDegreeStepAsync,
                QuestionSubjectStepAsync,
                EndQuestionStepAsync,
            }));

            InitialDialogId = nameof(WaterfallDialog);
        }
Ejemplo n.º 4
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();
        }
        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();
        }
        public void SetDialogConfiguration(DialogSet dialogSet)
        {
            AddPictureOfTheDayDialog(dialogSet);
            AddMarsRoverDataDialog(dialogSet);
            AddAsteroidDataDialog(dialogSet);

            //mars rover date prompt
            DateTimePrompt earthDatePrompt = new DateTimePrompt("EarthDatePrompt", DateValidatorAsync);

            dialogSet.Add(earthDatePrompt);

            NumberPrompt <int> numberOfPicturesPrompt = new NumberPrompt <int>("NumberOfPicturesPrompt", NumberValidatorAsync);

            dialogSet.Add(numberOfPicturesPrompt);

            //asteroid start && end date prompts
            DateTimePrompt startDatePrompt = new DateTimePrompt("StartDatePrompt", DateValidatorAsync);

            dialogSet.Add(startDatePrompt);
            DateTimePrompt endDatePrompt = new DateTimePrompt("EndDatePrompt", DateValidatorAsync);

            dialogSet.Add(endDatePrompt);

            //add choice options dialog
            var choicePrompt = new ChoicePrompt("GetChoices");

            dialogSet.Add(choicePrompt);

            //add generic confirmation dialog
            var confirmationPrompt = new ConfirmPrompt("ConfirmationDialog");

            dialogSet.Add(confirmationPrompt);
        }
        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();
        }
        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();
        }
Ejemplo n.º 9
0
        public TeacherDialog(string dialogId, ITeacherService teacherService, IEnumerable <WaterfallStep> steps = null) : base(dialogId)
        {
            _teacherService = teacherService;

            string fullPath = Path.Combine(new string[] { ".", ".", "Resources", "TeacherDialog.lg" });

            _lgEngine = Templates.ParseFile(fullPath);

            ChoicePrompt choicePrompt = new ChoicePrompt(nameof(ChoicePrompt));

            choicePrompt.ChoiceOptions = new ChoiceFactoryOptions {
                IncludeNumbers = false
            };
            choicePrompt.RecognizerOptions = new FindChoicesOptions {
                AllowPartialMatches = true
            };
            AddDialog(choicePrompt);
            AddDialog(new TextPrompt(nameof(TextPrompt)));
            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[]
            {
                IntroTeacherQuestionStepAsync,
                ResponseTeacherQuestionStepAsync,
                EndTeacherQuestionStepAsync
            }));

            InitialDialogId = nameof(WaterfallDialog);
        }
Ejemplo n.º 10
0
        public void ChoicePromptWithNullIdShouldFail()
        {
            var nullId = string.Empty;

            nullId = null;
            var choicePrompt = new ChoicePrompt(nullId);
        }
Ejemplo n.º 11
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();
        }
Ejemplo n.º 12
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();
        }
Ejemplo n.º 13
0
        public UnexFacilitiesDialog(string dialogId, IUnexFacilitiesService unexFacilititesService, IEnumerable <WaterfallStep> steps = null) : base(dialogId)
        {
            _lgEngine = Templates.ParseFile(Path.Combine(new string[] { ".", ".", "Resources", "UnexFacilitiesDialog.lg" }));
            _unexFacilitiesService = unexFacilititesService;

            ChoicePrompt choicePrompt = new ChoicePrompt(nameof(ChoicePrompt));

            choicePrompt.ChoiceOptions = new ChoiceFactoryOptions {
                IncludeNumbers = false
            };
            choicePrompt.RecognizerOptions = new FindChoicesOptions {
                AllowPartialMatches = true
            };
            AddDialog(choicePrompt);

            AddDialog(new TextPrompt(nameof(TextPrompt)));
            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[]
            {
                IntroFacilitiesQuestionStepAsync,
                IntermediateFacilitiesAnswerStepAsync,
                EndQuestionStepAsync,
            }));

            InitialDialogId = nameof(WaterfallDialog);
        }
Ejemplo n.º 14
0
        public CitaIMQBot(CitaIMQBotAccessors accessors)
        {
            _accessors = accessors ?? throw new ArgumentNullException(nameof(accessors));

            // The DialogSet needs a DialogState accessor, it will call it when it has a turn context.
            _dialogs = new DialogSet(accessors.DialogStateAccessor);
            var dialogState = accessors.DialogStateAccessor;

            _dialogs = new DialogSet(dialogState);
            _dialogs.Add(MainDialog.Instance);
            _dialogs.Add(ConsultarCitasDialog.Instance);
            _dialogs.Add(CrearCitaDialog.Instance);
            _dialogs.Add(SeleccionarAgendaEspecialidadDialog.Instance);
            _dialogs.Add(AgendaCrearCitaDialog.Instance);
            _dialogs.Add(EspecialidadCrearCitaDialog.Instance);

            _dialogs.Add(new ChoicePrompt("choicePrompt"));
            _dialogs.Add(new NumberPrompt <int>("numeroTarjeta", ValidarTarjetaAsync));
            _dialogs.Add(new DateTimePrompt("fechanacimientoPrompt", ValidarFechaNacimientoAsync, Culture.Spanish));
            _dialogs.Add(new ChoicePrompt("seleccionarTipoAgendaEspecialidadPrompt"));
            _dialogs.Add(new ChoicePrompt("seleccionarProvinciaPrompt"));
            _dialogs.Add(new TextPrompt("agendaPrompt", ValidarAgendaPrompt));
            var choiceagendasposibles = new ChoicePrompt("seleccionAgendaPosible");

            choiceagendasposibles.Style = Microsoft.Bot.Builder.Dialogs.Choices.ListStyle.Auto;
            _dialogs.Add(choiceagendasposibles);
            _dialogs.Add(new ChoicePrompt("confirmarAgendaPrompt"));
            _dialogs.Add(new DateTimePrompt("fechabusquedaPrompt", ValidarFechaBusquedaAsync, Culture.Spanish));
        }
Ejemplo n.º 15
0
        public async Task ShouldSendPromptAsANumberedList()
        {
            var convoState   = new ConversationState(new MemoryStorage());
            var testProperty = convoState.CreateProperty <Dictionary <string, object> >("test");

            var adapter = new TestAdapter()
                          .Use(convoState);

            await new TestFlow(adapter, async(turnContext, cancellationToken) =>
            {
                var state    = await testProperty.GetAsync(turnContext, () => new Dictionary <string, object>());
                var prompt   = new ChoicePrompt(Culture.English);
                prompt.Style = ListStyle.List;

                var dialogCompletion = await prompt.ContinueAsync(turnContext, state);
                if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                {
                    await prompt.BeginAsync(turnContext, state,
                                            new ChoicePromptOptions
                    {
                        PromptString = "favorite color?",
                        Choices      = ChoiceFactory.ToChoices(colorChoices)
                    });
                }
            })
            .Send("hello")
            .AssertReply("favorite color?\n\n   1. red\n   2. green\n   3. blue")
            .StartTestAsync();
        }
        public async Task ShouldSendPromptUsingHeroCard()
        {
            var convoState  = new ConversationState(new MemoryStorage());
            var dialogState = convoState.CreateProperty <DialogState>("dialogState");

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

            var dialogs    = new DialogSet(dialogState);
            var listPrompt = new ChoicePrompt("ChoicePrompt", defaultLocale: Culture.English)
            {
                Style = ListStyle.HeroCard,
            };

            dialogs.Add(listPrompt);

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

                var results = await dc.ContinueDialogAsync(cancellationToken);
                if (results.Status == DialogTurnStatus.Empty)
                {
                    await dc.PromptAsync(
                        "ChoicePrompt",
                        new PromptOptions
                    {
                        Prompt = new Activity {
                            Type = ActivityTypes.Message, Text = "favorite color?"
                        },
                        Choices = _colorChoices,
                    },
                        cancellationToken);
                }
            })
            .Send("hello")
            .AssertReply(HeroCardValidator(
                             new HeroCard
            {
                Text    = "favorite color?",
                Buttons = new List <CardAction>
                {
                    new CardAction {
                        Type = "imBack", Value = "red", Title = "red"
                    },
                    new CardAction {
                        Type = "imBack", Value = "green", Title = "green"
                    },
                    new CardAction {
                        Type = "imBack", Value = "blue", Title = "blue"
                    },
                },
            },
                             0))
            .StartTestAsync();
        }
Ejemplo n.º 17
0
 public async Task ShouldSendActivityBasedPromptWithSsml()
 {
     await new TestFlow(new TestAdapter(), async(context) =>
     {
         var choicePrompt = new ChoicePrompt(Culture.English);
         await choicePrompt.Prompt(context, MessageFactory.Text("test"), "spoken test");
     })
     .Send("hello")
     .AssertReply(SpeakValidator("test", "spoken test"))
     .StartTest();
 }
Ejemplo n.º 18
0
 public async Task ShouldSendPrompt()
 {
     await new TestFlow(new TestAdapter(), async(context) =>
     {
         var choicePrompt = new ChoicePrompt(Culture.English);
         await choicePrompt.Prompt(context, colorChoices, "favorite color?");
     })
     .Send("hello")
     .AssertReply(StartsWithValidator("favorite color?"))
     .StartTest();
 }
Ejemplo n.º 19
0
 public async Task ShouldSendPromptAsANumberedList()
 {
     await new TestFlow(new TestAdapter(), async(context) =>
     {
         var choicePrompt   = new ChoicePrompt(Culture.English);
         choicePrompt.Style = ListStyle.List;
         await choicePrompt.Prompt(context, colorChoices, "favorite color?");
     })
     .Send("hello")
     .AssertReply("favorite color?\n\n   1. red\n   2. green\n   3. blue")
     .StartTest();
 }
Ejemplo n.º 20
0
 public async Task ShouldSendPromptAsAnInlineList()
 {
     await new TestFlow(new TestAdapter(), async(context) =>
     {
         var choicePrompt   = new ChoicePrompt(Culture.English);
         choicePrompt.Style = ListStyle.Inline;
         await choicePrompt.Prompt(context, colorChoices, "favorite color?");
     })
     .Send("hello")
     .AssertReply("favorite color? (1) red, (2) green, or (3) blue")
     .StartTest();
 }
Ejemplo n.º 21
0
 public async Task ShouldSendPromptWithoutAddingAListButAddingSsml()
 {
     await new TestFlow(new TestAdapter(), async(context) =>
     {
         var choicePrompt   = new ChoicePrompt(Culture.English);
         choicePrompt.Style = ListStyle.None;
         await choicePrompt.Prompt(context, colorChoices, "favorite color?", "spoken prompt");
     })
     .Send("hello")
     .AssertReply(SpeakValidator("favorite color?", "spoken prompt"))
     .StartTest();
 }
Ejemplo n.º 22
0
        protected override async Task <IActivity> OnRenderPrompt(DialogContext dc, InputState state)
        {
            var locale = GetCulture(dc);
            var prompt = await base.OnRenderPrompt(dc, state);

            var channelId     = dc.Context.Activity.ChannelId;
            var choicePrompt  = new ChoicePrompt(this.Id);
            var choiceOptions = this.ChoiceOptions ?? ChoiceInput.DefaultChoiceOptions[locale];

            var choices = this.Choices.GetValue(dc.GetState());

            return(this.AppendChoices(prompt.AsMessageActivity(), channelId, choices, this.Style, choiceOptions));
        }
Ejemplo n.º 23
0
        public async Task ShouldSendPromptUsingSuggestedActions()
        {
            var convoState  = new ConversationState(new MemoryStorage());
            var dialogState = convoState.CreateProperty <DialogState>("dialogState");

            var adapter = new TestAdapter()
                          .Use(convoState);

            var dialogs    = new DialogSet(dialogState);
            var listPrompt = new ChoicePrompt("ChoicePrompt", defaultLocale: Culture.English);

            listPrompt.Style = ListStyle.SuggestedAction;
            dialogs.Add(listPrompt);

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

                var results = await dc.ContinueAsync(cancellationToken);
                if (!turnContext.Responded && !results.HasActive && !results.HasResult)
                {
                    await dc.PromptAsync("ChoicePrompt",
                                         new PromptOptions
                    {
                        Prompt = new Activity {
                            Type = ActivityTypes.Message, Text = "favorite color?"
                        },
                        Choices = colorChoices
                    },
                                         cancellationToken);
                }
            })
            .Send("hello")
            .AssertReply(SuggestedActionsValidator("favorite color?",
                                                   new SuggestedActions
            {
                Actions = new List <CardAction>
                {
                    new CardAction {
                        Type = "imBack", Value = "red", Title = "red"
                    },
                    new CardAction {
                        Type = "imBack", Value = "green", Title = "green"
                    },
                    new CardAction {
                        Type = "imBack", Value = "blue", Title = "blue"
                    },
                }
            }))
            .StartTestAsync();
        }
        public async Task ShouldCallCustomValidator()
        {
            var convoState  = new ConversationState(new MemoryStorage());
            var dialogState = convoState.CreateProperty <DialogState>("dialogState");

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

            var dialogs = new DialogSet(dialogState);

            PromptValidator <FoundChoice> validator = async(promptContext, cancellationToken) =>
            {
                await promptContext.Context.SendActivityAsync(MessageFactory.Text("validator called"), cancellationToken);

                return(true);
            };
            var listPrompt = new ChoicePrompt("ChoicePrompt", validator, Culture.English)
            {
                Style = ListStyle.None,
            };

            dialogs.Add(listPrompt);

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

                var results = await dc.ContinueDialogAsync(cancellationToken);
                if (results.Status == DialogTurnStatus.Empty)
                {
                    await dc.PromptAsync(
                        "ChoicePrompt",
                        new PromptOptions
                    {
                        Prompt = new Activity {
                            Type = ActivityTypes.Message, Text = "favorite color?"
                        },
                        Choices = _colorChoices,
                    },
                        cancellationToken);
                }
            })
            .Send("hello")
            .AssertReply(StartsWithValidator("favorite color?"))
            .Send("I'll take the red please.")
            .AssertReply("validator called")
            .StartTestAsync();
        }
Ejemplo n.º 25
0
        public OcelotDialog() : base(nameof(OcelotDialog))
        {
            proc = Ocelot.Storage.LoadProcess();

            var cp = new ChoicePrompt(nameof(ChoicePrompt));

            cp.Style = ListStyle.HeroCard;

            AddDialog(cp);
            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[] {
                ChoiceStepAsync,
                LoopStepAsync,
            }));

            InitialDialogId = nameof(WaterfallDialog);
        }
        public async Task ShouldRecognizeAChoice()
        {
            var convoState  = new ConversationState(new MemoryStorage());
            var dialogState = convoState.CreateProperty <DialogState>("dialogState");

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

            var dialogs = new DialogSet(dialogState);

            var listPrompt = new ChoicePrompt("ChoicePrompt", defaultLocale: Culture.English)
            {
                Style = ListStyle.None,
            };

            dialogs.Add(listPrompt);

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

                var results = await dc.ContinueDialogAsync(cancellationToken);
                if (results.Status == DialogTurnStatus.Empty)
                {
                    await dc.PromptAsync(
                        "ChoicePrompt",
                        new PromptOptions
                    {
                        Prompt = new Activity {
                            Type = ActivityTypes.Message, Text = "favorite color?"
                        },
                        Choices = _colorChoices,
                    },
                        cancellationToken);
                }
                else if (results.Status == DialogTurnStatus.Complete)
                {
                    var choiceResult = (FoundChoice)results.Result;
                    await turnContext.SendActivityAsync(MessageFactory.Text($"{choiceResult.Value}"), cancellationToken);
                }
            })
            .Send("hello")
            .AssertReply(StartsWithValidator("favorite color?"))
            .Send("red")
            .AssertReply("red")
            .StartTestAsync();
        }
Ejemplo n.º 27
0
        public async Task ShouldCallCustomValidator()
        {
            ConversationState convoState = new ConversationState(new MemoryStorage());
            var testProperty             = convoState.CreateProperty <Dictionary <string, object> >("test", () => new Dictionary <string, object>());

            TestAdapter adapter = new TestAdapter()
                                  .Use(convoState);

            PromptValidator <ChoiceResult> validator = (ITurnContext context, ChoiceResult result) =>
            {
                // TODO: the current model has no way for this status to bubble up
                result.Status = "validation failed";
                result.Value  = null;
                return(Task.CompletedTask);
            };

            await new TestFlow(adapter, async(turnContext) =>
            {
                var state    = await testProperty.GetAsync(turnContext);
                var prompt   = new ChoicePrompt(Culture.English, validator);
                prompt.Style = ListStyle.None;

                var dialogCompletion = await prompt.ContinueAsync(turnContext, state);
                if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                {
                    await prompt.BeginAsync(turnContext, state,
                                            new ChoicePromptOptions
                    {
                        PromptString = "favorite color?",
                        Choices      = ChoiceFactory.ToChoices(colorChoices)
                    });
                }
                else if (dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                {
                    if (dialogCompletion.Result == null)
                    {
                        await turnContext.SendActivityAsync("validation failed");
                    }
                }
            })
            .Send("hello")
            .AssertReply(StartsWithValidator("favorite color?"))
            .Send("I'll take the red please.")
            .AssertReply("validation failed")
            .StartTestAsync();
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Method which renders the prompt to the user given the current input state.
        /// </summary>
        /// <param name="dc">The <see cref="DialogContext"/> for the current turn of conversation.</param>
        /// <param name="state">Dialog <see cref="InputState"/>.</param>
        /// <param name="cancellationToken">Optional, the <see cref="CancellationToken"/> that can be used by other objects or threads to receive notice of cancellation.</param>
        /// <returns>Activity to send to the user.</returns>
        protected override async Task <IActivity> OnRenderPromptAsync(DialogContext dc, InputState state, CancellationToken cancellationToken = default(CancellationToken))
        {
            var locale = GetCulture(dc);
            var prompt = await base.OnRenderPromptAsync(dc, state, cancellationToken).ConfigureAwait(false);

            var channelId     = dc.Context.Activity.ChannelId;
            var choicePrompt  = new ChoicePrompt(this.Id);
            var choiceOptions = this.ChoiceOptions?.GetValue(dc.State) ?? ChoiceInput.DefaultChoiceOptions[locale];

            var(choices, error) = this.Choices.TryGetValue(dc.State);
            if (error != null)
            {
                throw new Exception(error);
            }

            return(this.AppendChoices(prompt.AsMessageActivity(), channelId, choices, this.Style.GetValue(dc.State), choiceOptions));
        }
Ejemplo n.º 29
0
        public RichCardsBot()
        {
            dialogs = new DialogSet();
            // Choice prompt with list style to show card types
            var cardPrompt = new ChoicePrompt(Culture.English)
            {
                Style = Microsoft.Bot.Builder.Prompts.ListStyle.List
            };

            cardOptions = GenerateOptions();

            // Register the card prompt
            dialogs.Add("cardPrompt", cardPrompt);

            // Create a dialog waterfall for prompting the user
            dialogs.Add("cardSelector", new WaterfallStep[] { ChoiceCardStep, ShowCardStep });
        }
Ejemplo n.º 30
0
        public async Task ShouldHandleAnUndefinedRequest()
        {
            ConversationState convoState = new ConversationState(new MemoryStorage());
            var testProperty             = convoState.CreateProperty <Dictionary <string, object> >("test", () => new Dictionary <string, object>());

            TestAdapter adapter = new TestAdapter()
                                  .Use(convoState);

            PromptValidator <ChoiceResult> validator = (ITurnContext context, ChoiceResult result) =>
            {
                Assert.IsTrue(false);
                return(Task.CompletedTask);
            };

            await new TestFlow(adapter, async(turnContext) =>
            {
                var state    = await testProperty.GetAsync(turnContext);
                var prompt   = new ChoicePrompt(Culture.English, validator);
                prompt.Style = ListStyle.None;

                var dialogCompletion = await prompt.ContinueAsync(turnContext, state);
                if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                {
                    await prompt.BeginAsync(turnContext, state,
                                            new ChoicePromptOptions
                    {
                        PromptString = "favorite color?",
                        Choices      = ChoiceFactory.ToChoices(colorChoices)
                    });
                }
                else if (dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                {
                    if (dialogCompletion.Result == null)
                    {
                        await turnContext.SendActivityAsync("NotRecognized");
                    }
                }
            })
            .Send("hello")
            .AssertReply(StartsWithValidator("favorite color?"))
            .Send("value shouldn't have been recognized.")
            .AssertReply("NotRecognized")
            .StartTestAsync();
        }