Search code examples
javasdkwatson-conversation

What do I need to provide in MessageRequest of the Converstation service to answer the first step in the conversation?


I have a Conversation Service client in Java (using the SDK)

ConversationService conversationService = new ConversationService(ConversationService.VERSION_DATE_2016_07_11, userName, password);
MessageRequest.Builder messageRequestBuilder = new MessageRequest.Builder();
messageRequestBuilder.inputText(question);
ServiceCall<MessageResponse> response = conversationService.message(workspaceId, messageRequestBuilder.build());
MessageResponse answer =  response.execute();

It does not matter what I provide as text, I always get the greetings message. To get around this I perform a second call which includes the entire context from the answer, like this

messageRequestBuilder = new MessageRequest.Builder();
messageRequestBuilder.context(answer.getContext());
messageRequestBuilder.inputText(question);
response = conversationService.message(workspaceId, messsageRequestBuilder.build());
answer =  response.execute();

Now I do get past the initial greeting text.

My question is: what do I need to provide at the minimum in each step of the conversation ?


Solution

  • The Watson Conversation service is stateless meaning that the state of the conversation is sent in context part of the JSON message request and response. So what you need to do is to get the context part from the JSON response of the Watson Conversation service and sent it back in the next request to the service including it in the message request.

    In the context there is the info which node was processed last and where will the next round of evaluation start.