Skip to content

Commit

Permalink
fix($server): Fix bug: missing multiple responses in output generic
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
noah-eigenfeld committed Aug 21, 2018
1 parent f2350e0 commit 2825cae
Show file tree
Hide file tree
Showing 2 changed files with 1,325 additions and 1,319 deletions.
16 changes: 11 additions & 5 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ app.post('/api/message', function (req, res) {
return res.status(err.code || 500).json(err);
}

console.log("\n\nData.output:");
console.log('\n\nData.output:');

console.log(data.output);

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

if (_.isArray(generic)) {
if (_.has(generic[0], 'text')) {
data.output.text = generic[0].text;
} else if (_.has(generic[0], 'title')) {
data.output.text = data.output.generic[0].title;
// Loop through generic and add all text to data.output.text.
// If there are multiple responses, this will add all of them
// to the response.
for(var i = 0; i < generic.length; i++) {
if (_.has(generic[i], 'text')) {
data.output.text.push(generic[i].text);
} else if (_.has(generic[i], 'title')) {
data.output.text.push(generic[i].title);
}
}
}
}

console.log("------------");
console.log("Output text:");
console.log(data.output.text);

Expand Down
Loading

0 comments on commit 2825cae

Please sign in to comment.