Skip to content

Commit

Permalink
Merge pull request #340 from chughts/master
Browse files Browse the repository at this point in the history
Allow Conversation Workspace Manager node to be configured through msg.params
  • Loading branch information
chughts committed Oct 8, 2017
2 parents be75572 + 1fe07ab commit d49c706
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 34 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Node-RED Watson Nodes for IBM Bluemix

<a href="https://cla-assistant.io/watson-developer-cloud/node-red-node-watson"><img src="https://cla-assistant.io/readme/badge/watson-developer-cloud/node-red-node-watson" alt="CLA assistant" /></a>

### New in version 0.5.18
- Allow Conversation Workspace Manager node to be dynamically configured.

### New in version 0.5.17
- CRUD methods for Entity Values and Dialog Nodes in Conversation Workspace Manager node.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-node-watson",
"version": "0.5.17",
"version": "0.5.18",
"description": "A collection of Node-RED nodes for IBM Watson services",
"dependencies": {
"alchemy-api": "^1.3.0",
Expand Down
63 changes: 63 additions & 0 deletions services/conversation/v1-workspace-manager.html
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,71 @@
<p>In this mode the selected dialog node is removed from the worskpace.
</p>
</li>
</ul>

<p>The node configurations can be overridden by setting
<ul>
<li>
<code>msg.params.workspace_id</code>
</li>
<li>
<code>msg.params.intent</code>
</li>
<li>
<code>msg.params.example</code>
</li>
<li>
<code>msg.params.entity</code>
</li>
<li>
<code>msg.params.entity_value</code>
</li>
<li>
<code>msg.params.dialog_node</code>
</li>

<li>
<code>msg.params.method</code>
<p>to one of the following values:
<select>
<option> listWorkspaces </option>
<option> getWorkspace </option>
<option> createWorkspace </option>
<option> updateWorkspace </option>
<option> deleteWorkspace </option>
<option> listIntents </option>
<option> getIntent </option>
<option> createIntent </option>
<option> updateIntent </option>
<option> deleteIntent </option>
<option> listExamples </option>
<option> createExample </option>
<option> deleteExample </option>
<option> listCounterExamples </option>
<option> createCounterExample</option>
<option> deleteCounterExample </option>
<option> listEntities </option>
<option> getEntity </option>
<option> createEntity </option>
<option> updateEntity </option>
<option> deleteEntity </option>
<option> listEntityValues </option>
<option> getEntityValue </option>
<option> addEntityValue </option>
<option> updateEntityValue </option>
<option> deleteEntityValue </option>
<option> listDialogNodes </option>
<option> getDialogNode </option>
<option> createDialogNode </option>
<option> updateDialogNode </option>
<option> deleteDialogNode </option>
</select>
</p>


</li>
</ul>
</p>

<p>For more information about the conversation service,
read the <a href="https://www.ibm.com/watson/developercloud/doc/conversation/index.html">
Expand Down
106 changes: 73 additions & 33 deletions services/conversation/v1-workspace-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,10 @@ module.exports = function (RED) {
return p;
}

function buildWorkspaceParams(method, config, params) {
var message = '';
function buildWorkspaceParams(msg, method, config, params) {
var message = '',
workspace_id = '';

switch (method) {
case 'getIntent':
case 'updateIntent':
Expand Down Expand Up @@ -649,8 +651,13 @@ module.exports = function (RED) {
case 'createDialogNode':
case 'updateDialogNode':
case 'deleteDialogNode':
if (config['cwm-workspace-id']) {
params['workspace_id'] = config['cwm-workspace-id'];
if (msg.params && msg.params.workspace_id) {
workspace_id = msg.params.workspace_id;
} else if (config['cwm-workspace-id']) {
workspace_id = config['cwm-workspace-id'];
}
if (workspace_id) {
params['workspace_id'] = workspace_id;
} else {
message = 'Workspace ID is required';
}
Expand All @@ -662,9 +669,10 @@ module.exports = function (RED) {
return Promise.resolve();
}

function buildIntentParams(method, config, params) {
var message = '';
var field = 'intent';
function buildIntentParams(msg, method, config, params) {
var message = '',
intent = '',
field = 'intent';

switch (method) {
case 'updateIntent':
Expand All @@ -675,8 +683,13 @@ module.exports = function (RED) {
case 'listExamples':
case 'createExample':
case 'deleteExample':
if (config['cwm-intent']) {
params[field] = config['cwm-intent'];
if (msg.params && msg.params.intent) {
intent = msg.params.intent;
} else if (config['cwm-intent']) {
intent = config['cwm-intent'];
}
if (intent) {
params[field] = intent;
} else {
message = 'a value for Intent is required';
}
Expand All @@ -688,9 +701,10 @@ module.exports = function (RED) {
return Promise.resolve();
}

function buildEntityParams(method, config, params) {
function buildEntityParams(msg, method, config, params) {
var message = '',
field = 'entity';
field = 'entity',
entity = '';

switch (method) {
case 'updateEntity':
Expand All @@ -703,8 +717,13 @@ module.exports = function (RED) {
case 'addEntityValue':
case 'updateEntityValue':
case 'deleteEntityValue':
if (config['cwm-entity']) {
params[field] = config['cwm-entity'];
if (msg.params && msg.params.entity) {
entity = msg.params.entity;
} else if (config['cwm-entity']) {
entity = config['cwm-entity'];
}
if (entity) {
params[field] = entity;
} else {
message = 'a value for Entity is required';
}
Expand All @@ -716,9 +735,10 @@ module.exports = function (RED) {
return Promise.resolve();
}

function buildEntityValueParams(method, config, params) {
function buildEntityValueParams(msg, method, config, params) {
var message = '',
field = 'value';
field = 'value',
entityValue = '';

switch (method) {
case 'updateEntityValue':
Expand All @@ -727,8 +747,13 @@ module.exports = function (RED) {
case 'getEntityValue':
case 'addEntityValue':
case 'deleteEntityValue':
if (config['cwm-entity-value']) {
params[field] = config['cwm-entity-value'];
if (msg.params && msg.params.entity_value) {
entityValue = msg.params.entity_value;
} else if (config['cwm-entity-value']) {
entityValue = config['cwm-entity-value'];
}
if (entityValue) {
params[field] = entityValue;
} else {
message = 'a value for Entity value is required';
}
Expand All @@ -740,18 +765,24 @@ module.exports = function (RED) {
return Promise.resolve();
}

function buildDialogParams(method, config, params) {
function buildDialogParams(msg, method, config, params) {
var message = '',
field = 'dialog_node';
field = 'dialog_node',
dialogID = '';

switch (method) {
case 'updateDialogNode':
field = 'old_dialog_node';
// deliberate no break
case 'getDialogNode':
case 'deleteDialogNode':
if (config['cwm-dialog-node']) {
params[field] = config['cwm-dialog-node'];
if (msg.params && msg.params.dialog_node) {
dialogID = msg.params.dialog_node;
} else if (config['cwm-dialog-node']) {
dialogID = config['cwm-dialog-node'];
}
if (dialogID) {
params[field] = dialogID;
} else {
message = 'a value for Dialog Node ID is required';
}
Expand All @@ -763,17 +794,22 @@ module.exports = function (RED) {
return Promise.resolve();
}


function buildExampleParams(method, config, params) {
var message = '';
function buildExampleParams(msg, method, config, params) {
var message = '',
example = '';

switch (method) {
case 'createExample':
case 'deleteExample':
case 'createCounterExample':
case 'deleteCounterExample':
if (config['cwm-example']) {
params['text'] = config['cwm-example'];
if (msg.params && msg.params.example) {
example = msg.params.example;
} else if (config['cwm-example']) {
example = config['cwm-example'];
}
if (example) {
params['text'] = example;
} else {
message = 'Example Input is required';
}
Expand All @@ -785,7 +821,6 @@ module.exports = function (RED) {
return Promise.resolve();
}


function buildExportParams(method, config, params) {
switch (method) {
case 'getIntent':
Expand All @@ -805,21 +840,21 @@ module.exports = function (RED) {
// Copy over the appropriate parameters for the required
// method from the node configuration
function buildParams(msg, method, config, params) {
var p = buildWorkspaceParams(method, config, params)
var p = buildWorkspaceParams(msg, method, config, params)
.then(function(){
return buildIntentParams(method, config, params);
return buildIntentParams(msg, method, config, params);
})
.then(function(){
return buildExampleParams(method, config, params);
return buildExampleParams(msg, method, config, params);
})
.then(function(){
return buildEntityParams(method, config, params);
return buildEntityParams(msg, method, config, params);
})
.then(function(){
return buildEntityValueParams(method, config, params);
return buildEntityValueParams(msg, method, config, params);
})
.then(function(){
return buildDialogParams(method, config, params);
return buildDialogParams(msg, method, config, params);
})
.then(function(){
return buildExportParams(method, config, params);
Expand Down Expand Up @@ -1032,6 +1067,11 @@ module.exports = function (RED) {
message = '',
params = {};

// All method to be overridden
if (msg.params && msg.params.method) {
method = msg.params.method;
}

username = sUsername || this.credentials.username;
password = sPassword || this.credentials.password || config.password;

Expand Down

0 comments on commit d49c706

Please sign in to comment.