Вместо context.data.val()
используйте change.after.exists()
Пожалуйста, проверьте эту функцию:
exports.sendNotification = functions.database.ref('/notifications/{user_id}/{notification_id}').onWrite((change, context) => {
const user_id = context.params.user_id;
const notification = context.params.notification_id;
console.log('We have a notification to send to : ', user_id);
if (!change.after.exists()) {
console.log('A notification has been deleted from the database:', notification);
return null;
}
const deviceToken = admin.database().ref(`/Users/${user_id}/deviceToken`).once('value');
return deviceToken.then(result => {
const token_id = result.val();
const payload = {
notification: {
title: "Friend Request",
body: "You've receieved a new Friend Request",
icon: "default"
}
};
return admin.messaging().sendToDevice(token_id, payload).then(response => {
console.log('This is the notification Feature');
});
});
});