Skip to content

Commit 2825cae

Browse files
fix($server): Fix bug: missing multiple responses in output generic
Instead of checking only the first object in the generic array, iterate through the whole array, adding text from each index (if it exists) to the output array.
1 parent f2350e0 commit 2825cae

2 files changed

Lines changed: 1325 additions & 1319 deletions

File tree

app.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ app.post('/api/message', function (req, res) {
5555
return res.status(err.code || 500).json(err);
5656
}
5757

58-
console.log("\n\nData.output:");
58+
console.log('\n\nData.output:');
5959

6060
console.log(data.output);
6161

@@ -66,14 +66,20 @@ app.post('/api/message', function (req, res) {
6666
var generic = output.generic;
6767

6868
if (_.isArray(generic)) {
69-
if (_.has(generic[0], 'text')) {
70-
data.output.text = generic[0].text;
71-
} else if (_.has(generic[0], 'title')) {
72-
data.output.text = data.output.generic[0].title;
69+
// Loop through generic and add all text to data.output.text.
70+
// If there are multiple responses, this will add all of them
71+
// to the response.
72+
for(var i = 0; i < generic.length; i++) {
73+
if (_.has(generic[i], 'text')) {
74+
data.output.text.push(generic[i].text);
75+
} else if (_.has(generic[i], 'title')) {
76+
data.output.text.push(generic[i].title);
77+
}
7378
}
7479
}
7580
}
7681

82+
console.log("------------");
7783
console.log("Output text:");
7884
console.log(data.output.text);
7985

0 commit comments

Comments
 (0)