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);
}
}
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());
}
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];
}
}
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());
}
}
}
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());
}
Aggregations