Skip to content

Instantly share code, notes, and snippets.

@randymxj
Last active February 15, 2017 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save randymxj/23bd73ca2c79fd65af2a673b657f75ba to your computer and use it in GitHub Desktop.
Save randymxj/23bd73ca2c79fd65af2a673b657f75ba to your computer and use it in GitHub Desktop.
'use strict';
/**
* This is a sample AWS Lambda instance with NodeJS
* Simply sending a POST request to Google Firebase
*/
const AWS = require('aws-sdk');
/**
* handler is the entry point of the button click
*/
exports.handler = (event, context, callback) => {
console.log('Received event:', event.clickType);
var request = require('request');
// Firebase auth key
var serverKey = "Firebase Server Key";
var clientToken= "Client Device Token";
var options = {
url: 'https://fcm.googleapis.com/fcm/send',
headers: {
'Authorization': 'key=' + serverKey
},
json: {
"to": clientToken,
"data": {
deviceId: `${event.serialNumber}`,
deviceName: 'IoT Button',
eventName: 'Click',
value: `${event.clickType}, ${event.batteryVoltage}`
}
}
};
request.post(options, function optionalCallback(err, httpResponse, body) {
if (err) {
return callback(err);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment