Skip to content

Commit

Permalink
Merge pull request #152 from ylecleach/master
Browse files Browse the repository at this point in the history
added an optional context. change node output format
  • Loading branch information
chughts committed Jul 12, 2016
2 parents 7e5eae3 + f2561da commit 4ff91ce
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
23 changes: 10 additions & 13 deletions services/conversation/v1.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,20 @@
<p><b>Usage</b></p>
<p>This node should be provided in input : </p>
<ul>
<li><code>msg.params.workspace_id</code> : unique identifier of the workspace to be used. Could be also configured in the node. Format: String </li>
<li><code>msg.payload</code> : the message of the conversation to analyse; Format: String </li>
<li><code>msg.params.workspace_id</code> : unique identifier of the workspace to be used. Could be also configured in the node. Format: String </li>
<li><code>msg.params.context</code> : A optional context object that includes state information for the conversation. When you send multiple requests for the same conversation, include the context object from the response. (<a href="http://www.ibm.com/watson/developercloud/conversation/api/v1/#send_input" target="_blank">documentation</a>). Format: JSON </li>
</ul>
<p>All Results will made available at <code>msg.result</code> in JSON format, with the following information :</p>
<ul>
<li><code>msg.result.input.text</code>: the input used for the analysis Format: String </li>
<li><code>msg.result.intents</code> : a array of Objects {"intent": string, confidence: number}. Example : { "intent": "weather", "confidence": 0.12767628721396487 }</li>
<li><code>msg.result.input.entities</code>: the input used for the analysis Format: String </li>
</ul>
<p>All Results will made available at <code>msg.payload</code> in JSON format. Check the <a href="http://www.ibm.com/watson/developercloud/conversation/api/v1/#send_input" target="_blank">documentation</a> for details.</p>

<p><b>Important</b> : before using this node, a workspace must be created and configured using the Watson Conversation Tool available in Bluemix, in the Watson Conversation instance detail page.</p>
<br/>

<p>For full details, please see the <a href="http://www.ibm.com/watson/developercloud/doc/conversation/" target="_blank">Watson Conversation API documentation</a></p>
<p>See also the <a href="https://watson-api-explorer.mybluemix.net/" target="_blank">API Explorer</a> and the <a href="http://www.ibm.com/watson/developercloud/doc/conversation/tutorial_basic.shtml" target="_blank">Tutorial</a>.</p>

<p>Check the sample Flow for this node on <a href="https://github.com/watson-developer-cloud/node-red-bluemix-starter" target="_blank">Watson Node-RED Starter</a></p>
<p><b>Documentation</b>
<ul>
<li><a href="http://www.ibm.com/watson/developercloud/doc/conversation/" target="_blank">Watson Conversation API documentation</a></li>
<li><a href="https://watson-api-explorer.mybluemix.net/" target="_blank">Watson API Explorer</a></li>
<li><a href="http://www.ibm.com/watson/developercloud/doc/conversation/tutorial_basic.shtml" target="_blank">Basic tutorial</a>
<li><a href="https://github.com/watson-developer-cloud/node-red-bluemix-starter" target="_blank">Sample Flow in the Watson Node-RED Starter</a>
</ul>
</script>


Expand Down
18 changes: 11 additions & 7 deletions services/conversation/v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,23 @@ module.exports = function (RED) {
}

function verifyInputs(node, msg, config) {
if (!config.workspaceid && !msg.params.workspace_id) {
node.error('Missing workspace_id. check node documentation.',msg);
return false;
}
// workspaceid can be either configured in the node,
// or sent into msg.params.workspace_id
if (config.workspaceid && config.workspaceid) {
node.workspaceid = config.workspaceid;
//console.log('node.workspaceid', node.workspaceid);
return true;
}
if (msg.params && msg.params.workspace_id) {
node.workspaceid = msg.params.workspace_id;
return true;
}
node.error('Missing workspace_id. check node documentation.',msg);
return false;
// option context in JSON format
if (msg.params && msg.params.context) {
node.context = msg.params.context;
}
return true;
}

function verifyServiceCredentials(node, msg) {
Expand Down Expand Up @@ -91,8 +95,7 @@ module.exports = function (RED) {
node.error(err);
return;
}
msg.result = body;
msg.payload = 'see msg.result';
msg.payload = body;
node.send(msg);
node.status({});
}
Expand All @@ -101,6 +104,7 @@ module.exports = function (RED) {
node.status({fill:'blue', shape:'dot' , text:'Calling Conversation service ...'});
params.workspace_id = node.workspaceid;
params.input = {text:msg.payload};
params.context =
// call POST /message through SDK
node.service.message(params, function(err, body) {
processResponse(err,body,node,msg);
Expand Down

0 comments on commit 4ff91ce

Please sign in to comment.