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();
}
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;
}
}
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());
}
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()));
}
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()));
}
Aggregations