Friday 28 July 2017

JavaScript error: sendMessage is not a function

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: 'http://ift.tt/1Q7nDgi', 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.

Submitted July 29, 2017 at 02:17AM by sk0620

No comments:

Post a Comment