forked from photon-hq/imessage-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathllms.txt
More file actions
247 lines (188 loc) · 5.24 KB
/
llms.txt
File metadata and controls
247 lines (188 loc) · 5.24 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# @photon-ai/imessage-kit - LLM Integration Guide
> This file helps AI assistants understand how to use this SDK correctly.
## Overview
A TypeScript SDK for iMessage automation on macOS. Works with Node.js and Bun.
## Installation
```bash
# Bun (recommended)
bun add @photon-ai/imessage-kit
# Node.js
npm install @photon-ai/imessage-kit better-sqlite3
```
## Core Patterns
### 1. Basic Setup
```typescript
import { IMessageSDK } from '@photon-ai/imessage-kit'
const sdk = new IMessageSDK({ debug: true })
// ... do work ...
await sdk.close() // Always close when done
```
### 2. Send Messages
```typescript
// Text
await sdk.send('+1234567890', 'Hello!')
// Images
await sdk.send('+1234567890', { images: ['/path/to/image.jpg'] })
// Files
await sdk.send('+1234567890', { files: ['/path/to/doc.pdf'] })
// Combined
await sdk.send('+1234567890', {
text: 'Check this out',
images: ['photo.jpg'],
files: ['report.pdf']
})
// To group chat (use chatId from listChats)
await sdk.send('chat45e2b868ce1e43da89af262922733382', 'Hello group!')
```
### 3. Query Messages
```typescript
// Get messages with filters
const result = await sdk.getMessages({
sender: '+1234567890',
unreadOnly: true,
limit: 20,
since: new Date('2025-01-01'),
search: 'keyword'
})
// Get unread grouped by sender
const unread = await sdk.getUnreadMessages()
for (const { sender, messages } of unread.groups) {
console.log(`${sender}: ${messages.length} unread`)
}
```
### 4. List Chats
```typescript
const chats = await sdk.listChats({
type: 'group', // 'all' | 'group' | 'dm'
hasUnread: true,
sortBy: 'recent',
search: 'Project',
limit: 20
})
```
### 5. Real-time Watching
```typescript
await sdk.startWatching({
onMessage: (msg) => { /* all messages */ },
onDirectMessage: (msg) => { /* DMs only */ },
onGroupMessage: (msg) => { /* groups only */ },
onError: (err) => { /* errors */ }
})
sdk.stopWatching()
```
### 6. Auto-Reply Bot
```typescript
await sdk.startWatching({
onDirectMessage: async (msg) => {
await sdk.message(msg)
.ifFromOthers()
.matchText(/hello/i)
.replyText('Hi there!')
.execute()
}
})
```
### 7. Scheduled Messages
```typescript
import { IMessageSDK, MessageScheduler } from '@photon-ai/imessage-kit'
const scheduler = new MessageScheduler(sdk)
// One-time
scheduler.schedule({
to: '+1234567890',
content: 'Reminder!',
sendAt: new Date(Date.now() + 5 * 60 * 1000)
})
// Recurring
scheduler.scheduleRecurring({
to: '+1234567890',
content: 'Daily update',
startAt: new Date(),
interval: 'daily' // 'hourly' | 'daily' | 'weekly' | 'monthly' | number (ms)
})
scheduler.destroy() // Cleanup
```
### 8. Smart Reminders (Human-friendly)
```typescript
import { IMessageSDK, Reminders } from '@photon-ai/imessage-kit'
const reminders = new Reminders(sdk)
// Relative time
reminders.in('5 minutes', '+1234567890', 'Break time!')
reminders.in('2 hours', '+1234567890', 'Call client')
// Specific time
reminders.at('5pm', '+1234567890', 'End of day')
reminders.at('tomorrow 9am', '+1234567890', 'Standup')
reminders.at('friday 2pm', '+1234567890', 'Weekly sync')
reminders.destroy() // Cleanup
```
## Message Object
```typescript
interface Message {
id: string
guid: string
text: string | null
sender: string // Phone or email
senderName: string | null
chatId: string
isGroupChat: boolean
isFromMe: boolean
isRead: boolean
service: 'iMessage' | 'SMS' | 'RCS'
attachments: Attachment[]
date: Date
}
```
## Error Handling
```typescript
import { SendError, DatabaseError } from '@photon-ai/imessage-kit'
try {
await sdk.send('+1234567890', 'Hello')
} catch (error) {
if (error instanceof SendError) {
// Handle send failure
}
}
```
## Best Practices
1. **Always close SDK**: Call `sdk.close()` when done
2. **Always destroy schedulers**: Call `scheduler.destroy()` or `reminders.destroy()`
3. **Use absolute paths** for files and images
4. **Check attachment existence** before downloading: `await attachmentExists(attachment)`
5. **Handle errors** with try-catch for send operations
6. **Use `ifFromOthers()`** in auto-reply to avoid infinite loops
## Common Mistakes to Avoid
1. ❌ Forgetting to call `sdk.close()` (leaks resources)
2. ❌ Using relative paths for attachments
3. ❌ Auto-replying without `ifFromOthers()` (causes loops)
4. ❌ Not handling errors in send operations
5. ❌ Forgetting to destroy scheduler/reminders
## ChatId Formats
- **Phone**: `'+1234567890'`
- **Email**: `'user@example.com'`
- **Group**: `'chat45e2b868ce1e43da89af262922733382'` (from listChats)
- **Service-prefixed**: `'iMessage;+1234567890'` (from database)
## Attachment Helpers
```typescript
import {
attachmentExists,
downloadAttachment,
getAttachmentSize,
isImageAttachment,
isVideoAttachment,
isAudioAttachment
} from '@photon-ai/imessage-kit'
```
## Duration Formats (for Reminders)
- `"30 seconds"`
- `"5 minutes"`
- `"2 hours"`
- `"1 day"`
- `"1 week"`
## Time Formats (for Reminders.at)
- `"5pm"`, `"5:30pm"`
- `"17:30"` (24-hour)
- `"tomorrow 9am"`
- `"friday 2pm"`
## Requirements
- macOS only
- Node.js >= 18 or Bun >= 1.0
- Full Disk Access permission