use of com.google.cloud.dialogflow.v2.Agent in project java-dialogflow by googleapis.
the class SetAgent method setAgent.
public static Agent setAgent(String parent, String displayName) throws IOException {
AgentsSettings agentsSettings = AgentsSettings.newBuilder().build();
try (AgentsClient client = AgentsClient.create(agentsSettings)) {
// Set the details of the Agent to create
Builder build = Agent.newBuilder();
build.setDefaultLanguageCode("en");
build.setDisplayName(displayName);
Agent agent = build.build();
// Make API request to create agent
Agent response = client.setAgent(agent);
System.out.println(response);
return response;
}
}
use of com.google.cloud.dialogflow.v2.Agent in project java-dialogflow by googleapis.
the class ConversationProfileManagement method createConversationProfileArticleSuggestion.
// Create a conversation profile with given values about Article Suggestion.
public static void createConversationProfileArticleSuggestion(String projectId, String displayName, String location, Optional<String> articleSuggestionKnowledgeBaseId) throws ApiException, IOException {
try (ConversationProfilesClient conversationProfilesClient = ConversationProfilesClient.create()) {
// Create a builder for agent assistance configuration
SuggestionConfig.Builder suggestionConfigBuilder = SuggestionConfig.newBuilder();
// Add knowledge base for Article Suggestion feature
if (articleSuggestionKnowledgeBaseId.isPresent()) {
KnowledgeBaseName articleSuggestionKbName = KnowledgeBaseName.of(projectId, articleSuggestionKnowledgeBaseId.get());
// Build configuration for Article Suggestion feature
SuggestionFeatureConfig articleSuggestionFeatureConfig = SuggestionFeatureConfig.newBuilder().setSuggestionFeature(SuggestionFeature.newBuilder().setType(Type.ARTICLE_SUGGESTION).build()).setSuggestionTriggerSettings(buildSuggestionTriggerSettings()).setQueryConfig(buildSuggestionQueryConfig(articleSuggestionKbName)).build();
// Add Article Suggestion feature to agent assistance configuration
suggestionConfigBuilder.addFeatureConfigs(articleSuggestionFeatureConfig);
}
LocationName locationName = LocationName.of(projectId, location);
// Set a conversation profile with target configurations
ConversationProfile targetConversationProfile = ConversationProfile.newBuilder().setDisplayName(displayName).setLanguageCode("en-US").setHumanAgentAssistantConfig(HumanAgentAssistantConfig.newBuilder().setHumanAgentSuggestionConfig(suggestionConfigBuilder.build())).build();
// Create a conversation profile
ConversationProfile createdConversationProfile = conversationProfilesClient.createConversationProfile(CreateConversationProfileRequest.newBuilder().setParent(locationName.toString()).setConversationProfile(targetConversationProfile).build());
System.out.println("====================");
System.out.println("Conversation Profile created:\n");
System.out.format("Display name: %s\n", createdConversationProfile.getDisplayName());
System.out.format("Name: %s\n", createdConversationProfile.getName());
}
}
use of com.google.cloud.dialogflow.v2.Agent 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;
}
use of com.google.cloud.dialogflow.v2.Agent 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);
}
use of com.google.cloud.dialogflow.v2.Agent in project java-dialogflow by googleapis.
the class AgentsClientTest method searchAgentsTest2.
@Test
public void searchAgentsTest2() throws Exception {
Agent responsesElement = Agent.newBuilder().build();
SearchAgentsResponse expectedResponse = SearchAgentsResponse.newBuilder().setNextPageToken("").addAllAgents(Arrays.asList(responsesElement)).build();
mockAgents.addResponse(expectedResponse);
ProjectName parent = ProjectName.of("[PROJECT]");
SearchAgentsPagedResponse pagedListResponse = client.searchAgents(parent);
List<Agent> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getAgentsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockAgents.getRequests();
Assert.assertEquals(1, actualRequests.size());
SearchAgentsRequest actualRequest = ((SearchAgentsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations