Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict'
- const functions = require('firebase-functions');
- const admin = require('firebase-admin');
- admin.initializeApp(functions.config().firebase);
- exports.sendNotification = functions.database.ref('/Notifications/{notification_id}').onWrite(event =>
- {
- const notification_id = event.params.notification_id;
- if(!event.data.val())
- {
- return console.log('A Notification has been deleted from the database : ', notification_id);
- }
- const notification_data = admin.database().ref('/Notifications/${notification_id}').once('value');
- return notification_data.then(dataResult =>
- {
- const id = dataResult.val().id;
- const about = dataResult.val().about;
- const title = dataResult.val().title;
- const name = dataResult.val().name;
- const date = dataResult.val().date;
- const message =
- {
- data:
- {
- id: '${id}',
- about: '${about}',
- title: '${title}',
- name: '${name}',
- date: '${date}',
- click_action: 'gr.teithe.it.it_app_TARGET_NOTIFICATION'
- },
- topic: 'notifications'
- };
- return admin.messaging().send(message).then(response =>
- {
- console.log('${name} upload an announcement on ${about}');
- });
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement