如何在Firebase中添加子项时在FCM中获取推送通知?

时间:2017-08-26 11:43:20

标签: node.js firebase firebase-realtime-database firebase-cloud-messaging android-notifications

Notification is to be sent when a child is added to /ADMIN/Orders

The notification has to be sent to each user who have the same Token ID

我的node.js代码是

'use strict'

var topic = "Users";

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

exports.updateOrder =     
functions.database.ref('/ADMIN/Orders/{order_id}').onWrite(event =>{

const order_id = event.params.order_id;

console.log("Today's order is updated!",order_id);

const deviceToken = admin.database().ref(`/USERS/{user_id}/TokenId`).once('value');

    return deviceToken.then(result => {

        const TokenId = result.val();

        const payload = {
            notification: {
            title: "Order is updated!",
            body: "Click to enter Yes/No",
            icon: "default"
        }
    };

    // return admin.messaging().sendToDevice(TokenId,payload).then(response =>{
    return admin.messaging().sendToTopic(topic, payload).then(response =>{

    console.log('This was the notification feature');

});


});
});

我的云功能(.js文件)显示成功执行,但推送通知仍然没有出现在我的手机上。

0 个答案:

没有答案