我正在搜索,但无法找到解决问题的方法,我需要一个示例,说明如何从云功能发送FCM消息,但是使用FIRESTORE,而不是数据库实时...
我需要查询“用户”文档,在该文档中我有令牌来发送消息...
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.sendNotificaction = functions.firestore
.document('messages/{messageID}')
.onCreate((snap, context) => {
const message = snap.data();
const messageType = message.type;
const userID = message.userID;
console.log(messageType);
console.log(userID);
// I NEED TO QUERY MY "USER" DOC WITH "userID" TO GET THE TOKEN
//let token = 'eHQMpJkde_o:APA91bGa5x1lWB7kbK92QgCGkpyMq4PuQJA83_tIMIfzRil1Poly7ZzVVLU2Cs0GCTs77jgQo1i6Nn3vpzrMl6X2Zw9tN3eQIuJSvXuqgNUTa2EJEkKAbmqiVb2MGGHhPTanITJ0lCgaFpQkJjgznfd-MO2pv9S2PQ';
let payload = {
notification: {
title: 'Notificacion from firebase',
body: 'Test',
sound: 'default',
badge: '1'
}
};
return admin.messaging().sendToDevice(token, payload);
//}
});