Search in sources :

Example 1 with Message

use of com.google.cloud.dialogflow.v2.Intent.Message in project MobileDicomViewer by awholeneworld.

the class MainActivity method sendMessageToBot.

private void sendMessageToBot(String message) {
    QueryInput input = QueryInput.newBuilder().setText(TextInput.newBuilder().setText(message).setLanguageCode("ko")).build();
    new SendMessageInBg(this, sessionName, sessionsClient, input).execute();
}
Also used : QueryInput(com.google.cloud.dialogflow.v2.QueryInput) SendMessageInBg(gachon.dicomviewer.helpers.SendMessageInBg)

Example 2 with Message

use of com.google.cloud.dialogflow.v2.Intent.Message 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 3 with Message

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

the class IntentManagementIT method testCreateIntent.

@Test
public void testCreateIntent() throws Exception {
    // Create the intent
    Intent intent = IntentManagement.createIntent(INTENT_DISPLAY_NAME, PROJECT_ID, TRAINING_PHRASE_PARTS, MESSAGE_TEXTS);
    assertNotNull(intent);
    List<String> intentIds = IntentManagement.getIntentIds(intent.getDisplayName(), PROJECT_ID);
    assertThat(intentIds.size()).isEqualTo(1);
    List<Intent> intents = IntentManagement.listIntents(PROJECT_ID);
    assertTrue(intents.size() > 0);
    assertThat(intents).contains(intent);
    for (String messageText : MESSAGE_TEXTS) {
        assertTrue(intent.getMessagesList().stream().anyMatch(message -> message.getText().toString().contains(messageText)));
    }
    for (String intentId : intentIds) {
        IntentManagement.deleteIntent(intentId, PROJECT_ID);
    }
    int numIntents = intents.size();
    intents = IntentManagement.listIntents(PROJECT_ID);
    assertEquals(numIntents - 1, intents.size());
}
Also used : PrintStream(java.io.PrintStream) Arrays(java.util.Arrays) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Assert.assertNotNull(org.junit.Assert.assertNotNull) RunWith(org.junit.runner.RunWith) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) UUID(java.util.UUID) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) List(java.util.List) Intent(com.google.cloud.dialogflow.v2.Intent) After(org.junit.After) AgentName(com.google.cloud.dialogflow.v2.AgentName) Assert.assertEquals(org.junit.Assert.assertEquals) IntentsClient(com.google.cloud.dialogflow.v2.IntentsClient) Before(org.junit.Before) Intent(com.google.cloud.dialogflow.v2.Intent) Test(org.junit.Test)

Example 4 with Message

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

the class ConversationsClientTest method listMessagesTest.

@Test
public void listMessagesTest() throws Exception {
    Message responsesElement = Message.newBuilder().build();
    ListMessagesResponse expectedResponse = ListMessagesResponse.newBuilder().setNextPageToken("").addAllMessages(Arrays.asList(responsesElement)).build();
    mockConversations.addResponse(expectedResponse);
    ConversationName parent = ConversationName.ofProjectConversationName("[PROJECT]", "[CONVERSATION]");
    ListMessagesPagedResponse pagedListResponse = client.listMessages(parent);
    List<Message> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getMessagesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockConversations.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListMessagesRequest actualRequest = ((ListMessagesRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) AbstractMessage(com.google.protobuf.AbstractMessage) ListMessagesPagedResponse(com.google.cloud.dialogflow.v2.ConversationsClient.ListMessagesPagedResponse) Test(org.junit.Test)

Example 5 with Message

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

the class ConversationsClientTest method listMessagesTest2.

@Test
public void listMessagesTest2() throws Exception {
    Message responsesElement = Message.newBuilder().build();
    ListMessagesResponse expectedResponse = ListMessagesResponse.newBuilder().setNextPageToken("").addAllMessages(Arrays.asList(responsesElement)).build();
    mockConversations.addResponse(expectedResponse);
    String parent = "parent-995424086";
    ListMessagesPagedResponse pagedListResponse = client.listMessages(parent);
    List<Message> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getMessagesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockConversations.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListMessagesRequest actualRequest = ((ListMessagesRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) AbstractMessage(com.google.protobuf.AbstractMessage) ListMessagesPagedResponse(com.google.cloud.dialogflow.v2.ConversationsClient.ListMessagesPagedResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 AgentName (com.google.cloud.dialogflow.v2.AgentName)2 ListMessagesPagedResponse (com.google.cloud.dialogflow.v2.ConversationsClient.ListMessagesPagedResponse)2 Intent (com.google.cloud.dialogflow.v2.Intent)2 IntentsClient (com.google.cloud.dialogflow.v2.IntentsClient)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 Message (com.google.cloud.dialogflow.v2.Intent.Message)1 TrainingPhrase (com.google.cloud.dialogflow.v2.Intent.TrainingPhrase)1 QueryInput (com.google.cloud.dialogflow.v2.QueryInput)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 SendMessageInBg (gachon.dicomviewer.helpers.SendMessageInBg)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 UUID (java.util.UUID)1 After (org.junit.After)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1