Created
December 18, 2020 20:25
-
-
Save sergueyarellano/c2940b08d185fc84a14a81a5f356e9e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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