title: node.js resolve promise and return value
body: <p>I use the Microsoft bot framework to come up with a "simple" PoC bot. I used a <a href="https://chatbotsmagazine.com/a-nodejs-chatbot-tutorial-part-1-a2abd1b1c715#.xkoxkhin4" rel="noreferrer">tutorial</a> as a basis and extend it.</p>
  
  <p>I've a couple of basic functions for differet intents (ie. greetings, goodbye, etc) and one with some more logic in it (reqstatus). </p>
  
  <p>The simple ones (ie greeting.js) return the answer nicely but the more complex one doesn't (reqstatus.js). Running the main code of reqstatus.js (without the first "const getReqStatus = (entity) => {") in a standalone script works.</p>
  
  <p><strong>server.js</strong> (main) -> see call in "if (intent) {"...</p>
  
  <pre><code>const getFeelings = require('./intents/feelings.js')
  const getGoodbyes = require('./intents/goodbyes.js')
  const getGreetings = require('./intents/greetings.js')
  const getHelp = require('./intents/help.js')
  const getReqStatus = require('./intents/reqstatus.js')
  ... 
  const bot = new builder.UniversalBot(connector)
  
  // Intents based on definitions on recast
  const INTENTS = {
    feelings: getFeelings,
    goodbyes: getGoodbyes,
    greetings: getGreetings,
    help: getHelp,
    reqstatus: getReqStatus,
  }
  
  // Event when Message received
  bot.dialog('/', (session) =&gt; {
    recastClient.textRequest(session.message.text)
    .then(res =&gt; {
    const intent = res.intent()
    const entity = res.get('request_number')
  
    console.log(`UserName: ${session.message.user.name}`)
    console.log(`Msg: ${session.message.text}`)
    console.log(`Intent: ${intent.slug}`) 
  
    if (intent) {
      INTENTS[intent.slug](entity)
      .then(res =&gt; session.send(res)) 
      .catch(err =&gt; session.send(err))
    }
    })
    .catch(() =&gt; session.send('Sorry I didn\'t get that. '))
    })
    ...
  </code></pre>
  
  <p><strong>greetings.js</strong> -> Returns the string ok</p>
  
  <pre><code>const getGreetings = () =&gt; {
    const answers = ['Hi, my name is SuperBot. Nice to meet you!', ] 
    return Promise.resolve((answers))
    }
  module.exports = getGreetings
  </code></pre>
  
  <p><strong>reqstatus.js</strong> -> Does not return anything</p>
  
  <pre><code>const getReqStatus = (entity) =&gt; {
    var request = require('request');
    var request_number = entity.toLowerCase()
    var output = [];
  
  
    // Processing
    var lineReader = require('readline').createInterface({
    input: fs.createReadStream('netreqs.csv')
    }); 
  
    lineReader.on('line', function (line) {
    var jsonFromLine = {};
    var lineSplit = line.split(';');
    jsonFromLine.req = lineSplit[0];
    jsonFromLine.req_count = lineSplit[1];
    jsonFromLine.req_type = lineSplit[2];
    //...
    var req_lowever = jsonFromLine.req.toLowerCase()
    if (req_lowever == request_number) {
       output.push( `Your request ${jsonFromLine.req} was received`);    
    // simplified
    }
    });
  
    // Output
    lineReader.on('close', function (line) {
    if (output == '') {
      output.push( `I was not able to find a request like ${request_number}.`);
      }
    console.log(output); // list output 
    return Promise.resolve(output); 
     });
    }
  module.exports = getReqStatus
  </code></pre>
  
  <p>I also tried to put getReqStatus in a function but that also didn't work. 
  After a lot of trying and googling I'm still stuck and wanted to ask the experts here. Thanks a lot in advance.</p>