services/alchemy_language/v1.js
function AlchemyFeatureExtractNode (config) {
    RED.nodes.createNode(this, config);
    var node = this;

    this.on('input', function (msg) {
      if (!msg.payload) {
        this.status({fill:'red', shape:'ring', text:'missing payload'});
        var message = 'Missing property: msg.payload';
        node.error(message, msg);
        return;
      }

      // If it is present the newly provided user entered key takes precedence over the existing one.
      apikey = s_apikey || this.credentials.apikey;
      this.status({});

      if (!apikey) {
        this.status({fill:'red', shape:'ring', text:'missing credentials'});
        var message = 'Missing Alchemy API service credentials';
        node.error(message, msg);
        return;
      }

      var alchemy_language = watson.alchemy_language( { api_key: apikey } );

      // Check which features have been requested.

      var enabled_features = Object.keys(FEATURES).filter(function (feature) {
        return config[feature]
      });


      if (!enabled_features.length) {
        this.status({fill:'red', shape:'ring', text:'no features selected'});
        var message = 'AlchemyAPI node must have at least one selected feature.';
        node.error(message, msg);
        return;
      }

      var params = buildParams(enabled_features, config, msg);

      // Splice in the additional options from msg.alchemy_options
      // eg. The user may have entered msg.alchemy_options = {maxRetrieve: 2};

      for (var key in msg.alchemy_options) { params[key] = msg.alchemy_options[key]; }

      alchemy_language.combined(params, function (err, response) {
        if (err || response.status === 'ERROR') {
          node.status({fill:'red', shape:'ring', text:'call to alchmeyapi language service failed'});
          console.log('Error:', msg, err);
          node.error(err, msg);
        }
        else {
          msg.features = {};
          //msg.features['all'] = response;

          Object.keys(FEATURES).forEach(function (feature) {
            var answer_feature = FEATURES[feature];

            msg.features[feature] = response[answer_feature] || {};
          });

          node.send(msg);
        }
      });

    });
  }
function AlchemyFeatureExtractNode (config) {
    RED.nodes.createNode(this, config);
    var node = this;

    this.on('input', function (msg) {
      if (!msg.payload) {
        this.status({fill:'red', shape:'ring', text:'missing payload'});
        var message = 'Missing property: msg.payload';
        node.error(message, msg);
        return;
      }

      // If it is present the newly provided user entered key takes precedence over the existing one.
      apikey = s_apikey || this.credentials.apikey;
      this.status({});

      if (!apikey) {
        this.status({fill:'red', shape:'ring', text:'missing credentials'});
        var message = 'Missing Alchemy API service credentials';
        node.error(message, msg);
        return;
      }

      var alchemy_language = watson.alchemy_language( { api_key: apikey } );

      // Check which features have been requested.

      var enabled_features = Object.keys(FEATURES).filter(function (feature) {
        return config[feature]
      });


      if (!enabled_features.length) {
        this.status({fill:'red', shape:'ring', text:'no features selected'});
        var message = 'AlchemyAPI node must have at least one selected feature.';
        node.error(message, msg);
        return;
      }

      var params = buildParams(enabled_features, config, msg);

      // Splice in the additional options from msg.alchemy_options
      // eg. The user may have entered msg.alchemy_options = {maxRetrieve: 2};

      for (var key in msg.alchemy_options) { params[key] = msg.alchemy_options[key]; }

      alchemy_language.combined(params, function (err, response) {
        if (err || response.status === 'ERROR') {
          node.status({fill:'red', shape:'ring', text:'call to alchmeyapi language service failed'});
          console.log('Error:', msg, err);
          node.error(err, msg);
        }
        else {
          msg.features = {};
          //msg.features['all'] = response;

          Object.keys(FEATURES).forEach(function (feature) {
            var answer_feature = FEATURES[feature];

            msg.features[feature] = response[answer_feature] || {};
          });

          node.send(msg);
        }
      });

    });
  }
function AlchemyFeatureExtractNode ( config ) { RED . nodes . createNode ( this , config ) ; var node = this ; this . on ( 'input' , function ( msg ) { if ( ! msg . payload ) { this . status ( { fill : 'red' , shape : 'ring' , text : 'missing payload' } ) ; var message = 'Missing property: msg.payload' ; node . error ( message , msg ) ; return ; } // If it is present the newly provided user entered key takes precedence over the existing one. apikey = s_apikey || this . credentials . apikey ; this . status ( { } ) ; if ( ! apikey ) { this . status ( { fill : 'red' , shape : 'ring' , text : 'missing credentials' } ) ; var message = 'Missing Alchemy API service credentials' ; node . error ( message , msg ) ; return ; } var alchemy_language = watson . alchemy_language ( { api_key : apikey } ) ; // Check which features have been requested. var enabled_features = Object . keys ( FEATURES ) . filter ( function ( feature ) { return config [ feature ] } ) ; if ( ! enabled_features . length ) { this . status ( { fill : 'red' , shape : 'ring' , text : 'no features selected' } ) ; var message = 'AlchemyAPI node must have at least one selected feature.' ; node . error ( message , msg ) ; return ; } var params = buildParams ( enabled_features , config , msg ) ; // Splice in the additional options from msg.alchemy_options // eg. The user may have entered msg.alchemy_options = {maxRetrieve: 2}; for ( var key in msg . alchemy_options ) { params [ key ] = msg . alchemy_options [ key ] ; } alchemy_language . combined ( params , function ( err , response ) { if ( err || response . status === 'ERROR' ) { node . status ( { fill : 'red' , shape : 'ring' , text : 'call to alchmeyapi language service failed' } ) ; console . log ( 'Error:' , msg , err ) ; node . error ( err , msg ) ; } else { msg . features = { } ; //msg.features['all'] = response; Object . keys ( FEATURES ) . forEach ( function ( feature ) { var answer_feature = FEATURES [ feature ] ; msg . features [ feature ] = response [ answer_feature ] || { } ; } ) ; node . send ( msg ) ; } } ) ; } ) ; }
This is the Alchemy Data Node
This is the Alchemy Data Node