Skip to content

Commit

Permalink
Merge pull request #189 from watson-developer-cloud/empty-response-ca…
Browse files Browse the repository at this point in the history
…uses-failure

Empty response causes failure
  • Loading branch information
germanattanasio authored Aug 21, 2018
2 parents ec7f19f + 8a813fa commit eb59368
Show file tree
Hide file tree
Showing 2 changed files with 1,328 additions and 1,320 deletions.
20 changes: 14 additions & 6 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,20 @@ app.post('/api/message', function (req, res) {

// This is a fix for now, as since Assistant version 2018-07-10,
// output text can now be in output.generic.text
if (data.output.text.length === 0) {
if (data.output.generic !== undefined) {
if (data.output.generic[0].text !== undefined) {
data.output.text = data.output.generic[0].text;
} else if (data.output.generic[0].title !== undefined) {
data.output.text = data.output.generic[0].title;
var output = data.output;
if (output.text.length === 0 && output.hasOwnProperty('generic')) {
var generic = output.generic;

if (Array.isArray(generic)) {
// 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 (generic[i].hasOwnProperty('text')) {
data.output.text.push(generic[i].text);
} else if (generic[i].hasOwnProperty('title')) {
data.output.text.push(generic[i].title);
}
}
}
}
Expand Down
Loading

0 comments on commit eb59368

Please sign in to comment.