Skip to content

Commit aa4cecd

Browse files
authored
Merge pull request #472 from chughts/091
091
2 parents 0bbd9b6 + 9b8b5dc commit aa4cecd

File tree

4 files changed

+37
-10
lines changed

4 files changed

+37
-10
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ Node-RED Watson Nodes for IBM Cloud
77

88
<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>
99

10+
11+
### New in version 0.9.1
12+
- 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.
13+
1014
### New in version 0.9.0
1115
- Node-RED & IBM-Watson & Use of promises on API invocation & IAM URL construct migration & Removal of default endpoint of
1216
- Assistant V1

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-red-node-watson",
3-
"version": "0.9.0",
3+
"version": "0.9.1",
44
"description": "A collection of Node-RED nodes for IBM Watson services",
55
"dependencies": {
66
"async": "^1.5.2",

services/assistant/v2.html

+4-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@
112112
If this field is not provided then the node will generate a new session_id and
113113
return it as part of the response. If the node is not used in multi-session mode, then
114114
a session_id need not be provided, to reset the session_id in single-session mode
115-
send a null value as the session_id. Format: String </li>
115+
send a null value as the session_id.
116+
Format: String </li>
117+
<li><code>msg.params.reset_session</code> (optional): Will force a session reset
118+
Format: Any </li>
116119
<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>
117120
<li><code>msg.params.timeout</code> (optional): The timeout period (in millisecond) for Watson request. Leave empty or set to 0 to disable. </li>
118121
<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>

services/assistant/v2.js

+28-8
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,27 @@ module.exports = function(RED) {
9595

9696
function setSessionID(msg) {
9797
let session_id = null;
98+
let id = null;
9899

99-
if (!config.multisession) {
100-
let id = node.context().flow.get('session_id');
101-
if (id) {
102-
session_id = id;
100+
if (msg.params && 'reset_session' in msg.params) {
101+
// There is a reset request, therefore no need
102+
// to look it up
103+
} else {
104+
if (!config.multisession) {
105+
if (msg.params && 'session_id' in msg.params && !msg.params.session_id) {
106+
// Have a session id in single session mode
107+
// but its a null string so force a reset of the session.
108+
} else {
109+
id = node.context().flow.get('session_id');
110+
}
111+
} else if (msg.params && msg.params.session_id) {
112+
let key = msg.params.session_id;
113+
id = node.context().flow.get('session-' + key);
103114
}
104-
} else if (msg.params && msg.params.session_id) {
105-
session_id = msg.params.session_id;
115+
}
116+
117+
if (id) {
118+
session_id = id;
106119
}
107120

108121
return session_id;
@@ -265,7 +278,8 @@ module.exports = function(RED) {
265278
return Promise.resolve();
266279
}
267280

268-
function checkSession(params) {
281+
282+
function checkSession(msg, params) {
269283
return new Promise(function resolver(resolve, reject){
270284
if (params.sessionId) {
271285
resolve();
@@ -280,6 +294,12 @@ module.exports = function(RED) {
280294
if (params.sessionId) {
281295
if (!config.multisession) {
282296
node.context().flow.set('session_id', params.sessionId);
297+
} else {
298+
let key = params.sessionId;
299+
if (msg.params && msg.params.session_id){
300+
key = msg.params.session_id;
301+
}
302+
node.context().flow.set('session-' + key, params.sessionId);
283303
}
284304
resolve();
285305
} else {
@@ -333,7 +353,7 @@ module.exports = function(RED) {
333353
return buildService(settings);
334354
})
335355
.then(function(){
336-
return checkSession(params);
356+
return checkSession(msg, params);
337357
})
338358
.then(function(){
339359
node.status({ fill: 'blue', shape: 'dot', text: 'Calling Assistant service ...'});

0 commit comments

Comments
 (0)