Skip to content

Commit

Permalink
Merge pull request #472 from chughts/091
Browse files Browse the repository at this point in the history
091
  • Loading branch information
chughts authored Feb 7, 2020
2 parents 0bbd9b6 + 9b8b5dc commit aa4cecd
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Node-RED Watson Nodes for IBM Cloud

<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.9.1
- Assistant V2 - Allow flow to assign a string session id. The node maps this user specified session id to the real session id. Additional param option allow session id to be reset.

### New in version 0.9.0
- Node-RED & IBM-Watson & Use of promises on API invocation & IAM URL construct migration & Removal of default endpoint of
- Assistant V1
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.9.0",
"version": "0.9.1",
"description": "A collection of Node-RED nodes for IBM Watson services",
"dependencies": {
"async": "^1.5.2",
Expand Down
5 changes: 4 additions & 1 deletion services/assistant/v2.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@
If this field is not provided then the node will generate a new session_id and
return it as part of the response. If the node is not used in multi-session mode, then
a session_id need not be provided, to reset the session_id in single-session mode
send a null value as the session_id. Format: String </li>
send a null value as the session_id.
Format: String </li>
<li><code>msg.params.reset_session</code> (optional): Will force a session reset
Format: Any </li>
<li><code>msg.params.assistant_id</code> : unique identifier of the assistant to be used. Could be also configured in the node. Format: String </li>
<li><code>msg.params.timeout</code> (optional): The timeout period (in millisecond) for Watson request. Leave empty or set to 0 to disable. </li>
<li><code>msg.params.alternate_intents</code> (optional) : whether to return more than one intent. Default is false. Set to true to return all matching intents. For example, return all intents when the confidence is not high to allow users to choose their intent.</li>
Expand Down
36 changes: 28 additions & 8 deletions services/assistant/v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,27 @@ module.exports = function(RED) {

function setSessionID(msg) {
let session_id = null;
let id = null;

if (!config.multisession) {
let id = node.context().flow.get('session_id');
if (id) {
session_id = id;
if (msg.params && 'reset_session' in msg.params) {
// There is a reset request, therefore no need
// to look it up
} else {
if (!config.multisession) {
if (msg.params && 'session_id' in msg.params && !msg.params.session_id) {
// Have a session id in single session mode
// but its a null string so force a reset of the session.
} else {
id = node.context().flow.get('session_id');
}
} else if (msg.params && msg.params.session_id) {
let key = msg.params.session_id;
id = node.context().flow.get('session-' + key);
}
} else if (msg.params && msg.params.session_id) {
session_id = msg.params.session_id;
}

if (id) {
session_id = id;
}

return session_id;
Expand Down Expand Up @@ -265,7 +278,8 @@ module.exports = function(RED) {
return Promise.resolve();
}

function checkSession(params) {

function checkSession(msg, params) {
return new Promise(function resolver(resolve, reject){
if (params.sessionId) {
resolve();
Expand All @@ -280,6 +294,12 @@ module.exports = function(RED) {
if (params.sessionId) {
if (!config.multisession) {
node.context().flow.set('session_id', params.sessionId);
} else {
let key = params.sessionId;
if (msg.params && msg.params.session_id){
key = msg.params.session_id;
}
node.context().flow.set('session-' + key, params.sessionId);
}
resolve();
} else {
Expand Down Expand Up @@ -333,7 +353,7 @@ module.exports = function(RED) {
return buildService(settings);
})
.then(function(){
return checkSession(params);
return checkSession(msg, params);
})
.then(function(){
node.status({ fill: 'blue', shape: 'dot', text: 'Calling Assistant service ...'});
Expand Down

0 comments on commit aa4cecd

Please sign in to comment.