Search code examples
node.jsbotframeworkskype-bots

Node - Export in the same file


Don't know how it is possible, but some how I'm trying to use the function that I am exporting in the same file.

exports.OnefunCall = function (session, builder, properties) {
var request = require("request");
request(url, function (error, response, body)
    {
        if (!error && response.statusCode == 200) {
            displayOnefunCallAnswer(body, session, builder);
        } else {
            session.send('Something went wrong. You can use the back or top command.');
            //session.beginDialog('/menu');
        }
    });
}

function displayOnefunCallAnswer(entityData, session, builder) {
// Code for display data
}

I have another function where I need to make the OnefunCall request. Can I use as below.

exports.AnotherfunCall = function (session, builder, properties) {
    // Some logic to perform AnotherfunCall and if the response is correct then call the OnefunCall
    module.exports.OnefunCall(session, builder, properties);
}

or is there any another way to perform this operation.


Solution

  • Yes, if you just want to export you can follow the following example

    function OnefunCall (session, builder, properties) {
          //do some code   
    }
    function AnotherfunCall (session, builder, properties) {
          //do some code   
          OnefunCall(a,b,c){
          } 
    }
    
    exports.OnefunCall = OnefunCall;
    exports.AnotherfunCall = AnotherfunCall;