Skip to content

Commit 7b3648c

Browse files
committed
Add payload check
1 parent d0c301e commit 7b3648c

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

services/assistant/v2.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,48 @@ module.exports = function(RED) {
7777
return Promise.resolve();
7878
}
7979

80+
function payloadCheck(msg) {
81+
if (msg.payload && 'string' != typeof msg.payload) {
82+
return Promise.reject('msg.payload must be either empty or a string');
83+
}
84+
return Promise.resolve();
85+
}
86+
8087
function idCheck(msg, config) {
8188
if (!config.assistant_id && !(msg.params && msg.params.assistant_id)) {
8289
return Promise.reject('Missing assistant_id. Check node documentation.');
8390
}
8491
return Promise.resolve();
8592
}
8693

94+
function buildInputParams(msg, config) {
95+
let params = {
96+
'message_type': 'text',
97+
'input' : msg.payload
98+
};
99+
100+
101+
return Promise.resolve(params);
102+
}
103+
87104
this.on('input', function(msg) {
88105
node.status({});
89106

90107
var creds = setCredentials(msg);
91108

92109
credentialCheck(creds.username, creds.password, creds.apikey)
110+
.then(function(){
111+
return payloadCheck(msg);
112+
})
93113
.then(function(){
94114
return idCheck(msg, config);
95115
})
96116
.then(function(){
117+
return buildInputParams(msg, config);
118+
})
119+
.then(function(params){
120+
console.log('params have been built');
121+
console.log(params);
97122
msg.payload = 'No functionality yet';
98123
return Promise.resolve();
99124
})

0 commit comments

Comments
 (0)