SHARE
TWEET

Untitled

a guest Dec 11th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import * as functions from "firebase-functions";
  2. import * as admin from "firebase-admin";
  3. admin.initializeApp();
  4.  
  5. //firebase deploy --only functions
  6. //const db = admin.firestore();
  7. const fcm = admin.messaging();
  8.  
  9. export const sendTopic = functions.firestore
  10.   .document("classi/{classeID}")
  11.   .onCreate(async snapshot => {
  12.     const body:any = snapshot.data();
  13.     console.log(body);
  14.  
  15.     if(body.public) {
  16.       const payload: admin.messaging.MessagingPayload = {
  17.         notification: {
  18.           title: `${body.subject} di ${body.event}`,
  19.           body: `Aggiunto da ${body.name} (Pubblico? ${body.public})`,
  20.           icon: "icon",
  21.           clickAction: "FLUTTER_NOTIFICATION_CLICK" //Only for onResume e onLaunch
  22.         }
  23.       };
  24.       return fcm.sendToTopic("classi", payload);
  25.     } else {
  26.       return null;
  27.     }
  28.   });
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