예제 #1
0
 public InputVariableProviderTests()
 {
     BuilderConfiguration            = new BuilderConfiguration();
     DocumentSerializer              = new DocumentSerializer(new DocumentTypeResolver().WithMessagingDocuments());
     ArtificialIntelligenceExtension = Substitute.For <IArtificialIntelligenceExtension>();
     ArtificialIntelligenceExtension
     .AnalyzeAsync(Arg.Is <AnalysisRequest>(r => r.Text == NoIntentInputText), Arg.Any <CancellationToken>())
     .Returns(NoIntentResponse);
     ArtificialIntelligenceExtension
     .AnalyzeAsync(Arg.Is <AnalysisRequest>(r => r.Text == IntentInputText), Arg.Any <CancellationToken>())
     .Returns(IntentResponse);
     ArtificialIntelligenceExtension
     .AnalyzeAsync(Arg.Is <AnalysisRequest>(r => r.Text == IntentAndEntityText), Arg.Any <CancellationToken>())
     .Returns(IntentsAndEntitiesResponse);
     ArtificialIntelligenceExtension
     .AnalyzeAsync(Arg.Is <AnalysisRequest>(r => r.Text == MultipleIntentsAndEntitiesText), Arg.Any <CancellationToken>())
     .Returns(MultipleIntentsAndEntitiesResponse);
     ArtificialIntelligenceExtension
     .GetContentResultAsync(Arg.Is <ContentCombination>(cc => cc.Intent == default), Arg.Any <CancellationToken>())
     .Returns(NoContentResult);
     ArtificialIntelligenceExtension
     .GetContentResultAsync(Arg.Is <ContentCombination>(cc => cc.Intent == LearnIntent.Id), Arg.Any <CancellationToken>())
     .Returns(ContentResultWithIntent);
     ArtificialIntelligenceExtension
     .GetContentResultAsync(Arg.Is <ContentCombination>(cc => cc.Intent == IntentAndEntityCombination.Intent &&
                                                        cc.Entities.SequenceEqual(IntentAndEntityCombination.Entities)), Arg.Any <CancellationToken>())
     .Returns(ContentResultWithIntentAndEntity);
     ArtificialIntelligenceExtension
     .GetContentResultAsync(Arg.Is <ContentCombination>(cc => cc.Intent == IntentAndMultipleEntitiesCombination.Intent &&
                                                        cc.Entities.SequenceEqual(IntentAndMultipleEntitiesCombination.Entities)), Arg.Any <CancellationToken>())
     .Returns(ContentResultWithIntentAndMultipleEntities);
 }
 public InputVariableProviderTests()
 {
     BuilderConfiguration            = new BuilderConfiguration();
     DocumentSerializer              = new DocumentSerializer(new DocumentTypeResolver().WithMessagingDocuments());
     ArtificialIntelligenceExtension = Substitute.For <IArtificialIntelligenceExtension>();
     ArtificialIntelligenceExtension.AnalyzeAsync(Arg.Is <AnalysisRequest>(r => r.Text == NoIntentInputText), Arg.Any <CancellationToken>()).Returns(NoIntentResponse);
     ArtificialIntelligenceExtension.AnalyzeAsync(Arg.Is <AnalysisRequest>(r => r.Text == IntentsAndEntitiesText), Arg.Any <CancellationToken>()).Returns(IntentsAndEntitiesResponse);
     ArtificialIntelligenceExtension.AnalyzeAsync(Arg.Is <AnalysisRequest>(r => r.Text == MultipleIntentsAndEntitiesText), Arg.Any <CancellationToken>()).Returns(MultipleIntentsAndEntitiesResponse);
 }
예제 #3
0
        public async Task ReceiveAsync(Message message, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (!message.Content.ToString().ToLower().Contains("blip"))
            {
                await _sender.SendMessageAsync("Mensagem Padrão", message.From, cancellationToken);

                return;
            }

            ArtificialIntelligenceExtension ia = new ArtificialIntelligenceExtension(_sender);
            AnalysisResponse resposta          = await ia.AnalyzeAsync(new AnalysisRequest()
            {
                Text = message.Content.ToString()
            });

            await _sender.SendMessageAsync(resposta.Intentions.First().Answer.Value, message.From, cancellationToken);
        }
예제 #4
0
        public async Task FlowWithoutEntityConditionsShouldChangeStateAndSendMessage()
        {
            // Arrange
            var input = new PlainText()
            {
                Text = "Ping!"
            };
            var messageType    = "text/plain";
            var messageContent = "This is my entity";
            var entityName     = "My entity name";
            var entityValue    = "My entity value";

            var flow = new Flow()
            {
                Id     = Guid.NewGuid().ToString(),
                States = new[]
                {
                    new State
                    {
                        Id      = "root",
                        Root    = true,
                        Input   = new Input(),
                        Outputs = new[]
                        {
                            new Output
                            {
                                StateId    = "my-entity",
                                Conditions = new[]
                                {
                                    new Condition()
                                    {
                                        Source = ValueSource.Entity,
                                        Entity = entityName,
                                        Values = new[]
                                        {
                                            entityValue
                                        }
                                    }
                                }
                            },
                            new Output
                            {
                                StateId = "ping"
                            }
                        }
                    },
                    new State
                    {
                        Id           = "my-entity",
                        InputActions = new[]
                        {
                            new Action
                            {
                                Type     = "SendMessage",
                                Settings = new JObject()
                                {
                                    { "type", messageType },
                                    { "content", messageContent }
                                }
                            }
                        }
                    },
                    new State
                    {
                        Id           = "ping",
                        InputActions = new[]
                        {
                            new Action
                            {
                                Type     = "SendMessage",
                                Settings = new JObject()
                                {
                                    { "type", messageType },
                                    { "content", "This is not supposed to be received..." }
                                }
                            }
                        }
                    }
                }
            };

            ArtificialIntelligenceExtension
            .AnalyzeAsync(Arg.Is <AnalysisRequest>(r => r.Text == input.Text), Arg.Any <CancellationToken>())
            .Returns(new AnalysisResponse()
            {
                Entities = new[]
                {
                    new EntityResponse()
                    {
                        Name  = entityName,
                        Value = entityValue
                    },
                    new EntityResponse()
                    {
                        Name  = "Other entity name",
                        Value = "Other entity value"
                    }
                }
            });

            var target = GetTarget();

            // Act
            await target.ProcessInputAsync(input, User, flow, CancellationToken);

            // Assert
            ContextProvider.Received(1).CreateContext(User, Arg.Is <LazyInput>(i => i.Content == input), flow);
            StateManager.Received(1).SetStateIdAsync(flow.Id, User, "my-entity", Arg.Any <CancellationToken>());
            StateManager.Received(1).DeleteStateIdAsync(flow.Id, User, Arg.Any <CancellationToken>());
            Sender
            .Received(1)
            .SendMessageAsync(
                Arg.Is <Message>(m =>
                                 m.Id != null &&
                                 m.To.ToIdentity().Equals(User) &&
                                 m.Type.ToString().Equals(messageType) &&
                                 m.Content.ToString() == messageContent),
                Arg.Any <CancellationToken>());
        }