public BuilderDeskNotificationReceiver(
     BuilderSettings settings,
     IStateManager stateManager,
     ISender sender,
     IContextProvider contextProvider,
     IDocumentSerializer documentSerializer,
     IEnvelopeSerializer envelopeSerializer,
     IArtificialIntelligenceExtension artificialIntelligenceExtension,
     IHelpDeskExtension helpDeskExtension,
     IUserOwnerResolver userOwnerResolver)
 {
     _settings          = settings;
     _stateManager      = stateManager;
     _sender            = sender;
     _contextProvider   = contextProvider;
     _helpDeskExtension = helpDeskExtension;
     _userOwnerResolver = userOwnerResolver;
     _lazyInput         = new LazyInput(
         new Message(),
         new Identity(),
         _settings.Flow.BuilderConfiguration,
         documentSerializer,
         envelopeSerializer,
         artificialIntelligenceExtension,
         CancellationToken.None);
 }
        private async Task <string> GetAnalyzedContentAsync(LazyInput input)
        {
            var analyzedContent = await input.AnalyzedContent;

            return(analyzedContent != default(AnalysisResponse)
                ? _documentSerializer.Serialize(analyzedContent)
                : default);
 public ActionTestsBase()
 {
     Context.Flow.Returns(Flow);
     From    = UserIdentity.ToNode();
     To      = OwnerIdentity.ToNode();
     Message = new Message()
     {
         From    = From,
         To      = To,
         Content = new PlainText()
         {
             Text = "Hello BLiP"
         }
     };
     Input = new LazyInput(
         Message,
         UserIdentity,
         new BuilderConfiguration(),
         new DocumentSerializer(new DocumentTypeResolver()),
         new EnvelopeSerializer(new DocumentTypeResolver()),
         null,
         CancellationToken);
     Context.Input.Returns(Input);
     Context.OwnerIdentity.Returns(OwnerIdentity);
     Context.UserIdentity.Returns(UserIdentity);
 }
 public TunnelVariableProviderTests()
 {
     TunnelExtension      = Substitute.For <ITunnelExtension>();
     BuilderConfiguration = new BuilderConfiguration();
     Message      = new Message();
     UserIdentity = new Identity("user", "msging.net");
     LazyInput    = new LazyInput(
         Message,
         UserIdentity,
         BuilderConfiguration,
         Substitute.For <IDocumentSerializer>(),
         Substitute.For <IEnvelopeSerializer>(),
         Substitute.For <IArtificialIntelligenceExtension>(),
         CancellationToken);
     Context.Input.Returns(LazyInput);
     Owner               = new Identity("owner", "msging.net");
     Originator          = new Node("originator", "msging.net", "instance");
     TunnelIdentity      = new Identity(EnvelopeId.NewId(), Take.Blip.Client.Extensions.Tunnel.TunnelExtension.TunnelAddress.Domain);
     ApplicationIdentity = new Identity("application", "msging.net");
     Message.To          = ApplicationIdentity.ToNode();
     Tunnel              = new Tunnel()
     {
         Owner       = Owner,
         Originator  = Originator,
         Destination = ApplicationIdentity
     };
 }
        private async Task <string> GetIntentVariableAsync(LazyInput input, string intentProperty)
        {
            var intent = await input.GetIntentAsync();

            if (intent == null)
            {
                return(null);
            }

            switch (intentProperty)
            {
            case "id":
                return(intent.Id);

            case "name":
                return(intent.Name);

            case "score":
                return(intent.Score?.ToString(CultureInfo.InvariantCulture));

            case "answer":
                var document = intent.Answer?.Value;
                if (document == null)
                {
                    return(null);
                }
                return(_documentSerializer.Serialize(document));
            }

            return(null);
        }
Esempio n. 6
0
        public async Task MessageWithoutMetadataShouldNotExecuteArtificialIntelligenceAnalyse()
        {
            // Arrange
            var requestJson = "{\"dialogState\":\"STARTED\",\"intent\":{\"confirmationStatus\":\"NONE\",\"name\":\"PlanMyTrip\",\"slots\":{\"fromCity\":{\"confirmationStatus\":\"NONE\",\"name\":\"fromCity\"},\"SlotName\":{\"confirmationStatus\":\"NONE\",\"name\":\"string\",\"resolutions\":{\"resolutionsPerAuthority\":[{\"authority\":\"string\",\"status\":{\"code\":\"ER_SUCCESS_MATCH\"},\"values\":[{\"value\":{\"name\":\"string\",\"id\":\"string\"}}]}]},\"value\":\"string\"},\"toCity\":{\"confirmationStatus\":\"NONE\",\"name\":\"toCity\",\"value\":\"Chicago\"},\"travelDate\":{\"confirmationStatus\":\"NONE\",\"name\":\"travelDate\"}}},\"locale\":\"en-US\",\"reason\":\"USER_INITIATED\",\"requestId\":\"amzn1.echo-api.request.1\",\"timestamp\":\"2019-03-23T00:34:14.000Z\",\"type\":\"IntentRequest\"}";
            var json        = JsonConvert.DeserializeObject <Dictionary <string, object> >(requestJson);

            var messageWithAnalyzable = new Message()
            {
                Content = new JsonDocument(json, MediaType.ApplicationJson)
            };

            var jsonInput = new LazyInput(
                messageWithAnalyzable,
                UserIdentity,
                new BuilderConfiguration(),
                new DocumentSerializer(new DocumentTypeResolver()),
                new EnvelopeSerializer(new DocumentTypeResolver()),
                ArtificialIntelligenceExtension,
                CancellationToken);

            // Act
            await jsonInput.AnalyzedContent;

            // Assert
            await ArtificialIntelligenceExtension.Received(0).AnalyzeAsync(
                Arg.Any <AnalysisRequest>(), Arg.Any <CancellationToken>()
                );
        }
Esempio n. 7
0
        public ContextBaseTests()
        {
            var documentTypeResolver = new DocumentTypeResolver().WithMessagingDocuments();

            ArtificialIntelligenceExtension = Substitute.For <IArtificialIntelligenceExtension>();
            ContactExtension           = Substitute.For <IContactExtension>();
            TunnelExtension            = Substitute.For <ITunnelExtension>();
            Logger                     = Substitute.For <ILogger>();
            Configuration              = Substitute.For <IConfiguration>();
            CacheOwnerCallerContactMap = new CacheOwnerCallerContactMap();
            Sender                     = Substitute.For <ISender>();
            Flow = new Flow()
            {
                Id            = "0",
                Configuration = new Dictionary <string, string>()
            };
            User        = "******";
            Application = "*****@*****.**";
            Input       = new LazyInput(
                new Message()
            {
                From    = User.ToNode(),
                To      = Application.ToNode(),
                Content = new PlainText()
                {
                    Text = "Hello world!"
                }
            },
                Flow.BuilderConfiguration,
                new DocumentSerializer(documentTypeResolver),
                new EnvelopeSerializer(documentTypeResolver),
                ArtificialIntelligenceExtension,
                CancellationToken);
            Configuration.ContactCacheExpiration.Returns(TimeSpan.FromMinutes(5));
        }
Esempio n. 8
0
        public async Task <bool> EvaluateConditionAsync(
            LazyInput lazyInput,
            IContext context,
            CancellationToken cancellationToken)
        {
            string comparisonValue;

            switch (Source)
            {
            case ValueSource.Input:
                comparisonValue = lazyInput.SerializedContent;
                break;

            case ValueSource.Context:
                comparisonValue = await context.GetVariableAsync(Variable, cancellationToken);

                break;

            case ValueSource.Intent:
                comparisonValue = (await lazyInput.GetIntentAsync())?.Name;
                break;

            case ValueSource.Entity:
                comparisonValue = (await lazyInput.GetEntityValue(Entity))?.Value;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            switch (Comparison.GetComparisonType())
            {
            case ComparisonType.Unary:
                var unaryComparisonFunc = Comparison.ToUnaryDelegate();

                return(unaryComparisonFunc(comparisonValue));

            case ComparisonType.Binary:
                var binaryComparisonFunc = Comparison.ToBinaryDelegate();

                switch (Operator)
                {
                case ConditionOperator.Or:
                    return(Values.Any(v => binaryComparisonFunc(comparisonValue, v)));

                case ConditionOperator.And:
                    return(Values.All(v => binaryComparisonFunc(comparisonValue, v)));

                default:
                    throw new ArgumentOutOfRangeException();
                }

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Esempio n. 9
0
        public async Task CheckIfAssistantResultWithoutCombinationsIsValid()
        {
            // Arrange
            LazyInput = new LazyInput(NoIntentMessage, UserIdentiy, BuilderConfiguration, DocumentSerializer, null, ArtificialIntelligenceExtension, CancellationToken);
            Context   = new ExtensionContext("me", "app", LazyInput, new Flow(), new List <InputVariableProvider>(), null);
            var target = GetTarget();

            // Act
            var actualId = await target.GetVariableAsync("contentAssistant.id", Context, CancellationToken);

            // Assert
            actualId.ShouldBe(NoContentResult.Id);
        }
        public async Task CheckIfMultipleIntentsAndEntitiesVariableIsValid()
        {
            // Arrange
            LazyInput = new LazyInput(MultipleIntentsAndEntitiesMessage, UserIdentiy, BuilderConfiguration, DocumentSerializer, null, ArtificialIntelligenceExtension, CancellationToken);
            Context   = new ExtensionContext("me", "app", LazyInput, new Builder.Models.Flow(), new List <InputVariableProvider>(), null);
            var target = GetTarget();

            // Act
            var actual = await target.GetVariableAsync("analysis", Context, CancellationToken);

            // Assert
            actual.ShouldBe(DocumentSerializer.Serialize(MultipleIntentsAndEntitiesResponse));
        }
        public static async Task <bool> EvaluateConditionsAsync(
            this IEnumerable <Condition> conditions,
            LazyInput lazyInput,
            IContext context,
            CancellationToken cancellationToken)
        {
            foreach (var outputCondition in conditions)
            {
                if (!await outputCondition.EvaluateConditionAsync(lazyInput, context, cancellationToken))
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 12
0
        public async Task CheckIfAssistantResultWithIntentAndMultipleEntitiesCombinationIsValid()
        {
            // Arrange
            LazyInput = new LazyInput(MultipleIntentsAndEntitiesMessage, UserIdentiy, BuilderConfiguration, DocumentSerializer, null, ArtificialIntelligenceExtension, CancellationToken);
            Context   = new ExtensionContext("me", "app", LazyInput, new Flow(), new List <InputVariableProvider>(), null);
            var target = GetTarget();

            // Act
            var actualValue = await target.GetVariableAsync("contentAssistant.result", Context, CancellationToken);

            var actualId = await target.GetVariableAsync("contentAssistant.id", Context, CancellationToken);

            // Assert
            actualValue.ShouldBe(ContentResultWithIntentAndMultipleEntities.Result.Content.ToString());
            actualId.ShouldBe(ContentResultWithIntentAndMultipleEntities.Id);
        }
Esempio n. 13
0
        public FlowManagerTestsBase()
        {
            SchedulerExtension = Substitute.For <ISchedulerExtension>();
            BucketExtension    = Substitute.For <IBucketExtension>();
            ArtificialIntelligenceExtension = Substitute.For <IArtificialIntelligenceExtension>();
            EventTrackExtension             = Substitute.For <IEventTrackExtension>();
            BroadcastExtension = Substitute.For <IBroadcastExtension>();
            ContactExtension   = Substitute.For <IContactExtension>();
            HelpDeskExtension  = Substitute.For <IHelpDeskExtension>();
            TunnelExtension    = Substitute.For <ITunnelExtension>();
            Sender             = Substitute.For <ISender>();
            StateManager       = Substitute.For <IStateManager>();
            ContextProvider    = Substitute.For <IContextProvider>();
            Context            = Substitute.For <IContext>();
            Logger             = new LoggerConfiguration().CreateLogger();
            ContextProvider
            .CreateContext(Arg.Any <Identity>(), Arg.Any <Identity>(), Arg.Any <LazyInput>(), Arg.Any <Flow>())
            .Returns(Context);
            UserIdentity        = new Identity("user", "domain");
            ApplicationIdentity = new Identity("application", "domain");
            Application         = new Application()
            {
                Identifier = ApplicationIdentity.Name,
                Domain     = ApplicationIdentity.Domain
            };
            Message = new Message()
            {
                From = UserIdentity.ToNode(),
                To   = ApplicationIdentity.ToNode()
            };
            Context.UserIdentity.Returns(UserIdentity);
            Input = new LazyInput(
                Message,
                UserIdentity,
                new BuilderConfiguration(),
                Substitute.For <IDocumentSerializer>(),
                Substitute.For <IEnvelopeSerializer>(),
                ArtificialIntelligenceExtension,
                CancellationToken);
            Context.Input.Returns(Input);

            TraceProcessor    = Substitute.For <ITraceProcessor>();
            UserOwnerResolver = Substitute.For <IUserOwnerResolver>();
            UserOwnerResolver
            .GetUserOwnerIdentitiesAsync(Arg.Any <Message>(), Arg.Any <BuilderConfiguration>(), Arg.Any <CancellationToken>())
            .Returns(new UserOwner(UserIdentity, ApplicationIdentity));
        }
Esempio n. 14
0
 public ActionTestsBase()
 {
     Context = Substitute.For <IContext>();
     From    = new Node(Guid.NewGuid().ToString(), "msging.net", "");
     Message = new Message()
     {
         From = From
     };
     Input = new LazyInput(
         Message,
         new BuilderConfiguration(),
         new DocumentSerializer(new DocumentTypeResolver()),
         new EnvelopeSerializer(new DocumentTypeResolver()),
         null,
         CancellationToken);
     Context.Input.Returns(Input);
 }
        private async Task <string> GetCurrentStateAsync(Message message, CancellationToken cancellationToken)
        {
            var(userIdentity, ownerIdentity) = await _userOwnerResolver.GetUserOwnerIdentitiesAsync(
                message, _settings.Flow.BuilderConfiguration, cancellationToken);

            var lazyInput = new LazyInput(
                message,
                userIdentity,
                _settings.Flow.BuilderConfiguration,
                _documentSerializer,
                _envelopeSerializer,
                _artificialIntelligenceExtension,
                cancellationToken);

            var context = _contextProvider.CreateContext(userIdentity, ownerIdentity, lazyInput, _settings.Flow);

            return(await _stateManager.GetStateIdAsync(context, cancellationToken));
        }
        public ContextBaseTests()
        {
            var documentTypeResolver = new DocumentTypeResolver().WithMessagingDocuments();

            ArtificialIntelligenceExtension = Substitute.For <IArtificialIntelligenceExtension>();
            ContactExtension  = Substitute.For <IContactExtension>();
            HelpDeskExtension = Substitute.For <IHelpDeskExtension>();
            TunnelExtension   = Substitute.For <ITunnelExtension>();
            Logger            = Substitute.For <ILogger>();
            Configuration     = Substitute.For <IConfiguration>();
            Sender            = Substitute.For <ISender>();
            Flow = new Flow()
            {
                Id            = "0",
                Configuration = new Dictionary <string, string>()
            };
            User        = "******";
            Application = new Application()
            {
                Identifier = "application",
                Domain     = "msging.net",
                Instance   = "default"
            };
            Input = new LazyInput(
                new Message()
            {
                From    = User.ToNode(),
                To      = ApplicationIdentity.ToNode(),
                Content = new PlainText()
                {
                    Text = "Hello world!"
                }
            },
                User,
                Flow.BuilderConfiguration,
                new DocumentSerializer(documentTypeResolver),
                new EnvelopeSerializer(documentTypeResolver),
                ArtificialIntelligenceExtension,
                CancellationToken);
        }
Esempio n. 17
0
 public ContextTests()
 {
     ValuesDictionary = new Dictionary <string, Document>(StringComparer.InvariantCultureIgnoreCase);
     ArtificialIntelligenceExtension = Substitute.For <IArtificialIntelligenceExtension>();
     ContextExtension = new DictionaryContextExtension(ValuesDictionary);
     ContactExtension = Substitute.For <IContactExtension>();
     Sender           = Substitute.For <ISender>();
     Flow             = new Flow()
     {
         Id            = "0",
         Configuration = new Dictionary <string, string>()
     };
     User  = "******";
     Input = new LazyInput(new PlainText()
     {
         Text = "Hello world!"
     },
                           Flow.Configuration,
                           new DocumentSerializer(),
                           new JsonNetSerializer(),
                           ArtificialIntelligenceExtension,
                           CancellationToken);
 }
        private async Task <string> GetEntityVariableAsync(LazyInput input, string entityName, string entityProperty)
        {
            var entity = await input.GetEntityValue(entityName);

            if (entity == null)
            {
                return(null);
            }

            switch (entityProperty)
            {
            case "id":
                return(entity.Id);

            case "name":
                return(entity.Name);

            case "value":
                return(entity.Value);
            }

            return(null);
        }