0

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.

Gaurav Paliwal
  • 1,556
  • 16
  • 27
Mukesh S
  • 367
  • 5
  • 19
  • 3
    Yes, you can do it that way. Usually, if you want to use it locally, you give it a normal local function name and use that locally and then assign that function name to module.exports so it can be used outside too. It just saves typing over what you've proposed. – jfriend00 May 12 '17 at 05:09
  • @jfriend00 Thanks man..! – Mukesh S May 12 '17 at 08:48

1 Answers1

1

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;
Kalana Demel
  • 3,220
  • 3
  • 21
  • 34