Programmatically interact with Watson Conversation

  1. In your editor, create a file named index.js.
  2. 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');
  3. 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
    });
  4. 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));
    }
    });
  5. In your terminal window, enter the following command to run the code:
    node index.js
    You should see a response from Watson: