Exemplo n.º 1
0
        public RootDialog() : base(nameof(RootDialog))
        {
            string[] paths    = { ".", "Dialogs", $"RootDialog.lg" };
            var      fullPath = Path.Combine(paths);

            _templates = Templates.ParseFile(fullPath);

            Triggers = new List <OnCondition>
            {
                new OnConversationUpdateActivity()
                {
                    Actions = WelcomeUserSteps()
                },
                new OnUnknownIntent()
                {
                    Actions = new List <Dialog>()
                    {
                        new SendActivity("${AdaptiveCard()}"),
                        new SendActivity("${SeeAnotherCardPrompt()}")
                    }
                }
            };

            Generator = new TemplateEngineLanguageGenerator(_templates);
        }
        public RootDialog() : base(nameof(RootDialog))
        {
            string[] paths    = { ".", "MainDialog", $"{nameof(RootDialog)}.lg" };
            var      fullPath = Path.Combine(paths);

            Recognizer = CreateReconRecognizer();

            CreateAuthenticationInput();

            Triggers = new List <OnCondition>()
            {
                CreateUnknownIntent(),

                TextInputIntent(),

                NumberInputIntent(),

                ConfirmInputIntent(),

                ChoiceInputIntent(),

                DateTimeIntent(),

                AttachmentIntent(),

                CallLogIn(),

                CallLogOut()
            };


            Generator = new TemplateEngineLanguageGenerator(Templates.ParseFile(fullPath));
        }
Exemplo n.º 3
0
        public MainDialog(ILogger <MainDialog> logger)
            : base(nameof(MainDialog))
        {
            _logger = logger;

            // combine path for cross platform support
            string[] paths            = { ".", "Resources", "MainDialog.LG" };
            string   mainDialogLGFile = Path.Combine(paths);

            paths = new string[] { ".", "Resources", "Cards.LG" };
            string cardsLGFile = Path.Combine(paths);

            string[] lgFiles = { mainDialogLGFile, cardsLGFile };

            // For simple LG resolution, we will call the TemplateEngine directly.
            _lgEngine = new TemplateEngine().AddFiles(lgFiles);

            _activityGenerator = new TextMessageActivityGenerator();

            _lgGenerator = new TemplateEngineLanguageGenerator(_lgEngine);

            AddDialog(new ChoicePrompt(nameof(ChoicePrompt)));
            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[]
            {
                ChoiceCardStepAsync,
                ShowCardStepAsync,
            }));

            // The initial child Dialog to run.
            InitialDialogId = nameof(WaterfallDialog);
        }
        public async Task TestMultiLangImport()
        {
            var resourceExplorer = new ResourceExplorer().LoadProject(GetProjectFolder(), monitorChanges: false);

            // use LG file as entrance
            var lgResourceGroup = LGResourceLoader.GroupByLocale(resourceExplorer);

            var resource  = resourceExplorer.GetResource("a.en-US.lg") as FileResource;
            var generator = new TemplateEngineLanguageGenerator(resource.FullName, lgResourceGroup);
            var result    = await generator.GenerateAsync(GetDialogContext(), "${templatea()}", null);

            Assert.AreEqual("from a.en-us.lg", result);

            // import b.en-us.lg
            result = await generator.GenerateAsync(GetDialogContext(), "${templateb()}", null);

            Assert.AreEqual("from b.en-us.lg", result);

            // fallback to c.en.lg
            result = await generator.GenerateAsync(GetDialogContext(), "${templatec()}", null);

            Assert.AreEqual("from c.en.lg", result);

            // there is no 'greeting' template in b.en-us.lg, no more fallback to b.lg
            var ex = await Assert.ThrowsExceptionAsync <Exception>(async() => await generator.GenerateAsync(GetDialogContext(), "${greeting()}", null));

            Assert.IsTrue(ex.Message.Contains("greeting does not have an evaluator"));

            resource  = resourceExplorer.GetResource("a.lg") as FileResource;
            generator = new TemplateEngineLanguageGenerator(resource.FullName, lgResourceGroup);

            result = await generator.GenerateAsync(GetDialogContext(), "${templatea()}", null);

            Assert.AreEqual("from a.lg", result);

            result = await generator.GenerateAsync(GetDialogContext(), "${templateb()}", null);

            Assert.AreEqual("from b.lg", result);

            // ignore the "en" in c.en.lg, just load c.lg
            result = await generator.GenerateAsync(GetDialogContext(), "${templatec()}", null);

            Assert.AreEqual("from c.lg", result);

            result = await generator.GenerateAsync(GetDialogContext(), "${greeting()}", null);

            Assert.AreEqual("hi", result);
        }
Exemplo n.º 5
0
        public RootDialog() : base(nameof(RootDialog))
        {
            string[] paths    = { ".", "Dialogs", $"RootDialog.lg" };
            var      fullPath = Path.Combine(paths);

            _templates = Templates.ParseFile(fullPath);

            Triggers = new List <OnCondition>
            {
                new OnConversationUpdateActivity()
                {
                    Actions = WelcomeUserSteps()
                }
            };

            Generator = new TemplateEngineLanguageGenerator(_templates);
        }
Exemplo n.º 6
0
        public RootDialog() : base(nameof(RootDialog))
        {
            string[] paths    = { ".", "Dialogs", $"RootDialog.lg" };
            string   fullPath = Path.Combine(paths);

            // These steps are executed when this Adaptive Dialog begins
            Triggers = new List <OnCondition>()
            {
                // Add a rule to welcome user
                new OnConversationUpdateActivity()
                {
                    Actions = WelcomeUserSteps()
                },

                // Respond to user on message activity
                new OnUnknownIntent()
                {
                    Actions = GatheUserInformation()
                },
            };
            Generator = new TemplateEngineLanguageGenerator(Templates.ParseFile(fullPath));
        }
 public async Task TestNotFoundTemplate()
 {
     var context = GetDialogContext(string.Empty);
     var lg      = new TemplateEngineLanguageGenerator();
     await lg.GenerateAsync(context, "${tesdfdfsst()}", null);
 }
Exemplo n.º 8
0
 public async Task TestNotFoundTemplate()
 {
     var context = GetDialogContext(string.Empty);
     var lg      = new TemplateEngineLanguageGenerator();
     await Assert.ThrowsAsync <InvalidOperationException>(() => lg.GenerateAsync(context, "${tesdfdfsst()}", null));
 }
Exemplo n.º 9
0
 public async Task TestNotFoundTemplate()
 {
     var context = GetTurnContext(string.Empty);
     var lg      = new TemplateEngineLanguageGenerator(string.Empty, "test", resourceResolver);
     await lg.Generate(context, "[tesdfdfsst]", null);
 }
Exemplo n.º 10
0
        public RootDialog() : base(nameof(RootDialog))
        {
            string[] paths    = { ".", "Dialogs", $"RootDialog.lg" };
            var      fullPath = Path.Combine(paths);

            _templates = Templates.ParseFile(fullPath);

            Recognizer = new RegexRecognizer()
            {
                Intents = new List <IntentPattern>()
                {
                    new IntentPattern()
                    {
                        Intent  = "ChangeLang",
                        Pattern = "(language|speak|change)"
                    },
                    new IntentPattern()
                    {
                        Intent  = "Help",
                        Pattern = "(help|options)"
                    },
                    new IntentPattern()
                    {
                        Intent  = "Hero",
                        Pattern = "hero"
                    }
                }
            };

            Triggers = new List <OnCondition>
            {
                new OnConversationUpdateActivity()
                {
                    Actions = WelcomeUserSteps()
                },
                new OnIntent()
                {
                    Intent  = "ChangeLang",
                    Actions = new List <Dialog>()
                    {
                        new TextInput()
                        {
                            AlwaysPrompt  = true,
                            Property      = "dialog.LanguagePreference",
                            Prompt        = new ActivityTemplate("${LanguageChoicePrompt()}"),
                            InvalidPrompt = new ActivityTemplate("${InvalidChoice()}"),
                            Validations   = new List <BoolExpression>()
                            {
                                new BoolExpression("this.value == 'en' || this.value == 'it' || this.value == 'fr' || this.value == 'es'")
                            }
                        },
                        new SetProperty()
                        {
                            Property = "user.LanguagePreference",
                            Value    = "=dialog.LanguagePreference"
                        },
                        new SendActivity("${ShowSelection()}"),
                    }
                },
                new OnIntent()
                {
                    Intent  = "Hero",
                    Actions = new List <Dialog>()
                    {
                        new SendActivity("${HeroCard()}")
                    }
                },
                new OnIntent()
                {
                    Intent  = "Help",
                    Actions = new List <Dialog>()
                    {
                        new SendActivity("${HelpInfo()}")
                    }
                },
                new OnUnknownIntent()
                {
                    Actions = new List <Dialog>()
                    {
                        new SendActivity("You said: '${turn.Activity.Text}'"),
                    }
                }
            };

            Generator = new TemplateEngineLanguageGenerator(_templates);
        }
Exemplo n.º 11
0
        public RootDialog() : base(nameof(RootDialog))
        {
            string[] paths    = { ".", "Dialogs", $"RootDialog.lg" };
            var      fullPath = Path.Combine(paths);

            _templates = Templates.ParseFile(fullPath);

            Triggers = new List <OnCondition>
            {
                new OnConversationUpdateActivity()
                {
                    Actions = WelcomeUserSteps()
                },
                new OnUnknownIntent()
                {
                    Actions = new List <Dialog>()
                    {
                        new TextInput()
                        {
                            Prompt        = new ActivityTemplate("${NamePrompt()}"),
                            Property      = "user.Name",
                            AlwaysPrompt  = true,
                            InvalidPrompt = new ActivityTemplate("${InvalidName()}"),
                            Validations   = new List <BoolExpression>
                            {
                                new BoolExpression("length(this.value) > 0")
                            }
                        },
                        new SendActivity("${GreetWithName()}"),
                        new NumberInput()
                        {
                            Prompt        = new ActivityTemplate("${AgePrompt()}"),
                            Property      = "user.Age",
                            AlwaysPrompt  = true,
                            InvalidPrompt = new ActivityTemplate("${InvalidAge()}"),
                            Validations   = new List <BoolExpression>()
                            {
                                new BoolExpression("this.value >= 18"),
                                new BoolExpression("this.value <= 120")
                            }
                        },
                        new SendActivity("${AckAge()}"),
                        new DateTimeInput()
                        {
                            Prompt       = new ActivityTemplate("${FlightPrompt()}"),
                            Property     = "dialog.TravelDate",
                            AlwaysPrompt = true,
                            Validations  = new List <BoolExpression>()
                            {
                                "isDefinite(this.value[0].timex)"
                            },
                            InvalidPrompt = new ActivityTemplate("${InvalidDate()}")
                        },
                        new SetProperty()
                        {
                            Property = "user.TravelDate",
                            Value    = "=formatDateTime(dialog.TravelDate[0].Value, 'MM/dd/yyyy')"
                        },
                        new SendActivity("${SummaryInfo()}"),
                        new SendActivity("${ThankYouMessage()}"),
                        new SendActivity("${RestartPrompt()}")
                    }
                }
            };

            Generator = new TemplateEngineLanguageGenerator(_templates);
        }