unoffical wafrn mirror
wafrn.net
atproto
social-network
activitypub
1import { Job } from "bullmq";
2import { logger } from "../logger.js";
3import { handleDeliveryError } from "../pushNotifications.js";
4import { Expo } from "expo-server-sdk";
5
6const expoClient = new Expo()
7
8export async function checkPushNotificationDelivery(job: Job<{ ticketIds: string[] }>) {
9 const { ticketIds } = job.data
10 let receiptIdChunks = expoClient.chunkPushNotificationReceiptIds(ticketIds);
11 for (const chunk of receiptIdChunks) {
12 try {
13 const receipts = await expoClient.getPushNotificationReceiptsAsync(chunk)
14
15 // The receipts specify whether Apple or Google successfully received the
16 // notification and information about an error, if one occurred.
17 for (const receiptId in receipts) {
18 const receipt = receipts[receiptId]
19 if (receipt.status === 'error') {
20 await handleDeliveryError(receipt)
21 }
22 }
23 } catch (error) {
24 // TODO: retry checking the delivery of the notification after some time
25 logger.error(error)
26 }
27 }
28}