This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// If you use this as a template, replace IBM Corp. with your own name. | |
// Sample Node-RED node file | |
// Require main module | |
var RED = require(process.env.NODE_RED_HOME+"/red/red"); | |
var nforce = require('nforce'); | |
var http = require('http'), | |
faye = require('faye'); | |
var client; | |
var oauth; | |
function SalesforceInNode(n) { | |
RED.nodes.createNode(this,n); | |
this.active = true; | |
this.topic = n.topic; | |
var node = this; | |
console.log(n); | |
var org = nforce.createConnection({ | |
clientId: n.clientId, | |
clientSecret: n.clientSecret, | |
redirectUri: n.redirectUri | |
}); | |
org.authenticate({ username: n.username, password: n.password + n.token}, function(err, _oauth) { | |
if(err) { | |
console.error('unable to authenticate to sfdc'); | |
console.log(err); | |
process.exit(code=0); | |
} else { | |
console.log("authenticated"); | |
console.log("oauth"); | |
console.log(_oauth); | |
oauth = _oauth; | |
client = new faye.Client(oauth.instance_url + '/cometd/28.0'); | |
client.setHeader("Authorization", "OAuth " + oauth.access_token); | |
var subscription = client.subscribe('/topic/' + n.pushTopicName, function(message) { | |
var msg = { topic:n.pushTopicName, payload:message.sobject, location:"Chicago", lang:"en" }; | |
node.send(msg); | |
//console.log("received!"); | |
//console.log(message.sobject); | |
}); | |
} | |
}); | |
this.on("close", function() { | |
console.log("closing"); | |
}); | |
} | |
// Register the node by name. This must be called before overriding any of the | |
// Node functions. | |
RED.nodes.registerType("salesforce in",SalesforceInNode); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment