Search in sources :

Example 1 with Intent

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

the class ITSystemTest method getIntentsTest.

@Test
public void getIntentsTest() {
    GetIntentRequest request = GetIntentRequest.newBuilder().setName(intentsName).build();
    Intent intent = intentsClient.getIntent(request);
    assertIntentDetails(intent);
}
Also used : GetIntentRequest(com.google.cloud.dialogflow.cx.v3beta1.GetIntentRequest) Intent(com.google.cloud.dialogflow.cx.v3beta1.Intent) Test(org.junit.Test)

Example 2 with Intent

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

the class ITSystemTest method listIntentsTest.

@Test
public void listIntentsTest() {
    ListIntentsRequest request = ListIntentsRequest.newBuilder().setParent(agentName).build();
    IntentsClient.ListIntentsPagedResponse pagedListResponse = intentsClient.listIntents(request);
    List<Intent> intents = Lists.newArrayList(pagedListResponse.iterateAll());
    boolean isIntentExists = false;
    for (Intent intent : intents) {
        if (intent.getName().equals(intentsName)) {
            assertIntentDetails(intent);
            isIntentExists = true;
        }
    }
    assertTrue(isIntentExists);
}
Also used : IntentsClient(com.google.cloud.dialogflow.cx.v3beta1.IntentsClient) ListIntentsRequest(com.google.cloud.dialogflow.cx.v3beta1.ListIntentsRequest) Intent(com.google.cloud.dialogflow.cx.v3beta1.Intent) Test(org.junit.Test)

Example 3 with Intent

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

the class CreateIntent method createIntent.

// Create an intent of the given intent type.
public static Intent createIntent(String displayName, String projectId, String locationId, String agentId, List<String> trainingPhrasesParts) throws IOException, ApiException {
    IntentsSettings.Builder intentsSettingsBuilder = IntentsSettings.newBuilder();
    if (locationId.equals("global")) {
        intentsSettingsBuilder.setEndpoint("dialogflow.googleapis.com:443");
    } else {
        intentsSettingsBuilder.setEndpoint(locationId + "-dialogflow.googleapis.com:443");
    }
    IntentsSettings intentsSettings = intentsSettingsBuilder.build();
    // Instantiates a client
    try (IntentsClient intentsClient = IntentsClient.create(intentsSettings)) {
        // Set the project agent name using the projectID (my-project-id), locationID (global), and
        // agentID (UUID).
        AgentName parent = AgentName.of(projectId, locationId, agentId);
        // Build the trainingPhrases from the trainingPhrasesParts.
        List<TrainingPhrase> trainingPhrases = new ArrayList<>();
        for (String trainingPhrase : trainingPhrasesParts) {
            trainingPhrases.add(TrainingPhrase.newBuilder().addParts(Part.newBuilder().setText(trainingPhrase).build()).setRepeatCount(1).build());
        }
        // Build the intent.
        Intent intent = Intent.newBuilder().setDisplayName(displayName).addAllTrainingPhrases(trainingPhrases).build();
        // Performs the create intent request.
        Intent response = intentsClient.createIntent(parent, intent);
        return response;
    }
}
Also used : IntentsSettings(com.google.cloud.dialogflow.cx.v3beta1.IntentsSettings) TrainingPhrase(com.google.cloud.dialogflow.cx.v3beta1.Intent.TrainingPhrase) IntentsClient(com.google.cloud.dialogflow.cx.v3beta1.IntentsClient) ArrayList(java.util.ArrayList) Intent(com.google.cloud.dialogflow.cx.v3beta1.Intent) AgentName(com.google.cloud.dialogflow.cx.v3beta1.AgentName)

Example 4 with Intent

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

the class ListTrainingPhrases method listTrainingPhrases.

// DialogFlow API List Training Phrases sample.
public static void listTrainingPhrases(String projectId, String location, String agentId, String intentId) throws IOException {
    try (IntentsClient client = IntentsClient.create()) {
        // Set the intent name
        IntentName name = IntentName.of(projectId, location, agentId, intentId);
        // Compose the get-intent request
        GetIntentRequest request = GetIntentRequest.newBuilder().setName(name.toString()).build();
        // Make API request to get intent
        Intent response = client.getIntent(request);
        // Loop through the results
        for (Intent.TrainingPhrase phrase : response.getTrainingPhrasesList()) {
            System.out.println("***********************************************");
            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.cx.v3.IntentsClient) IntentName(com.google.cloud.dialogflow.cx.v3.IntentName) GetIntentRequest(com.google.cloud.dialogflow.cx.v3.GetIntentRequest) Intent(com.google.cloud.dialogflow.cx.v3.Intent)

Example 5 with Intent

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

the class CreateIntentIT method testCreateIntentRegional.

@Test
public void testCreateIntentRegional() throws Exception {
    Intent result = CreateIntent.createIntent(DISPLAY_NAME, PROJECT_ID, LOCATION_REGIONAL, AGENT_ID_REGIONAL, TRAINING_PHRASES_PARTS);
    newIntentNameRegional = result.getName();
    System.out.println("intent name new:" + newIntentNameRegional);
    assertEquals(result.getTrainingPhrasesCount(), TRAINING_PHRASES_PARTS.size());
    for (TrainingPhrase trainingPhrase : result.getTrainingPhrasesList()) {
        assertEquals(trainingPhrase.getPartsCount(), 1);
        String partText = trainingPhrase.getParts(0).getText();
        assertTrue(partText.equals("red") || partText.equals("blue") || partText.equals("green"));
    }
}
Also used : TrainingPhrase(com.google.cloud.dialogflow.cx.v3beta1.Intent.TrainingPhrase) Intent(com.google.cloud.dialogflow.cx.v3beta1.Intent) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)12 Intent (com.google.cloud.dialogflow.v2.Intent)10 IntentsClient (com.google.cloud.dialogflow.v2.IntentsClient)8 Intent (com.google.cloud.dialogflow.cx.v3beta1.Intent)7 QueryInput (com.google.cloud.dialogflow.v2.QueryInput)5 QueryResult (com.google.cloud.dialogflow.v2.QueryResult)5 SessionName (com.google.cloud.dialogflow.v2.SessionName)5 SessionsClient (com.google.cloud.dialogflow.v2.SessionsClient)5 AgentName (com.google.cloud.dialogflow.v2.AgentName)4 DetectIntentResponse (com.google.cloud.dialogflow.v2.DetectIntentResponse)4 ListIntentsPagedResponse (com.google.cloud.dialogflow.v2.IntentsClient.ListIntentsPagedResponse)4 AbstractMessage (com.google.protobuf.AbstractMessage)4 Intent (com.google.cloud.dialogflow.cx.v3.Intent)3 IntentsClient (com.google.cloud.dialogflow.cx.v3.IntentsClient)3 TrainingPhrase (com.google.cloud.dialogflow.cx.v3beta1.Intent.TrainingPhrase)3 DetectIntentRequest (com.google.cloud.dialogflow.v2.DetectIntentRequest)3 TextInput (com.google.cloud.dialogflow.v2.TextInput)3 FieldMask (com.google.protobuf.FieldMask)3 ArrayList (java.util.ArrayList)3 IntentsClient (com.google.cloud.dialogflow.cx.v3beta1.IntentsClient)2