Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = {
"prettier",
],
"rules": {
"prettier/prettier": ["error", {"singleQuote": true, "printWidth": 100}],
"prettier/prettier": ["error"],
"prefer-const": "error",
"prefer-rest-params": "off", // https://github.com/mysticatea/eslint-plugin-node/issues/63
// The rest of these override rules that are enabled by one of the configs we extend but not compatible with current codebase
Expand Down
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"tabWidth": 2,
"singleQuote": true,
"trailingComma": "es5",
"parser": "babel"
"parser": "babel",
"arrowParens": "avoid"
}
49 changes: 0 additions & 49 deletions dependency-lint.yml

This file was deleted.

20 changes: 10 additions & 10 deletions examples/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module.exports = {
"parserOptions": { "ecmaVersion": 6 },
"rules": {
"no-console": "off",
"node/no-missing-require": "off",
"require-jsdoc": "off",
"valid-jsdoc": "off",
"no-process-exit": "off",
"prefer-const": "off",
"no-var": "off"
}
parserOptions: { ecmaVersion: 6 },
rules: {
'no-console': 'off',
'node/no-missing-require': 'off',
'require-jsdoc': 'off',
'valid-jsdoc': 'off',
'no-process-exit': 'off',
'prefer-const': 'off',
'no-var': 'off',
},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess our lint config should follow the lint rules, huh? 👍

};
18 changes: 8 additions & 10 deletions examples/assistant.v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ var AssistantV1 = require('ibm-watson/assistant/v1');
* Instantiate the Watson Assistant Service
*/
var assistant = new AssistantV1({
username: process.env.ASSISTANT_USERNAME || '<assistant_username>',
password: process.env.ASSISTANT_PASSWORD || '<assistant_password>',
version: '2018-02-16'
// See: https://github.com/watson-developer-cloud/node-sdk#authentication
// iam_apikey: 'INSERT YOUR IAM API KEY HERE',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for the latest version, this should be authenticator and not iam_apikey

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this mean we need to add an authentication field?

version: '2020-04-30',
});

/**
* Calls the assistant message api.
* returns a promise
*/
var message = function(text, context) {
var message = function (text, context) {
var payload = {
workspace_id: process.env.WORKSPACE_ID || '<workspace_id>',
input: {
text: text
text: text,
},
context: context
context: context,
};
return new Promise((resolve, reject) =>
assistant.message(payload, function(err, data) {
assistant.message(payload, function (err, data) {
if (err) {
reject(err);
} else {
Expand All @@ -49,9 +49,7 @@ message('first message', undefined)
})
.then(response2 => {
console.log(JSON.stringify(response2, null, 2), '\n--------');
console.log(
'Note that the two reponses should have the same context.conversation_id'
);
console.log('Note that the two reponses should have the same context.conversation_id');
})
.catch(err => {
// APPLICATION-SPECIFIC CODE TO PROCESS THE ERROR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,6 @@
* Service credentials can be provided directly in this file, or can be saved to a .env file located in the
* same directory.
*
* Requirements:
* 1. Tone Analyzer Service instance:
* - https://cloud.ibm.com/catalog/services/tone-analyzer
* - credentials for this service to be provided below in tone_analyzer variable
* - replace <tone_analyzer_username> and <tone_analyzer_password>
* 2. Assistant Service instance:
* - https://cloud.ibm.com/catalog/services/watson-assistant
* - credentials for this service to be provided below in the assistant variable
* - replace <assistant_username> and <assistant_password>
* 3. Workspace id:
* - a workspace containing intents, entities and dialog nodes must be created using the tool
* available through the IBM Cloud Assistant Service. Details are available at
* https://github.com/watson-developer-cloud/assistant-simple#workspace
* - replace <workspace_id> in the payload variable
*
* Run the code using the command:
* node tone_assistant_integration.v1.js
*/

'use strict';
Expand All @@ -39,18 +22,18 @@ require('dotenv').config({ silent: true });
* Instantiate the Watson Assistant Service
*/
var assistant = new AssistantV1({
username: process.env.ASSISTANT_USERNAME || '<assistant_username>',
password: process.env.ASSISTANT_PASSWORD || '<assistant_password>',
version: '2017-05-26'
// See: https://github.com/watson-developer-cloud/node-sdk#authentication
// iam_apikey: 'INSERT YOUR IAM API KEY HERE',
version: '2020-04-30',
});

/**
* Instantiate the Watson Tone Analyzer Service
*/
var toneAnalyzer = new ToneAnalyzerV3({
username: process.env.TONE_ANALYZER_USERNAME || '<tone_analyzer_username>',
password: process.env.TONE_ANALYZER_PASSWORD || '<tone_analyzer_password>',
version: '2017-09-21'
// See: https://github.com/watson-developer-cloud/node-sdk#authentication
// iam_apikey: 'INSERT YOUR IAM API KEY HERE',
version: '2017-09-21',
});

/**
Expand All @@ -66,8 +49,8 @@ var maintainToneHistoryInContext = true;
var payload = {
workspace_id: process.env.WORKSPACE_ID || '<workspace_id>',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The keys are now camel case: workspaceId

input: {
text: 'I am not happy today :('
}
text: 'I am not happy today :(',
},
};

/**
Expand All @@ -84,12 +67,8 @@ function invokeToneAssistant(payload, maintainToneHistoryInContext) {
tone_detection
.invokeToneAsync(payload, toneAnalyzer)
.then(tone => {
tone_detection.updateUserTone(
payload,
tone,
maintainToneHistoryInContext
);
assistant.message(payload, function(err, data) {
tone_detection.updateUserTone(payload, tone, maintainToneHistoryInContext);
assistant.message(payload, function (err, data) {
if (err) {
// APPLICATION-SPECIFIC CODE TO PROCESS THE ERROR
// FROM ASSISTANT SERVICE
Expand All @@ -101,7 +80,7 @@ function invokeToneAssistant(payload, maintainToneHistoryInContext) {
}
});
})
.catch(function(err) {
.catch(function (err) {
console.log(JSON.stringify(err, null, 2));
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ module.exports = {
* (which contains the user's input text)
*/
function invokeToneAsync(assistantPayload, toneAnalyzer) {
return new Promise(function(resolve, reject) {
toneAnalyzer.tone({ text: assistantPayload.input.text }, function(error, data) {
return new Promise(function (resolve, reject) {
toneAnalyzer.tone({ text: assistantPayload.input.text }, function (error, data) {
if (error) {
reject(error);
} else {
Expand Down Expand Up @@ -101,7 +101,7 @@ function updateTone(user, tones, maintainHistory) {
var primaryTone = null;
var primaryToneScore = null;

tones.forEach(function(tone) {
tones.forEach(function (tone) {
if (tone.score > maxScore) {
maxScore = tone.score;
primaryTone = tone.tone_name.toLowerCase();
Expand Down
6 changes: 3 additions & 3 deletions examples/browserify/public/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var output = document.getElementById('output');
* @return {Promise<String>} returns a promise that resolves to a string token
*/
function getToken() {
return fetch('/api/token/tone_analyzer').then(function(response) {
return fetch('/api/token/tone_analyzer').then(function (response) {
return response.text();
});
}
Expand All @@ -34,7 +34,7 @@ function analyze(token) {
{
text: input.value,
},
function(err, result) {
function (err, result) {
if (err) {
output.innerHTML = err;
return console.log(err);
Expand All @@ -44,6 +44,6 @@ function analyze(token) {
);
}

btn.onclick = function() {
btn.onclick = function () {
getToken().then(analyze);
};
13 changes: 6 additions & 7 deletions examples/browserify/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ app.get(
'/bundle.js',
expressBrowserify('public/client.js', {
watch: isDev,
debug: isDev
debug: isDev,
})
);

Expand All @@ -22,13 +22,12 @@ dotenv.load({ silent: true });

// For local development, specify the username and password or set env properties
var ltAuthService = new AuthorizationV1({
username: process.env.TONE_ANALYZER_USERNAME || '<username>',
password: process.env.TONE_ANALYZER_PASSWORD || '<password>',
url: ToneAnalyzerV3.URL
// See: https://github.com/watson-developer-cloud/node-sdk#authentication
// iam_apikey: 'INSERT YOUR IAM API KEY HERE',
});

app.get('/api/token/tone_analyzer', function(req, res) {
ltAuthService.getToken(function(err, token) {
app.get('/api/token/tone_analyzer', function (req, res) {
ltAuthService.getToken(function (err, token) {
if (err) {
console.log('Error retrieving token: ', err);
return res.status(500).send('Error retrieving token');
Expand All @@ -38,6 +37,6 @@ app.get('/api/token/tone_analyzer', function(req, res) {
});

var port = process.env.PORT || process.env.VCAP_APP_PORT || 3000;
app.listen(port, function() {
app.listen(port, function () {
console.log('Watson browserify example server running at http://localhost:%s/', port);
});
10 changes: 4 additions & 6 deletions examples/compare-comply.v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ const fs = require('fs');
const CompareComplyV1 = require('ibm-watson/compare-comply/v1');

const compareComply = new CompareComplyV1({
// if left unspecified here, the SDK will fall back to the COMPARE_COMPLY_IAM_APIKEY
// environment property, and then IBM Cloud's VCAP_SERVICES environment property
iam_apikey: 'YOUR APIKEY',
url: 'https://gateway.watsonplatform.net/compare-comply/api',
version: '2018-12-06'
// See: https://github.com/watson-developer-cloud/node-sdk#authentication
// iam_apikey: 'INSERT YOUR IAM API KEY HERE',
version: '2018-12-06',
});

const params = {
Expand All @@ -26,4 +24,4 @@ compareComply.compareDocuments(params, (error, data) => {
} else {
console.log(data);
}
);
});
18 changes: 6 additions & 12 deletions examples/discovery.v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@ var DiscoveryV1 = require('ibm-watson/discovery/v1');
var fs = require('fs');

var discovery = new DiscoveryV1({
// if left unspecified here, the SDK will fall back to the DISCOVERY_USERNAME and DISCOVERY_PASSWORD
// environment properties, and then IBM Cloud's VCAP_SERVICES environment property
// username: 'INSERT YOUR USERNAME FOR THE SERVICE HERE',
// password: 'INSERT YOUR PASSWORD FOR THE SERVICE HERE'
// url: 'INSERT YOUR URL FOR THE SERVICE HERE'
username: 'YOUR USERNAME',
password: 'YOUR PASSWORD',
version: '2018-03-05',
url: 'https://gateway.watsonplatform.net/discovery/api/'
// See: https://github.com/watson-developer-cloud/node-sdk#authentication
// iam_apikey: 'INSERT YOUR IAM API KEY HERE',
version: '2020-04-30',
});

discovery.getEnvironments({}, function(error, data) {
discovery.getEnvironments({}, function (error, data) {
console.log(JSON.stringify(data, null, 2));
});

Expand All @@ -26,9 +20,9 @@ discovery.addDocument(
{
environment_id: 'YOUR ENVIRONMENT ID',
collection_id: 'YOUR COLLECTION ID',
file: file
file: file,
},
function(error, data) {
function (error, data) {
if (error) {
console.log(error);
} else {
Expand Down
16 changes: 9 additions & 7 deletions examples/language_translator.v3.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@ const LanguageTranslatorV3 = require('ibm-watson/language-translator/v3');
* Instantiate the Watson Language Translator Service
*/
const languageTranslator = new LanguageTranslatorV3({
username: process.env.LANGUAGE_TRANSLATOR_USERNAME || '<language_translator_username>',
password: process.env.LANGUAGE_TRANSLATOR_PASSWORD || '<language_translator_password>',
version: '2019-01-10'
// See: https://github.com/watson-developer-cloud/node-sdk#authentication
// iam_apikey: 'INSERT YOUR IAM API KEY HERE',
version: '2020-04-30',
});

const params = {
text: "Hello, this is a example of translating language with Watson.",
text: 'Hello, this is a example of translating language with Watson.',
source: 'en',
target: 'es',
}
};

// return the body - primary use case

languageTranslator.translate(params)
languageTranslator
.translate(params)
.then(body => {
console.log(JSON.stringify(body, null, 2));
console.log('\n');
Expand All @@ -34,7 +35,8 @@ languageTranslator.translate(params)

params.return_response = true;

languageTranslator.translate(params)
languageTranslator
.translate(params)
.then(res => {
console.log(JSON.stringify(res, null, 2));
})
Expand Down
Loading