I need your help with my code, I need to send a notification when a user does action from his app to notify another user(which I have his device token).
What I already did: first, install node.js and from it download firebase admin SDK and login and connect it to my project on firebase until I got Firebase CLI connected successfully.
then I opened the index.js file and add this code to it:
const functions = require('firebase-functions');
//import admin module
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.pushNotification = functions.database.ref('/YourNode/{pushId}').onWrite((change, context) => {
console.log('Push notification event triggered');
// Get the current value of what was written to the Realtime Database.
const valueObject = change.after.val();
// Create a notification
const payload = {
notification: {
title: valueObject.title,
body: valueObject.message,
sound: "default"
}
};
//Create an options object that contains the time to live for the notification and the priority
const options = {
priority: "high",
timeToLive: 60 * 60 * 24
};
return admin.messaging().sendToTopic("pushNotifications", payload, options);
});
and then I return to cmd screen and enter firebase deploy but at this point, it returns an error which is:
and when I google this problem I figured that I need to pay for a membership to firebase, right?
What I need
1- If that's right is my code and my steps right? and what should I do next to get the notifications working?
2- Can you help to give me the right and specific steps to accomplish that?
Please don't give me any link to firebase, I read All of the documentation and really confused.
Thanks for your time, waiting for your help :)
