Node.js - Get return value from call back function with Azure Bot Framework

I have been started to built a chatbot using node.js within Azure Bot Framework. I need to get return value from a HTTP request's response result. I was using the "normal" way of function (callback){} in node.s, but no luck to get the return result. I did a research and then found out this article "Microsoft Bot Framework Node SDK and LUIS".

Refer to this article, I finally work out the way of getting return value as below.

var rp = require('request');
bot.dialog('SearchHotels', [
 function (session) {
   var destinationUrl="XXXX";
  callRemoteSite(destinationUrl, (responseString) => {
            session.send(responseString);
     });
}
function searchHotels(destinationUrl, callback) {

 rp(destinationUrl, function(error, response, body) {
          var json= parseFinance(body);
         callback(json);
  })
}

The advantage of above function is you can get the call back value from the function within the same JavaScript file. Or you can do the same way as the reference article to call another file's function.

Comments

Popular posts from this blog

Top JavaScript courses helping you develop SPFx webPart with ReactJS and AngularJS

Effective LLM Prompting skills

Enable the Microsoft Power BI report file type (.pbix) in SharePoint Search