You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -64,8 +65,9 @@ Credentials are checked for in the following order:
64
65
1. Hard-coded or programatic credentials passed to the service constructor
65
66
66
67
2. Environment variables:
67
-
-`SERVICE_NAME_USERNAME` and `SERVICE_NAME_PASSWORD` environment properties (or `SERVICE_NAME_API_KEY` when appropriate) and, optionally, `SERVICE_NAME_URL`
68
+
-`SERVICE_NAME_USERNAME` and `SERVICE_NAME_PASSWORD` environment properties
68
69
- If using IAM: `SERVICE_NAME_IAM_APIKEY` and optionally `SERVICE_NAME_IAM_URL`, or `SERVICE_NAME_IAM_ACCESS_TOKEN`
70
+
- Optionally, `SERVICE_NAME_URL`
69
71
70
72
3. IBM-Cloud-supplied credentials (via the `VCAP_SERVICES` JSON-encoded environment property)
71
73
@@ -187,6 +189,39 @@ var discovery = new DiscoveryV1({
187
189
});
188
190
```
189
191
192
+
### Callbacks vs Promises
193
+
194
+
All SDK methods are asynchronous, as they are making network requests to Watson services. To handle receiving the data from these requests, the SDK offers support for both Promises and Callback functions. A Promise will be returned by default unless a Callback function is provided.
195
+
196
+
```js
197
+
constdiscovery=newwatson.DiscoveryV1({
198
+
/* iam_apikey, version, url, etc... */
199
+
});
200
+
201
+
// using Promises
202
+
discovery.listEnvironments()
203
+
.then(body=> {
204
+
console.log(JSON.stringify(body, null, 2));
205
+
})
206
+
.catch(err=> {
207
+
console.log(err);
208
+
});
209
+
210
+
// using Promises provides the ability to use async / await
211
+
asyncfunctioncallDiscovery() { // note that callDiscovery also returns a Promise
212
+
constbody=awaitdiscovery.listEnvironments();
213
+
}
214
+
215
+
// using a Callback function
216
+
discovery.listEnvironments((err, res) => {
217
+
if (err) {
218
+
console.log(err);
219
+
} else {
220
+
console.log(JSON.stringify(res, null, 2));
221
+
}
222
+
});
223
+
```
224
+
190
225
### Setting the service URL
191
226
192
227
You can set the service URL by calling the setServiceUrl() method.
@@ -231,6 +266,8 @@ assistant.message({
231
266
232
267
To retrieve the HTTP response, all methods can be called with a callback function with three parameters, with the third being the response. Users for example may retrieve the response headers with this usage pattern.
233
268
269
+
If using Promises, the parameter `return_response` must be added and set to `true`. Then, the result returned will be equivalent to the third argument in the callback function - the entire response.
270
+
234
271
Here is an example of how to access the response headers for Watson Assistant:
Use the [Assistant][conversation] service to determine the intent of a message.
419
+
Use the [Assistant][assistant] service to determine the intent of a message.
371
420
372
421
Note: You must first create a workspace via IBM Cloud. See [the documentation](https://console.bluemix.net/docs/services/conversation/index.html#about) for details.
### Integration of Tone Analyzer with Conversation
749
-
Sample code for [integrating Tone Analyzer and Conversation][conversation_tone_analyzer_example] is provided in the [examples directory][examples].
794
+
Sample code for [integrating Tone Analyzer and Assistant][assistant_tone_analyzer_example] is provided in the [examples directory][examples].
750
795
751
796
## Unauthenticated requests
752
-
By default, the library tries to use Basic Auth and will ask for `api_key`or `username` and `password`and send an `Authorization: Basic XXXXXXX`. You can avoid this by using:
797
+
By default, the library tries to authenticate and will ask for `iam_apikey`, `iam_access_token`, or `username` and `password`to send an `Authorization` header. You can avoid this by using:
753
798
754
799
`use_unauthenticated`.
755
800
@@ -796,7 +841,6 @@ This library is licensed under Apache 2.0. Full license text is available in
796
841
See [CONTRIBUTING](https://github.com/watson-developer-cloud/node-sdk/blob/master/.github/CONTRIBUTING.md).
0 commit comments