From da6e1a66a3b064fa7b6e1d07823228f452970bfe Mon Sep 17 00:00:00 2001 From: Yves Le Cleach Date: Tue, 12 Jul 2016 14:20:57 +0200 Subject: [PATCH] added an optional context. change node output format --- services/conversation/v1.html | 23 ++++++++++------------- services/conversation/v1.js | 18 +++++++++++------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/services/conversation/v1.html b/services/conversation/v1.html index 70cf5750..98d4e115 100644 --- a/services/conversation/v1.html +++ b/services/conversation/v1.html @@ -46,23 +46,20 @@

Usage

This node should be provided in input :

-

All Results will made available at msg.result in JSON format, with the following information :

- +

All Results will made available at msg.payload in JSON format. Check the documentation for details.

Important : 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.

-
- -

For full details, please see the Watson Conversation API documentation

-

See also the API Explorer and the Tutorial.

- -

Check the sample Flow for this node on Watson Node-RED Starter

+

Documentation +

diff --git a/services/conversation/v1.js b/services/conversation/v1.js index 2f3ce0ac..977d9dc6 100644 --- a/services/conversation/v1.js +++ b/services/conversation/v1.js @@ -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) { @@ -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({}); } @@ -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);