-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsimple-push-test.ts
More file actions
executable file
·82 lines (71 loc) · 1.98 KB
/
Copy pathsimple-push-test.ts
File metadata and controls
executable file
·82 lines (71 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env bun
import { createApnsService } from "@/api/shared/notifications/services/apns-push.service";
import { prisma } from "@/utils/prisma";
// Simple version - just provide an XMTP ID and it will send a basic test notification
async function quickPushTest(xmtpId: string) {
console.log(`🔥 Quick Push Test for identity (xmtpId): ${xmtpId}\n`);
// Find any APNS device linked to this identity
const firstDevice = await prisma.device.findFirst({
where: {
pushTokenType: "apns",
pushToken: { not: null },
identities: {
some: {
identity: {
xmtpId,
},
},
},
},
include: {
identities: {
include: {
identity: true,
},
},
},
});
if (!firstDevice) {
console.log("❌ No APNS device found for this identity");
return;
}
console.log(
`📱 Found device: ${firstDevice.id || "Unnamed"} (${firstDevice.os})`,
);
const apnsService = createApnsService();
if (!apnsService) {
console.log("❌ APNS not configured");
return;
}
const messageData = {
contentTopic: "test-topic",
messageType: "test",
encryptedMessage: "Hello from the backend! 👋",
timestamp: Date.now().toString() + "000000",
};
console.log("📤 Sending notification...");
const result = await apnsService.sendPushNotification({
device: firstDevice,
notification: {
inboxId: firstDevice.identities[0].identity.xmtpId,
notificationType: "Protocol",
notificationData: messageData,
apiJWT: "dummy-jwt-token",
},
});
if (result.success) {
console.log("✅ Push notification sent successfully!");
} else {
console.log(`❌ Failed: ${result.error}`);
}
}
const xmtpId = process.argv[2];
if (!xmtpId) {
console.log("Usage: bun run scripts/simple-push-test.ts <xmtpId>");
process.exit(1);
}
quickPushTest(xmtpId)
.then(() => prisma.$disconnect())
.catch((error: unknown) => {
console.error(error);
});