整合ibm沃森的谈话

时间:2018-01-08 15:00:03

标签: ibm-watson chatbot

我目前正致力于使用ibm watson对话创建聊天机器人。我已经使用必要的意图和对话框在bluemix中创建了我的聊天机器人。现在我想将它与java应用程序集成。谁可以帮我这个事。?

1 个答案:

答案 0 :(得分:0)

import com.ibm.watson.developer_cloud.conversation.v1.Conversation;
import com.ibm.watson.developer_cloud.conversation.v1.model.*; 
public class Conversation {
public static void main( String[] args ) throws Exception
{

String input ="Hello";
//To Call Conversation Api to print its welcome Message.
response = conversationAPI("",context); 
context = response.getContext();
response = conversationAPI(input,context); 
}
}
catch (IOException e) 
    {
    e.printStackTrace();
    }
}

public static MessageResponse conversationAPI(String input,Context context)
{
Conversation service = new Conversation("");
service.setUsernameAndPassword("", ""); //
MessageOptions  newMessage = new MessageOptions.Builder().workspaceId("").input(new InputData.Builder(input).build()).context(context).build();
MessageResponse response = service.message(newMessage).execute();
int TextSize= response.getOutput().getText().size();
for(int x=0;x<TextSize;x++)
{

    System.out.println(response.getOutput().getText().get(x));
}

return response;
} 

}