Reputation: 493
The conversation service has its java code written as
import com.ibm.watson.developer_cloud.conversation.v1.ConversationService;
import com.ibm.watson.developer_cloud.conversation.v1.model.MessageRequest;
import com.ibm.watson.developer_cloud.conversation.v1.model.MessageResponse;
/*
some code written here
*/
MessageRequest newMessage = new MessageRequest.Builder().inputText(input).context(context).build();
My main question is how to write this
**MessageRequest newMessage = new MessageRequest.Builder().inputText(input).context(context).build();**
in clojure.
This is what i did so far is
(ns clj.core
(:import
(com.ibm.watson.developer_cloud.conversation.v1 ConversationService)
(com.ibm.watson.developer_cloud.conversation.v1.model MessageRequest)
(com.ibm.watson.developer_cloud.conversation.v1.model MessageResponse)))
(let [username "foo"
password "bar"
input "hello"
context {}
workspaceId "ibm-watson-id"
service (ConversationService. "2017-08-26")
userPass (.setUsernameAndPassword service username password)
;obviously this is wrong
;dont know how to get this right
newMessage (.build (.context context (.inputText input (MessageRequest.Builder.))))
response (.message service workspaceId newMessage)]
response)
Please help. Thanks
Upvotes: 1
Views: 233
Reputation: 493
aha, eventually figured it out, it seems the MessageRequest class has another class called Builder
All i did was to reference this class and tweak the needful
(ns clj.core
(:import
(com.ibm.watson.developer_cloud.conversation.v1 ConversationService)
(com.ibm.watson.developer_cloud.conversation.v1.model MessageRequest)
(com.ibm.watson.developer_cloud.conversation.v1.model MessageResponse)))
(let [username "foo"
password "bar"
input "hello"
context {}
workspaceId "ibm-watson-id"
service (ConversationService. "2017-08-26")
userPass (.setUsernameAndPassword service username password)
;just wanna make it work
msgReq (MessageRequest$Builder.)
inputText (.inputText msgReq input)
content (.context inputText context)
newMessage (.build content)
response (.execute (.message service workspaceId newMessage))]
(println "Watson Response: " response))
Upvotes: 3