Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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"
}
55 changes: 1 addition & 54 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,52 +404,6 @@ If you have issues with the APIs or have a question about the Watson services, s

## IBM Watson services

### Authorization

The Authorization service can generate auth tokens for situations where providing the service username/password is undesirable.

Tokens are valid for 1 hour and may be sent using the `X-Watson-Authorization-Token` header or the `watson-token` query param.
Note that the token is supplied URL-encoded, and will not be accepted if it is double-encoded in a querystring.

> _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.
The Authorization SDK now supports returning IAM Access Tokens when instantiated with an IAM API key.

```js
const watson = require('ibm-watson');
const { IamAuthenticator } = require('ibm-watson/auth');
const { BasicAuthenticator } = require('ibm-watson/auth');

// to get an IAM Access Token
const authorization = new watson.AuthorizationV1({
authenticator: new IamAuthenticator({ apikey: 'fakekey-1234' }),
});

authorization.getToken(function (err, token) {
if (!token) {
console.log('error: ', err);
} else {
// Use your token here
}
});

// to get a Watson Token - NOW DEPRECATED
const authorization = new watson.AuthorizationV1({
authenticator: new BasicAuthenticator({ username: 'TTS username', password: 'TTS password' }),
url: 'https://stream.watsonplatform.net/authorization/api', // Speech tokens
});

authorization.getToken({
url: 'https://stream.watsonplatform.net/text-to-speech/api'
},
function (err, token) {
if (!token) {
console.log('error: ', err);
} else {
// Use your token here
}
});
```

### Assistant v2

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


## Composing services

### Integration of Tone Analyzer with Conversation
Sample code for [integrating Tone Analyzer and Assistant][assistant_tone_analyzer_example] is provided in the [examples directory][examples].

## Unauthenticated requests
The SDK always expects an authenticator to be passed in. To make an unautuhenticated request, use the `NoAuthAuthenticator`.

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

## Tests

Running all the tests:
```sh
$ npm test
Expand Down Expand Up @@ -909,6 +858,4 @@ This library is licensed under Apache 2.0. Full license text is available in
[speech_to_text]: https://www.ibm.com/watson/services/speech-to-text/
[language_translator]: https://www.ibm.com/watson/services/language-translator/
[examples]: https://github.com/watson-developer-cloud/node-sdk/tree/master/examples
[assistant_tone_analyzer_example]: https://github.com/watson-developer-cloud/node-sdk/tree/master/examples/conversation_tone_analyzer_integration
[license]: http://www.apache.org/licenses/LICENSE-2.0
[ibm-cloud-onboarding]: http://cloud.ibm.com/registration?target=/developer/watson&cm_sp=WatsonPlatform-WatsonServices-_-OnPageNavLink-IBMWatson_SDKs-_-Node
49 changes: 0 additions & 49 deletions dependency-lint.yml

This file was deleted.

6 changes: 3 additions & 3 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ You can use docker to test issues you have with the SDK.
- Change the node version as needed `FROM node:<your-version>`
- For valid node base images on docker see <https://hub.docker.com/_/node>

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

- Set dockerfile to execute code file
- Set dockerfile to execute code file
- Add line `CMD [ "<executable>" ]`

- For more information on dockerfile construction please visit <https://docs.docker.com/engine/reference/builder/>

3. Build and run the docker image.
Expand Down
2 changes: 0 additions & 2 deletions examples/.env.example

This file was deleted.

12 changes: 0 additions & 12 deletions examples/.eslintrc.js

This file was deleted.

3 changes: 3 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## IBM Watson Node SDK Examples

The examples in this folder assume you already have [service credentials](https://github.com/watson-developer-cloud/node-sdk#getting-credentials).
47 changes: 17 additions & 30 deletions examples/assistant.v1.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,47 @@
'use strict';

var AssistantV1 = require('ibm-watson/assistant/v1');
const 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'
const assistant = new AssistantV1({
// See: https://github.com/watson-developer-cloud/node-sdk#authentication
version: '2020-04-01',
});

/**
* Calls the assistant message api.
* returns a promise
*/
var message = function(text, context) {
var payload = {
workspace_id: process.env.WORKSPACE_ID || '<workspace_id>',
const messageAsync = function (text, context) {
const payload = {
workspaceId: 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) {
if (err) {
reject(err);
} else {
resolve(data);
}
})
);
return assistant.message(payload);
};

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

// invoke a second call to assistant
return message('second message', response1.context);
return messageAsync('second message', response1.result.context);
})
.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(JSON.stringify(response2.result, null, 2), '\n--------');
console.log('Note that the two reponses should have the same context.conversation_id');
})
.catch(err => {
.catch(error => {
// APPLICATION-SPECIFIC CODE TO PROCESS THE ERROR
// FROM ASSISTANT SERVICE
console.error(JSON.stringify(err, null, 2));
console.error(JSON.stringify(error, null, 2));
});
9 changes: 0 additions & 9 deletions examples/assistant_tone_analyzer_integration/.env.example

This file was deleted.

2 changes: 0 additions & 2 deletions examples/assistant_tone_analyzer_integration/.gitignore

This file was deleted.

30 changes: 0 additions & 30 deletions examples/assistant_tone_analyzer_integration/README.md

This file was deleted.

Loading