SHARE
TWEET

Untitled

a guest Dec 18th, 2018 246 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict'
  2.  
  3. const functions = require('firebase-functions');
  4. const admin = require('firebase-admin');
  5.  
  6. admin.initializeApp(functions.config().firebase);
  7.  
  8. exports.sendNotification = functions.database.ref('/Notifications/{notification_id}').onWrite(event =>
  9. {
  10.     const notification_id = event.params.notification_id;
  11.  
  12.     if(!event.data.val())
  13.     {
  14.         return console.log('A Notification has been deleted from the database : ', notification_id);
  15.     }
  16.  
  17.     const notification_data = admin.database().ref('/Notifications/${notification_id}').once('value');
  18.  
  19.     return notification_data.then(dataResult =>
  20.     {
  21.         const id = dataResult.val().id;
  22.         const about = dataResult.val().about;
  23.         const title = dataResult.val().title;
  24.         const name = dataResult.val().name;
  25.         const date = dataResult.val().date;
  26.    
  27.         const message =
  28.         {
  29.             data:
  30.             {
  31.                 id: '${id}',
  32.                 about: '${about}',
  33.                 title: '${title}',
  34.                 name: '${name}',
  35.                 date: '${date}',
  36.                 click_action: 'gr.teithe.it.it_app_TARGET_NOTIFICATION'
  37.             },
  38.             topic: 'notifications'
  39.         };
  40.  
  41.         return admin.messaging().send(message).then(response =>
  42.         {
  43.             console.log('${name} upload an announcement  on ${about}');
  44.         });
  45.     }
  46. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top