![](/img/trans.png)
[英]Sending FCM Push Notification in Kotlin Client App - Firebase Cloud Messaging
[英]Cloud functions with Firebase Realtime Database not triggering onCreate and not sending FCM notification
我正在尝试根据 RealtimeDatabase 的 onCreate 事件自动发送通知,但是 function 从不触发并且从不记录任何内容。
代码:
// The Cloud Functions for Firebase SDK to create Cloud Functions and set up triggers.
const functions = require('firebase-functions');
// The Firebase Admin SDK to access Firestore.
const admin = require('firebase-admin');
admin.initializeApp();
exports.notificationOnArticleCreate = functions.database.ref().onCreate((snapshot, context) => {
const payload = {
notification: {
title: 'cloud function demo',
body: 'this is a test notification'
}
};
admin.messaging().send(payload).then((response) => {
console.log('Successfully sent message:', response);
return {success: true};
}).catch((error) => {
return {error: error.code};
});
console.log('test test');
})
我很惊讶这甚至编译/部署: functions.database.ref().onCreate
。
您需要指出创建节点的路径,例如
functions.database.ref("/messages/{message}").onCreate(...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.