【发布时间】:2019-09-01 13:07:57
【问题描述】:
我将 firebase 函数用于推送通知触发器。
我可以发送通知,但在触发器启动时我无法读取某些数据。
我尝试了常用的 firebase 数据库功能,但它们不起作用。
const admin = require('firebase-admin')
admin.initializeApp(functions.config().firebase)
let fcm = ''
exports.sendNewMessageNotification = functions.database.ref('/xxx/userInformations/{uid}/')
.onWrite((change:any) => {
// console.log(change.before)
const payload = {
notification: {
title: 'Kahve Falı',
body: 'Falın geldi!',
}
}
admin.database().ref('/xxx/userInformations/{uid}/fortunes')
.once('value')
.then((snapshot:any) => {
console.log('snapshot.val()')//I want to get that snaphot.val()
});
fcm = change.before._data.fcm;
return admin.messaging().sendToDevice(fcm, payload);
});
它不会读取该快照。它以不同的方式返回 null 或 undefined。
我不能那样做这条线;
.then((snapshot) => {
如果我不输入:any,它会给我一个 VS Code 错误。
【问题讨论】:
标签: node.js firebase firebase-realtime-database google-cloud-functions