Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
'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