services/assistant/v1-workspace-manager.js
function Node (config) {
    RED.nodes.createNode(this, config);
    var node = this;

    this.on('input', function (msg) {
      var method = config['cwm-custom-mode'],
        message = '',
        params = {};

      username = sUsername || this.credentials.username;
      password = sPassword || this.credentials.password || config.password;
      apikey = sApikey || this.credentials.apikey || config.apikey;

      // All method to be overridden
      if (msg.params) {
        if (msg.params.method) {
          method = msg.params.method;
        }
        if (msg.params.username) {
          username = msg.params.username;
        }
        if (msg.params.password) {
          password = msg.params.password;
        }
        if (msg.params.apikey) {
          apikey = msg.params.apikey;
        }
        if (msg.params.version) {
          version = msg.params.version;
        }
      }
      endpoint = sEndpoint;
      if ((!config['cwm-default-endpoint']) && config['cwm-service-endpoint']) {
        endpoint = config['cwm-service-endpoint'];
      }

      node.status({});
      initialCheck(apikey, username, password, method)
        .then(function(){
          return buildParams(msg, method, config, params);
        })
        .then(function(){
          return checkForFile(method);
        })
        .then(function(fileNeeded){
          if (fileNeeded) {
            if (msg.payload instanceof Buffer) {
              return loadFile(node, method, params, msg);
            }
            // If the data is a json object then it will not
            // have been detected as a buffer.
            return setWorkspaceParams(method, params, msg.payload);
          }
          return Promise.resolve(params);
        })
        .then(function(p){
          params = p;
          node.status({fill:'blue', shape:'dot', text:'executing'});
          return executeMethod(node, method, params, msg);
        })
        .then(function(){
          temp.cleanup();
          node.status({});
          node.send(msg);
        })
        .catch(function(err){
          temp.cleanup();
          payloadutils.reportError(node,msg,err);
        });

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

    this.on('input', function (msg) {
      var method = config['cwm-custom-mode'],
        message = '',
        params = {};

      username = sUsername || this.credentials.username;
      password = sPassword || this.credentials.password || config.password;
      apikey = sApikey || this.credentials.apikey || config.apikey;

      // All method to be overridden
      if (msg.params) {
        if (msg.params.method) {
          method = msg.params.method;
        }
        if (msg.params.username) {
          username = msg.params.username;
        }
        if (msg.params.password) {
          password = msg.params.password;
        }
        if (msg.params.apikey) {
          apikey = msg.params.apikey;
        }
        if (msg.params.version) {
          version = msg.params.version;
        }
      }
      endpoint = sEndpoint;
      if ((!config['cwm-default-endpoint']) && config['cwm-service-endpoint']) {
        endpoint = config['cwm-service-endpoint'];
      }

      node.status({});
      initialCheck(apikey, username, password, method)
        .then(function(){
          return buildParams(msg, method, config, params);
        })
        .then(function(){
          return checkForFile(method);
        })
        .then(function(fileNeeded){
          if (fileNeeded) {
            if (msg.payload instanceof Buffer) {
              return loadFile(node, method, params, msg);
            }
            // If the data is a json object then it will not
            // have been detected as a buffer.
            return setWorkspaceParams(method, params, msg.payload);
          }
          return Promise.resolve(params);
        })
        .then(function(p){
          params = p;
          node.status({fill:'blue', shape:'dot', text:'executing'});
          return executeMethod(node, method, params, msg);
        })
        .then(function(){
          temp.cleanup();
          node.status({});
          node.send(msg);
        })
        .catch(function(err){
          temp.cleanup();
          payloadutils.reportError(node,msg,err);
        });

    });
  }
function Node ( config ) { RED . nodes . createNode ( this , config ) ; var node = this ; this . on ( 'input' , function ( msg ) { var method = config [ 'cwm-custom-mode' ] , message = '' , params = { } ; username = sUsername || this . credentials . username ; password = sPassword || this . credentials . password || config . password ; apikey = sApikey || this . credentials . apikey || config . apikey ; // All method to be overridden if ( msg . params ) { if ( msg . params . method ) { method = msg . params . method ; } if ( msg . params . username ) { username = msg . params . username ; } if ( msg . params . password ) { password = msg . params . password ; } if ( msg . params . apikey ) { apikey = msg . params . apikey ; } if ( msg . params . version ) { version = msg . params . version ; } } endpoint = sEndpoint ; if ( ( ! config [ 'cwm-default-endpoint' ] ) && config [ 'cwm-service-endpoint' ] ) { endpoint = config [ 'cwm-service-endpoint' ] ; } node . status ( { } ) ; initialCheck ( apikey , username , password , method ) . then ( function ( ) { return buildParams ( msg , method , config , params ) ; } ) . then ( function ( ) { return checkForFile ( method ) ; } ) . then ( function ( fileNeeded ) { if ( fileNeeded ) { if ( msg . payload instanceof Buffer ) { return loadFile ( node , method , params , msg ) ; } // If the data is a json object then it will not // have been detected as a buffer. return setWorkspaceParams ( method , params , msg . payload ) ; } return Promise . resolve ( params ) ; } ) . then ( function ( p ) { params = p ; node . status ( { fill : 'blue' , shape : 'dot' , text : 'executing' } ) ; return executeMethod ( node , method , params , msg ) ; } ) . then ( function ( ) { temp . cleanup ( ) ; node . status ( { } ) ; node . send ( msg ) ; } ) . catch ( function ( err ) { temp . cleanup ( ) ; payloadutils . reportError ( node , msg , err ) ; } ) ; } ) ; }
This is the Conversation Workspace Manager Node
This is the Conversation Workspace Manager Node