I’m trying to manage the receipt IDs after sending push notification through node JS.
The issue is that the response to :
expo.getPushNotificationReceiptsAsync(chunk)
is always returning an object like this :
{
'02430945-426d-4f41-ae0d-b93163cf805f': { status: 'ok' },
'1df40b3c-558d-4484-91d7-57cf4a6cedc4': { status: 'ok' },
}
As you can see there is no message or details object.
I tried not to use chunk function but still the same issue.
My code
connection.query(
`SELECT receipt_id FROM users_expo_receipt WHERE CreatedAt > '${anHourAgo}' AND details is NULL`,
async function (err, result) {
if (err) console.log(err);
for (let receiptId of result) {
allReceiptId.push(receiptId.receipt_id);
}
console.log(allReceiptId);
let receiptIdChunks =
expo.chunkPushNotificationReceiptIds(allReceiptId);
(async () => {
for (let chunk of receiptIdChunks) {
try {
let receipts = await expo.getPushNotificationReceiptsAsync(chunk);
console.log(receipts);
for (let receiptId in receipts) {
let { status, message, details } = receipts[receiptId];
if (status === "ok") {
continue;
} else if (status === "error") {
console.error(
`There was an error sending a notification: ${message}`
);
if (details && details.error) {
// The error codes are listed in the Expo documentation:
// https://docs.expo.io/push-notifications/sending-notifications/#individual-errors
// You must handle the errors appropriately.
console.error(`The error code is ${details.error}`);
}
}
}
} catch (error) {
console.error(error);
}
}
})();
}
);