Skip to content

Commit fde46cf

Browse files
fix: update dependencies and examples (#1036)
1 parent c6953c0 commit fde46cf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+12411
-25226
lines changed

.eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = {
1313
"prettier",
1414
],
1515
"rules": {
16-
"prettier/prettier": ["error", {"singleQuote": true, "printWidth": 100}],
16+
"prettier/prettier": ["error"],
1717
"prefer-const": "error",
1818
"prefer-rest-params": "off", // https://github.com/mysticatea/eslint-plugin-node/issues/63
1919
// The rest of these override rules that are enabled by one of the configs we extend but not compatible with current codebase

.prettierrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
"tabWidth": 2,
55
"singleQuote": true,
66
"trailingComma": "es5",
7-
"parser": "babel"
7+
"parser": "babel",
8+
"arrowParens": "avoid"
89
}

README.md

+1-54
Original file line numberDiff line numberDiff line change
@@ -404,52 +404,6 @@ If you have issues with the APIs or have a question about the Watson services, s
404404

405405
## IBM Watson services
406406

407-
### Authorization
408-
409-
The Authorization service can generate auth tokens for situations where providing the service username/password is undesirable.
410-
411-
Tokens are valid for 1 hour and may be sent using the `X-Watson-Authorization-Token` header or the `watson-token` query param.
412-
Note that the token is supplied URL-encoded, and will not be accepted if it is double-encoded in a querystring.
413-
414-
> _NOTE_: Authenticating with the `X-Watson-Authorization-Token` header or the `watson-token` query param is now deprecated. The token continues to work with Cloud Foundry services, but is not supported for services that use Identity and Access Management (IAM) authentication. For details see [Authenticating with IAM tokens](https://cloud.ibm.com/docs/watson?topic=watson-iam#iam) or the README in the IBM Watson SDK you use.
415-
The Authorization SDK now supports returning IAM Access Tokens when instantiated with an IAM API key.
416-
417-
```js
418-
const watson = require('ibm-watson');
419-
const { IamAuthenticator } = require('ibm-watson/auth');
420-
const { BasicAuthenticator } = require('ibm-watson/auth');
421-
422-
// to get an IAM Access Token
423-
const authorization = new watson.AuthorizationV1({
424-
authenticator: new IamAuthenticator({ apikey: 'fakekey-1234' }),
425-
});
426-
427-
authorization.getToken(function (err, token) {
428-
if (!token) {
429-
console.log('error: ', err);
430-
} else {
431-
// Use your token here
432-
}
433-
});
434-
435-
// to get a Watson Token - NOW DEPRECATED
436-
const authorization = new watson.AuthorizationV1({
437-
authenticator: new BasicAuthenticator({ username: 'TTS username', password: 'TTS password' }),
438-
url: 'https://stream.watsonplatform.net/authorization/api', // Speech tokens
439-
});
440-
441-
authorization.getToken({
442-
url: 'https://stream.watsonplatform.net/text-to-speech/api'
443-
},
444-
function (err, token) {
445-
if (!token) {
446-
console.log('error: ', err);
447-
} else {
448-
// Use your token here
449-
}
450-
});
451-
```
452-
453407
### Assistant v2
454408

455409
Use the [Assistant][assistant] service to determine the intent of a message.
@@ -842,12 +796,6 @@ visualRecognition.classify(params)
842796
});
843797
```
844798

845-
846-
## Composing services
847-
848-
### Integration of Tone Analyzer with Conversation
849-
Sample code for [integrating Tone Analyzer and Assistant][assistant_tone_analyzer_example] is provided in the [examples directory][examples].
850-
851799
## Unauthenticated requests
852800
The SDK always expects an authenticator to be passed in. To make an unautuhenticated request, use the `NoAuthAuthenticator`.
853801

@@ -872,6 +820,7 @@ $ NODE_DEBUG='axios' node app.js
872820
where `app.js` is your Node.js file.
873821

874822
## Tests
823+
875824
Running all the tests:
876825
```sh
877826
$ npm test
@@ -909,6 +858,4 @@ This library is licensed under Apache 2.0. Full license text is available in
909858
[speech_to_text]: https://www.ibm.com/watson/services/speech-to-text/
910859
[language_translator]: https://www.ibm.com/watson/services/language-translator/
911860
[examples]: https://github.com/watson-developer-cloud/node-sdk/tree/master/examples
912-
[assistant_tone_analyzer_example]: https://github.com/watson-developer-cloud/node-sdk/tree/master/examples/conversation_tone_analyzer_integration
913-
[license]: http://www.apache.org/licenses/LICENSE-2.0
914861
[ibm-cloud-onboarding]: http://cloud.ibm.com/registration?target=/developer/watson&cm_sp=WatsonPlatform-WatsonServices-_-OnPageNavLink-IBMWatson_SDKs-_-Node

dependency-lint.yml

-49
This file was deleted.

docker/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ You can use docker to test issues you have with the SDK.
99
- Change the node version as needed `FROM node:<your-version>`
1010
- For valid node base images on docker see <https://hub.docker.com/_/node>
1111

12-
- Copy code/file that you wish to test into the dockerfile
12+
- Copy code/file that you wish to test into the dockerfile
1313
- Add line `COPY <src>... <dest>`
1414

15-
- Set dockerfile to execute code file
15+
- Set dockerfile to execute code file
1616
- Add line `CMD [ "<executable>" ]`
17-
17+
1818
- For more information on dockerfile construction please visit <https://docs.docker.com/engine/reference/builder/>
1919

2020
3. Build and run the docker image.

examples/.env.example

-2
This file was deleted.

examples/.eslintrc.js

-12
This file was deleted.

examples/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## IBM Watson Node SDK Examples
2+
3+
The examples in this folder assume you already have [service credentials](https://github.com/watson-developer-cloud/node-sdk#getting-credentials).

examples/assistant.v1.js

+17-30
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,47 @@
1-
'use strict';
2-
3-
var AssistantV1 = require('ibm-watson/assistant/v1');
1+
const AssistantV1 = require('ibm-watson/assistant/v1');
42

53
/**
64
* Instantiate the Watson Assistant Service
75
*/
8-
var assistant = new AssistantV1({
9-
username: process.env.ASSISTANT_USERNAME || '<assistant_username>',
10-
password: process.env.ASSISTANT_PASSWORD || '<assistant_password>',
11-
version: '2018-02-16'
6+
const assistant = new AssistantV1({
7+
// See: https://github.com/watson-developer-cloud/node-sdk#authentication
8+
version: '2020-04-01',
129
});
1310

1411
/**
1512
* Calls the assistant message api.
1613
* returns a promise
1714
*/
18-
var message = function(text, context) {
19-
var payload = {
20-
workspace_id: process.env.WORKSPACE_ID || '<workspace_id>',
15+
const messageAsync = function (text, context) {
16+
const payload = {
17+
workspaceId: process.env.WORKSPACE_ID || '<workspace_id>',
2118
input: {
22-
text: text
19+
text: text,
2320
},
24-
context: context
21+
context: context,
2522
};
26-
return new Promise((resolve, reject) =>
27-
assistant.message(payload, function(err, data) {
28-
if (err) {
29-
reject(err);
30-
} else {
31-
resolve(data);
32-
}
33-
})
34-
);
23+
return assistant.message(payload);
3524
};
3625

3726
// This example makes two successive calls to assistant service.
3827
// Note how the context is passed:
3928
// In the first message the context is undefined. The service starts a new assistant.
4029
// The context returned from the first call is passed in the second request - to continue the assistant.
41-
message('first message', undefined)
30+
messageAsync('first message', undefined)
4231
.then(response1 => {
4332
// APPLICATION-SPECIFIC CODE TO PROCESS THE DATA
4433
// FROM ASSISTANT SERVICE
45-
console.log(JSON.stringify(response1, null, 2), '\n--------');
34+
console.log(JSON.stringify(response1.result, null, 2), '\n--------');
4635

4736
// invoke a second call to assistant
48-
return message('second message', response1.context);
37+
return messageAsync('second message', response1.result.context);
4938
})
5039
.then(response2 => {
51-
console.log(JSON.stringify(response2, null, 2), '\n--------');
52-
console.log(
53-
'Note that the two reponses should have the same context.conversation_id'
54-
);
40+
console.log(JSON.stringify(response2.result, null, 2), '\n--------');
41+
console.log('Note that the two reponses should have the same context.conversation_id');
5542
})
56-
.catch(err => {
43+
.catch(error => {
5744
// APPLICATION-SPECIFIC CODE TO PROCESS THE ERROR
5845
// FROM ASSISTANT SERVICE
59-
console.error(JSON.stringify(err, null, 2));
46+
console.error(JSON.stringify(error, null, 2));
6047
});

examples/assistant_tone_analyzer_integration/.env.example

-9
This file was deleted.

examples/assistant_tone_analyzer_integration/.gitignore

-2
This file was deleted.

examples/assistant_tone_analyzer_integration/README.md

-30
This file was deleted.

0 commit comments

Comments
 (0)