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

340
Views
¿Cómo obtener el token fcm de un usuario de Firestore?

Tengo problemas para enviar mensajes fcm y obtengo el error

Los tokens de registro proporcionados a sendToDevice() deben ser una cadena no vacía o una matriz no vacía.

Estoy usando funciones de base de fuego para enviar los mensajes. Esta es la parte de la función que define el token. En el registro, el token es efB_l9RCMEIErl8m...

 exports.newUpdateReqText = functions.firestore .document('texts/{id}').onCreate(snap => { const afterData = snap.data() let name = afterData.name; let phone = afterData.phone.replace(/[^0-9]+/g, ""); let created = afterData.created; let userId = afterData.userId; return admin.firestore() .collection('users') .doc(userId) .get() .then(doc => { let token = doc.data().fcm_token functions.logger.log(token) const payload = { notification: { title: 'Please update your profile', message: `Hi ${name}! It looks like your profile isn't complete. Please provide the rest of the required information ASAP. https://mvpeventstaffing.com/profile.`, }, data: { "title": 'Please update your profile', "body": `Hi ${name}! It looks like your profile isn't complete. Please provide the rest of the required information ASAP. https://mvpeventstaffing.com/profile.`, "action_item": "venue", "action_id": "1", "actionable": "true", "priority": "high", }, } return admin.messaging().sendToDevice(token, payload) .then((response)=> { return console.log("Successfully sent message:", response); }) .catch((error) =>{ console.log("Error sending message:", error); }); })

Al leer respuestas a preguntas similares en este sitio, comúnmente responden que la forma de obtener el token es esta:

 const getdevicetokenpromise = db.ref(`/DriversAvailable/${key}/token`).once('value');

Pero, por lo que puedo decir, eso es con db en tiempo real, no con firestore. Obtengo db.ref no es una función cuando traté de escribirlo así.

Entonces, ¿mis datos se almacenan de manera incorrecta? ¿Estoy accediendo de forma incorrecta? ¿O mi función para enviar el mensaje es incorrecta? Cualquier ayuda sería apreciada.

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!