Skip to content

Commit 217a826

Browse files
committed
Build up input options
1 parent 7962db6 commit 217a826

2 files changed

Lines changed: 61 additions & 12 deletions

File tree

services/assistant/v2.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@
6969

7070
<div class="form-row">
7171
<label>&nbsp;</label>
72-
<input type="checkbox" id="node-input-returncontext" style="display: inline-block; width: auto; vertical-align: top;">
73-
<label for="node-input-returncontext" style="width: 70%;"> Return Context</label>
72+
<input type="checkbox" id="node-input-return_context" style="display: inline-block; width: auto; vertical-align: top;">
73+
<label for="node-input-return_context" style="width: 70%;"> Return Context</label>
7474
</div>
7575

7676
<div class="form-row">
7777
<label>&nbsp;</label>
78-
<input type="checkbox" id="node-input-alternate-intents" style="display: inline-block; width: auto; vertical-align: top;">
79-
<label for="node-input-alternate-intents" style="width: 70%;"> Return Alternate Intents</label>
78+
<input type="checkbox" id="node-input-alternate_intents" style="display: inline-block; width: auto; vertical-align: top;">
79+
<label for="node-input-alternate_intents" style="width: 70%;"> Return Alternate Intents</label>
8080
</div>
8181

8282
<div class="form-row">
@@ -166,8 +166,8 @@
166166
assistant_id: {value: ''},
167167
debug: {value: false},
168168
restart: {value: false},
169-
returncontext: {value: true},
170-
alternateintents: {value: false},
169+
return_context: {value: true},
170+
alternate_intents: {value: false},
171171
multisession: {value: true}
172172
},
173173
credentials: {

services/assistant/v2.js

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,18 @@ module.exports = function(RED) {
106106
return session_id;
107107
}
108108

109-
function setContext(msg, config, session_id) {
109+
function checkAndSet(source, target, field) {
110+
if (source[field]) {
111+
target[field] = source[field];
112+
}
113+
}
114+
115+
function setContext(msg, session_id) {
110116
let context = null;
111-
if (session_id) {
117+
if (msg.params) {
118+
checkAndSet(msg.params, params, 'context');
119+
}
120+
if (!context && session_id) {
112121
let c = null
113122
c = node.context().flow.get('context-' + session_id);
114123
if (c) {
@@ -118,18 +127,58 @@ module.exports = function(RED) {
118127
return context;
119128
}
120129

130+
function setAdditionalContext(msg, params) {
131+
if (msg.additional_context) {
132+
params.context = params.context ? params.context : {};
133+
134+
for (prop in msg.additional_context) {
135+
if (msg.additional_context.hasOwnProperty(prop)) {
136+
params.context[prop] = msg.additional_context[prop];
137+
}
138+
}
139+
}
140+
}
141+
142+
function setAssistantID(msg, params, config) {
143+
checkAndSet(config, params, 'assistant_id');
144+
if (msg.params) {
145+
checkAndSet(msg.params, params, 'assistant_id');
146+
}
147+
}
148+
149+
function setInputOptions(msg, params, config) {
150+
// Setting the flags this way works as their default
151+
// values are false.
152+
['alternate_intents',
153+
'return_context',
154+
'restart',
155+
'debug'].forEach((f) => {
156+
checkAndSet(config, params.input.options, f);
157+
if (msg.params) {
158+
checkAndSet(msg.params, params.input.options, f);
159+
}
160+
});
161+
}
162+
121163
function buildInputParams(msg, config) {
122164
let params = {
123-
'message_type': 'text',
124-
'input' : msg.payload,
165+
'input' : {
166+
'message_type': 'text',
167+
'text' : msg.payload,
168+
'options' : {}
169+
},
125170
'session_id' : setSessionID(msg, config)
126171
};
127172

128-
let context = setContext(msg, config, params.session_id);
173+
let context = setContext(msg, params.session_id);
129174
if (context) {
130175
params.context = context;
131-
// Look for additional context
132176
}
177+
setAdditionalContext(msg, params);
178+
setAssistantID(msg, params, config);
179+
setInputOptions(msg, params, config);
180+
181+
//verifyOptionalInputs(node, msg, config, params);
133182

134183
return Promise.resolve(params);
135184
}

0 commit comments

Comments
 (0)