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文件)显示成功执行,但推送通知仍然没有出现在我的手机上。