services/dialog/v1.js
function performCreate(node,dialog,msg) {
    var params = {}
    node.status({fill:'blue', shape:'dot', text:'requesting create of new dialog template'});	 
    //if ('file' in msg.dialog_params && 'dialog_name' in msg.dialog_params) {
    if ('dialog_name' in msg.dialog_params) {  
      // extension supported : only XML
      // TODO : support other API format (json and encrypted crt)
      temp.open({suffix: '.xml'}, function (err, info) {
        if (err) throw err;
        //var fileBuffer = msg.dialog_params['file'];
        var fileBuffer = msg.payload;
        fs.writeFile(info.path, fileBuffer, function (err) {
            if (err) {
              console.error(err);
              throw err;
            }
            var aFileStream = fs.createReadStream(info.path);
            params.file = aFileStream;
            params.name = msg.dialog_params['dialog_name'];
            // Watson SDK call
            dialog.createDialog(params, function(err, dialog_data){
                  node.status({});
                  if (err) {
                    node.status({fill:'red', shape:'ring', text:'call to dialog service failed'}); 
                    node.error(err, msg);
                  } else {
                    msg.dialog = dialog_data;     
                    msg.payload = 'Check msg.dialog dialog data';
                    node.send(msg);
                  }       
            });  
        });
     });
    } /* else if (! 'file' in msg.dialog_params) {
      var errtxt = 'Missing Dialog template file';
      node.status({fill:'red', shape:'ring', text:errtxt}); 		
      node.error(errtxt, msg);
    }*/
    else {
      errtxt = 'dialog_name not specified';
      node.status({fill:'red', shape:'ring', text:errtxt}); 		
      node.error(errtxt, msg); 
    }   
  }
function performCreate(node,dialog,msg) {
    var params = {}
    node.status({fill:'blue', shape:'dot', text:'requesting create of new dialog template'});	 
    //if ('file' in msg.dialog_params && 'dialog_name' in msg.dialog_params) {
    if ('dialog_name' in msg.dialog_params) {  
      // extension supported : only XML
      // TODO : support other API format (json and encrypted crt)
      temp.open({suffix: '.xml'}, function (err, info) {
        if (err) throw err;
        //var fileBuffer = msg.dialog_params['file'];
        var fileBuffer = msg.payload;
        fs.writeFile(info.path, fileBuffer, function (err) {
            if (err) {
              console.error(err);
              throw err;
            }
            var aFileStream = fs.createReadStream(info.path);
            params.file = aFileStream;
            params.name = msg.dialog_params['dialog_name'];
            // Watson SDK call
            dialog.createDialog(params, function(err, dialog_data){
                  node.status({});
                  if (err) {
                    node.status({fill:'red', shape:'ring', text:'call to dialog service failed'}); 
                    node.error(err, msg);
                  } else {
                    msg.dialog = dialog_data;     
                    msg.payload = 'Check msg.dialog dialog data';
                    node.send(msg);
                  }       
            });  
        });
     });
    } /* else if (! 'file' in msg.dialog_params) {
      var errtxt = 'Missing Dialog template file';
      node.status({fill:'red', shape:'ring', text:errtxt}); 		
      node.error(errtxt, msg);
    }*/
    else {
      errtxt = 'dialog_name not specified';
      node.status({fill:'red', shape:'ring', text:errtxt}); 		
      node.error(errtxt, msg); 
    }   
  }
function performCreate ( node , dialog , msg ) { var params = { } node . status ( { fill : 'blue' , shape : 'dot' , text : 'requesting create of new dialog template' } ) ; //if ('file' in msg.dialog_params && 'dialog_name' in msg.dialog_params) { if ( 'dialog_name' in msg . dialog_params ) { // extension supported : only XML // TODO : support other API format (json and encrypted crt) temp . open ( { suffix : '.xml' } , function ( err , info ) { if ( err ) throw err ; //var fileBuffer = msg.dialog_params['file']; var fileBuffer = msg . payload ; fs . writeFile ( info . path , fileBuffer , function ( err ) { if ( err ) { console . error ( err ) ; throw err ; } var aFileStream = fs . createReadStream ( info . path ) ; params . file = aFileStream ; params . name = msg . dialog_params [ 'dialog_name' ] ; // Watson SDK call dialog . createDialog ( params , function ( err , dialog_data ) { node . status ( { } ) ; if ( err ) { node . status ( { fill : 'red' , shape : 'ring' , text : 'call to dialog service failed' } ) ; node . error ( err , msg ) ; } else { msg . dialog = dialog_data ; msg . payload = 'Check msg.dialog dialog data' ; node . send ( msg ) ; } } ) ; } ) ; } ) ; } /* else if (! 'file' in msg.dialog_params) {
      var errtxt = 'Missing Dialog template file';
      node.status({fill:'red', shape:'ring', text:errtxt}); 		
      node.error(errtxt, msg);
    }*/ else { errtxt = 'dialog_name not specified' ; node . status ( { fill : 'red' , shape : 'ring' , text : errtxt } ) ; node . error ( errtxt , msg ) ; } }
This function creates a new dialog template. The name must be unique, the file can be in any accepted format, and be either a text file or a binary buffer.
This function creates a new dialog template . The name must be unique the file can be in any accepted format and be either a text file or a binary buffer .