Using Watson API on Meteor

Hi,

I’m trying to use the Watson API (node SDK) and I can’t seem to get the results back from the API call to the client. I know that the client cannot store the results from the meteor method call because of async problems but how else would I approach this issue? This is the example from the Watson api:

var ToneAnalyzerV3 = require('watson-developer-cloud/tone-analyzer/v3');
 
var tone_analyzer = new ToneAnalyzerV3({
  username: '<username>',
  password: '<password>',
  version_date: '2016-05-19'
});
 
tone_analyzer.tone({ text: 'Greetings from Watson Developer Cloud!' },
  function(err, tone) {
    if (err)
      console.log(err);
    else
      console.log(JSON.stringify(tone, null, 2));
});

I’m trying to grab the “tone” from the tone_analyzer.tone call. How can I call this on the server side, and use this tone on my client side without using a database to store it? I also tried session variables, reactive methods package, and writing it on the client side but none of them worked out. Any help or guidance would be appreciated!

The API is a native/node based call inside the meteor server side method, I assume? This means you must wrap it in a (meteorhacks/async) Async.runSync or Meteor wrap/async type function, then return when done, and return the result to the method call. If you are not using the native rest API via the Meteor HTTP methods that support Fibers, you have to handle the non fiber/node based async call a special way (if you are using the Watson node library).

1 Like

Awesome. Thanks for pushing me towards the right direction! Everything works as intended now after using the Async package. Thanks for the help.