Search in sources :

Example 16 with Agent

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;
    }
}
Also used : Agent(com.google.cloud.dialogflow.v2.Agent) AgentsSettings(com.google.cloud.dialogflow.v2.AgentsSettings) AgentsClient(com.google.cloud.dialogflow.v2.AgentsClient) Builder(com.google.cloud.dialogflow.v2.Agent.Builder)

Example 17 with Agent

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());
    }
}
Also used : ConversationProfile(com.google.cloud.dialogflow.v2.ConversationProfile) SuggestionConfig(com.google.cloud.dialogflow.v2.HumanAgentAssistantConfig.SuggestionConfig) SuggestionFeatureConfig(com.google.cloud.dialogflow.v2.HumanAgentAssistantConfig.SuggestionFeatureConfig) ConversationProfilesClient(com.google.cloud.dialogflow.v2.ConversationProfilesClient) KnowledgeBaseName(com.google.cloud.dialogflow.v2.KnowledgeBaseName) LocationName(com.google.cloud.dialogflow.v2.LocationName)

Example 18 with Agent

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;
}
Also used : Context(com.google.cloud.dialogflow.v2.Context) IntentsClient(com.google.cloud.dialogflow.v2.IntentsClient) Intent(com.google.cloud.dialogflow.v2.Intent) AgentName(com.google.cloud.dialogflow.v2.AgentName)

Example 19 with Agent

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);
}
Also used : IntentsClient(com.google.cloud.dialogflow.v2.IntentsClient) After(org.junit.After)

Example 20 with Agent

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()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) SearchAgentsPagedResponse(com.google.cloud.dialogflow.v2.AgentsClient.SearchAgentsPagedResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 IntentsClient (com.google.cloud.dialogflow.v2.IntentsClient)5 Agent (com.google.cloud.dialogflow.cx.v3.Agent)4 Builder (com.google.cloud.dialogflow.cx.v3.Agent.Builder)4 AgentsClient (com.google.cloud.dialogflow.cx.v3.AgentsClient)4 AgentsSettings (com.google.cloud.dialogflow.cx.v3.AgentsSettings)4 Agent (com.google.cloud.dialogflow.cx.v3beta1.Agent)4 Agent (com.google.cloud.dialogflow.v2.Agent)3 SearchAgentsPagedResponse (com.google.cloud.dialogflow.v2.AgentsClient.SearchAgentsPagedResponse)3 Intent (com.google.cloud.dialogflow.v2.Intent)3 AbstractMessage (com.google.protobuf.AbstractMessage)3 AgentName (com.google.cloud.dialogflow.v2.AgentName)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 PrintStream (java.io.PrintStream)2 Agent (lcm2.Agent)2 Action (lcm2.simulation.Action)2 NamespaceBinding (org.sbolstandard.core.datatree.Datatree.NamespaceBinding)2 NamespaceBinding (org.sbolstandard.core.datatree.NamespaceBinding)2 Activity (org.sbolstandard.core2.Activity)2 Agent (org.sbolstandard.core2.Agent)2