Skip to content

Conversation v1 #278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 6, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
conversation v1 and a readme entry (untested)
  • Loading branch information
nfriedly committed Jun 29, 2016
commit b092762eacec1146b11b3795203a77d3e970eb8c
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ APIs and SDKs that use cognitive computing to solve complex problems.
* [Alchemy Data News](#alchemy-data-news)
* [Authorization](#authorization)
* [Concept Insights](#concept-insights)
* [Conversation](#conversation)
* [Dialog](#dialog)
* [Document Conversion](#document-conversion)
* [Language Translator](#language-translator)
Expand Down Expand Up @@ -239,6 +240,34 @@ concept_insights.graphs.annotateText(params, function(err, res) {
});
```

### Conversation

Use the [Conversation](http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/conversation.html) service to determine the intent of a message.

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.

```js
var watson = require('watson-developer-cloud');

var conversation = watson.conversation({
username: '<username>',
password: '<password>',
version: 'v1',
version_date: '2016-07-04'
});

conversation.message({
input: 'What's the weather?',
workspace_id: '<workspace id>'
}, function(err, response) {
if (err) {
console.error(err);
} else {
console.log(JSON.stringify(response, null, 2));
}
});
```

### Dialog
Use the Dialog service to list all the dialogs you have.

Expand All @@ -248,7 +277,8 @@ var watson = require('watson-developer-cloud');
var dialog = watson.dialog({
username: '<username>',
password: '<password>',
version: 'v1'
version: 'v1',
version_date: '2015-12-01'
});

dialog.getDialogs({}, function (err, dialogs) {
Expand Down
68 changes: 68 additions & 0 deletions services/conversation/v1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* Copyright 2015 IBM Corp. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

var extend = require('extend');
var requestFactory = require('../../lib/requestwrapper');
var pick = require('object.pick');

/**
*
* @param options
* @constructor
*/
function Conversation(options) {

// Check if 'version_date' was provided
if (typeof options.version_date === 'undefined') {
throw new Error('Argument error: version_date was not specified, use 2016-07-04');
}

// Default URL
var serviceDefaults = {
url: 'https://gateway.watsonplatform.net/conversation-v1/api',
qs: {
version: options.version_date
}
};

// Replace default options with user provided
this._options = extend(serviceDefaults, options);
}

/**
* Returns a response to a user utterance.
* @param {Object} params { workspace_id: '', }
*/
Conversation.prototype.message = function(params, callback) {
params = params || {};

var parameters = {
options: {
url: '/v1/workspaces/{workspace_id}/message',
method: 'POST',
json: true,
body: pick(params, ['input', 'context']),
path: pick(params, ['workspace_id'])
},
requiredParams: ['workspace_id'],
defaultOptions: this._options
};
return requestFactory(parameters, callback);
};

module.exports = Conversation;