Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with sending push notifications #1114

Open
kvigon opened this issue Nov 3, 2023 · 0 comments
Open

Problems with sending push notifications #1114

kvigon opened this issue Nov 3, 2023 · 0 comments

Comments

@kvigon
Copy link

kvigon commented Nov 3, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant