使用Cloud Functions发送FCM通知..问题

时间:2018-10-23 13:37:01

标签: firebase firebase-realtime-database firebase-cloud-messaging google-cloud-functions

我正在尝试通过Cloud函数发送FCM通知,但是它不起作用...

这是代码...我怀疑数据库的路径不正确!

var functions = require("firebase-functions");
let admin = require('firebase-admin');

admin.initializeApp(functions.config().firebase);


exports.sendPush = functions.database.ref('/messages/{messageId}').onCreate(event => {

    let payload = {
        notification: {
            title: 'Firebase Notification',
            body: 'Coming from DB Trigger!',
            sound: 'default',
            badge: '1'
        }
    };

    let tokens = 'e28NuXH_8gY:APA91bGdDjb....';
    admin.messaging().sendToDevice(tokens, payload);
});

这是数据库设计:

DB Image ONE

DB Image TWO

0 个答案:

没有答案