Skip to content

Commit

Permalink
refactor($libraries): Removed lodash and console calls
Browse files Browse the repository at this point in the history
Replaced all lodash calls with methods that don't depend on the lodash library. Also removed
console.log expressions that were used for testing.
  • Loading branch information
noah-eigenfeld committed Aug 21, 2018
1 parent 2825cae commit 2f801d6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
17 changes: 4 additions & 13 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
var express = require('express'); // app server
var bodyParser = require('body-parser'); // parser for post requests
var AssistantV1 = require('watson-developer-cloud/assistant/v1'); // watson sdk
var _ = require('lodash'); // lodash

var app = express();

Expand Down Expand Up @@ -55,34 +54,26 @@ app.post('/api/message', function (req, res) {
return res.status(err.code || 500).json(err);
}

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

console.log(data.output);

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

if (_.isArray(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 (_.has(generic[i], 'text')) {
if (generic[i].hasOwnProperty('text')) {
data.output.text.push(generic[i].text);
} else if (_.has(generic[i], 'title')) {
} else if (generic[i].hasOwnProperty('title')) {
data.output.text.push(generic[i].title);
}
}
}
}

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

return res.json(updateMessage(payload, data));
});
});
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"body-parser": "^1.18.3",
"dotenv": "^6.0.0",
"express": "^4.16.3",
"lodash": "^4.17.10",
"watson-developer-cloud": "^3.7.0"
},
"publishConfig": {
Expand Down

0 comments on commit 2f801d6

Please sign in to comment.