Exemplo n.º 1
0
        private void AddDisableDataset(string query, AutofillId[] autofillIds, FillResponse.Builder responseBuilder, bool isManual)
        {
            bool isQueryDisabled = IsQueryDisabled(query);

            if (isQueryDisabled && !isManual)
            {
                return;
            }
            bool isForDisable = !isQueryDisabled;
            var  sender       = IntentBuilder.GetDisableIntentSenderForResponse(this, query, isManual, isForDisable);

            RemoteViews presentation = AutofillHelper.NewRemoteViews(PackageName,
                                                                     GetString(isForDisable ? Resource.String.autofill_disable : Resource.String.autofill_enable_for, new Java.Lang.Object[] { GetDisplayNameForQuery(query, this) }), Resource.Drawable.ic_menu_close_grey);

            var datasetBuilder = new Dataset.Builder(presentation);

            datasetBuilder.SetAuthentication(sender);

            foreach (var autofillId in autofillIds)
            {
                datasetBuilder.SetValue(autofillId, AutofillValue.ForText("PLACEHOLDER"));
            }

            responseBuilder.AddDataset(datasetBuilder.Build());
        }
Exemplo n.º 2
0
        //FR-10.1: Getting the jobs assigned for the day
        //FR-10.2: Requesting the jobs assigned for the day
        //FR-10.3: Requesting jobs assigned for the day when there aren’t any

        public Intent DefineIntent()
        {
            return(IntentBuilder.For(Constants.Intents.GetAssignedVisits)
                   .TriggerOn("Can you tell me what visits I have today?")
                   .TriggerOn("Can you tell me my visits for the day?")
                   .TriggerOn("Can you tell what my visits are for the day?")
                   .TriggerOn("Could you tell what my visits are for the day?")
                   .TriggerOn("Can you tell me what visits I have for the day?")
                   .TriggerOn("Can you tell me what visits I have?")
                   .TriggerOn("Could you tell me what visits I have?")
                   .TriggerOn("Get visits assigned to me for today.")
                   .TriggerOn("Get my visits for today.")
                   .TriggerOn("Get my visits for the day.")
                   .TriggerOn("What are my visits today.")
                   .TriggerOn("What visits do I have today?")
                   .TriggerOn("What are my jobs today?")
                   .TriggerOn("Tell me what are my visits today.")
                   .TriggerOn("Tell me my visits today.")
                   .TriggerOn("Tell my my jobs today")
                   .TriggerOn("What do I do today.")
                   .TriggerOn("What do I have to do today.")
                   .TriggerOn("Get visits")
                   .TriggerOn("Get today's visits")
                   .TriggerOn("Get my visits")
                   .TriggerOn("Get my visits for the day")
                   .TriggerOn("Could you get my visits?")
                   .TriggerOn("Get jobs for today")
                   .TriggerOn("Get my jobs for today")
                   .TriggerOn("Can you get my jobs for today")
                   .FulfillWithWebhook()
                   .Build());
        }
Exemplo n.º 3
0
        public void ReturnAFullyPopulatedIntentIfAddAllIsCalled()
        {
            string       expectedName      = string.Empty.GetRandom();
            string       expectedUtterance = string.Empty.GetRandom();
            string       expectedResponse  = string.Empty.GetRandom();
            double       expectedScore     = (0.99).GetRandom();
            IntentEntity expectedEntity1   = new IntentEntity()
            {
                Name = string.Empty.GetRandom(), Type = string.Empty.GetRandom()
            };
            IntentEntity expectedEntity2 = new IntentEntity()
            {
                Name = string.Empty.GetRandom(), Type = string.Empty.GetRandom()
            };

            var target = new IntentBuilder();
            var actual = target
                         .AddAll(expectedName, expectedScore,
                                 expectedUtterance, expectedResponse,
                                 expectedEntity1, expectedEntity2)
                         .Build();

            Assert.Equal(expectedName, actual.Name);
            Assert.Equal(expectedScore, actual.Score);
            Assert.Equal(expectedUtterance, actual.Utterance);
            Assert.Equal(expectedResponse, actual.IntentResponse);
            Assert.Equal(2, actual.IntentEntities.Count());
            Assert.Equal(expectedEntity1.Name, actual.IntentEntities.Single(e => e.Type == expectedEntity1.Type).Name);
            Assert.Equal(expectedEntity2.Name, actual.IntentEntities.Single(e => e.Type == expectedEntity2.Type).Name);
        }
Exemplo n.º 4
0
        public void ReturnAnIntentInstance()
        {
            var target = new IntentBuilder();
            var actual = target.Build();

            Assert.NotNull(actual);
        }
Exemplo n.º 5
0
        protected override void _PreRender(CancellationTokenSource tokenSource = null)
        {
            _elementData = new EffectIntents();

            IEnumerable <ElementNode> targetNodes = GetNodesToRenderOn();

            List <IndividualTwinkleDetails> twinkles = null;

            if (!IndividualElements)
            {
                twinkles = GenerateTwinkleData();
            }

            int    totalNodes = targetNodes.Count();
            double i          = 0;

            foreach (ElementNode node in targetNodes)
            {
                if (tokenSource != null && tokenSource.IsCancellationRequested)
                {
                    return;
                }

                if (node != null)
                {
                    bool discreteColors = HasDiscreteColors && ColorModule.isElementNodeDiscreteColored(node);
                    var  intents        = RenderElement(node, i++ / totalNodes, discreteColors, twinkles);
                    _elementData.Add(IntentBuilder.ConvertToStaticArrayIntents(intents, TimeSpan, discreteColors));
                }
            }
        }
Exemplo n.º 6
0
        public async Task RouteAnKnownIntentToTheProperHandler()
        {
            string intentName = "hijklmnop";
            string routeUri   = $"http://www.{intentName}.com";

            var containerBuilder    = new Autofac.ContainerBuilder();
            var httpResponseMessage = new Mock <IHttpResponseMessage>();
            var httpResponseTask    = Task.Run(() => httpResponseMessage.Object);

            httpResponseMessage.SetupGet(m => m.Content).Returns(_routesJson);

            var httpProxy = new Mock <IHttpProxy>();

            httpProxy.Setup(p => p.GetAsync(It.IsAny <string>(), It.IsAny <IEnumerable <KeyValuePair <string, string> > >())).Returns(httpResponseTask);
            containerBuilder.RegisterInstance <IHttpProxy>(httpProxy.Object);

            var cmdProcessor = new Mock <ICommandProcessor>(MockBehavior.Loose);

            containerBuilder.RegisterInstance <ICommandProcessor>(cmdProcessor.Object);

            var intent  = new IntentBuilder().Random().AddName(intentName);
            var request = new UserRequestBuilder().Random().AddIntent(intent).Build();

            var serviceProvider = new AutofacServiceProvider(containerBuilder.Build());

            var target = new DataServiceRouter.Engine(serviceProvider, string.Empty);
            var actual = await target.HandleRequestAsync(request);

            cmdProcessor.Verify(p => p.ProcessAsync(routeUri, It.IsAny <UserRequest>()), Times.Once);
        }
        public async Task RouteAnKnownIntentToTheProperHandler()
        {
            string intentName = string.Empty.GetRandom();
            string routeUri   = $"http://www.{intentName}.com";

            var cmdProcessor = new Mock <ICommandProcessor>(MockBehavior.Loose);

            var routes = new RouteCollectionBuilder(string.Empty.GetRandom())
                         .Add(intentName, routeUri).Build().AsJsonString();
            var routeCollection = new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("intentRoutes", routes)
            };
            var config = new ConfigurationBuilder().AddInMemoryCollection(routeCollection).Build();

            var containerBuilder = new Autofac.ContainerBuilder();

            containerBuilder.RegisterInstance <ICommandProcessor>(cmdProcessor.Object);
            containerBuilder.RegisterInstance <IConfiguration>(config);
            var serviceProvider = new AutofacServiceProvider(containerBuilder.Build());

            var intent  = new IntentBuilder().Random().AddName(intentName);
            var request = new UserRequestBuilder().Random().AddIntent(intent).Build();

            var target = new ConfigRouter.Engine(serviceProvider);
            var actual = await target.HandleRequestAsync(request);

            cmdProcessor.Verify(p => p.ProcessAsync(routeUri, It.IsAny <UserRequest>()), Times.Once);
        }
 public Intent DefineIntent()
 {
     return(IntentBuilder.CancelRequestFor(Constants.Intents.CancelQuoteNumberRequestedModifyQuote)
            .RequiresContext(Constants.Contexts.QuoteNumberRequested)
            .RespondsWith("Okay. I won't change any quotes.")
            .Build());
 }
        protected void RestartApp()
        {
            Intent intent = IntentBuilder.GetRestartAppIntent(this);

            StartActivity(intent);
            Finish();
        }
Exemplo n.º 10
0
 //FR-4.4: Requesting for the list of visits that should be marked complete when it exists
 //FR-4.6: Invalid responds to list visits that should be marked complete
 public Intent DefineIntent()
 {
     return(IntentBuilder.YesRequestFor(Constants.Intents.GetCompletableVisitsDetails)
            .RequiresContext(Constants.Contexts.AskedIfUserWantsCompletableDetails)
            .FulfillWithWebhook()
            .Build());
 }
        public async Task RouteAnKnownIntentToTheProperHandlerUsingAJsonConfigFile()
        {
            string intentName = "hijklmnop";
            string routeUri   = $"http://www.{intentName}.com";

            var cmdProcessor = new Mock <ICommandProcessor>(MockBehavior.Loose);

            var config = new ConfigurationBuilder()
                         .AddJsonFile("routes.json")
                         .Build();

            var containerBuilder = new Autofac.ContainerBuilder();

            containerBuilder.RegisterInstance <ICommandProcessor>(cmdProcessor.Object);
            containerBuilder.RegisterInstance <IConfiguration>(config);
            var serviceProvider = new AutofacServiceProvider(containerBuilder.Build());

            var intent  = new IntentBuilder().Random().AddName(intentName);
            var request = new UserRequestBuilder().Random().AddIntent(intent).Build();

            var target = new ConfigRouter.Engine(serviceProvider);
            var actual = await target.HandleRequestAsync(request);

            cmdProcessor.Verify(p => p.ProcessAsync(routeUri, It.IsAny <UserRequest>()), Times.Once);
        }
Exemplo n.º 12
0
        //FR-9.1: Getting the amount of jobs assigned for the day
        //FR-9.2: Requesting for the amount of jobs assigned to them for the day when there isn’t any
        //FR-9.3: Requesting for the amount of jobs assigned to them for the day when there is only one
        //FR-9.4: Requesting for the amount of jobs assigned to them for the day when there is multiple

        public Intent DefineIntent()
        {
            return(IntentBuilder.For(Constants.Intents.GetAmountVisits)
                   .TriggerOn("How many visits do I have?")
                   .TriggerOn("How many visits do I have today?")
                   .TriggerOn("How many sites do I need to visit today?")
                   .TriggerOn("How many sites do I need to visit?")
                   .TriggerOn("How many jobs do I have today?")
                   .TriggerOn("How many jobs do I have?")
                   .TriggerOn("Could you let me know how many places I need to go to today?")
                   .TriggerOn("Could you let me know how many jobs I have?")
                   .TriggerOn("Could you let me know how many visits I have?")
                   .TriggerOn("Could you let me know how many visits I have today?")
                   .TriggerOn("Tell me how many visits I have today.")
                   .TriggerOn("Tell me number of visits today")
                   .TriggerOn("Tell me how many jobs today")
                   .TriggerOn("Tell me how many visits today")
                   .TriggerOn("What is the number of visits today")
                   .TriggerOn("What is the number of jobs today")
                   .TriggerOn("How much work do I have today")
                   .TriggerOn("How much work do I have")
                   .TriggerOn("How much work today")
                   .TriggerOn("How many jobs today")
                   .TriggerOn("How many visits today")
                   .TriggerOn("Can you let me know how many jobs I have?")
                   .TriggerOn("Get todays visits")
                   .FulfillWithWebhook()
                   .Build());
        }
Exemplo n.º 13
0
        //FR-3.6: Specifying the new valid quote cash value
        //FR-3.7: Specifying an invalid new quote cash value

        public Intent DefineIntent()
        {
            return(IntentBuilder.For(Constants.Intents.NewQuoteRequestedModifyQuote)
                   .RequiresContext(Constants.Contexts.QuoteDetailsSet)
                   .TriggerOn($"[{Entity.Any}:{Constants.Variables.ServiceName}:Mowing]")
                   .TriggerOn($"Could you please change " +
                              $"[{Entity.Any}:{Constants.Variables.ServiceName}:Mowing] to " +
                              $"$[{Entity.Number}:{Constants.Variables.Price}:20]")
                   .TriggerOn($"Update " +
                              $"[{Entity.Any}:{Constants.Variables.ServiceName}:Mowing] to " +
                              $"$[{Entity.Number}:{Constants.Variables.Price}:20]")
                   .TriggerOn($"Change " +
                              $"[{Entity.Any}:{Constants.Variables.ServiceName}:Mowing] to " +
                              $"$[{Entity.Number}:{Constants.Variables.Price}:20]")
                   .TriggerOn($"Modify " +
                              $"[{Entity.Any}:{Constants.Variables.ServiceName}:Mowing] to " +
                              $"$[{Entity.Number}:{Constants.Variables.Price}:20]")
                   .RequireParameter(ParameterBuilder.Of(Constants.Variables.ServiceName, Entity.Any)
                                     .WithPrompt("What is the name of the service?")
                                     )
                   .RequireParameter(ParameterBuilder.Of(Constants.Variables.Price, Entity.Number)
                                     .WithPrompt("What cost would you like to update it to?")
                                     .WithPrompt("What cost price do you want me to update to?")
                                     )
                   .FulfillWithWebhook()
                   .Build());
        }
        public void ReturnAUserRequestWithTheSpecifiedIntent()
        {
            var intent = new IntentBuilder().Random().Build();
            var actual = new UserRequestBuilder().AddIntent(intent).Build();

            Assert.Equal(intent.Name, actual.Intent.Name);
        }
Exemplo n.º 15
0
 //FR-3.8: Cancel a quote modification when prompted for quote details
 public Intent DefineIntent()
 {
     return(IntentBuilder.CancelRequestFor(Constants.Intents.CancelDescribingModifyQuote)
            .RequiresContext(Constants.Contexts.QuoteDetailsRequested)
            .TriggerOn("Stop modifying quote")
            .RespondsWith("Okay I won't change anything. Talk to you later.")
            .Build());
 }
Exemplo n.º 16
0
        public void ReturnAnIntentWithALead()
        {
            double expected = (1.0).GetRandom();
            var    target   = new IntentBuilder();
            var    actual   = target.AddLead(expected).Build();

            Assert.Equal(expected, actual.Lead);
        }
 public Intent DefineIntent()
 {
     return(IntentBuilder.NoRequestFor(Constants.Intents.DontGetCompletableVisitsDetails)
            .RequiresContext(Constants.Contexts.AskedIfUserWantsCompletableDetails)
            .RespondsWith("Ok, see you later.")
            .RespondsWith("Ok, goodbye.")
            .Build());
 }
Exemplo n.º 18
0
        public void ReturnAnIntentWithAResponse()
        {
            string expected = string.Empty.GetRandom();
            var    target   = new IntentBuilder();
            var    actual   = target.AddResponse(expected).Build();

            Assert.Equal(expected, actual.IntentResponse);
        }
 public Intent DefineIntent()
 {
     return(IntentBuilder.For(Constants.Intents.Laughing)
            .TriggerOn("lol")
            .TriggerOn("haha")
            .TriggerOn("youre funny")
            .RespondsWith("xD")
            .Build());
 }
 public Intent DefineIntent()
 {
     return(IntentBuilder.For("THANK_YOU_EASTER_EGG")
            .TriggerOn("Thanks")
            .TriggerOn("Thank you")
            .TriggerOn("Thanks a lot")
            .RespondsWith("No thanks.")
            .Build());
 }
Exemplo n.º 21
0
 public Intent DefineIntent()
 {
     return(IntentBuilder.For(Constants.Intents.NotWorking)
            .TriggerOn("It's not working?")
            .TriggerOn("Something is broken")
            .TriggerOn("Nothing works")
            .TriggerOn("You're stupid")
            .RespondsWith("It's probably just a null pointer exception.")
            .Build());
 }
 public Intent DefineIntent()
 {
     return(IntentBuilder.For(Constants.Intents.Welcome)
            .RequiresEvent(Events.WELCOME_EVENT)
            .TriggerOn($"Can I talk to {Constants.AssistantName}")
            .TriggerOn("I need to organize my jobs")
            .TriggerOn("I want to manage my jobs")
            .RespondsWith("How can I help?")
            .Build());
 }
 public Intent DefineIntent()
 {
     return(IntentBuilder.For(Constants.Intents.Help)
            .TriggerOn("What can you do.")
            .TriggerOn("What to do")
            .TriggerOn("How to use app")
            .TriggerOn("help")
            .FulfillWithWebhook()
            .Build());
 }
Exemplo n.º 24
0
        public void ReturnAFullyPopulatedIntentIfRandomIsCalled()
        {
            var target = new IntentBuilder();
            var actual = target.Random().Build();

            Assert.NotEqual(string.Empty, actual.Name);
            Assert.NotEqual(0.0, actual.Score);
            Assert.NotEqual(string.Empty, actual.Utterance);
            Assert.NotEqual(string.Empty, actual.IntentResponse);
            Assert.NotEmpty(actual.IntentEntities);
        }
 public Intent DefineIntent()
 {
     return(IntentBuilder.For(Constants.Intents.QuoteNumberRequestedModifyQuote)
            .RequiresContext(Constants.Contexts.QuoteNumberRequested)
            .TriggerOn($"[{Entity.Number}:{Constants.Variables.QuoteNumber}:2]")
            .RequireParameter(ParameterBuilder.Of(Constants.Variables.QuoteNumber, Entity.Number)
                              .WithPrompt("What was the quote number?")
                              )
            .FulfillWithWebhook()
            .Build());
 }
Exemplo n.º 26
0
 public Intent DefineIntent()
 {
     return(IntentBuilder.For(Constants.Intents.WhoAreYou)
            .TriggerOn("Who are you?")
            .TriggerOn("What are you?")
            .TriggerOn("What am I talking to?")
            .TriggerOn("Who am I talking to?")
            .TriggerOn("Who exactly am I talking to?")
            .RespondsWith("I'm just your friendly neighbourhood OctopusApp!")
            .Build());
 }
Exemplo n.º 27
0
        public static EffectIntents RenderNode(IElementNode node, double level, Color color, TimeSpan duration)
        {
            var elementData = new EffectIntents();

            if (node.Element != null && level > 0)
            {
                IIntent intent = IntentBuilder.CreateIntent(color, color, level, level, TimeSpan.FromMilliseconds(duration.TotalMilliseconds));
                elementData.AddIntentForElement(node.Element.Id, intent, TimeSpan.Zero);
            }
            return(elementData);
        }
        private List <Dataset> BuildEntryDatasets(string query, string queryDomain, string queryPackage, AutofillId[] autofillIds, StructureParser parser,
                                                  DisplayWarning warning)
        {
            List <Dataset> result = new List <Dataset>();

            Kp2aLog.Log("AF: BuildEntryDatasets");
            var suggestedEntries = GetSuggestedEntries(query).ToDictionary(e => e.DatasetName, e => e);

            Kp2aLog.Log("AF: BuildEntryDatasets found " + suggestedEntries.Count + " entries");
            foreach (var filledAutofillFieldCollection in suggestedEntries.Values)
            {
                if (filledAutofillFieldCollection == null)
                {
                    continue;
                }

                if (warning == DisplayWarning.None)
                {
                    FilledAutofillFieldCollection partitionData =
                        AutofillHintsHelper.FilterForPartition(filledAutofillFieldCollection, parser.AutofillFields.FocusedAutofillCanonicalHints);

                    Kp2aLog.Log("AF: Add dataset");

                    result.Add(AutofillHelper.NewDataset(this, parser.AutofillFields, partitionData, IntentBuilder));
                }
                else
                {
                    //return an "auth" dataset (actually for just warning the user in case domain/package dont match)
                    var sender =
                        IntentBuilder.GetAuthIntentSenderForWarning(this, query, queryDomain, queryPackage, warning);
                    var datasetName = filledAutofillFieldCollection.DatasetName;
                    if (datasetName == null)
                    {
                        Kp2aLog.Log("AF: dataset name is null");
                        continue;
                    }

                    RemoteViews presentation =
                        AutofillHelper.NewRemoteViews(PackageName, datasetName, AppNames.LauncherIcon);

                    var datasetBuilder = new Dataset.Builder(presentation);
                    datasetBuilder.SetAuthentication(sender);
                    //need to add placeholders so we can directly fill after ChooseActivity
                    foreach (var autofillId in autofillIds)
                    {
                        datasetBuilder.SetValue(autofillId, AutofillValue.ForText("PLACEHOLDER"));
                    }
                    Kp2aLog.Log("AF: Add auth dataset");
                    result.Add(datasetBuilder.Build());
                }
            }

            return(result);
        }
Exemplo n.º 29
0
 public Intent DefineIntent()
 {
     return(IntentBuilder.For(Constants.Intents.Fallback)
            .TriggerOnFallback()
            .RespondsWith("I didn't get that. Can you say it again?")
            .RespondsWith("Can you say that again?")
            .RespondsWith("One more time?")
            .RespondsWith("I didn't quite get that.")
            .RespondsWith("One more time?")
            .Build());
 }
Exemplo n.º 30
0
        public void ReturnADefaultIntentIfNoBuilderMethodsAreCalled()
        {
            var target = new IntentBuilder();
            var actual = target.Build();

            Assert.Equal(string.Empty, actual.Name);
            Assert.Equal(0.0, actual.Score);
            Assert.Equal(string.Empty, actual.Utterance);
            Assert.Equal(string.Empty, actual.IntentResponse);
            Assert.Empty(actual.IntentEntities);
        }