コード例 #1
0
        public static void CreateNewIntent(string messageText, string trainingPhrasesPart)
        {
            IntentsClient client = IntentsClient.Create();

            Intent.Types.Message.Types.Text text = new Intent.Types.Message.Types.Text();
            text.Text_.Add(messageText);

            Intent.Types.Message message = new Intent.Types.Message()
            {
                Text = text
            };

            List <Intent.Types.TrainingPhrase.Types.Part> phraseParts = new List <Intent.Types.TrainingPhrase.Types.Part>();

            phraseParts.Add(new Intent.Types.TrainingPhrase.Types.Part()
            {
                Text = trainingPhrasesPart
            });

            Intent.Types.TrainingPhrase trainingPhrase = new Intent.Types.TrainingPhrase();
            trainingPhrase.Parts.AddRange(phraseParts);

            Intent intent = new Intent();

            intent.DisplayName = trainingPhrasesPart;
            intent.Messages.Add(message);
            intent.TrainingPhrases.Add(trainingPhrase);

            Intent newIntent = client.CreateIntent(
                parent: new AgentName(projectId),
                intent: intent
                );

            Console.WriteLine($"Created Intent: {newIntent.Name}");
        }
コード例 #2
0
 /// <summary>Snippet for CreateIntent</summary>
 public void CreateIntent1()
 {
     // Snippet: CreateIntent(ProjectAgentName,Intent,CallSettings)
     // Create client
     IntentsClient intentsClient = IntentsClient.Create();
     // Initialize request argument(s)
     ProjectAgentName parent = new ProjectAgentName("[PROJECT]");
     Intent           intent = new Intent();
     // Make the request
     Intent response = intentsClient.CreateIntent(parent, intent);
     // End snippet
 }
コード例 #3
0
 /// <summary>Snippet for CreateIntent</summary>
 public void CreateIntentResourceNames()
 {
     // Snippet: CreateIntent(AgentName, Intent, CallSettings)
     // Create client
     IntentsClient intentsClient = IntentsClient.Create();
     // Initialize request argument(s)
     AgentName parent = AgentName.FromProjectLocationAgent("[PROJECT]", "[LOCATION]", "[AGENT]");
     Intent    intent = new Intent();
     // Make the request
     Intent response = intentsClient.CreateIntent(parent, intent);
     // End snippet
 }
コード例 #4
0
 /// <summary>Snippet for CreateIntent</summary>
 public void CreateIntent()
 {
     // Snippet: CreateIntent(string, Intent, CallSettings)
     // Create client
     IntentsClient intentsClient = IntentsClient.Create();
     // Initialize request argument(s)
     string parent = "projects/[PROJECT]/locations/[LOCATION]/agents/[AGENT]";
     Intent intent = new Intent();
     // Make the request
     Intent response = intentsClient.CreateIntent(parent, intent);
     // End snippet
 }
コード例 #5
0
 /// <summary>Snippet for CreateIntent</summary>
 public void CreateIntent_RequestObject()
 {
     // Snippet: CreateIntent(CreateIntentRequest,CallSettings)
     // Create client
     IntentsClient intentsClient = IntentsClient.Create();
     // Initialize request argument(s)
     CreateIntentRequest request = new CreateIntentRequest
     {
         ParentAsProjectAgentName = new ProjectAgentName("[PROJECT]"),
         Intent = new Intent(),
     };
     // Make the request
     Intent response = intentsClient.CreateIntent(request);
     // End snippet
 }
コード例 #6
0
 /// <summary>Snippet for CreateIntent</summary>
 public void CreateIntentRequestObject()
 {
     // Snippet: CreateIntent(CreateIntentRequest, CallSettings)
     // Create client
     IntentsClient intentsClient = IntentsClient.Create();
     // Initialize request argument(s)
     CreateIntentRequest request = new CreateIntentRequest
     {
         ParentAsAgentName = AgentName.FromProjectLocationAgent("[PROJECT]", "[LOCATION]", "[AGENT]"),
         Intent            = new Intent(),
         LanguageCode      = "",
     };
     // Make the request
     Intent response = intentsClient.CreateIntent(request);
     // End snippet
 }
コード例 #7
0
        public async Task CreateAsync()
        {
            try
            {
                IEnumerable <Model.Intent> intentList =
                    (await _intentService.GetIntentsAsync()).GetMappedResponse <IEnumerable <Model.Intent>, IEnumerable <Model.Intent> >(_mapper);

                if (intentList.Any())
                {
                    IntentsClient client = IntentsClient.Create();
                    foreach (Model.Intent intentResponse in intentList)
                    {
                        Intent intent = new Intent();
                        intent.DefaultResponsePlatforms.Add(Platform.ActionsOnGoogle);
                        intent.DisplayName = intentResponse.DisplayName;
                        intent.Messages.Add(AddIntentDefault(intentResponse.Text));
                        intent.Messages.Add(AddCustomPayload(intentResponse.AllocatedTime));

                        if (intentResponse.ParentIntentId != null)
                        {
                            intent.ParentFollowupIntentName = intentList.Where(x => x.Id == intentResponse.ParentIntentId).FirstOrDefault().DialogflowGeneratedName;
                        }

                        if (intentResponse.InputContext != null)
                        {
                            foreach (string inputContext in intentResponse.InputContext.Split(','))
                            {
                                intent.InputContextNames.Add(AddIntentInputContext(inputContext));
                            }
                        }

                        if (intentResponse.OutputContext != null)
                        {
                            foreach (string outputContext in intentResponse.OutputContext.Split(','))
                            {
                                intent.OutputContexts.Add(AddIntentOutputContext(outputContext));
                            }
                        }

                        if (intentResponse.IntentTrainingPhrase.Any())
                        {
                            foreach (Model.IntentTrainingPhrase trainingPhrase in intentResponse.IntentTrainingPhrase)
                            {
                                intent.TrainingPhrases.Add(AddIntentTrainingPhrase(trainingPhrase));
                            }
                        }

                        if (intentResponse.IntentParameter.Any())
                        {
                            foreach (Model.IntentParameter parameter in intentResponse.IntentParameter)
                            {
                                intent.Parameters.Add(AddIntentParameter(parameter));
                            }
                        }

                        if (intentResponse.IntentSuggestion.Any())
                        {
                            intent.Messages.Add(AddIntentSuggestion(intentResponse.IntentSuggestion.Select(x => x.Title).ToList()));
                        }

                        intent = client.CreateIntent(parent: new ProjectAgentName("ht-interview-chatbot"), intent: intent);
                        intentResponse.DialogflowGeneratedIntentId = intent.IntentName.IntentId;
                        intentResponse.DialogflowGeneratedName     = intent.Name;
                        intentResponse.DialogflowGeneratedIntent   = JsonConvert.SerializeObject(intent);
                        await _intentService.UpdateIntentsAsync(_mapper.Map <Model.Intent>(intentResponse));
                    }
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
        }