Programmatically interact with Watson Conversation
- In your editor, create a file named index.js.
- In the index.js file, initialize dotenv by adding the following code:
const dotenv = require( 'dotenv');
dotenv.config()
const ConversationV1 = require( 'watson-developer-cloud/conversation/v1');
- Create a new instance of the Conversation service:
const conversation = new ConversationV1({
username: process.env.USERNAME,
password: process.env.PASSWORD,
version_date: ConversationV1.VERSION_DATE_2016_09_20
});
- Make a request to Watson Conversation by using the message API and print Watson’s response:
conversation.message({
input: {
text: ' '
},
workspace_id: process.env.WORKSPACE_ID
}, function(err, response) {
if (err) {
console.error(err);
} else {
console.log(JSON.stringify(response, null, 2));
}
});
- In your terminal window, enter the following command to run the code:
node index.js
You should see a response from Watson:
