88 * Service credentials can be provided directly in this file, or can be saved to a .env file located in the
99 * same directory.
1010 *
11- * Requirements:
12- * 1. Tone Analyzer Service instance:
13- * - https://cloud.ibm.com/catalog/services/tone-analyzer
14- * - credentials for this service to be provided below in tone_analyzer variable
15- * - replace <tone_analyzer_username> and <tone_analyzer_password>
16- * 2. Assistant Service instance:
17- * - https://cloud.ibm.com/catalog/services/watson-assistant
18- * - credentials for this service to be provided below in the assistant variable
19- * - replace <assistant_username> and <assistant_password>
20- * 3. Workspace id:
21- * - a workspace containing intents, entities and dialog nodes must be created using the tool
22- * available through the IBM Cloud Assistant Service. Details are available at
23- * https://github.com/watson-developer-cloud/assistant-simple#workspace
24- * - replace <workspace_id> in the payload variable
25- *
26- * Run the code using the command:
27- * node tone_assistant_integration.v1.js
2811 */
2912
3013'use strict' ;
@@ -39,18 +22,18 @@ require('dotenv').config({ silent: true });
3922 * Instantiate the Watson Assistant Service
4023 */
4124var assistant = new AssistantV1 ( {
42- username : process . env . ASSISTANT_USERNAME || '<assistant_username>' ,
43- password : process . env . ASSISTANT_PASSWORD || '<assistant_password> ',
44- version : '2017-05-26'
25+ // See: https://github.com/watson-developer-cloud/node-sdk#authentication
26+ // iam_apikey: 'INSERT YOUR IAM API KEY HERE ',
27+ version : '2020-04-30' ,
4528} ) ;
4629
4730/**
4831 * Instantiate the Watson Tone Analyzer Service
4932 */
5033var toneAnalyzer = new ToneAnalyzerV3 ( {
51- username : process . env . TONE_ANALYZER_USERNAME || '<tone_analyzer_username>' ,
52- password : process . env . TONE_ANALYZER_PASSWORD || '<tone_analyzer_password> ',
53- version : '2017-09-21'
34+ // See: https://github.com/watson-developer-cloud/node-sdk#authentication
35+ // iam_apikey: 'INSERT YOUR IAM API KEY HERE ',
36+ version : '2017-09-21' ,
5437} ) ;
5538
5639/**
@@ -66,8 +49,8 @@ var maintainToneHistoryInContext = true;
6649var payload = {
6750 workspace_id : process . env . WORKSPACE_ID || '<workspace_id>' ,
6851 input : {
69- text : 'I am not happy today :('
70- }
52+ text : 'I am not happy today :(' ,
53+ } ,
7154} ;
7255
7356/**
@@ -84,12 +67,8 @@ function invokeToneAssistant(payload, maintainToneHistoryInContext) {
8467 tone_detection
8568 . invokeToneAsync ( payload , toneAnalyzer )
8669 . then ( tone => {
87- tone_detection . updateUserTone (
88- payload ,
89- tone ,
90- maintainToneHistoryInContext
91- ) ;
92- assistant . message ( payload , function ( err , data ) {
70+ tone_detection . updateUserTone ( payload , tone , maintainToneHistoryInContext ) ;
71+ assistant . message ( payload , function ( err , data ) {
9372 if ( err ) {
9473 // APPLICATION-SPECIFIC CODE TO PROCESS THE ERROR
9574 // FROM ASSISTANT SERVICE
@@ -101,7 +80,7 @@ function invokeToneAssistant(payload, maintainToneHistoryInContext) {
10180 }
10281 } ) ;
10382 } )
104- . catch ( function ( err ) {
83+ . catch ( function ( err ) {
10584 console . log ( JSON . stringify ( err , null , 2 ) ) ;
10685 } ) ;
10786}
0 commit comments