Search in sources :

Example 36 with Agent

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

the class CreateFlow method createFlow.

// Create a flow in the specified agent.
public static Flow createFlow(String displayName, String projectId, String locationId, String agentId, Map<String, String> eventsToFulfillmentMessages) throws IOException, ApiException {
    FlowsSettings.Builder flowsSettingsBuilder = FlowsSettings.newBuilder();
    if (locationId.equals("global")) {
        flowsSettingsBuilder.setEndpoint("dialogflow.googleapis.com:443");
    } else {
        flowsSettingsBuilder.setEndpoint(locationId + "-dialogflow.googleapis.com:443");
    }
    FlowsSettings flowsSettings = flowsSettingsBuilder.build();
    // Instantiates a client
    try (FlowsClient flowsClient = FlowsClient.create(flowsSettings)) {
        // Set the project agent name using the projectID (my-project-id), locationID (global), and
        // agentID (UUID).
        AgentName parent = AgentName.of(projectId, locationId, agentId);
        // Build the EventHandlers for the flow using the mapping from events to fulfillment messages.
        List<EventHandler> eventHandlers = new ArrayList<>();
        for (Map.Entry<String, String> item : eventsToFulfillmentMessages.entrySet()) {
            eventHandlers.add(EventHandler.newBuilder().setEvent(// Event (sys.no-match-default)
            item.getKey()).setTriggerFulfillment(Fulfillment.newBuilder().addMessages(ResponseMessage.newBuilder().setText(Text.newBuilder().addText(item.getValue()).build()).build()).build()).build());
        }
        // Build the flow.
        Flow flow = Flow.newBuilder().setDisplayName(displayName).addAllEventHandlers(eventHandlers).build();
        // Performs the create flow request.
        Flow response = flowsClient.createFlow(parent, flow);
        // TODO : Uncomment if you want to print response
        // System.out.format("Flow created: %s\n", response.toString());
        flowsClient.shutdown();
        return response;
    }
}
Also used : FlowsClient(com.google.cloud.dialogflow.cx.v3beta1.FlowsClient) FlowsSettings(com.google.cloud.dialogflow.cx.v3beta1.FlowsSettings) ArrayList(java.util.ArrayList) EventHandler(com.google.cloud.dialogflow.cx.v3beta1.EventHandler) AgentName(com.google.cloud.dialogflow.cx.v3beta1.AgentName) Map(java.util.Map) Flow(com.google.cloud.dialogflow.cx.v3beta1.Flow)

Example 37 with Agent

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

the class TestCasesClientTest method listTestCaseResultsTest.

@Test
public void listTestCaseResultsTest() throws Exception {
    TestCaseResult responsesElement = TestCaseResult.newBuilder().build();
    ListTestCaseResultsResponse expectedResponse = ListTestCaseResultsResponse.newBuilder().setNextPageToken("").addAllTestCaseResults(Arrays.asList(responsesElement)).build();
    mockTestCases.addResponse(expectedResponse);
    TestCaseName parent = TestCaseName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[TEST_CASE]");
    ListTestCaseResultsPagedResponse pagedListResponse = client.listTestCaseResults(parent);
    List<TestCaseResult> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getTestCaseResultsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockTestCases.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListTestCaseResultsRequest actualRequest = ((ListTestCaseResultsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListTestCaseResultsPagedResponse(com.google.cloud.dialogflow.cx.v3beta1.TestCasesClient.ListTestCaseResultsPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) Test(org.junit.Test)

Example 38 with Agent

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

the class TestCasesClientTest method listTestCasesTest.

@Test
public void listTestCasesTest() throws Exception {
    TestCase responsesElement = TestCase.newBuilder().build();
    ListTestCasesResponse expectedResponse = ListTestCasesResponse.newBuilder().setNextPageToken("").addAllTestCases(Arrays.asList(responsesElement)).build();
    mockTestCases.addResponse(expectedResponse);
    AgentName parent = AgentName.of("[PROJECT]", "[LOCATION]", "[AGENT]");
    ListTestCasesPagedResponse pagedListResponse = client.listTestCases(parent);
    List<TestCase> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getTestCasesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockTestCases.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListTestCasesRequest actualRequest = ((ListTestCasesRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListTestCasesPagedResponse(com.google.cloud.dialogflow.cx.v3beta1.TestCasesClient.ListTestCasesPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) Test(org.junit.Test)

Example 39 with Agent

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

the class UpdateIntentTest method setUp.

@Before
public void setUp() throws IOException {
    stdOut = new ByteArrayOutputStream();
    System.setOut(new PrintStream(stdOut));
    Builder build = Agent.newBuilder();
    build.setDefaultLanguageCode("en");
    build.setDisplayName("temp_agent_" + UUID.randomUUID().toString());
    build.setTimeZone("America/Los_Angeles");
    Agent agent = build.build();
    String apiEndpoint = "global-dialogflow.googleapis.com:443";
    String parentPath = "projects/" + PROJECT_ID + "/locations/global";
    AgentsSettings agentsSettings = AgentsSettings.newBuilder().setEndpoint(apiEndpoint).build();
    AgentsClient client = AgentsClient.create(agentsSettings);
    parent = client.createAgent(parentPath, agent).getName();
    UpdateIntentTest.agentID = parent.split("/")[5];
    try (IntentsClient intentsClient = IntentsClient.create()) {
        com.google.cloud.dialogflow.cx.v3.Intent.Builder intent = Intent.newBuilder();
        intent.setDisplayName("temp_intent_" + UUID.randomUUID().toString());
        UpdateIntentTest.intentPath = intentsClient.createIntent(parent, intent.build()).getName();
        UpdateIntentTest.intentID = UpdateIntentTest.intentPath.split("/")[7];
    }
}
Also used : PrintStream(java.io.PrintStream) Agent(com.google.cloud.dialogflow.cx.v3.Agent) IntentsClient(com.google.cloud.dialogflow.cx.v3.IntentsClient) Builder(com.google.cloud.dialogflow.cx.v3.Agent.Builder) Intent(com.google.cloud.dialogflow.cx.v3.Intent) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AgentsSettings(com.google.cloud.dialogflow.cx.v3.AgentsSettings) AgentsClient(com.google.cloud.dialogflow.cx.v3.AgentsClient) Before(org.junit.Before)

Aggregations

Test (org.junit.Test)23 AbstractMessage (com.google.protobuf.AbstractMessage)18 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 ArrayList (java.util.ArrayList)3 AgentName (com.google.cloud.dialogflow.cx.v3beta1.AgentName)2 ListAgentsPagedResponse (com.google.cloud.dialogflow.cx.v3beta1.AgentsClient.ListAgentsPagedResponse)2 Flow (com.google.cloud.dialogflow.cx.v3beta1.Flow)2 Intent (com.google.cloud.dialogflow.cx.v3beta1.Intent)2 Page (com.google.cloud.dialogflow.cx.v3beta1.Page)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