Skip to content

Commit eb59368

Browse files
Merge pull request #189 from watson-developer-cloud/empty-response-causes-failure
Empty response causes failure
2 parents ec7f19f + 8a813fa commit eb59368

File tree

2 files changed

+1328
-1320
lines changed

2 files changed

+1328
-1320
lines changed

app.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,20 @@ app.post('/api/message', function (req, res) {
5656

5757
// This is a fix for now, as since Assistant version 2018-07-10,
5858
// output text can now be in output.generic.text
59-
if (data.output.text.length === 0) {
60-
if (data.output.generic !== undefined) {
61-
if (data.output.generic[0].text !== undefined) {
62-
data.output.text = data.output.generic[0].text;
63-
} else if (data.output.generic[0].title !== undefined) {
64-
data.output.text = data.output.generic[0].title;
59+
var output = data.output;
60+
if (output.text.length === 0 && output.hasOwnProperty('generic')) {
61+
var generic = output.generic;
62+
63+
if (Array.isArray(generic)) {
64+
// Loop through generic and add all text to data.output.text.
65+
// If there are multiple responses, this will add all of them
66+
// to the response.
67+
for(var i = 0; i < generic.length; i++) {
68+
if (generic[i].hasOwnProperty('text')) {
69+
data.output.text.push(generic[i].text);
70+
} else if (generic[i].hasOwnProperty('title')) {
71+
data.output.text.push(generic[i].title);
72+
}
6573
}
6674
}
6775
}

0 commit comments

Comments
 (0)