我在onCreate时使用Firebase Cloud Functions进行推送通知。请帮忙。
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.sendNotification = functions.database.ref('/messages/diyetisyen/{uname}/{msgid}/message')
.onCreate((snapshot, context) => {
let message = snapshot.val();
let uname = context.params.uname;
//let uname_slice = uname.slice(0,(uname.length-4)) + uname.slice((uname.length-3));
let root = snapshot.ref.root;
let tokenRef = root.child('/users/' + uname + '/token').ref;
let payload = {
data: {
custom_notification: JSON.stringify({
body: message + 'a',
title: 'title'
})
}
};
let options = { priority: "high" };
return tokenRef.once('value')
.then(dataSnapshot => {
let token = dataSnapshot.val();
console.log('2 n'+'message n' + message +'n tokenref n' + tokenRef +'n token n' + token +'n uname n' + uname+'n gönderiliyor');
return admin.messaging().sendToDevice(token, payload, options);
});
});
我收到消息,令牌,uname正确,但
admin.messaging((.sendToDevice(token,payload,options(;不起作用。
我更改了有效负载,例如
const payload = {
notification: {
title: 'title',
body: message + ''
}
};
它正在起作用。