gpt4 book ai didi

javascript - Firecloud 功能未触发?

转载 作者:行者123 更新时间:2023-12-02 22:39:26 25 4
gpt4 key购买 nike

这是我的函数,它甚至不是由 firebase 函数云触发的!我收到一条错误消息:错误:函数执行失败。细节:无法读取未定义的属性“ref”

     //send the push notification 
exports.sendPushNotification = functions.database.ref('contacts/').onCreate(event => {

const root = event.after.ref.root
var messages = []

//return the main promise
return root.child('/users').once('value').then(function (snapshot) {
snapshot.forEach(function (childSnapshot) {

var expoToken = childSnapshot.val().expoToken;

messages.push({
"to": expoToken,
"sound": "default",
"body": "New Note Added"
});
});
//firebase.database then() respved a single promise that resolves
//once all the messages have been resolved
return Promise.all(messages)

})
.then(messages => {
// console.log(messages)
fetch('https://exp.host/--/api/v2/push/send', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(messages)

});
})
.catch(reason => {
console.log(reason)
})


});

最佳答案

onCreate 更改为以下内容:


exports.sendPushNotification = functions.database.ref("contacts/").onCreate((snap, context) => {
const createdData = snap.val();

在您的情况下,要获取root,请执行以下操作:

const roots = snap.ref.root

您可以在此处找到更多信息:

https://firebase.google.com/docs/functions/beta-v1-diff

关于javascript - Firecloud 功能未触发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58632288/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com