jakariamasud

orderNotification

Oct 20th, 2020
997
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         const functions = require('firebase-functions');
  2.         const admin = require('firebase-admin');
  3.         admin.initializeApp();
  4.     exports.offerTrigger =functions.database.ref('order_notification_list/{orderId}')
  5.         .onCreate((snap, context) =>{
  6.         const userData=snap.val();
  7.     const orderId=context.params.orderId;
  8.     const adminRef=admin.database().ref('/tokens/'+orderId);
  9.     adminRef.once('value',(snapshot)=>{
  10.     const token=snapshot.val()['my_token'];
  11.     const name=userData['name'];
  12.     const price=userData['price'];
  13.     const address=userData['address'];
  14.         const payload={
  15.                         notification:{
  16.                                 title:"Your have a new order!",
  17.                                 body: name +'Placed ' +price + 'form '+address
  18.                             },
  19.                         data:{
  20.                                 sendername:name
  21.                             }    
  22.                     }
  23.                    
  24.     return admin.messaging().sendToDevice(token,payload).catch((error=>{
  25.                         console.log("error occured in"+error);
  26.                        
  27.                     }))
  28.    
  29.    
  30. })
  31.  
  32.    
  33. })
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×