Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

205
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda