···11+import { Job } from "bullmq";
22+import { logger } from "../logger.js";
33+import { handleDeliveryError } from "../pushNotifications.js";
44+import { Expo } from "expo-server-sdk";
55+66+const expoClient = new Expo()
77+88+export async function checkPushNotificationDelivery(job: Job<{ ticketIds: string[] }>) {
99+ const { ticketIds } = job.data
1010+ let receiptIdChunks = expoClient.chunkPushNotificationReceiptIds(ticketIds);
1111+ for (const chunk of receiptIdChunks) {
1212+ try {
1313+ const receipts = await expoClient.getPushNotificationReceiptsAsync(chunk)
1414+1515+ // The receipts specify whether Apple or Google successfully received the
1616+ // notification and information about an error, if one occurred.
1717+ for (const receiptId in receipts) {
1818+ const receipt = receipts[receiptId]
1919+ if (receipt.status === 'error') {
2020+ await handleDeliveryError(receipt)
2121+ }
2222+ }
2323+ } catch (error) {
2424+ // TODO: retry checking the delivery of the notification after some time
2525+ logger.error(error)
2626+ }
2727+ }
2828+}