A basic pusher trigger for AWS Lambda using promises.
Related to pusher/pusher-http-node#67
npm install --save pusher-lambda-promise
Require the module, and initialize Pusher with settings.
const Pusher = require('pusher-lambda-promise');
const pusher = new Pusher({
appId: process.env.PUSHER_APP_ID,
key: process.env.PUSHER_APP_KEY,
secret: process.env.PUSHER_APP_SECRET,
cluster: process.env.PUSHER_APP_CLUSTER
});
Trigger single event
pusher.trigger('update', 'private-channel', {
foo: 'foo',
bar: 'bar'
}).then((results) => {
console.log(results);
}).catch((error) => {
console.error(error);
});
Trigger batch events
const batch = [
{
foo: 'foo',
bar: 'bar'
},
{
foo: 'foo',
bar: 'bar'
}
];
pusher.triggerBatch(batch)
.then((results) => {
console.log(results);
}).catch((error) => {
console.error(error);
});