我们尝试发送通知取决于将数据添加到firebase实时数据库中的一个集合中,但是我们有多个数据库,我们引用了该数据库,但是看着db仍然引用了默认数据库,我们可以在代码中进行更改:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
var serviceAccount = require("./newkey.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://....." //link of db here
});
ref = admin.database().ref();
exports.pushNotification = functions.database.ref('/Message /{pushId}').onWrite( event => {
//the problem is here this function still listening to the default databse although after put the link of needed database above in databaseURL
console.log('Push notification event triggered');
var valueObject = event.data.val();
const payload = {
notification: {
title: valueObject.title,
body: valueObject.message,
sound: "default"
},
data: {
title: valueObject.title,
message: valueObject.message
}
};
const options = {
priority: "high",
timeToLive: 60 * 60 * 24 //24 hours
};
return admin.messaging().sendToTopic("notifications", payload, options);
});