I'm quite new in NodeJS, but I'm struggling also with concept of passing variables / objects between functions. I appreciate any help on what I am doing wrong.
Please, consider this code:
incoming request:
{
sender: '32165498732165845',
text: 'shopping',
originalRequest:
{
sender: { id: '32165498732165845' },
recipient: { id: '87971441647898' },
timestamp: 1488196261509,
message: { mid: 'mid.1488196261509:c7ccb7f608', seq: 36372, text: 'shopping' }
},
type: 'facebook'
}
Extracting relevant variables:
var userId = request.sender;
var listName = request.text;
bot.js:
var listOps = require('./listops/test.js');
listOps.setActive(function (userId, listName, callback) {
console.log ('Here I expect a callback!');
return callback; // This will send the message back to user.
});
listops/test.js:
exports.setActive = function(userId, listName, callback) {
var message = "User number " + userId + " asks to create a list with name " + listName + ".";
console.log(userId);
console.log(listName);
callback (message);
}
Now my issue is that in listOps.js
the outcome of both console logs is not the value I expect, it says [Function]
and undefined
. Therefore I suspect, that this is a root cause for error message [TypeError: callback is not a function]
.
I'm using Claudia.js in Lambda.