예제 #1
0
        public async Task UpdateIntentAsync3()
        {
            Mock <Intents.IntentsClient> mockGrpcClient = new Mock <Intents.IntentsClient>(MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateOperationsClient())
            .Returns(new Mock <Operations.OperationsClient>().Object);
            UpdateIntentRequest request = new UpdateIntentRequest
            {
                Intent       = new Intent(),
                LanguageCode = "languageCode-412800396",
            };
            Intent expectedResponse = new Intent
            {
                IntentName               = new IntentName("[PROJECT]", "[INTENT]"),
                DisplayName              = "displayName1615086568",
                Priority                 = 1165461084,
                IsFallback               = false,
                MlDisabled               = true,
                Action                   = "action-1422950858",
                ResetContexts            = true,
                RootFollowupIntentName   = "rootFollowupIntentName402253784",
                ParentFollowupIntentName = "parentFollowupIntentName-1131901680",
            };

            mockGrpcClient.Setup(x => x.UpdateIntentAsync(request, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <Intent>(Task.FromResult(expectedResponse), null, null, null, null));
            IntentsClient client   = new IntentsClientImpl(mockGrpcClient.Object, null);
            Intent        response = await client.UpdateIntentAsync(request);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
 /// <summary>Snippet for UpdateIntent</summary>
 public void UpdateIntent_RequestObject()
 {
     // Snippet: UpdateIntent(UpdateIntentRequest,CallSettings)
     // Create client
     IntentsClient intentsClient = IntentsClient.Create();
     // Initialize request argument(s)
     UpdateIntentRequest request = new UpdateIntentRequest
     {
         Intent = new Intent(),
     };
     // Make the request
     Intent response = intentsClient.UpdateIntent(request);
     // End snippet
 }
        /// <summary>Snippet for UpdateIntentAsync</summary>
        public async Task UpdateIntentAsync_RequestObject()
        {
            // Snippet: UpdateIntentAsync(UpdateIntentRequest,CallSettings)
            // Additional: UpdateIntentAsync(UpdateIntentRequest,CancellationToken)
            // Create client
            IntentsClient intentsClient = await IntentsClient.CreateAsync();

            // Initialize request argument(s)
            UpdateIntentRequest request = new UpdateIntentRequest
            {
                Intent = new Intent(),
            };
            // Make the request
            Intent response = await intentsClient.UpdateIntentAsync(request);

            // End snippet
        }
        public async stt::Task UpdateIntentRequestObjectAsync()
        {
            moq::Mock <Intents.IntentsClient> mockGrpcClient = new moq::Mock <Intents.IntentsClient>(moq::MockBehavior.Strict);
            UpdateIntentRequest request = new UpdateIntentRequest
            {
                Intent       = new Intent(),
                LanguageCode = "language_code2f6c7160",
                UpdateMask   = new wkt::FieldMask(),
            };
            Intent expectedResponse = new Intent
            {
                IntentName      = IntentName.FromProjectLocationAgentIntent("[PROJECT]", "[LOCATION]", "[AGENT]", "[INTENT]"),
                DisplayName     = "display_name137f65c2",
                TrainingPhrases =
                {
                    new Intent.Types.TrainingPhrase(),
                },
                Parameters =
                {
                    new Intent.Types.Parameter(),
                },
                Priority   = 1546225849,
                IsFallback = true,
                Labels     =
                {
                    {
                        "key8a0b6e3c",
                        "value60c16320"
                    },
                },
                Description = "description2cf9da67",
            };

            mockGrpcClient.Setup(x => x.UpdateIntentAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <Intent>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            IntentsClient client = new IntentsClientImpl(mockGrpcClient.Object, null);
            Intent        responseCallSettings = await client.UpdateIntentAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            Intent responseCancellationToken = await client.UpdateIntentAsync(request, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
        public void UpdateIntent()
        {
            moq::Mock <Intents.IntentsClient> mockGrpcClient = new moq::Mock <Intents.IntentsClient>(moq::MockBehavior.Strict);
            UpdateIntentRequest request = new UpdateIntentRequest
            {
                Intent     = new Intent(),
                UpdateMask = new wkt::FieldMask(),
            };
            Intent expectedResponse = new Intent
            {
                IntentName      = IntentName.FromProjectLocationAgentIntent("[PROJECT]", "[LOCATION]", "[AGENT]", "[INTENT]"),
                DisplayName     = "display_name137f65c2",
                TrainingPhrases =
                {
                    new Intent.Types.TrainingPhrase(),
                },
                Parameters =
                {
                    new Intent.Types.Parameter(),
                },
                Priority   = 1546225849,
                IsFallback = true,
                Labels     =
                {
                    {
                        "key8a0b6e3c",
                        "value60c16320"
                    },
                },
                Description = "description2cf9da67",
            };

            mockGrpcClient.Setup(x => x.UpdateIntent(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            IntentsClient client   = new IntentsClientImpl(mockGrpcClient.Object, null);
            Intent        response = client.UpdateIntent(request.Intent, request.UpdateMask);

            xunit::Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
        public void UpdateIntent2()
        {
            Mock <Intents.IntentsClient> mockGrpcClient = new Mock <Intents.IntentsClient>(MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateOperationsClient())
            .Returns(new Mock <Operations.OperationsClient>().Object);
            UpdateIntentRequest expectedRequest = new UpdateIntentRequest
            {
                Intent       = new Intent(),
                LanguageCode = "languageCode-412800396",
                UpdateMask   = new FieldMask(),
            };
            Intent expectedResponse = new Intent
            {
                IntentName               = new IntentName("[PROJECT]", "[INTENT]"),
                DisplayName              = "displayName1615086568",
                Priority                 = 1165461084,
                IsFallback               = false,
                MlDisabled               = true,
                Action                   = "action-1422950858",
                ResetContexts            = true,
                RootFollowupIntentName   = "rootFollowupIntentName402253784",
                ParentFollowupIntentName = "parentFollowupIntentName-1131901680",
            };

            mockGrpcClient.Setup(x => x.UpdateIntent(expectedRequest, It.IsAny <CallOptions>()))
            .Returns(expectedResponse);
            IntentsClient client       = new IntentsClientImpl(mockGrpcClient.Object, null);
            Intent        intent       = new Intent();
            string        languageCode = "languageCode-412800396";
            FieldMask     updateMask   = new FieldMask();
            Intent        response     = client.UpdateIntent(intent, languageCode, updateMask);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
예제 #7
0
        public AlertModel UpdateIntent(Intencion intencion, List <FraseEntrenamientoModel> frases)
        {
            var intento   = new IntentoModel();
            var resultado = new AlertModel();

            try
            {
                var fileSavePath = System.Web.HttpContext.Current.Server.MapPath("~/Dialogflow.json/") + ConstantesWeb.DialogFlow.FilePrivateKeyIdJson;

                if ((System.IO.File.Exists(fileSavePath)))
                {
                    var cred = GoogleCredential.FromFile(fileSavePath);

                    var channel = new Channel(SessionsClient.DefaultEndpoint.Host, SessionsClient.DefaultEndpoint.Port, cred.ToChannelCredentials());

                    var client = IntentsClient.Create(channel);

                    GetIntentRequest getRequest = new GetIntentRequest
                    {
                        IntentName = new IntentName(ConstantesWeb.DialogFlow.ProjectId, intencion.IdDialogFlow),
                        IntentView = IntentView.Full
                    };


                    var intent = client.GetIntent(getRequest);



                    //Actualizar Frases de Entrenamiento
                    intent.TrainingPhrases.Clear();
                    foreach (var frase_ in frases)
                    {
                        var trainingPhrasesParts = new List <string>();
                        trainingPhrasesParts.Add(frase_.Descripcion);
                        var phraseParts = new List <Intent.Types.TrainingPhrase.Types.Part>();
                        foreach (var part in trainingPhrasesParts)
                        {
                            phraseParts.Add(new Intent.Types.TrainingPhrase.Types.Part()
                            {
                                Text = part
                            });
                        }
                        var trainingPhrase = new Intent.Types.TrainingPhrase();
                        trainingPhrase.Parts.AddRange(phraseParts);
                        intent.TrainingPhrases.Add(trainingPhrase);
                    }

                    //Actualizar Respuesta
                    intent.Messages.Clear();
                    var text = new Intent.Types.Message.Types.Text();
                    text.Text_.Add(intencion.Respuesta);
                    var message_ = new Intent.Types.Message()
                    {
                        Text = text
                    };
                    intent.Messages.Add(message_);


                    UpdateIntentRequest updRequest = new UpdateIntentRequest
                    {
                        Intent = intent
                    };
                    Intent response = client.UpdateIntent(updRequest);


                    resultado.DisplayName = response.DisplayName;
                    resultado.Mensaje     = "UPDATE-OK";
                }
            }
            catch (Exception ex)
            {
                resultado.MessageError = "ERROR: " + ex.Message;
                resultado.Mensaje      = "UPDATE-ERROR";
            }

            return(resultado);
        }