Meteor Intercom
A package to use Intercom.io easily with Meteor.
Installation
Intercom can be installed with Meteor's package manager:
$ meteor add percolate:intercom
API
Ensure you have Meteor.settings.intercom.secret
and Meteor.settings.public.intercom.id
defined to the values provided to you by Intercom. Also define Meteor.settings.public.intercom.apikey
if you intend to use Intercom on the server side.
Some Intercom subscription packages allow for anonymous users. To enable the use of anonymous users, set Meteor.settings.public.intercom.allowAnonymous
to true
.
By default, the package will send up the user's id, creation date, and hash (if defined, see below). To send custom data, set:
1IntercomSettings.userInfo = function(user, info) { 2 // add properties to the info object, for instance: 3 if (user.services.google) { 4 info.email = user.services.google.email; 5 info['name'] = user.services.google.given_name + ' ' + user.services.google.family_name; 6 } 7}
email
and name
are preset fields provided by Intercom. You may add any additional custom user attribute.
If you need to wait on a user subscription for e.g. the hash to come down, you can return false
in your userInfo
function to tell the package to wait.
1IntercomSettings.userInfo = function (user, info) { 2 if (!user.intercomHash) { 3 return false; // the hash isn't loaded to the users collection yet. come back later. 4 } 5 // ... 6}
If you want to add fields sent to intercom for an anonymous user, you can add them through in the anonymousInfo
function.
1IntercomSettings.anonymousInfo = function ( info ) { 2 // check all router subscriptions have loaded 3 if (!Router.current() || !Router.current().ready()) 4 return false; 5 6 info.anonymous = true; 7 return; 8};
On the server, you can also interact with the Intercom API via the official intercom-node client.
1// Create an event for a user 2IntercomClient.events.create({ 3 event_name: 'Test event', 4 created_at: Math.floor(new Date().getTime()/1000), 5 user_id: '<Insert meteor user id>' 6}, function (d) { 7 console.log(d); 8});
Notes
This package will automatically subscribe the current user to the currentUserIntercomHash
publication which will add an intercomHash
property to your user documents enabling the use of intercom's secure mode.
License
MIT. (c) Percolate Studio, maintained by Tom Coleman (@tmeasday)
Meteor Intercom was developed as part of the Verso project.