Search in sources :

Example 6 with Agent

use of com.google.cloud.dialogflow.v2.Agent in project java-dialogflow by googleapis.

the class IntentManagement method createIntent.

// [END dialogflow_list_intents]
// [START dialogflow_create_intent]
/**
 * Create an intent of the given intent type
 *
 * @param displayName The display name of the intent.
 * @param projectId Project/Agent Id.
 * @param trainingPhrasesParts Training phrases.
 * @param messageTexts Message texts for the agent's response when the intent is detected.
 * @return The created Intent.
 */
public static Intent createIntent(String displayName, String projectId, List<String> trainingPhrasesParts, List<String> messageTexts) throws ApiException, IOException {
    // Instantiates a client
    try (IntentsClient intentsClient = IntentsClient.create()) {
        // Set the project agent name using the projectID (my-project-id)
        AgentName parent = AgentName.of(projectId);
        // Build the trainingPhrases from the trainingPhrasesParts
        List<TrainingPhrase> trainingPhrases = new ArrayList<>();
        for (String trainingPhrase : trainingPhrasesParts) {
            trainingPhrases.add(TrainingPhrase.newBuilder().addParts(Part.newBuilder().setText(trainingPhrase).build()).build());
        }
        // Build the message texts for the agent's response
        Message message = Message.newBuilder().setText(Text.newBuilder().addAllText(messageTexts).build()).build();
        // Build the intent
        Intent intent = Intent.newBuilder().setDisplayName(displayName).addMessages(message).addAllTrainingPhrases(trainingPhrases).build();
        // Performs the create intent request
        Intent response = intentsClient.createIntent(parent, intent);
        System.out.format("Intent created: %s\n", response);
        return response;
    }
}
Also used : TrainingPhrase(com.google.cloud.dialogflow.v2.Intent.TrainingPhrase) IntentsClient(com.google.cloud.dialogflow.v2.IntentsClient) Message(com.google.cloud.dialogflow.v2.Intent.Message) ArrayList(java.util.ArrayList) Intent(com.google.cloud.dialogflow.v2.Intent) AgentName(com.google.cloud.dialogflow.v2.AgentName)

Example 7 with Agent

use of com.google.cloud.dialogflow.v2.Agent in project java-dialogflow by googleapis.

the class IntentManagement method deleteIntent.

// [END dialogflow_create_intent]
// [START dialogflow_delete_intent]
/**
 * Delete intent with the given intent type and intent value
 *
 * @param intentId The id of the intent.
 * @param projectId Project/Agent Id.
 */
public static void deleteIntent(String intentId, String projectId) throws ApiException, IOException {
    // Instantiates a client
    try (IntentsClient intentsClient = IntentsClient.create()) {
        IntentName name = IntentName.of(projectId, intentId);
        // Performs the delete intent request
        intentsClient.deleteIntent(name);
    }
}
Also used : IntentsClient(com.google.cloud.dialogflow.v2.IntentsClient) IntentName(com.google.cloud.dialogflow.v2.IntentName)

Example 8 with Agent

use of com.google.cloud.dialogflow.v2.Agent 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 9 with Agent

use of com.google.cloud.dialogflow.v2.Agent in project java-dialogflow by googleapis.

the class AgentsClientTest method searchAgentsTest3.

@Test
public void searchAgentsTest3() throws Exception {
    Agent responsesElement = Agent.newBuilder().build();
    SearchAgentsResponse expectedResponse = SearchAgentsResponse.newBuilder().setNextPageToken("").addAllAgents(Arrays.asList(responsesElement)).build();
    mockAgents.addResponse(expectedResponse);
    String parent = "parent-995424086";
    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, 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)

Example 10 with Agent

use of com.google.cloud.dialogflow.v2.Agent in project java-dialogflow by googleapis.

the class ITSystemTest method searchAgentsTest.

@Test
public void searchAgentsTest() {
    SearchAgentsRequest request = SearchAgentsRequest.newBuilder().setParent(PROJECT_NAME.toString()).build();
    for (Agent actualAgent : agentsClient.searchAgents(request).iterateAll()) {
        assertEquals(PROJECT_NAME.toString(), actualAgent.getParent());
        assertEquals(DISPLAY_NAME, actualAgent.getDisplayName());
        assertEquals(DEFAULT_LANGUAGE_CODE, actualAgent.getDefaultLanguageCode());
        assertEquals(TIME_ZONE, actualAgent.getTimeZone());
        assertEquals(Agent.MatchMode.MATCH_MODE_HYBRID, actualAgent.getMatchMode());
        assertEquals(Agent.ApiVersion.API_VERSION_V2, actualAgent.getApiVersion());
        assertEquals(Agent.Tier.TIER_STANDARD, actualAgent.getTier());
    }
}
Also used : Agent(com.google.cloud.dialogflow.v2.Agent) SearchAgentsRequest(com.google.cloud.dialogflow.v2.SearchAgentsRequest) 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