【发布时间】:2019-11-13 10:38:23
【问题描述】:
我已经尝试了所有我知道的方法来让这个云函数正常工作,但我不知道这个云函数出于什么原因将 event.params 评估为未定义。
我的云功能是:-
'use-strict'
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotification = functions.database.ref('posts/{post}').onWrite(event => {
const payload = {
notification: {
title: "Title",
body: event.params.post,
icon: "default"
}
};
return admin.messaging().sendToDevice(payload).then(result => {
console.log("notification Sent")
});
});
我得到的错误:-
sendNotification
TypeError: Cannot read property 'post' of undefined at exports.sendNotification.functions.database.ref.onWrite.event(/srv/index.js: 11: 23) at cloudFunction(/srv/node_modules / firebase - functions / lib / cloud - functions.js: 119: 23) at / worker / worker.js: 825: 24 at < anonymous > at process._tickDomainCallback(internal / process / next_tick.js: 229: 7)
我的数据库有一个名为“posts”的直接子级。每当我在其中添加一个孩子时说{post} 函数触发但我无法获得{post} 值。
【问题讨论】:
标签: android firebase firebase-realtime-database firebase-cloud-messaging google-cloud-functions