I have a nodejs project from which I need to send push notifications to devices. I have the app configured in firebase and sending test messages from firebase console works fine. But from my code in nodejs its not working but the response message is success.
RESPONSE
Successfully sent notification
{
responses: [
{
success: true,
messageId: 'projects/bioter-app/messages/0:1661888947319442%2fcd2f4df9fd7ecd'
}
],
successCount: 1,
failureCount: 0
}
CODE TO SEND MESSAGES
import { initializeApp, cert } from "firebase-admin/app";
import { messaging } from "firebase-admin";
import path from "path";
export interface IPushNotificacion {
token: string,
data: {
title: string,
message: string
}
}
initializeApp({
credential: cert(path.join(__dirname, 'keys', 'bioter-app-firebase-adminsdk-11lci-9e163aab29.json'))
})
export const sendMessage = (messages: IPushNotificacion[]) => {
if (!messages.length) return
messaging().sendAll(messages)
.then(response => {
console.log(`Successfully sent notification`)
console.log(response)
})
.catch(err => {
console.log('Notification could not be sent ')
console.log(err)
})
}
I tried reading firebase admin docs for cloud messages but i wasnt able to identify my problem. https://firebase.google.com/docs/cloud-messaging/server