@photon-ai/advanced-imessage-kit 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +603 -215
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -16,15 +16,14 @@ Advanced iMessage Kit is a comprehensive iMessage SDK for **reading**, **sending
16
16
 
17
17
  ## Features
18
18
 
19
- - **🔒 Type Safe** - Complete TypeScript support with full type definitions
20
- - **⚡ Real-time Communication** - WebSocket-based event system for instant message updates
21
- - **📱 Complete API** - Send text, attachments, reactions, edit messages, and more
22
- - **👥 Group Management** - Create groups, manage members, set group icons
23
- - **📎 Rich Attachments** - Send images, files, stickers, and contact cards
24
- - **📎 Rich Attachments** - Send images, files, voice messages, stickers, and contact cards
25
- - **🔍 Advanced Querying** - Powerful message filtering and search capabilities
26
- - **📊 Analytics** - Message counts, delivery status, and chat statistics
27
- - **🎯 Event-driven** - Listen for new messages, typing indicators, and status changes
19
+ - ** Type Safe** - Complete TypeScript support with full type definitions
20
+ - ** Real-time Communication** - WebSocket-based event system for instant message updates
21
+ - ** Complete API** - Send text, attachments, reactions, edit messages, and more
22
+ - ** Group Management** - Create groups, manage members, set group icons
23
+ - ** Rich Attachments** - Send images, files, voice messages, stickers, and contact cards
24
+ - ** Advanced Querying** - Powerful message filtering and search capabilities
25
+ - ** Analytics** - Message counts, delivery status, and chat statistics
26
+ - ** Event-driven** - Listen for new messages, typing indicators, and status changes
28
27
 
29
28
  ## Quick Start
30
29
 
@@ -39,28 +38,28 @@ bun add @photon-ai/advanced-imessage-kit
39
38
  ### Basic Usage
40
39
 
41
40
  ```typescript
42
- import { AdvancedIMessageKit } from '@photon-ai/advanced-imessage-kit'
41
+ import { SDK } from "@photon-ai/advanced-imessage-kit";
43
42
 
44
- const sdk = new AdvancedIMessageKit({
45
- serverUrl: '{your-subdomain}.imsgd.photon.codes' // Your subdomain is the unique link address assigned to you
46
- })
43
+ const sdk = SDK({
44
+ serverUrl: "{your-subdomain}.imsgd.photon.codes", // Your subdomain is the unique link address assigned to you
45
+ });
47
46
 
48
47
  // Connect to the server
49
- await sdk.connect()
48
+ await sdk.connect();
50
49
 
51
50
  // Listen for new messages
52
- sdk.on('new-message', (message) => {
53
- console.log('New message:', message.text)
54
- })
51
+ sdk.on("new-message", (message) => {
52
+ console.log("New message:", message.text);
53
+ });
55
54
 
56
55
  // Send a message
57
56
  await sdk.messages.sendMessage({
58
- chatGuid: 'any;-;+1234567890',
59
- message: 'Hello World!'
60
- })
57
+ chatGuid: "any;-;+1234567890",
58
+ message: "Hello World!",
59
+ });
61
60
 
62
61
  // Disconnect when done
63
- await sdk.disconnect()
62
+ await sdk.disconnect();
64
63
  ```
65
64
 
66
65
  ## Core API
@@ -68,31 +67,31 @@ await sdk.disconnect()
68
67
  ### Initialization & Connection
69
68
 
70
69
  ```typescript
71
- import { AdvancedIMessageKit } from '@photon-ai/advanced-imessage-kit'
70
+ import { SDK } from "@photon-ai/advanced-imessage-kit";
72
71
 
73
- const sdk = new AdvancedIMessageKit({
74
- serverUrl: '{your-subdomain}.imsgd.photon.codes', // Your subdomain is the unique link address assigned to you
75
- logLevel: 'info' // Log level: 'debug' | 'info' | 'warn' | 'error'
76
- })
72
+ const sdk = SDK({
73
+ serverUrl: "{your-subdomain}.imsgd.photon.codes", // Your subdomain is the unique link address assigned to you
74
+ logLevel: "info", // Log level: 'debug' | 'info' | 'warn' | 'error'
75
+ });
77
76
 
78
77
  // Connect to server
79
- await sdk.connect()
78
+ await sdk.connect();
80
79
 
81
80
  // Check connection status
82
- sdk.on('ready', () => {
83
- console.log('SDK is ready!')
84
- })
81
+ sdk.on("ready", () => {
82
+ console.log("SDK is ready!");
83
+ });
85
84
 
86
85
  // Graceful disconnect
87
- await sdk.disconnect()
86
+ await sdk.disconnect();
88
87
  ```
89
88
 
90
89
  ### Connection Management
91
90
 
92
91
  ```typescript
93
92
  // Message deduplication (prevents duplicate processing)
94
- sdk.clearProcessedMessages(1000) // Clear old processed message records
95
- const count = sdk.getProcessedMessageCount() // Get processed message count
93
+ sdk.clearProcessedMessages(1000); // Clear old processed message records
94
+ const count = sdk.getProcessedMessageCount(); // Get processed message count
96
95
  ```
97
96
 
98
97
  ## Message Operations
@@ -102,24 +101,24 @@ const count = sdk.getProcessedMessageCount() // Get processed message count
102
101
  ```typescript
103
102
  // Send text message
104
103
  const message = await sdk.messages.sendMessage({
105
- chatGuid: 'any;-;+1234567890',
106
- message: 'Hello World!'
107
- })
104
+ chatGuid: "any;-;+1234567890",
105
+ message: "Hello World!",
106
+ });
108
107
 
109
108
  // Send message with options
110
109
  await sdk.messages.sendMessage({
111
- chatGuid: 'any;-;+1234567890',
112
- message: 'Important message',
113
- subject: 'Subject line',
114
- effectId: 'com.apple.messages.effect.CKConfettiEffect'
115
- })
110
+ chatGuid: "any;-;+1234567890",
111
+ message: "Important message",
112
+ subject: "Subject line",
113
+ effectId: "com.apple.messages.effect.CKConfettiEffect",
114
+ });
116
115
 
117
116
  // Reply to message
118
117
  await sdk.messages.sendMessage({
119
- chatGuid: 'any;-;+1234567890',
120
- message: 'This is a reply',
121
- selectedMessageGuid: 'original-message-guid'
122
- })
118
+ chatGuid: "any;-;+1234567890",
119
+ message: "This is a reply",
120
+ selectedMessageGuid: "original-message-guid",
121
+ });
123
122
  ```
124
123
 
125
124
  ### Message Querying
@@ -127,19 +126,19 @@ await sdk.messages.sendMessage({
127
126
  ```typescript
128
127
  // Get messages with filters
129
128
  const messages = await sdk.messages.getMessages({
130
- chatGuid: 'any;-;+1234567890',
131
- limit: 50,
132
- offset: 0
133
- })
129
+ chatGuid: "any;-;+1234567890",
130
+ limit: 50,
131
+ offset: 0,
132
+ });
134
133
 
135
134
  // Get message counts
136
135
  const totalCount = await sdk.messages.getMessageCount({
137
- chatGuid: 'any;-;+1234567890',
138
- after: 1640995200000, // Timestamp
139
- before: 1641081600000 // Timestamp
140
- })
136
+ chatGuid: "any;-;+1234567890",
137
+ after: 1640995200000, // Timestamp
138
+ before: 1641081600000, // Timestamp
139
+ });
141
140
 
142
- const sentCount = await sdk.messages.getSentMessageCount()
141
+ const sentCount = await sdk.messages.getSentMessageCount();
143
142
  ```
144
143
 
145
144
  ### Message Actions
@@ -147,23 +146,23 @@ const sentCount = await sdk.messages.getSentMessageCount()
147
146
  ```typescript
148
147
  // Edit message
149
148
  await sdk.messages.editMessage({
150
- messageGuid: 'message-guid',
151
- editedMessage: 'Updated text',
152
- backwardsCompatibilityMessage: 'Updated text'
153
- })
149
+ messageGuid: "message-guid",
150
+ editedMessage: "Updated text",
151
+ backwardsCompatibilityMessage: "Updated text",
152
+ });
154
153
 
155
154
  // Add reaction
156
155
  await sdk.messages.sendReaction({
157
- chatGuid: 'any;-;+1234567890',
158
- messageGuid: 'message-guid',
159
- reaction: 'love', // Options: love, like, dislike, laugh, emphasize, question, -love, -like, etc.
160
- partIndex: 0 // Optional: defaults to 0
161
- })
156
+ chatGuid: "any;-;+1234567890",
157
+ messageGuid: "message-guid",
158
+ reaction: "love", // Options: love, like, dislike, laugh, emphasize, question, -love, -like, etc.
159
+ partIndex: 0, // Optional: defaults to 0
160
+ });
162
161
 
163
162
  // Unsend message
164
163
  await sdk.messages.unsendMessage({
165
- messageGuid: 'message-guid'
166
- })
164
+ messageGuid: "message-guid",
165
+ });
167
166
  ```
168
167
 
169
168
  ## Chat Management
@@ -172,70 +171,70 @@ await sdk.messages.unsendMessage({
172
171
 
173
172
  ```typescript
174
173
  // Get all chats
175
- const chats = await sdk.chats.getChats()
174
+ const chats = await sdk.chats.getChats();
176
175
 
177
176
  // Get specific chat
178
- const chat = await sdk.chats.getChat('chat-guid', {
179
- with: ['participants', 'lastMessage']
180
- })
177
+ const chat = await sdk.chats.getChat("chat-guid", {
178
+ with: ["participants", "lastMessage"],
179
+ });
181
180
 
182
181
  // Create new chat
183
182
  const newChat = await sdk.chats.createChat({
184
- addresses: ['+1234567890', '+0987654321'],
185
- message: 'Hello everyone!',
186
- service: 'iMessage', // 'iMessage' or 'SMS'
187
- method: 'private-api' // 'apple-script' or 'private-api'
188
- })
183
+ addresses: ["+1234567890", "+0987654321"],
184
+ message: "Hello everyone!",
185
+ service: "iMessage", // 'iMessage' or 'SMS'
186
+ method: "private-api", // 'apple-script' or 'private-api'
187
+ });
189
188
  ```
190
189
 
191
190
  ### Group Management
192
191
 
193
192
  ```typescript
194
193
  // Update group name
195
- await sdk.chats.updateChat('chat-guid', {
196
- displayName: 'My Group Chat'
197
- })
194
+ await sdk.chats.updateChat("chat-guid", {
195
+ displayName: "My Group Chat",
196
+ });
198
197
 
199
198
  // Add participant
200
- await sdk.chats.addParticipant('chat-guid', '+1234567890')
199
+ await sdk.chats.addParticipant("chat-guid", "+1234567890");
201
200
 
202
201
  // Remove participant
203
- await sdk.chats.removeParticipant('chat-guid', '+1234567890')
202
+ await sdk.chats.removeParticipant("chat-guid", "+1234567890");
204
203
 
205
204
  // Leave group
206
- await sdk.chats.leaveChat('chat-guid')
205
+ await sdk.chats.leaveChat("chat-guid");
207
206
  ```
208
207
 
209
208
  ### Group Icons
210
209
 
211
210
  ```typescript
212
211
  // Set group icon
213
- await sdk.chats.setGroupIcon('chat-guid', '/path/to/image.jpg')
212
+ await sdk.chats.setGroupIcon("chat-guid", "/path/to/image.jpg");
214
213
 
215
214
  // Get group icon
216
- const iconBuffer = await sdk.chats.getGroupIcon('chat-guid')
215
+ const iconBuffer = await sdk.chats.getGroupIcon("chat-guid");
217
216
 
218
217
  // Remove group icon
219
- await sdk.chats.removeGroupIcon('chat-guid')
218
+ await sdk.chats.removeGroupIcon("chat-guid");
220
219
  ```
221
220
 
222
221
  ### Chat Status
223
222
 
224
223
  ```typescript
225
224
  // Mark as read/unread
226
- await sdk.chats.markChatRead('chat-guid')
227
- await sdk.chats.markChatUnread('chat-guid')
225
+ await sdk.chats.markChatRead("chat-guid");
226
+ await sdk.chats.markChatUnread("chat-guid");
228
227
 
229
228
  // Typing indicators
230
- await sdk.chats.startTyping('chat-guid')
231
- await sdk.chats.stopTyping('chat-guid')
229
+ await sdk.chats.startTyping("chat-guid");
230
+ await sdk.chats.stopTyping("chat-guid");
232
231
 
233
232
  // Get chat messages
234
- const messages = await sdk.chats.getChatMessages('chat-guid', {
235
- limit: 100,
236
- offset: 0,
237
- sort: 'DESC'
238
- })
233
+ const messages = await sdk.chats.getChatMessages("chat-guid", {
234
+ limit: 100,
235
+ offset: 0,
236
+ sort: "DESC",
237
+ });
239
238
  ```
240
239
 
241
240
  ## Attachments & Media
@@ -245,17 +244,17 @@ const messages = await sdk.chats.getChatMessages('chat-guid', {
245
244
  ```typescript
246
245
  // Send file attachment
247
246
  const message = await sdk.attachments.sendAttachment({
248
- chatGuid: 'any;-;+1234567890',
249
- filePath: '/path/to/file.jpg',
250
- fileName: 'custom-name.jpg' // Optional
251
- })
247
+ chatGuid: "any;-;+1234567890",
248
+ filePath: "/path/to/file.jpg",
249
+ fileName: "custom-name.jpg", // Optional
250
+ });
252
251
 
253
252
  // Send sticker
254
253
  await sdk.attachments.sendSticker({
255
- chatGuid: 'any;-;+1234567890',
256
- filePath: '/path/to/sticker.png',
257
- selectedMessageGuid: 'message-to-reply-to' // Optional
258
- })
254
+ chatGuid: "any;-;+1234567890",
255
+ filePath: "/path/to/sticker.png",
256
+ selectedMessageGuid: "message-to-reply-to", // Optional
257
+ });
259
258
  ```
260
259
 
261
260
  ### Voice Messages
@@ -265,32 +264,34 @@ Voice messages differ from regular audio attachments. Ensure the audio file path
265
264
  ```typescript
266
265
  // Send voice message
267
266
  const message = await sdk.attachments.sendAttachment({
268
- chatGuid: 'any;-;+1234567890',
269
- filePath: '/path/to/audio.mp3',
270
- isAudioMessage: true
271
- })
267
+ chatGuid: "any;-;+1234567890",
268
+ filePath: "/path/to/audio.mp3",
269
+ isAudioMessage: true,
270
+ });
272
271
 
273
272
  // Detect and handle incoming audio messages
274
- sdk.on('new-message', async (msg) => {
275
- if (msg.isAudioMessage) {
276
- const att = msg.attachments?.[0]
277
- if (att) {
278
- // Download original audio attachment
279
- const audioBuffer = await sdk.attachments.downloadAttachment(att.guid, { original: true })
280
- // Save or process audioBuffer
281
- }
273
+ sdk.on("new-message", async (msg) => {
274
+ if (msg.isAudioMessage) {
275
+ const att = msg.attachments?.[0];
276
+ if (att) {
277
+ // Download original audio attachment
278
+ const audioBuffer = await sdk.attachments.downloadAttachment(att.guid, {
279
+ original: true,
280
+ });
281
+ // Save or process audioBuffer
282
282
  }
283
- })
283
+ }
284
+ });
284
285
  ```
285
286
 
286
287
  ### Attachment Info
287
288
 
288
289
  ```typescript
289
290
  // Get attachment details
290
- const attachment = await sdk.attachments.getAttachment('attachment-guid')
291
+ const attachment = await sdk.attachments.getAttachment("attachment-guid");
291
292
 
292
293
  // Get attachment count
293
- const count = await sdk.attachments.getAttachmentCount()
294
+ const count = await sdk.attachments.getAttachmentCount();
294
295
  ```
295
296
 
296
297
  ## Contacts & Handles
@@ -299,16 +300,16 @@ const count = await sdk.attachments.getAttachmentCount()
299
300
 
300
301
  ```typescript
301
302
  // Get all contacts
302
- const contacts = await sdk.contacts.getContacts()
303
+ const contacts = await sdk.contacts.getContacts();
303
304
 
304
305
  // Get contact card
305
- const contactCard = await sdk.contacts.getContactCard('+1234567890')
306
+ const contactCard = await sdk.contacts.getContactCard("+1234567890");
306
307
 
307
308
  // Share contact card
308
- await sdk.contacts.shareContactCard('chat-guid')
309
+ await sdk.contacts.shareContactCard("chat-guid");
309
310
 
310
311
  // Check if should share contact
311
- const shouldShare = await sdk.contacts.shouldShareContact('chat-guid')
312
+ const shouldShare = await sdk.contacts.shouldShareContact("chat-guid");
312
313
  ```
313
314
 
314
315
  ### Handle Operations
@@ -316,46 +317,274 @@ const shouldShare = await sdk.contacts.shouldShareContact('chat-guid')
316
317
  ```typescript
317
318
  // Query handles
318
319
  const result = await sdk.handles.queryHandles({
319
- address: '+1234567890',
320
- with: ['chats'],
321
- limit: 50
322
- })
320
+ address: "+1234567890",
321
+ with: ["chats"],
322
+ limit: 50,
323
+ });
323
324
 
324
325
  // Get handle availability
325
- const isAvailable = await sdk.handles.getHandleAvailability('handle-guid', 'imessage')
326
+ const isAvailable = await sdk.handles.getHandleAvailability(
327
+ "handle-guid",
328
+ "imessage"
329
+ );
326
330
 
327
331
  // Get focus status
328
- const focusStatus = await sdk.handles.getHandleFocusStatus('handle-guid')
332
+ const focusStatus = await sdk.handles.getHandleFocusStatus("handle-guid");
329
333
  ```
330
334
 
331
335
  ## Real-time Events
332
336
 
337
+ The SDK emits various events for real-time updates. All events can be listened to using the `on()` method.
338
+
339
+ ### Core Events
340
+
341
+ #### `ready`
342
+
343
+ Emitted when the SDK is fully connected and ready to use.
344
+
333
345
  ```typescript
334
- // Message events
335
- sdk.on('new-message', (message) => {
336
- console.log('New message received:', message.text)
337
- })
346
+ sdk.on("ready", () => {
347
+ console.log("SDK connected and ready");
348
+ });
349
+ ```
338
350
 
339
- sdk.on('updated-message', (message) => {
340
- console.log('Message updated:', message.guid)
341
- })
351
+ #### `connect`
342
352
 
343
- // Typing indicators
344
- sdk.on('typing-indicator', (data) => {
345
- console.log('Typing status changed:', data)
346
- })
353
+ Emitted when Socket.IO connection is established.
354
+
355
+ ```typescript
356
+ sdk.on("connect", () => {
357
+ console.log("Socket.IO connected");
358
+ });
359
+ ```
360
+
361
+ #### `disconnect`
362
+
363
+ Emitted when Socket.IO connection is lost.
364
+
365
+ ```typescript
366
+ sdk.on("disconnect", () => {
367
+ console.log("Socket.IO disconnected");
368
+ });
369
+ ```
370
+
371
+ #### `error`
372
+
373
+ Emitted when an error occurs.
374
+
375
+ ```typescript
376
+ sdk.on("error", (error) => {
377
+ console.error("SDK error:", error);
378
+ });
379
+ ```
380
+
381
+ ### Message Events
382
+
383
+ #### `new-message`
384
+
385
+ Emitted when a new message is received or sent.
386
+
387
+ ```typescript
388
+ sdk.on("new-message", (message) => {
389
+ console.log("New message received:", message.text);
390
+ console.log("From:", message.handle?.address);
391
+ console.log("GUID:", message.guid);
392
+ });
393
+ ```
394
+
395
+ #### `updated-message` / `message-updated`
396
+
397
+ Emitted when a message status changes (delivered, read, etc.).
398
+
399
+ ```typescript
400
+ sdk.on("updated-message", (message) => {
401
+ const status = message.dateRead
402
+ ? "read"
403
+ : message.dateDelivered
404
+ ? "delivered"
405
+ : "sent";
406
+ console.log(`Message ${message.guid} is now ${status}`);
407
+ });
408
+ ```
409
+
410
+ #### `message-send-error`
411
+
412
+ Emitted when sending a message fails.
413
+
414
+ ```typescript
415
+ sdk.on("message-send-error", (data) => {
416
+ console.error("Failed to send message:", data);
417
+ });
418
+ ```
347
419
 
348
- // Connection events
349
- sdk.on('ready', () => {
350
- console.log('SDK connected and ready')
351
- })
420
+ ### Chat Events
352
421
 
353
- sdk.on('error', (error) => {
354
- console.error('SDK error:', error)
355
- })
422
+ #### `chat-read-status-changed`
356
423
 
424
+ Emitted when a chat is marked as read or unread.
425
+
426
+ ```typescript
427
+ sdk.on("chat-read-status-changed", ({ chatGuid, read }) => {
428
+ console.log(`Chat ${chatGuid} marked as ${read ? "read" : "unread"}`);
429
+ });
430
+ ```
431
+
432
+ ### Group Chat Events
433
+
434
+ #### `group-name-change`
435
+
436
+ Emitted when a group chat name is changed.
437
+
438
+ ```typescript
439
+ sdk.on("group-name-change", (data) => {
440
+ console.log(`Group renamed to: ${data.message.groupTitle}`);
441
+ });
442
+ ```
443
+
444
+ #### `participant-added`
445
+
446
+ Emitted when someone is added to a group chat.
447
+
448
+ ```typescript
449
+ sdk.on("participant-added", (data) => {
450
+ console.log(`Participant added to ${data.chat.displayName}`);
451
+ });
452
+ ```
453
+
454
+ #### `participant-removed`
455
+
456
+ Emitted when someone is removed from a group chat.
457
+
458
+ ```typescript
459
+ sdk.on("participant-removed", (data) => {
460
+ console.log(`Participant removed from ${data.chat.displayName}`);
461
+ });
462
+ ```
463
+
464
+ #### `participant-left`
465
+
466
+ Emitted when someone leaves a group chat.
467
+
468
+ ```typescript
469
+ sdk.on("participant-left", (data) => {
470
+ console.log(`Participant left ${data.chat.displayName}`);
471
+ });
472
+ ```
473
+
474
+ #### `group-icon-changed`
475
+
476
+ Emitted when a group chat icon is changed.
477
+
478
+ ```typescript
479
+ sdk.on("group-icon-changed", (data) => {
480
+ console.log("Group icon changed");
481
+ });
482
+ ```
483
+
484
+ #### `group-icon-removed`
485
+
486
+ Emitted when a group chat icon is removed.
487
+
488
+ ```typescript
489
+ sdk.on("group-icon-removed", (data) => {
490
+ console.log("Group icon removed");
491
+ });
492
+ ```
493
+
494
+ ### Private API Events
495
+
496
+ #### `typing-indicator`
497
+
498
+ Emitted when someone is typing. Requires Private API.
499
+
500
+ ```typescript
501
+ sdk.on("typing-indicator", (data) => {
502
+ console.log("Typing status changed:", data);
503
+ });
504
+ ```
505
+
506
+ #### `ft-call-status-changed`
507
+
508
+ Emitted when FaceTime call status changes.
509
+
510
+ ```typescript
511
+ sdk.on("ft-call-status-changed", ({ callUuid, status }) => {
512
+ console.log(`FaceTime call ${callUuid}: ${status}`);
513
+ });
514
+ ```
515
+
516
+ ### Find My Events
517
+
518
+ #### `new-findmy-location`
519
+
520
+ Emitted when a Find My friend's location updates.
521
+
522
+ ```typescript
523
+ sdk.on("new-findmy-location", ({ name, friendId, location }) => {
524
+ console.log(`${name} location: ${location.latitude}, ${location.longitude}`);
525
+ });
526
+ ```
527
+
528
+ ### Scheduled Message Events
529
+
530
+ #### `scheduled-message-sent`
531
+
532
+ Emitted when a scheduled message is sent.
533
+
534
+ ```typescript
535
+ sdk.on("scheduled-message-sent", (data) => {
536
+ console.log("Scheduled message sent:", data);
537
+ });
538
+ ```
539
+
540
+ #### `scheduled-message-error`
541
+
542
+ Emitted when a scheduled message fails.
543
+
544
+ ```typescript
545
+ sdk.on("scheduled-message-error", (data) => {
546
+ console.error("Scheduled message error:", data);
547
+ });
548
+ ```
549
+
550
+ #### `scheduled-message-created`
551
+
552
+ Emitted when a scheduled message is created.
553
+
554
+ ```typescript
555
+ sdk.on("scheduled-message-created", (data) => {
556
+ console.log("Scheduled message created:", data);
557
+ });
558
+ ```
559
+
560
+ #### `scheduled-message-updated`
561
+
562
+ Emitted when a scheduled message is updated.
563
+
564
+ ```typescript
565
+ sdk.on("scheduled-message-updated", (data) => {
566
+ console.log("Scheduled message updated:", data);
567
+ });
568
+ ```
569
+
570
+ #### `scheduled-message-deleted`
571
+
572
+ Emitted when a scheduled message is deleted.
573
+
574
+ ```typescript
575
+ sdk.on("scheduled-message-deleted", (data) => {
576
+ console.log("Scheduled message deleted:", data);
577
+ });
578
+ ```
579
+
580
+ ### Event Management
581
+
582
+ ```typescript
357
583
  // Remove event listeners
358
- sdk.off('new-message', messageHandler)
584
+ sdk.off("new-message", messageHandler);
585
+
586
+ // Remove all listeners for an event
587
+ sdk.removeAllListeners("new-message");
359
588
  ```
360
589
 
361
590
  ## Advanced Features
@@ -364,27 +593,27 @@ sdk.off('new-message', messageHandler)
364
593
 
365
594
  ```typescript
366
595
  // Create FaceTime link
367
- const link = await sdk.facetime.createFaceTimeLink()
368
- console.log('FaceTime link:', link)
596
+ const link = await sdk.facetime.createFaceTimeLink();
597
+ console.log("FaceTime link:", link);
369
598
 
370
599
  // Listen for FaceTime status changes
371
- sdk.on('facetime-status-change', (data) => {
372
- console.log('FaceTime status:', data.status)
373
- })
600
+ sdk.on("facetime-status-change", (data) => {
601
+ console.log("FaceTime status:", data.status);
602
+ });
374
603
  ```
375
604
 
376
605
  ### iCloud Services
377
606
 
378
607
  ```typescript
379
608
  // Get Find My Friends
380
- const friends = await sdk.icloud.getFindMyFriends()
609
+ const friends = await sdk.icloud.getFindMyFriends();
381
610
 
382
611
  // Get Find My Devices
383
- const devices = await sdk.icloud.getFindMyDevices()
612
+ const devices = await sdk.icloud.getFindMyDevices();
384
613
 
385
614
  // Refresh data
386
- await sdk.icloud.refreshFindMyFriends()
387
- await sdk.icloud.refreshFindMyDevices()
615
+ await sdk.icloud.refreshFindMyFriends();
616
+ await sdk.icloud.refreshFindMyDevices();
388
617
  ```
389
618
 
390
619
  ### Scheduled Messages
@@ -392,57 +621,57 @@ await sdk.icloud.refreshFindMyDevices()
392
621
  ```typescript
393
622
  // Create scheduled message
394
623
  const scheduled = await sdk.scheduledMessages.createScheduledMessage({
395
- chatGuid: 'any;-;+1234567890',
396
- message: 'This message was scheduled!',
397
- scheduledFor: new Date(Date.now() + 60000), // 1 minute from now
398
- schedule: { type: 'once' }
399
- })
624
+ chatGuid: "any;-;+1234567890",
625
+ message: "This message was scheduled!",
626
+ scheduledFor: new Date(Date.now() + 60000), // 1 minute from now
627
+ schedule: { type: "once" },
628
+ });
400
629
 
401
630
  // Get all scheduled messages
402
- const allScheduled = await sdk.scheduledMessages.getScheduledMessages()
631
+ const allScheduled = await sdk.scheduledMessages.getScheduledMessages();
403
632
 
404
633
  // Update scheduled message
405
- await sdk.scheduledMessages.updateScheduledMessage('schedule-id', {
406
- message: 'Updated message'
407
- })
634
+ await sdk.scheduledMessages.updateScheduledMessage("schedule-id", {
635
+ message: "Updated message",
636
+ });
408
637
 
409
638
  // Delete scheduled message
410
- await sdk.scheduledMessages.deleteScheduledMessage('schedule-id')
639
+ await sdk.scheduledMessages.deleteScheduledMessage("schedule-id");
411
640
  ```
412
641
 
413
642
  ### Server Information
414
643
 
415
644
  ```typescript
416
645
  // Get server info
417
- const serverInfo = await sdk.server.getServerInfo()
646
+ const serverInfo = await sdk.server.getServerInfo();
418
647
 
419
648
  // Get message statistics
420
- const stats = await sdk.server.getMessageStats()
649
+ const stats = await sdk.server.getMessageStats();
421
650
 
422
651
  // Get server logs
423
- const logs = await sdk.server.getServerLogs(100)
652
+ const logs = await sdk.server.getServerLogs(100);
424
653
 
425
654
  // Get alerts
426
- const alerts = await sdk.server.getAlerts()
655
+ const alerts = await sdk.server.getAlerts();
427
656
 
428
657
  // Mark alerts as read
429
- await sdk.server.markAlertAsRead(['alert-id-1', 'alert-id-2'])
658
+ await sdk.server.markAlertAsRead(["alert-id-1", "alert-id-2"]);
430
659
  ```
431
660
 
432
661
  ## Error Handling
433
662
 
434
663
  ```typescript
435
664
  try {
436
- await sdk.messages.sendMessage({
437
- chatGuid: 'invalid-guid',
438
- message: 'Test'
439
- })
665
+ await sdk.messages.sendMessage({
666
+ chatGuid: "invalid-guid",
667
+ message: "Test",
668
+ });
440
669
  } catch (error) {
441
- if (error.response?.status === 404) {
442
- console.error('Chat not found')
443
- } else {
444
- console.error('Send failed:', error.message)
445
- }
670
+ if (error.response?.status === 404) {
671
+ console.error("Chat not found");
672
+ } else {
673
+ console.error("Send failed:", error.message);
674
+ }
446
675
  }
447
676
  ```
448
677
 
@@ -450,8 +679,8 @@ try {
450
679
 
451
680
  ```typescript
452
681
  interface ClientConfig {
453
- serverUrl?: string // Your subdomain: '{your-subdomain}.imsgd.photon.codes'
454
- logLevel?: 'debug' | 'info' | 'warn' | 'error' // Default: 'info'
682
+ serverUrl?: string; // Your subdomain: '{your-subdomain}.imsgd.photon.codes'
683
+ logLevel?: "debug" | "info" | "warn" | "error"; // Default: 'info'
455
684
  }
456
685
  ```
457
686
 
@@ -461,21 +690,21 @@ interface ClientConfig {
461
690
 
462
691
  ```typescript
463
692
  // Always disconnect when done
464
- process.on('SIGINT', async () => {
465
- await sdk.disconnect()
466
- process.exit(0)
467
- })
693
+ process.on("SIGINT", async () => {
694
+ await sdk.disconnect();
695
+ process.exit(0);
696
+ });
468
697
  ```
469
698
 
470
699
  ### Event Handling
471
700
 
472
701
  ```typescript
473
702
  // Use specific event handlers
474
- sdk.on('new-message', handleNewMessage)
475
- sdk.on('error', handleError)
703
+ sdk.on("new-message", handleNewMessage);
704
+ sdk.on("error", handleError);
476
705
 
477
706
  // Remove listeners when needed
478
- sdk.off('new-message', handleNewMessage)
707
+ sdk.off("new-message", handleNewMessage);
479
708
  ```
480
709
 
481
710
  ### Performance Optimization
@@ -483,43 +712,202 @@ sdk.off('new-message', handleNewMessage)
483
712
  ```typescript
484
713
  // Use pagination for large queries
485
714
  const messages = await sdk.messages.getMessages({
486
- chatGuid: 'any;-;+1234567890',
487
- limit: 100,
488
- offset: 0
489
- })
715
+ chatGuid: "any;-;+1234567890",
716
+ limit: 100,
717
+ offset: 0,
718
+ });
490
719
 
491
720
  // Clear processed message records (prevents memory leaks)
492
- sdk.clearProcessedMessages(1000)
721
+ sdk.clearProcessedMessages(1000);
493
722
 
494
723
  // Get processed message count
495
- const processedCount = sdk.getProcessedMessageCount()
724
+ const processedCount = sdk.getProcessedMessageCount();
496
725
  ```
497
726
 
498
727
  ## Examples
499
728
 
500
- Check the `/examples` directory for complete working examples:
501
-
502
- - `demo-basic.ts` - Basic SDK usage and event listening
503
- - `demo-advanced.ts` - Advanced SDK features
504
- - `message-send.ts` - Send messages
505
- - `message-attachment.ts` - Send files and images
506
- - `message-audio.ts` - Send voice messages
507
- - `message-contact-card.ts` - Send contact cards
508
- - `message-edit.ts` - Edit messages
509
- - `message-unsend.ts` - Unsend messages
510
- - `message-reaction.ts` - Add reactions
511
- - `message-reply.ts` - Reply to messages
512
- - `message-typing.ts` - Typing indicators
513
- - `message-scheduled.ts` - Scheduled messages
514
- - `message-search.ts` - Search messages
515
- - `message-stats.ts` - Message statistics
516
- - `chat-group.ts` - Group chat management
517
- - `chat-fetch.ts` - Fetch chat data
518
- - `contact-list.ts` - Contact management
519
- - `facetime-link.ts` - FaceTime integration
520
- - `findmy-friends.ts` - Find My integration
521
- - `auto-reply-hey.ts` - Auto-reply example
729
+ The SDK includes comprehensive examples in the `examples/` directory. All examples can be run using Bun:
730
+
731
+ ### Basic Examples
732
+
733
+ #### `demo-basic.ts` - Listen for Messages
734
+
735
+ Simple message listener demonstrating event handling.
736
+
737
+ ```bash
738
+ bun run examples/demo-basic.ts
739
+ ```
740
+
741
+ #### `message-send.ts` - Send a Message
742
+
743
+ Send a text message to a contact or chat.
744
+
745
+ ```bash
746
+ CHAT_GUID="+1234567890" bun run examples/message-send.ts
747
+ ```
748
+
749
+ #### `message-attachment.ts` - Send Files
750
+
751
+ Send images, videos, or other files as attachments.
752
+
753
+ ```bash
754
+ CHAT_GUID="+1234567890" bun run examples/message-attachment.ts
755
+ ```
756
+
757
+ #### `message-audio.ts` - Send Voice Messages
758
+
759
+ Send voice messages (audio attachments with special handling).
760
+
761
+ ```bash
762
+ CHAT_GUID="+1234567890" AUDIO_FILE_PATH="/path/to/audio.m4a" bun run examples/message-audio.ts
763
+ ```
764
+
765
+ ### Advanced Examples
766
+
767
+ #### `message-reaction.ts` - Reactions (Tapbacks)
768
+
769
+ Add and remove reactions to messages.
770
+
771
+ ```bash
772
+ CHAT_GUID="chat-guid" MESSAGE_GUID="message-guid" bun run examples/message-reaction.ts
773
+ ```
774
+
775
+ #### `message-edit.ts` - Edit Messages
776
+
777
+ Edit a sent message. Requires macOS Ventura (13.0) or newer and Private API.
778
+
779
+ ```bash
780
+ CHAT_GUID="chat-guid" bun run examples/message-edit.ts
781
+ ```
782
+
783
+ #### `message-unsend.ts` - Unsend Messages
784
+
785
+ Unsend a message within 2 minutes of sending. Requires macOS Ventura (13.0) or newer and Private API.
786
+
787
+ ```bash
788
+ CHAT_GUID="chat-guid" bun run examples/message-unsend.ts
789
+ ```
790
+
791
+ #### `message-typing.ts` - Typing Indicators
792
+
793
+ Start and stop typing indicators in a chat. Requires Private API.
794
+
795
+ ```bash
796
+ CHAT_GUID="chat-guid" bun run examples/message-typing.ts
797
+ ```
798
+
799
+ #### `message-contact-card.ts` - Share Contact Cards
800
+
801
+ Share contact cards in chats. Requires macOS Big Sur (11.0) or newer and Private API.
802
+
803
+ ```bash
804
+ CHAT_GUID="chat-guid" CONTACT_ADDRESS="email-or-phone" bun run examples/message-contact-card.ts
805
+ ```
806
+
807
+ #### `message-reply-sticker.ts` - Send Stickers
808
+
809
+ Send stickers and multipart messages. Requires Private API.
810
+
811
+ ```bash
812
+ CHAT_GUID="chat-guid" STICKER_PATH="path/to/image.jpg" bun run examples/message-reply-sticker.ts
813
+ ```
814
+
815
+ #### `message-effects.ts` - Message Effects
816
+
817
+ Send messages with visual effects (confetti, fireworks, balloons, etc.). Requires Private API.
818
+
819
+ ```bash
820
+ CHAT_GUID="chat-guid" bun run examples/message-effects.ts
821
+ ```
822
+
823
+ #### `message-reply.ts` - Reply to Messages
824
+
825
+ Reply to a specific message in a chat.
826
+
827
+ ```bash
828
+ CHAT_GUID="chat-guid" MESSAGE_GUID="message-guid" bun run examples/message-reply.ts
829
+ ```
830
+
831
+ #### `chat-fetch.ts` - Fetch Chats
832
+
833
+ Retrieve and filter chats from the database.
834
+
835
+ ```bash
836
+ bun run examples/chat-fetch.ts
837
+ ```
838
+
839
+ #### `chat-group.ts` - Group Chat Management
840
+
841
+ List and monitor group chats, track membership changes.
842
+
843
+ ```bash
844
+ bun run examples/chat-group.ts
845
+ ```
846
+
847
+ #### `message-search.ts` - Search Messages
848
+
849
+ Search through message history with filtering options.
850
+
851
+ ```bash
852
+ bun run examples/message-search.ts
853
+ ```
854
+
855
+ #### `message-stats.ts` - Message Statistics
856
+
857
+ View message statistics, chat activity, and analytics.
858
+
859
+ ```bash
860
+ bun run examples/message-stats.ts
861
+ ```
862
+
863
+ #### `message-scheduled.ts` - Schedule Messages
864
+
865
+ Schedule one-time and recurring messages.
866
+
867
+ ```bash
868
+ CHAT_GUID="+1234567890" bun run examples/message-scheduled.ts
869
+ ```
870
+
871
+ #### `facetime-link.ts` - FaceTime Links
872
+
873
+ Create FaceTime links programmatically. Requires macOS Monterey (12.0) or newer and Private API.
874
+
875
+ ```bash
876
+ bun run examples/facetime-link.ts
877
+ ```
878
+
879
+ #### `findmy-friends.ts` - Find My Integration
880
+
881
+ Track friends and devices via Find My network.
882
+
883
+ ```bash
884
+ bun run examples/findmy-friends.ts
885
+ ```
886
+
887
+ #### `contact-list.ts` - Contact Access
888
+
889
+ Access and search macOS Contacts database.
890
+
891
+ ```bash
892
+ bun run examples/contact-list.ts
893
+ ```
894
+
895
+ #### `demo-advanced.ts` - Advanced Features
896
+
897
+ Demonstrates permissions checking, chat retrieval, and event monitoring.
898
+
899
+ ```bash
900
+ bun run examples/demo-advanced.ts
901
+ ```
902
+
903
+ #### `auto-reply-hey.ts` - Auto-Reply Example
904
+
905
+ Automatic reply example that responds to incoming messages.
906
+
907
+ ```bash
908
+ bun run examples/auto-reply-hey.ts
909
+ ```
522
910
 
523
911
  ## License
524
912
 
525
- MIT License
913
+ MIT License
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@photon-ai/advanced-imessage-kit",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Powerful TypeScript iMessage SDK with real-time message processing",
5
5
  "keywords": [
6
6
  "imessage",