It's easy to implement custom notifications with firebase. When the bid is placed, write the user's token and the message in a node in firebase
notificationRef.push.setValue(new NotificationModel("bid accepted", firebaseUser().getToken()))
Now to send the notification, we will use firebase functions
Install Node.js
Install firebase with node
npm install -g firebase-tools
Import firebase
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
then send the notification when the notification node
in firebase
is written
exports.bidNotification = functions.database.ref('/notification/{pushId}').onWrite((event) => {
const data = event.data;
console.log('Notification received');
if(!data.changed()){
console.log('Nothing changed');
return;
}
const payLoad = {
notification:{
title: 'App name',
body: data.val().message,
sound: "default"
}
};
const options = {
priority: "high",
timeToLive: 60*60
};
return admin.messaging().sendToDevice(data.val().token, payLoad, options);
});
Finally, deploy your functions on firebase using the CLI
Here is more: https://firebase.google.com/docs/functions/get-started
Enjoy