Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

198
Views
Trouble with Firebase Function to send out cloud message

I am having trouble executing a cloud function that sends a custom notification to each user. For some reason the notification does not go out at all. I don't know if it is because of the promise not being properly handled. Following is the code:

exports.scheduledMonMorngRingValueNotification = functions.pubsub.schedule('00 20 * * MON').timeZone('Asia/Kolkata').onRun((context) => {
  
  var db = admin.firestore();
  const promises = [];

  db.collection("collection_A").get().then(async snapshot => {

    await snapshot.forEach(async item => {

      await db.collection('collection_B').doc(item.id).get().then(bItem => {

        // ... Some data crunching

        payload = {
         token: token,
         fcm_options: {
          analytics_label: 'aLabel',
         },
         notification: {
          title: title,
          body: body,
          image: img
         },
        };
        
        promises.push(admin.messaging().send(payload));
        
      }).catch(reason => {
        console.log('Could not fetch bItm: ' + reason);
      });

    });

  }).catch(error => {
    console.log('Could not fetch: ' + error);
  });

  return Promise.all(promises).then((result) => {
   console.log('Promise all passed: ' + result + ' Promises: ' + promises);
  }).catch((error) => {
   console.log('Promise all failed: ' + error);
  });

});
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!