Firebase Event Listener. I want to execute if data says: "friend request" and not just on data change.
I've tried to search for listeners. I found: https://firebase.google.com/docs/database/admin/retrieve-data
I feel like I'm close, but I need help with the specifics.
exports.sendNotification = functions.database.ref('/Notifications/{user_id}/{notification_id}').onWrite((change, context) => {
const user_id = context.params.user_id;
const notification_id = context.params.notification_id;
const deviceToken = admin.database().ref('/' + user_id +'/device_token').once('value');
return deviceToken.then(result => {
const token_id = result.val();
const payload = {
notification: {
title: "Friend Request",
body: "You've received a new Friend Request! <3",
icon: "default"
}
};
});
});
My code executes(as expected), both when I write but also when I delete. However: Is there a way to instead, check if something specific is written to the database?
Bear with me, coming from java. But something like:
functions.database.ref('/Notifications/{user_id}/{notification_id}/type("friend request")')
.onWrite((write, context) => {.....
I want a listener, to check what data/notification type, I'm writing to the database. And then execute accordingly.
Best regards.