use of com.google.cloud.dialogflow.v2.Intent 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()));
}
}
}
}
use of com.google.cloud.dialogflow.v2.Intent in project java-dialogflow by googleapis.
the class ITSystemTest method setUp.
@BeforeClass
public static void setUp() throws IOException {
agentsClient = AgentsClient.create();
/* create entity */
entityTypesClient = EntityTypesClient.create();
EntityType createEntityType = EntityType.newBuilder().setDisplayName(ENTITY_NAME).setKind(EntityType.Kind.KIND_LIST).addEntities(ENTITY).build();
CreateEntityTypeRequest entityTypeRequest = CreateEntityTypeRequest.newBuilder().setParent(PROJECT_AGENT_NAME.toString()).setEntityType(createEntityType).build();
entityType = entityTypesClient.createEntityType(entityTypeRequest);
entityName = entityType.getName().substring(entityType.getName().lastIndexOf("/")).replace("/", "");
entityTypeName = EntityTypeName.of(PROJECT_ID, entityName);
/* create intents */
intentsClient = IntentsClient.create();
Intent createIntent = Intent.newBuilder().setDisplayName(INTENT_NAME).addEvents(EVENT_NAME).setAction(ACTION_NAME).build();
CreateIntentRequest intentRequest = CreateIntentRequest.newBuilder().setParent(PROJECT_AGENT_NAME.toString()).setIntent(createIntent).build();
intent = intentsClient.createIntent(intentRequest);
intentId = intent.getName().substring(intent.getName().lastIndexOf("/")).replace("/", "");
intentName = IntentName.of(PROJECT_ID, intentId);
/* create session */
sessionsClient = SessionsClient.create();
/* create context */
contextsClient = ContextsClient.create();
Context createContext = Context.newBuilder().setName(CONTEXT_NAME.toString()).setLifespanCount(LIFE_SPAN_COUNT).build();
CreateContextRequest request = CreateContextRequest.newBuilder().setParent(SESSION_NAME.toString()).setContext(createContext).build();
context = contextsClient.createContext(request);
}
use of com.google.cloud.dialogflow.v2.Intent in project java-dialogflow by googleapis.
the class IntentsClientTest method listIntentsTest.
@Test
public void listIntentsTest() throws Exception {
Intent responsesElement = Intent.newBuilder().build();
ListIntentsResponse expectedResponse = ListIntentsResponse.newBuilder().setNextPageToken("").addAllIntents(Arrays.asList(responsesElement)).build();
mockIntents.addResponse(expectedResponse);
AgentName parent = AgentName.ofProjectName("[PROJECT]");
ListIntentsPagedResponse pagedListResponse = client.listIntents(parent);
List<Intent> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getIntentsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockIntents.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListIntentsRequest actualRequest = ((ListIntentsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.dialogflow.v2.Intent in project java-dialogflow by googleapis.
the class IntentsClientTest method listIntentsTest2.
@Test
public void listIntentsTest2() throws Exception {
Intent responsesElement = Intent.newBuilder().build();
ListIntentsResponse expectedResponse = ListIntentsResponse.newBuilder().setNextPageToken("").addAllIntents(Arrays.asList(responsesElement)).build();
mockIntents.addResponse(expectedResponse);
String parent = "parent-995424086";
ListIntentsPagedResponse pagedListResponse = client.listIntents(parent);
List<Intent> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getIntentsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockIntents.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListIntentsRequest actualRequest = ((ListIntentsRequest) actualRequests.get(0));
Assert.assertEquals(parent, actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.dialogflow.v2.Intent in project java-dialogflow by googleapis.
the class IntentsClientTest method listIntentsTest3.
@Test
public void listIntentsTest3() throws Exception {
Intent responsesElement = Intent.newBuilder().build();
ListIntentsResponse expectedResponse = ListIntentsResponse.newBuilder().setNextPageToken("").addAllIntents(Arrays.asList(responsesElement)).build();
mockIntents.addResponse(expectedResponse);
AgentName parent = AgentName.ofProjectName("[PROJECT]");
String languageCode = "languageCode-2092349083";
ListIntentsPagedResponse pagedListResponse = client.listIntents(parent, languageCode);
List<Intent> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getIntentsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockIntents.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListIntentsRequest actualRequest = ((ListIntentsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertEquals(languageCode, actualRequest.getLanguageCode());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations