我想知道是否有办法使用node.js在firebase中检索_random数字并将其封装在我的通知主体部分中。我试图创建一个数组并从firebase读取所有内容到数组中,但它没有帮助
exports.sendFigureNotification = functions.database.ref('_random').onWrite(event => {
var rootRef = admin.database().ref();
rootRef.once("value", function(snapshot) {
});
const payload = {
notification: {
title: 'Title',
body: 'The Cloud Function works', //use _random to get figure at index key
badge: '1',
sound: 'default'
}
};
const options = {
priority:"high",
timeToLive: 60 * 60 * 24, //24 hours
content_available: true
};
const topic = "HBF"
console.log('Sending notifications');
return admin.messaging().sendToTopic(topic, payload, options);
});