This post is again a part of the series to create a chat bot using IBM Bluemix, Watson Conversation, Java and for chat client window, Facebook. Till now we have cloned the project successfully in eclipse, http://mytechthinking.in/2017/06/13/ibm-bluemix-cloning-source-code-from-git/. Now we will see how to integrate a Java application to Watson Conversation and also how to create dialogues in Conversation.
Training Watson Conversation:
Start by going to the dashboard of Conversation, similar to the image shown below.In the Conversation dashboard, IBM has given a good tutorial for start to a beginner. I recommend going through the tutorial to understand the terms like intents, entity and dialogue. Click on the launch tool to start creating with workspace for Conversation.Click on create a new workspace, and give a name and description to the workspace.Clicking on Create button will launch the build screen of the Conversation. From here we can create intents, entities and dialogs. Start with creating intents, intents represents the user input. For example I have created an intent named ‘Greetings’. For Watson to understand we have to give at least 5 examples for the intent.
Now after creating intent, let’s move to dialogue tab to create a reply for the intent. In the dialogue, you can use the value from the context that we can send through our middleware application (in our case Java application). In this response, I have used the username from context. You can multiple responses, and can set the response variation order as a sequence as well as random.
Now our dialogue is ready, let’s create the connection for Conversation to the Java application. For that let’s go back to the Conversation dashboard and click on Connection tab on side nav bar. Then click on create connection button and select the Java Liberty application to create the connection. That’s it the conversation is deployed and connected, now to use it we have to write a java program.
Integrating Conversation service with Java application:
To integrate Conversation service lets go to eclipse and to the project which we have cloned. You can use any build tool to build the project I have used maven as a building tool. For that, I have converted the project into Maven project and created a skeleton Maven project. To do that go to the working directory and run the following program (before that make sure Maven is installed ).
mvn archetype:generate -DgroupId=com.ibm.developer -DartifactId=mavenFromScratch -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
Then in the pom.xml, lets add the conversation dependencies.
Now let’s create a simple Java program to chat with Conversation.
In this program give the user name, password and workspace Id, of the conversation app. Which you can get it from the conversation deploy tab.Now lets run the application and see the result.
So, as you can see we have successfully integrated the chat with Watson Conversation. And also bot is replying with value from the context.
In the next tutorial we will see how to integrate our java application with Facebook chat to have an end to end chat bot.