Skip to content

Commit d2228a3

Browse files
authored
Merge pull request watson-developer-cloud#278 from watson-developer-cloud/conversation-v1
Conversation v1
2 parents 65ce1fa + 9251f5f commit d2228a3

File tree

4 files changed

+105
-2
lines changed

4 files changed

+105
-2
lines changed

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ APIs and SDKs that use cognitive computing to solve complex problems.
2323
* [Alchemy Data News](#alchemy-data-news)
2424
* [Authorization](#authorization)
2525
* [Concept Insights](#concept-insights)
26+
* [Conversation](#conversation)
2627
* [Dialog](#dialog)
2728
* [Document Conversion](#document-conversion)
2829
* [Language Translator](#language-translator)
@@ -239,6 +240,34 @@ concept_insights.graphs.annotateText(params, function(err, res) {
239240
});
240241
```
241242

243+
### Conversation
244+
245+
Use the [Conversation](http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/conversation.html) service to determine the intent of a message.
246+
247+
Note: you must first create a workspace via Bluemix. See [the documentation](http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/conversation/overview.shtml) for details.
248+
249+
```js
250+
var watson = require('watson-developer-cloud');
251+
252+
var conversation = watson.conversation({
253+
username: '<username>',
254+
password: '<password>',
255+
version: 'v1',
256+
version_date: '2016-07-01'
257+
});
258+
259+
conversation.message({
260+
input: 'What\'s the weather?',
261+
workspace_id: '<workspace id>'
262+
}, function(err, response) {
263+
if (err) {
264+
console.error(err);
265+
} else {
266+
console.log(JSON.stringify(response, null, 2));
267+
}
268+
});
269+
```
270+
242271
### Dialog
243272
Use the Dialog service to list all the dialogs you have.
244273

@@ -248,7 +277,8 @@ var watson = require('watson-developer-cloud');
248277
var dialog = watson.dialog({
249278
username: '<username>',
250279
password: '<password>',
251-
version: 'v1'
280+
version: 'v1',
281+
version_date: '2015-12-01'
252282
});
253283

254284
dialog.getDialogs({}, function (err, dialogs) {

services/conversation/v1-experimental.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ function Conversation(options) {
3131
if (typeof options.version_date === 'undefined') {
3232
throw new Error('Argument error: version_date was not specified, use 2016-05-19');
3333
}
34+
35+
if (!options.silent) {
36+
// eslint-disable-next-line no-console
37+
console.warn(new Error("Watson Conversation v1-experimental is sunset as of 2016-08-01. Please upgrade to v1. Set {silent: true} to disable this message.").stack);
38+
}
3439

3540
// Default URL
3641
var serviceDefaults = {

services/conversation/v1.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* Copyright 2015 IBM Corp. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
var extend = require('extend');
20+
var requestFactory = require('../../lib/requestwrapper');
21+
var pick = require('object.pick');
22+
23+
/**
24+
*
25+
* @param options
26+
* @constructor
27+
*/
28+
function Conversation(options) {
29+
30+
// Check if 'version_date' was provided
31+
if (typeof options.version_date === 'undefined') {
32+
throw new Error('Argument error: version_date was not specified, use 2016-07-01');
33+
}
34+
35+
// Default URL
36+
var serviceDefaults = {
37+
url: 'https://gateway.watsonplatform.net/conversation/api',
38+
qs: {
39+
version: options.version_date
40+
}
41+
};
42+
43+
// Replace default options with user provided
44+
this._options = extend(serviceDefaults, options);
45+
}
46+
47+
/**
48+
* Returns a response to a user utterance.
49+
* @param {Object} params { workspace_id: '', }
50+
*/
51+
Conversation.prototype.message = function(params, callback) {
52+
params = params || {};
53+
54+
var parameters = {
55+
options: {
56+
url: '/v1/workspaces/{workspace_id}/message',
57+
method: 'POST',
58+
json: true,
59+
body: pick(params, ['input', 'context']),
60+
path: pick(params, ['workspace_id'])
61+
},
62+
requiredParams: ['workspace_id'],
63+
defaultOptions: this._options
64+
};
65+
return requestFactory(parameters, callback);
66+
};
67+
68+
module.exports = Conversation;

test/test.integration-all-services.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ describe('integration-all-services', function() {
8686
describe('functional_visual_recognition', function() {
8787

8888
describe('v3', function() {
89-
this.timeout(TWENTY_SECONDS);
89+
this.timeout(THIRTY_SECONDS * 2);
9090
var visual_recognition = watson.visual_recognition(auth.visual_recognition.v3);
9191

9292
it('should return error when invalid api_key', function(done) {

0 commit comments

Comments
 (0)