Search in sources :

Example 11 with Intent

use of com.google.cloud.dialogflow.cx.v3.Intent 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 12 with Intent

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

the class IntentManagementIT method testCreateIntent.

@Test
public void testCreateIntent() throws Exception {
    // Create the intent
    Intent intent = IntentManagement.createIntent(INTENT_DISPLAY_NAME, PROJECT_ID, TRAINING_PHRASE_PARTS, MESSAGE_TEXTS);
    assertNotNull(intent);
    List<String> intentIds = IntentManagement.getIntentIds(intent.getDisplayName(), PROJECT_ID);
    assertThat(intentIds.size()).isEqualTo(1);
    List<Intent> intents = IntentManagement.listIntents(PROJECT_ID);
    assertTrue(intents.size() > 0);
    assertThat(intents).contains(intent);
    for (String messageText : MESSAGE_TEXTS) {
        assertTrue(intent.getMessagesList().stream().anyMatch(message -> message.getText().toString().contains(messageText)));
    }
    for (String intentId : intentIds) {
        IntentManagement.deleteIntent(intentId, PROJECT_ID);
    }
    int numIntents = intents.size();
    intents = IntentManagement.listIntents(PROJECT_ID);
    assertEquals(numIntents - 1, intents.size());
}
Also used : PrintStream(java.io.PrintStream) Arrays(java.util.Arrays) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Assert.assertNotNull(org.junit.Assert.assertNotNull) RunWith(org.junit.runner.RunWith) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) UUID(java.util.UUID) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) List(java.util.List) Intent(com.google.cloud.dialogflow.v2.Intent) After(org.junit.After) AgentName(com.google.cloud.dialogflow.v2.AgentName) Assert.assertEquals(org.junit.Assert.assertEquals) IntentsClient(com.google.cloud.dialogflow.v2.IntentsClient) Before(org.junit.Before) Intent(com.google.cloud.dialogflow.v2.Intent) Test(org.junit.Test)

Example 13 with Intent

use of com.google.cloud.dialogflow.cx.v3.Intent 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 14 with Intent

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

the class ITSystemTest method listIntentsTest.

@Test
public void listIntentsTest() {
    ListIntentsRequest request = ListIntentsRequest.newBuilder().setParent(PROJECT_AGENT_NAME.toString()).build();
    for (Intent actualIntent : intentsClient.listIntents(request).iterateAll()) {
        if (intent.getName().equals(actualIntent.getName())) {
            assertEquals(intent.getDisplayName(), actualIntent.getDisplayName());
            assertEquals(intent.getAction(), actualIntent.getAction());
            assertEquals(intent.getEvents(0), actualIntent.getEvents(0));
            assertEquals(intent.getEventsCount(), actualIntent.getEventsCount());
        }
    }
}
Also used : ListIntentsRequest(com.google.cloud.dialogflow.v2.ListIntentsRequest) Intent(com.google.cloud.dialogflow.v2.Intent) Test(org.junit.Test)

Example 15 with Intent

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

the class ITSystemTest method getIntentTest.

@Test
public void getIntentTest() {
    GetIntentRequest request = GetIntentRequest.newBuilder().setName(intentName.toString()).build();
    Intent actualIntent = intentsClient.getIntent(request);
    assertEquals(intent.getName(), actualIntent.getName());
    assertEquals(intent.getDisplayName(), actualIntent.getDisplayName());
    assertEquals(intent.getAction(), actualIntent.getAction());
    assertEquals(intent.getEvents(0), actualIntent.getEvents(0));
    assertEquals(intent.getEventsCount(), actualIntent.getEventsCount());
}
Also used : GetIntentRequest(com.google.cloud.dialogflow.v2.GetIntentRequest) Intent(com.google.cloud.dialogflow.v2.Intent) Test(org.junit.Test)

Aggregations

Intent (com.google.cloud.dialogflow.v2.Intent)10 Test (org.junit.Test)10 Intent (com.google.cloud.dialogflow.cx.v3beta1.Intent)7 IntentsClient (com.google.cloud.dialogflow.v2.IntentsClient)7 AgentName (com.google.cloud.dialogflow.v2.AgentName)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 FieldMask (com.google.protobuf.FieldMask)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 PrintStream (java.io.PrintStream)3 ArrayList (java.util.ArrayList)3 Before (org.junit.Before)3 ListIntentsPagedResponse (com.google.cloud.dialogflow.cx.v3.IntentsClient.ListIntentsPagedResponse)2 IntentsClient (com.google.cloud.dialogflow.cx.v3beta1.IntentsClient)2 Context (com.google.cloud.dialogflow.v2.Context)2 GetIntentRequest (com.google.cloud.dialogflow.v2.GetIntentRequest)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 BeforeClass (org.junit.BeforeClass)2 Agent (com.google.cloud.dialogflow.cx.v3.Agent)1