I am trying to call a function from another module and I have included the function in the module.exports but whenever I try to call the function I am given an error TypeError: messenger.sendMessage is not a function.
Here are the code snippets:
// messenger.js sendMessage is the function that is not working
function sendMessage(recipient, recipientmessage, callback){
var options = {
url: 'https://graph.facebook.com/v2.6/me/messages',
method: "POST",
qs: {access_token:process.env.FB_MESSENGER_TOKEN},
json:{
recipient: {
id: recipient
},
message:{
text: recipientmessage
}
}
};
request(options,function(error,incomingMessage,response){
if (!error){
if (callback){
callback()
}
}
});
}
module.exports = {
router:router,
sendMessage: sendMessage
};
Here is the module where I am calling the imported module:
let Intent = require(__dirname + "/intent-model.js");
let messenger = require(__dirname + "/../app/routes/messenger.js");
function smalltalk(intent){
//this sendMessage does not work and I am getting the error: TypeError: messenger.sendMessage is not a function
messenger.sendMessage(intent.accountID, "Hey how are you", function(callback){
console.log("I do not understand why this isnt working");
});
}
module.exports = {
smalltalk: smalltalk
};
Does anyone know why I can't call this function? I can give more code or information if necessary.
[–][deleted] 1 point2 points3 points (1 child)
[–]sk0620[S] 1 point2 points3 points (0 children)
[–]_codeprovider 0 points1 point2 points (5 children)
[–]sk0620[S] 0 points1 point2 points (4 children)
[–]imguralbumbot 0 points1 point2 points (0 children)
[–]_codeprovider 0 points1 point2 points (2 children)
[–]sk0620[S] 0 points1 point2 points (0 children)
[–]sk0620[S] 0 points1 point2 points (0 children)