Search in sources :

Example 6 with IntentsClient

use of com.google.cloud.dialogflow.v2.IntentsClient in project java-dialogflow by googleapis.

the class UpdateIntent method updateIntent.

// DialogFlow API Update Intent sample.
public static void updateIntent(String projectId, String intentId, String location, String displayName) throws IOException {
    try (IntentsClient client = IntentsClient.create()) {
        String intentPath = "projects/" + projectId + "/locations/" + location + "/agent/intents/" + intentId;
        Builder intentBuilder = client.getIntent(intentPath).toBuilder();
        intentBuilder.setDisplayName(displayName);
        FieldMask fieldMask = FieldMask.newBuilder().addPaths("display_name").build();
        Intent intent = intentBuilder.build();
        UpdateIntentRequest request = UpdateIntentRequest.newBuilder().setIntent(intent).setLanguageCode("en").setUpdateMask(fieldMask).build();
        // Make API request to update intent using fieldmask
        Intent response = client.updateIntent(request);
        System.out.println(response);
    }
}
Also used : IntentsClient(com.google.cloud.dialogflow.v2.IntentsClient) Builder(com.google.cloud.dialogflow.v2.Intent.Builder) Intent(com.google.cloud.dialogflow.v2.Intent) FieldMask(com.google.protobuf.FieldMask) UpdateIntentRequest(com.google.cloud.dialogflow.v2.UpdateIntentRequest)

Example 7 with IntentsClient

use of com.google.cloud.dialogflow.v2.IntentsClient in project java-dialogflow by googleapis.

the class UpdateIntentIT method setUp.

@Before
public void setUp() throws IOException {
    stdOut = new ByteArrayOutputStream();
    System.setOut(new PrintStream(stdOut));
    try (IntentsClient intentsClient = IntentsClient.create()) {
        com.google.cloud.dialogflow.v2.Intent.Builder intent = Intent.newBuilder();
        intent.setDisplayName("temp_intent_" + UUID.randomUUID().toString());
        UpdateIntentIT.intentPath = intentsClient.createIntent(parent, intent.build()).getName();
        UpdateIntentIT.intentID = UpdateIntentIT.intentPath.split("/")[6];
    }
}
Also used : PrintStream(java.io.PrintStream) IntentsClient(com.google.cloud.dialogflow.v2.IntentsClient) Intent(com.google.cloud.dialogflow.v2.Intent) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Before(org.junit.Before)

Example 8 with IntentsClient

use of com.google.cloud.dialogflow.v2.IntentsClient in project java-dialogflow by googleapis.

the class IntentManagement method listIntents.

// [START dialogflow_list_intents]
/**
 * List intents
 *
 * @param projectId Project/Agent Id.
 * @return Intents found.
 */
public static List<Intent> listIntents(String projectId) throws ApiException, IOException {
    List<Intent> intents = Lists.newArrayList();
    // Instantiates a client
    try (IntentsClient intentsClient = IntentsClient.create()) {
        // Set the project agent name using the projectID (my-project-id)
        AgentName parent = AgentName.of(projectId);
        // Performs the list intents request
        for (Intent intent : intentsClient.listIntents(parent).iterateAll()) {
            System.out.println("====================");
            System.out.format("Intent name: '%s'\n", intent.getName());
            System.out.format("Intent display name: '%s'\n", intent.getDisplayName());
            System.out.format("Action: '%s'\n", intent.getAction());
            System.out.format("Root followup intent: '%s'\n", intent.getRootFollowupIntentName());
            System.out.format("Parent followup intent: '%s'\n", intent.getParentFollowupIntentName());
            System.out.format("Input contexts:\n");
            for (String inputContextName : intent.getInputContextNamesList()) {
                System.out.format("\tName: %s\n", inputContextName);
            }
            System.out.format("Output contexts:\n");
            for (Context outputContext : intent.getOutputContextsList()) {
                System.out.format("\tName: %s\n", outputContext.getName());
            }
            intents.add(intent);
        }
    }
    return intents;
}
Also used : Context(com.google.cloud.dialogflow.v2.Context) IntentsClient(com.google.cloud.dialogflow.v2.IntentsClient) Intent(com.google.cloud.dialogflow.v2.Intent) AgentName(com.google.cloud.dialogflow.v2.AgentName)

Example 9 with IntentsClient

use of com.google.cloud.dialogflow.v2.IntentsClient in project java-dialogflow by googleapis.

the class ListTrainingPhrases method listTrainingPhrases.

// DialogFlow API List Training Phrases sample.
public static void listTrainingPhrases(String projectId, String intentId) throws IOException {
    try (IntentsClient client = IntentsClient.create()) {
        // Set the intent name
        IntentName name = IntentName.of(projectId, intentId);
        // Compose the get-intent request
        GetIntentRequest request = GetIntentRequest.newBuilder().setName(name.toString()).setIntentView(IntentView.INTENT_VIEW_FULL).build();
        // Make API request to update intent
        Intent response = client.getIntent(request);
        // Loop through the results
        for (Intent.TrainingPhrase phrase : response.getTrainingPhrasesList()) {
            System.out.println("***********************************************");
            System.out.println(String.format("Phrase ID: %s", phrase.getName()));
            List<Intent.TrainingPhrase.Part> parts = phrase.getPartsList();
            for (Intent.TrainingPhrase.Part part : parts) {
                System.out.println(String.format("Training Phrase: %s", part.getText()));
            }
        }
    }
}
Also used : IntentsClient(com.google.cloud.dialogflow.v2.IntentsClient) IntentName(com.google.cloud.dialogflow.v2.IntentName) GetIntentRequest(com.google.cloud.dialogflow.v2.GetIntentRequest) Intent(com.google.cloud.dialogflow.v2.Intent)

Example 10 with IntentsClient

use of com.google.cloud.dialogflow.v2.IntentsClient in project java-dialogflow by googleapis.

the class UpdateIntentIT method tearDown.

@After
public void tearDown() throws IOException {
    stdOut = null;
    System.setOut(null);
    IntentsClient client = IntentsClient.create();
    String intentPath = "projects/" + PROJECT_ID + "/locations/global/agent/intents/" + UpdateIntentIT.intentID;
    client.deleteIntent(intentPath);
}
Also used : IntentsClient(com.google.cloud.dialogflow.v2.IntentsClient) After(org.junit.After)

Aggregations

IntentsClient (com.google.cloud.dialogflow.v2.IntentsClient)8 Intent (com.google.cloud.dialogflow.v2.Intent)7 Intent (com.google.cloud.dialogflow.cx.v3.Intent)3 IntentsClient (com.google.cloud.dialogflow.cx.v3.IntentsClient)3 AgentName (com.google.cloud.dialogflow.v2.AgentName)3 ArrayList (java.util.ArrayList)3 Context (com.google.cloud.dialogflow.v2.Context)2 IntentName (com.google.cloud.dialogflow.v2.IntentName)2 FieldMask (com.google.protobuf.FieldMask)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 PrintStream (java.io.PrintStream)2 Before (org.junit.Before)2 Agent (com.google.cloud.dialogflow.cx.v3.Agent)1 Builder (com.google.cloud.dialogflow.cx.v3.Agent.Builder)1 AgentsClient (com.google.cloud.dialogflow.cx.v3.AgentsClient)1 AgentsSettings (com.google.cloud.dialogflow.cx.v3.AgentsSettings)1 GetIntentRequest (com.google.cloud.dialogflow.cx.v3.GetIntentRequest)1 Builder (com.google.cloud.dialogflow.cx.v3.Intent.Builder)1 IntentName (com.google.cloud.dialogflow.cx.v3.IntentName)1 UpdateIntentRequest (com.google.cloud.dialogflow.cx.v3.UpdateIntentRequest)1