import { Expo, ExpoPushMessage } from 'expo-server-sdk' const expo = new Expo() async function sendNotification({ token, title, subtitle, body, data, badgeNumber = 1, operatingSystem = '', }) { const message: ExpoPushMessage = { title, subtitle, body, data, badge: badgeNumber, to: token, priority: 'high', ttl: 1000 * 60, sound: 'default', ...(operatingSystem === 'ANDROID' && { channelId: 'general', }), } const chunks = expo.chunkPushNotifications([message]) const tickets = await expo.sendPushNotificationsAsync(chunks[0]) if (tickets[0].status !== 'ok') { throw new Error( `Couldn't send expo notification to ${token} because: "${ tickets[0].message }. ${JSON.stringify(message, null, 2)}"` ) } // FOLLOWED EXPO STEPS BUT FOUND SIMPLER // let receiptIdChunks = expo.chunkPushNotificationReceiptIds([tickets[0]?.id]) // console.log('receiptIdChunks', receiptIdChunks) // let receipts = await expo.getPushNotificationReceiptsAsync(receiptIdChunks[0]) // console.log('receipts', receipts) // const hasError = receipts.some(receipt => receipt.status === 'error') // // console.log('hasError', hasError) // if (hasError) { // throw new Error(`Couldn't send expo notification to ${token}`) // } } // ExponentPushToken[hkqG5MN1qtMzdH0GFZptA-] // DEMO@USEWALTER.COM // ExponentPushToken[77nlAKGZghg9LmNlLQKTVY] // THIERRY // ExponentPushToken[Q3SbRUBaprciNzH0GxMa1Z] // Thierry walter resident v4 // ExponentPushToken[NICks_Dp8ZeKL_SJS21aWL] // Thierry android // sendNotification({ // token: 'ExponentPushToken[NICks_Dp8ZeKL_SJS21aWL]', // title: 'TEST NOTIFICATION', // subtitle: `TEST SUBTITLE`, // body: `TEST BODY`, // data: { // test: 123 // } // }) // .then(() => console.log('success')) // .catch(console.error) export default { sendNotification, }