Skip to content

Problems with sending push notifications  #1114

Open
@kvigon

Description

@kvigon

Good afternoon
There is an iOS application that receives push notifications; for this purpose, a server part was created in node.js with Firebase cloud functions. There is a standard synchronous function for sending notifications, but it works with great loss, so we are trying to make it asynchronous, but we are faced with a problem.

Below is the code, testing on silent notifications

var allMesseges = []
const sendAllMessages = async () => {
const sendMessege = allMesseges.map(async (message) => {
let response = await admin.messaging().send(message);
});
await Promise.all(sendMessege);
};

exports.allSilentPushTrigerAsync = functions.database.ref('/development/allSilentPushTrigerAsync/').onWrite(async event=> {
let snap = await db.ref("users").once("value")
let users = snap.val()
for (const [key, user] of Object.entries(users)) {
if (user.details.pushToken) {
const message = {
apns: {
headers: {
"apns-push-type": "background",
"apns-priority": "5",
},
payload: {
"aps" : {
"content-available" : 1
},
},
},
token: user.details.pushToken,
};
allMesseges.push(message)
}
}
await sendAllMessages()
})

We get an error in the logs

allSilentPushTrigerAsync
pzhv27hvepg4
Error: Requested entity was not found.
at Function.fromServerError (/workspace/node_modules/firebase-admin/lib/utils/error.js:254:16)
at createFirebaseError (/workspace/node_modules/firebase-admin/lib/messaging/messaging-errors-internal.js:35:47)
at /workspace/node_modules/firebase-admin/lib/messaging/messaging-api-request-internal.js:79:75
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async /workspace/index.js:180:28
at async Promise.all (index 4)
at async sendAllMessages (/workspace/index.js:182:9)
at async /workspace/index.js:207:10

at async /workspace/index.js:180:28 refers to the line of code:
let response = await admin.messaging().send(message);

at async /workspace/index.js:207:10 refers to the line of code:
await sendAllMessages()

Please tell me what the problem is.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions