Skip to content

Instantly share code, notes, and snippets.

Created December 19, 2013 20:29
Show Gist options
  • Save ReidCarlberg/8045742 to your computer and use it in GitHub Desktop.
Save ReidCarlberg/8045742 to your computer and use it in GitHub Desktop.
// 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); = true;
this.topic = n.topic;
var node = this;
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');
} else {
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" };
this.on("close", function() {
// 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