Search in sources :

Example 21 with MessageOptions

use of com.ibm.watson.developer_cloud.conversation.v1.model.MessageOptions in project java-sdk by watson-developer-cloud.

the class ConversationServiceIT method testStartAConversationWithoutMessage.

/**
 * Test start a conversation without message.
 */
@Test()
public void testStartAConversationWithoutMessage() {
    MessageOptions options = new MessageOptions.Builder(workspaceId).build();
    service.message(options).execute();
}
Also used : MessageOptions(com.ibm.watson.developer_cloud.conversation.v1.model.MessageOptions) Test(org.junit.Test)

Example 22 with MessageOptions

use of com.ibm.watson.developer_cloud.conversation.v1.model.MessageOptions in project java-sdk by watson-developer-cloud.

the class ConversationServiceIT method testExample.

/**
 * Test Example.
 */
@Test
public void testExample() {
    // Conversation service = new Conversation(Conversation.VERSION_DATE_2017_05_26);
    // service.setUsernameAndPassword("<username>", "<password>");
    InputData input = new InputData.Builder("Hi").build();
    MessageOptions options = new MessageOptions.Builder(workspaceId).input(input).build();
    // sync
    MessageResponse response = service.message(options).execute();
    System.out.println(response);
    // async
    service.message(options).enqueue(new ServiceCallback<MessageResponse>() {

        @Override
        public void onResponse(MessageResponse response) {
            System.out.println(response);
        }

        @Override
        public void onFailure(Exception e) {
        }
    });
    // rx callback
    service.message(options).rx().thenApply(new CompletableFuture.Fun<MessageResponse, OutputData>() {

        @Override
        public OutputData apply(MessageResponse message) {
            return message.getOutput();
        }
    }).thenAccept(new CompletableFuture.Action<OutputData>() {

        @Override
        public void accept(OutputData output) {
            System.out.println(output);
        }
    });
    // rx async callback
    service.message(options).rx().thenApplyAsync(new CompletableFuture.Fun<MessageResponse, OutputData>() {

        @Override
        public OutputData apply(MessageResponse message) {
            return message.getOutput();
        }
    }).thenAccept(new CompletableFuture.Action<OutputData>() {

        @Override
        public void accept(OutputData output) {
            System.out.println(output);
        }
    });
    // rx sync
    try {
        MessageResponse rxMessageResponse = service.message(options).rx().get();
        System.out.println(rxMessageResponse);
    } catch (Exception ex) {
    // Handle exception
    }
}
Also used : CompletableFuture(jersey.repackaged.jsr166e.CompletableFuture) MessageOptions(com.ibm.watson.developer_cloud.conversation.v1.model.MessageOptions) MessageResponse(com.ibm.watson.developer_cloud.conversation.v1.model.MessageResponse) OutputData(com.ibm.watson.developer_cloud.conversation.v1.model.OutputData) InputData(com.ibm.watson.developer_cloud.conversation.v1.model.InputData) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Test(org.junit.Test)

Example 23 with MessageOptions

use of com.ibm.watson.developer_cloud.conversation.v1.model.MessageOptions in project java-sdk by watson-developer-cloud.

the class ConversationServiceIT method testReadme.

/**
 * Test README.
 */
@Test
public void testReadme() {
    // Conversation service = new Conversation(Conversation.VERSION_DATE_2017_05_26);
    // service.setUsernameAndPassword("<username>", "<password>");
    InputData input = new InputData.Builder("Hi").build();
    MessageOptions options = new MessageOptions.Builder(workspaceId).input(input).build();
    MessageResponse response = service.message(options).execute();
    System.out.println(response);
}
Also used : MessageOptions(com.ibm.watson.developer_cloud.conversation.v1.model.MessageOptions) MessageResponse(com.ibm.watson.developer_cloud.conversation.v1.model.MessageResponse) InputData(com.ibm.watson.developer_cloud.conversation.v1.model.InputData) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)20 MessageOptions (com.ibm.watson.developer_cloud.assistant.v1.model.MessageOptions)12 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)10 MessageOptions (com.ibm.watson.developer_cloud.conversation.v1.model.MessageOptions)10 MessageResponse (com.ibm.watson.developer_cloud.assistant.v1.model.MessageResponse)7 MessageResponse (com.ibm.watson.developer_cloud.conversation.v1.model.MessageResponse)6 InputData (com.ibm.watson.developer_cloud.assistant.v1.model.InputData)5 InputData (com.ibm.watson.developer_cloud.conversation.v1.model.InputData)5 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)4 JsonObject (com.google.gson.JsonObject)3 CompletableFuture (jersey.repackaged.jsr166e.CompletableFuture)3 JsonParser (com.google.gson.JsonParser)2 Assistant (com.ibm.watson.developer_cloud.assistant.v1.Assistant)2 Context (com.ibm.watson.developer_cloud.assistant.v1.model.Context)2 OutputData (com.ibm.watson.developer_cloud.assistant.v1.model.OutputData)2 RuntimeEntity (com.ibm.watson.developer_cloud.assistant.v1.model.RuntimeEntity)2 RuntimeIntent (com.ibm.watson.developer_cloud.assistant.v1.model.RuntimeIntent)2 Context (com.ibm.watson.developer_cloud.conversation.v1.model.Context)2 RuntimeEntity (com.ibm.watson.developer_cloud.conversation.v1.model.RuntimeEntity)2 RuntimeIntent (com.ibm.watson.developer_cloud.conversation.v1.model.RuntimeIntent)2