Force.com Chatter API plugin for nforce
The Chatter API is #massive so the plugin is a work in progress. The following functionality has been implemented. Pull requests are welcome!
The test/chatter.js mocha test has sample code.
See the Chatter Developer's Guide for complete and official documentation.
$ npm install nforce-chatter
Require nforce and nforce-chatter in your app and create a client connection to a Salesforce Remote Access Application with the
chatter plugin enabled.
var nforce = require'nforce'chatter = require'nforce-chatter'nforcevar org = nforcecreateConnectionclientId: 'SOME_OAUTH_CLIENT_ID'clientSecret: 'SOME_OAUTH_CLIENT_SECRET'redirectUri: ''apiVersion: 'v32.0' // optional, defaults to current salesforce API versionenvironment: 'production' // optional, salesforce 'sandbox' or 'production', production defaultmode: 'multi' // optional, 'single' or 'multi' user mode, multi defaultplugins: 'chatter';
Now we just need to authenticate and get our salesforce OAuth credentials. Here is one way to do this in multi-user mode...
// multi user modevar oauth;orgauthenticate username: 'email@example.com' password: 'mypassword'// store the oauth object for this userif!err oauth = resp;;
...or in single-user mode...
// single-user modeorgauthenticate username: 'firstname.lastname@example.org' password: 'mypassword'// the oauth object was stored in the connection objectif!err console.log'Cached Token: ' + orgoauthaccess_token;
See the nforce readme for more detailed instruction on the awesome features of nforce.
The API of nforce-chatter follows typical node.js standards. Callbacks will always pass an optional error object, and a response object. The response object closely resembles the typical responses from the Salesforce REST API.
API calls take two arguments:
orgchatterrecordFeedid: '0037000000TWktt'if !err console.logresp;if err console.logerr;;
If you are using multi-user mode, pass the connection info in the hash with the
orgchatterrecordFeedid: '0037000000TWktt' oauth: oauthif !err console.logresp;if err console.logerr;;
The mocha tests currently run directly against a Saleforce org. I would like to switch them to use nock in the near future. To run the tests, first you'll need to rename
test/config.js and enter your connection parameters. Then run the tests.
$ npm test
Returns Chatter statistics for a salesforce user.
id: Required. The id of the user to return statistics for.
Returns the context user's news feed.
Returns the feed for a specified record.
id: Required. The id of the record to return the feed for.
Returns the feed for a specified group.
id: Required. The id of the group to return the feed for.
Posts a new feeditem for a record.
id: Required. The ID of the parent this feed element is being posted to. This value can be the ID of a user, group, or record, or the string me to indicate the context user.
text: Required. The text of the post.
Posts a new comment on a feeditem.
id: Required. The id of the feeditem to post the comment
text: Required. The text of the comment.
Likes the specified feeditem.
id: Required. The id of the feeditem to like.
v0.0.1: Initial release.