Hi, I’m using firebase function and cloud messaging to send notifications.
the way it works is when a webhook pushed an entry to real time database the function will be called to send push notifs to all users using expo https://exp.host/--/api/v2/push/send
but I’m encountering these errors
It says on the pricing plan that cloud messaging and function is free but why am I experiencing this error? I’m on Spark plan
this is how I send or handle the function
var fetch = require('node-fetch')
const functions = require('firebase-functions')
const admin = require('firebase-admin')
admin.initializeApp(functions.config().firebase)
exports.sendPushNotifications = functions.database.ref('new_content_store/{id}').onCreate(() => {
var messages = []
return admin
.database()
.ref('users')
.once('value')
.then(snapshot => {
snapshot.forEach(childSnapshot => {
var expoToken = childSnapshot.val().expoToken
if (expoToken) {
messages.push({
to: expoToken,
body: 'Test Notification'
})
}
})
return Promise.all(messages)
})
.then(messages => {
fetch('https://exp.host/--/api/v2/push/send', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(messages)
})
})
})
I’ve done a research too, but most of the answers/problems are dated back 2017 with the old firebase plan. And there is also a similar question to mine here but got no answers.