Skip to content

Instantly share code, notes, and snippets.

@sergueyarellano
Created December 18, 2020 20:25
Show Gist options
  • Save sergueyarellano/c2940b08d185fc84a14a81a5f356e9e3 to your computer and use it in GitHub Desktop.
Save sergueyarellano/c2940b08d185fc84a14a81a5f356e9e3 to your computer and use it in GitHub Desktop.
const admin = require('firebase-admin')
const serviceAccount = JSON.parse(process.env.FIREBASE_CRED_KEY)
// intialize app just once. Firebase will complain if we do it for each lambda execution
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: 'https://yourproject.firebaseio.com'
})
module.exports.lambda = async (event, context) => {
/**
* compose push notification message
*/
const options = {
priority: 'high',
timeToLive: 60 * 60 * 24
}
const registrationToken = data.token
const message = {
notification: {
title: 'Reminder',
body: 'Don\'t forget your activities for today!'
},
data: { // metadata
activities: data.activities.join(','),
}
}
/**
* send message
*/
await admin.messaging().sendToDevice(registrationToken, message, options)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment