@elizaos/plugin-imessage 2.0.0-alpha.3 → 2.0.0-alpha.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.
- package/dist/accounts.d.ts +135 -0
- package/dist/accounts.d.ts.map +1 -0
- package/dist/accounts.js +209 -0
- package/dist/accounts.js.map +1 -0
- package/dist/actions/index.d.ts +5 -0
- package/dist/actions/index.d.ts.map +1 -0
- package/{src/actions/index.ts → dist/actions/index.js} +1 -1
- package/dist/actions/index.js.map +1 -0
- package/dist/actions/sendMessage.d.ts +6 -0
- package/dist/actions/sendMessage.d.ts.map +1 -0
- package/dist/actions/sendMessage.js +161 -0
- package/dist/actions/sendMessage.js.map +1 -0
- package/dist/config.d.ts +60 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +8 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -0
- package/dist/providers/chatContext.d.ts +6 -0
- package/dist/providers/chatContext.d.ts.map +1 -0
- package/dist/providers/chatContext.js +59 -0
- package/dist/providers/chatContext.js.map +1 -0
- package/dist/providers/index.d.ts +5 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/{src/providers/index.ts → dist/providers/index.js} +1 -1
- package/dist/providers/index.js.map +1 -0
- package/dist/rpc.d.ts +194 -0
- package/dist/rpc.d.ts.map +1 -0
- package/dist/rpc.js +301 -0
- package/dist/rpc.js.map +1 -0
- package/dist/service.d.ts +71 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +433 -0
- package/dist/service.js.map +1 -0
- package/dist/types.d.ts +163 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +136 -0
- package/dist/types.js.map +1 -0
- package/package.json +18 -3
- package/__tests__/integration.test.ts +0 -548
- package/build.ts +0 -16
- package/src/accounts.ts +0 -379
- package/src/actions/sendMessage.ts +0 -218
- package/src/config.ts +0 -82
- package/src/index.ts +0 -113
- package/src/providers/chatContext.ts +0 -86
- package/src/rpc.ts +0 -485
- package/src/service.ts +0 -589
- package/src/types.ts +0 -291
- package/tsconfig.json +0 -20
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* iMessage service implementation for ElizaOS.
|
|
3
|
+
*/
|
|
4
|
+
import { type IAgentRuntime, Service } from "@elizaos/core";
|
|
5
|
+
import { type IIMessageService, type IMessageChat, type IMessageMessage, type IMessageSendOptions, type IMessageSendResult, type IMessageSettings } from "./types.js";
|
|
6
|
+
/**
|
|
7
|
+
* iMessage service for ElizaOS agents.
|
|
8
|
+
* Note: This only works on macOS.
|
|
9
|
+
*/
|
|
10
|
+
export declare class IMessageService extends Service implements IIMessageService {
|
|
11
|
+
static serviceType: string;
|
|
12
|
+
capabilityDescription: string;
|
|
13
|
+
private settings;
|
|
14
|
+
private connected;
|
|
15
|
+
private pollInterval;
|
|
16
|
+
private lastMessageId;
|
|
17
|
+
/**
|
|
18
|
+
* Start the iMessage service.
|
|
19
|
+
*/
|
|
20
|
+
static start(runtime: IAgentRuntime): Promise<IMessageService>;
|
|
21
|
+
/**
|
|
22
|
+
* Stop the iMessage service.
|
|
23
|
+
*/
|
|
24
|
+
stop(): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Check if the service is connected.
|
|
27
|
+
*/
|
|
28
|
+
isConnected(): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Check if running on macOS.
|
|
31
|
+
*/
|
|
32
|
+
isMacOS(): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Send a message via iMessage.
|
|
35
|
+
*/
|
|
36
|
+
sendMessage(to: string, text: string, options?: IMessageSendOptions): Promise<IMessageSendResult>;
|
|
37
|
+
/**
|
|
38
|
+
* Get recent messages.
|
|
39
|
+
*/
|
|
40
|
+
getRecentMessages(limit?: number): Promise<IMessageMessage[]>;
|
|
41
|
+
/**
|
|
42
|
+
* Get chats.
|
|
43
|
+
*/
|
|
44
|
+
getChats(): Promise<IMessageChat[]>;
|
|
45
|
+
/**
|
|
46
|
+
* Get current settings.
|
|
47
|
+
*/
|
|
48
|
+
getSettings(): IMessageSettings | null;
|
|
49
|
+
private loadSettings;
|
|
50
|
+
private validateSettings;
|
|
51
|
+
private sendSingleMessage;
|
|
52
|
+
private sendViaCli;
|
|
53
|
+
private sendViaAppleScript;
|
|
54
|
+
private runAppleScript;
|
|
55
|
+
private startPolling;
|
|
56
|
+
private pollForNewMessages;
|
|
57
|
+
private isAllowed;
|
|
58
|
+
private parseMessagesResult;
|
|
59
|
+
private parseChatsResult;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Parse tab-delimited AppleScript messages output.
|
|
63
|
+
* Expected format per line: "id\ttext\tdate_sent\tis_from_me\tchat_identifier\tsender"
|
|
64
|
+
*/
|
|
65
|
+
export declare function parseMessagesFromAppleScript(result: string): IMessageMessage[];
|
|
66
|
+
/**
|
|
67
|
+
* Parse tab-delimited AppleScript chats output.
|
|
68
|
+
* Expected format per line: "chat_identifier\tdisplay_name\tparticipant_count\tlast_message_date"
|
|
69
|
+
*/
|
|
70
|
+
export declare function parseChatsFromAppleScript(result: string): IMessageChat[];
|
|
71
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,EAAqB,KAAK,aAAa,EAAU,OAAO,EAAE,MAAM,eAAe,CAAC;AACvF,OAAO,EAGL,KAAK,gBAAgB,EAErB,KAAK,YAAY,EAKjB,KAAK,eAAe,EAEpB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EAGtB,MAAM,YAAY,CAAC;AAIpB;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,OAAQ,YAAW,gBAAgB;IACtE,MAAM,CAAC,WAAW,EAAE,MAAM,CAAyB;IAEnD,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process";
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
import { platform } from "node:os";
|
|
7
|
+
import { promisify } from "node:util";
|
|
8
|
+
import { logger, Service } from "@elizaos/core";
|
|
9
|
+
import { DEFAULT_POLL_INTERVAL_MS, formatPhoneNumber, IMESSAGE_SERVICE_NAME, IMessageCliError, IMessageConfigurationError, IMessageEventTypes, IMessageNotSupportedError, isPhoneNumber, splitMessageForIMessage, } from "./types.js";
|
|
10
|
+
const execAsync = promisify(exec);
|
|
11
|
+
/**
|
|
12
|
+
* iMessage service for ElizaOS agents.
|
|
13
|
+
* Note: This only works on macOS.
|
|
14
|
+
*/
|
|
15
|
+
export class IMessageService extends Service {
|
|
16
|
+
static serviceType = IMESSAGE_SERVICE_NAME;
|
|
17
|
+
capabilityDescription = "iMessage service for sending and receiving messages on macOS";
|
|
18
|
+
settings = null;
|
|
19
|
+
connected = false;
|
|
20
|
+
pollInterval = null;
|
|
21
|
+
lastMessageId = null;
|
|
22
|
+
/**
|
|
23
|
+
* Start the iMessage service.
|
|
24
|
+
*/
|
|
25
|
+
static async start(runtime) {
|
|
26
|
+
logger.info("Starting iMessage service...");
|
|
27
|
+
const service = new IMessageService(runtime);
|
|
28
|
+
// Check if running on macOS
|
|
29
|
+
if (!service.isMacOS()) {
|
|
30
|
+
throw new IMessageNotSupportedError();
|
|
31
|
+
}
|
|
32
|
+
// Load settings
|
|
33
|
+
service.settings = service.loadSettings();
|
|
34
|
+
await service.validateSettings();
|
|
35
|
+
// Start polling for new messages
|
|
36
|
+
if (service.settings.pollIntervalMs > 0) {
|
|
37
|
+
service.startPolling();
|
|
38
|
+
}
|
|
39
|
+
service.connected = true;
|
|
40
|
+
logger.info("iMessage service started");
|
|
41
|
+
// Emit connection ready event
|
|
42
|
+
runtime.emitEvent(IMessageEventTypes.CONNECTION_READY, {
|
|
43
|
+
runtime,
|
|
44
|
+
service,
|
|
45
|
+
});
|
|
46
|
+
return service;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Stop the iMessage service.
|
|
50
|
+
*/
|
|
51
|
+
async stop() {
|
|
52
|
+
logger.info("Stopping iMessage service...");
|
|
53
|
+
this.connected = false;
|
|
54
|
+
if (this.pollInterval) {
|
|
55
|
+
clearInterval(this.pollInterval);
|
|
56
|
+
this.pollInterval = null;
|
|
57
|
+
}
|
|
58
|
+
this.settings = null;
|
|
59
|
+
this.lastMessageId = null;
|
|
60
|
+
logger.info("iMessage service stopped");
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Check if the service is connected.
|
|
64
|
+
*/
|
|
65
|
+
isConnected() {
|
|
66
|
+
return this.connected;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Check if running on macOS.
|
|
70
|
+
*/
|
|
71
|
+
isMacOS() {
|
|
72
|
+
return platform() === "darwin";
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Send a message via iMessage.
|
|
76
|
+
*/
|
|
77
|
+
async sendMessage(to, text, options) {
|
|
78
|
+
if (!this.settings) {
|
|
79
|
+
return { success: false, error: "Service not initialized" };
|
|
80
|
+
}
|
|
81
|
+
// Format phone number if needed
|
|
82
|
+
const target = isPhoneNumber(to) ? formatPhoneNumber(to) : to;
|
|
83
|
+
// Split message if too long
|
|
84
|
+
const chunks = splitMessageForIMessage(text);
|
|
85
|
+
for (const chunk of chunks) {
|
|
86
|
+
const result = await this.sendSingleMessage(target, chunk, options);
|
|
87
|
+
if (!result.success) {
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// Emit sent event
|
|
92
|
+
if (this.runtime) {
|
|
93
|
+
this.runtime.emitEvent(IMessageEventTypes.MESSAGE_SENT, {
|
|
94
|
+
runtime: this.runtime,
|
|
95
|
+
to: target,
|
|
96
|
+
text,
|
|
97
|
+
hasMedia: Boolean(options?.mediaUrl),
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
success: true,
|
|
102
|
+
messageId: Date.now().toString(),
|
|
103
|
+
chatId: target,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Get recent messages.
|
|
108
|
+
*/
|
|
109
|
+
async getRecentMessages(limit = 50) {
|
|
110
|
+
if (!this.settings) {
|
|
111
|
+
return [];
|
|
112
|
+
}
|
|
113
|
+
// Use CLI or AppleScript to get recent messages
|
|
114
|
+
const script = `
|
|
115
|
+
tell application "Messages"
|
|
116
|
+
set AppleScript's text item delimiters to tab
|
|
117
|
+
set outputLines to {}
|
|
118
|
+
repeat with i from 1 to ${limit}
|
|
119
|
+
try
|
|
120
|
+
set msg to item i of (get messages)
|
|
121
|
+
set msgLine to (id of msg) & tab & (text of msg) & tab & ((date of msg) as string) & tab & (is_from_me of msg as string) & tab & (chat_identifier of msg as string) & tab & (handle of sender of msg)
|
|
122
|
+
set end of outputLines to msgLine
|
|
123
|
+
end try
|
|
124
|
+
end repeat
|
|
125
|
+
set AppleScript's text item delimiters to linefeed
|
|
126
|
+
set outputText to outputLines as string
|
|
127
|
+
set AppleScript's text item delimiters to ""
|
|
128
|
+
return outputText
|
|
129
|
+
end tell
|
|
130
|
+
`;
|
|
131
|
+
try {
|
|
132
|
+
const result = await this.runAppleScript(script);
|
|
133
|
+
// Parse result and return messages
|
|
134
|
+
return this.parseMessagesResult(result);
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
logger.warn(`Failed to get recent messages: ${error}`);
|
|
138
|
+
return [];
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Get chats.
|
|
143
|
+
*/
|
|
144
|
+
async getChats() {
|
|
145
|
+
if (!this.settings) {
|
|
146
|
+
return [];
|
|
147
|
+
}
|
|
148
|
+
const script = `
|
|
149
|
+
tell application "Messages"
|
|
150
|
+
set chatList to {}
|
|
151
|
+
repeat with c in chats
|
|
152
|
+
set chatId to id of c
|
|
153
|
+
set chatName to name of c
|
|
154
|
+
set end of chatList to {chatId, chatName}
|
|
155
|
+
end repeat
|
|
156
|
+
return chatList
|
|
157
|
+
end tell
|
|
158
|
+
`;
|
|
159
|
+
try {
|
|
160
|
+
const result = await this.runAppleScript(script);
|
|
161
|
+
return this.parseChatsResult(result);
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
logger.warn(`Failed to get chats: ${error}`);
|
|
165
|
+
return [];
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Get current settings.
|
|
170
|
+
*/
|
|
171
|
+
getSettings() {
|
|
172
|
+
return this.settings;
|
|
173
|
+
}
|
|
174
|
+
// Private methods
|
|
175
|
+
loadSettings() {
|
|
176
|
+
if (!this.runtime) {
|
|
177
|
+
throw new IMessageConfigurationError("Runtime not initialized");
|
|
178
|
+
}
|
|
179
|
+
const getStringSetting = (key, envKey, defaultValue = "") => {
|
|
180
|
+
const value = this.runtime?.getSetting(key);
|
|
181
|
+
if (typeof value === "string")
|
|
182
|
+
return value;
|
|
183
|
+
return process.env[envKey] || defaultValue;
|
|
184
|
+
};
|
|
185
|
+
const cliPath = getStringSetting("IMESSAGE_CLI_PATH", "IMESSAGE_CLI_PATH", "imsg");
|
|
186
|
+
const dbPath = getStringSetting("IMESSAGE_DB_PATH", "IMESSAGE_DB_PATH") || undefined;
|
|
187
|
+
const pollIntervalMs = Number(getStringSetting("IMESSAGE_POLL_INTERVAL_MS", "IMESSAGE_POLL_INTERVAL_MS")) ||
|
|
188
|
+
DEFAULT_POLL_INTERVAL_MS;
|
|
189
|
+
const dmPolicy = getStringSetting("IMESSAGE_DM_POLICY", "IMESSAGE_DM_POLICY", "pairing");
|
|
190
|
+
const groupPolicy = getStringSetting("IMESSAGE_GROUP_POLICY", "IMESSAGE_GROUP_POLICY", "allowlist");
|
|
191
|
+
const allowFromRaw = getStringSetting("IMESSAGE_ALLOW_FROM", "IMESSAGE_ALLOW_FROM");
|
|
192
|
+
const allowFrom = allowFromRaw
|
|
193
|
+
? allowFromRaw
|
|
194
|
+
.split(",")
|
|
195
|
+
.map((s) => s.trim())
|
|
196
|
+
.filter(Boolean)
|
|
197
|
+
: [];
|
|
198
|
+
const enabledRaw = getStringSetting("IMESSAGE_ENABLED", "IMESSAGE_ENABLED", "true");
|
|
199
|
+
const enabled = enabledRaw !== "false";
|
|
200
|
+
return {
|
|
201
|
+
cliPath,
|
|
202
|
+
dbPath,
|
|
203
|
+
pollIntervalMs,
|
|
204
|
+
dmPolicy,
|
|
205
|
+
groupPolicy,
|
|
206
|
+
allowFrom,
|
|
207
|
+
enabled,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
async validateSettings() {
|
|
211
|
+
if (!this.settings) {
|
|
212
|
+
throw new IMessageConfigurationError("Settings not loaded");
|
|
213
|
+
}
|
|
214
|
+
// Check if CLI tool exists (if specified and not default)
|
|
215
|
+
if (this.settings.cliPath !== "imsg") {
|
|
216
|
+
if (!existsSync(this.settings.cliPath)) {
|
|
217
|
+
logger.warn(`iMessage CLI not found at ${this.settings.cliPath}, will use AppleScript`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
// Check if Messages app is accessible
|
|
221
|
+
try {
|
|
222
|
+
await this.runAppleScript('tell application "Messages" to return 1');
|
|
223
|
+
}
|
|
224
|
+
catch (_error) {
|
|
225
|
+
throw new IMessageConfigurationError("Cannot access Messages app. Ensure Full Disk Access is granted.");
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
async sendSingleMessage(to, text, options) {
|
|
229
|
+
// Try CLI first if available
|
|
230
|
+
if (this.settings?.cliPath && this.settings.cliPath !== "imsg") {
|
|
231
|
+
try {
|
|
232
|
+
return await this.sendViaCli(to, text, options);
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
logger.debug(`CLI send failed, falling back to AppleScript: ${error}`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
// Fall back to AppleScript
|
|
239
|
+
return await this.sendViaAppleScript(to, text, options);
|
|
240
|
+
}
|
|
241
|
+
async sendViaCli(to, text, options) {
|
|
242
|
+
if (!this.settings) {
|
|
243
|
+
return { success: false, error: "Service not initialized" };
|
|
244
|
+
}
|
|
245
|
+
const args = [to, text];
|
|
246
|
+
if (options?.mediaUrl) {
|
|
247
|
+
args.push("--attachment", options.mediaUrl);
|
|
248
|
+
}
|
|
249
|
+
try {
|
|
250
|
+
await execAsync(`"${this.settings.cliPath}" ${args.map((a) => `"${a}"`).join(" ")}`);
|
|
251
|
+
return { success: true, messageId: Date.now().toString(), chatId: to };
|
|
252
|
+
}
|
|
253
|
+
catch (error) {
|
|
254
|
+
const err = error;
|
|
255
|
+
throw new IMessageCliError(err.message || "CLI command failed", err.code);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
async sendViaAppleScript(to, text, _options) {
|
|
259
|
+
// Escape text for AppleScript
|
|
260
|
+
const escapedText = text.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
261
|
+
let script;
|
|
262
|
+
if (to.startsWith("chat_id:")) {
|
|
263
|
+
// Send to existing chat
|
|
264
|
+
const chatId = to.slice(8);
|
|
265
|
+
script = `
|
|
266
|
+
tell application "Messages"
|
|
267
|
+
set targetChat to chat id "${chatId}"
|
|
268
|
+
send "${escapedText}" to targetChat
|
|
269
|
+
end tell
|
|
270
|
+
`;
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
// Send to buddy (phone/email)
|
|
274
|
+
script = `
|
|
275
|
+
tell application "Messages"
|
|
276
|
+
set targetService to 1st account whose service type = iMessage
|
|
277
|
+
set targetBuddy to participant "${to}" of targetService
|
|
278
|
+
send "${escapedText}" to targetBuddy
|
|
279
|
+
end tell
|
|
280
|
+
`;
|
|
281
|
+
}
|
|
282
|
+
try {
|
|
283
|
+
await this.runAppleScript(script);
|
|
284
|
+
return { success: true, messageId: Date.now().toString(), chatId: to };
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
return { success: false, error: `AppleScript error: ${error}` };
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
async runAppleScript(script) {
|
|
291
|
+
try {
|
|
292
|
+
const { stdout } = await execAsync(`osascript -e '${script.replace(/'/g, "'\"'\"'")}'`);
|
|
293
|
+
return stdout.trim();
|
|
294
|
+
}
|
|
295
|
+
catch (error) {
|
|
296
|
+
const err = error;
|
|
297
|
+
throw new Error(err.stderr || err.message || "AppleScript execution failed");
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
startPolling() {
|
|
301
|
+
if (!this.settings) {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
this.pollInterval = setInterval(async () => {
|
|
305
|
+
try {
|
|
306
|
+
await this.pollForNewMessages();
|
|
307
|
+
}
|
|
308
|
+
catch (error) {
|
|
309
|
+
logger.debug(`Polling error: ${error}`);
|
|
310
|
+
}
|
|
311
|
+
}, this.settings.pollIntervalMs);
|
|
312
|
+
}
|
|
313
|
+
async pollForNewMessages() {
|
|
314
|
+
if (!this.runtime) {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
const messages = await this.getRecentMessages(10);
|
|
318
|
+
for (const msg of messages) {
|
|
319
|
+
// Skip if we've already seen this message
|
|
320
|
+
if (this.lastMessageId && msg.id <= this.lastMessageId) {
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
// Skip messages from self
|
|
324
|
+
if (msg.isFromMe) {
|
|
325
|
+
continue;
|
|
326
|
+
}
|
|
327
|
+
// Check DM policy
|
|
328
|
+
if (!this.isAllowed(msg.handle)) {
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
// Emit message received event
|
|
332
|
+
this.runtime.emitEvent(IMessageEventTypes.MESSAGE_RECEIVED, {
|
|
333
|
+
runtime: this.runtime,
|
|
334
|
+
message: msg,
|
|
335
|
+
});
|
|
336
|
+
this.lastMessageId = msg.id;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
isAllowed(handle) {
|
|
340
|
+
if (!this.settings) {
|
|
341
|
+
return false;
|
|
342
|
+
}
|
|
343
|
+
if (this.settings.dmPolicy === "open") {
|
|
344
|
+
return true;
|
|
345
|
+
}
|
|
346
|
+
if (this.settings.dmPolicy === "disabled") {
|
|
347
|
+
return false;
|
|
348
|
+
}
|
|
349
|
+
if (this.settings.dmPolicy === "allowlist") {
|
|
350
|
+
return this.settings.allowFrom.some((allowed) => allowed.toLowerCase() === handle.toLowerCase());
|
|
351
|
+
}
|
|
352
|
+
// pairing - allow and track
|
|
353
|
+
return true;
|
|
354
|
+
}
|
|
355
|
+
parseMessagesResult(result) {
|
|
356
|
+
return parseMessagesFromAppleScript(result);
|
|
357
|
+
}
|
|
358
|
+
parseChatsResult(result) {
|
|
359
|
+
return parseChatsFromAppleScript(result);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Parse tab-delimited AppleScript messages output.
|
|
364
|
+
* Expected format per line: "id\ttext\tdate_sent\tis_from_me\tchat_identifier\tsender"
|
|
365
|
+
*/
|
|
366
|
+
export function parseMessagesFromAppleScript(result) {
|
|
367
|
+
const messages = [];
|
|
368
|
+
if (!result || !result.trim()) {
|
|
369
|
+
return messages;
|
|
370
|
+
}
|
|
371
|
+
for (const line of result.split("\n")) {
|
|
372
|
+
const trimmed = line.trim();
|
|
373
|
+
if (!trimmed) {
|
|
374
|
+
continue;
|
|
375
|
+
}
|
|
376
|
+
const fields = trimmed.split("\t");
|
|
377
|
+
if (fields.length < 6) {
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
const [id, text, dateSent, isFromMeStr, chatIdentifier, sender] = fields;
|
|
381
|
+
const isFromMe = isFromMeStr === "1" || isFromMeStr.toLowerCase() === "true";
|
|
382
|
+
let timestamp;
|
|
383
|
+
const parsed = Number(dateSent);
|
|
384
|
+
if (!Number.isNaN(parsed) && parsed > 0) {
|
|
385
|
+
timestamp = parsed;
|
|
386
|
+
}
|
|
387
|
+
else {
|
|
388
|
+
const dateObj = new Date(dateSent);
|
|
389
|
+
timestamp = Number.isNaN(dateObj.getTime()) ? 0 : dateObj.getTime();
|
|
390
|
+
}
|
|
391
|
+
messages.push({
|
|
392
|
+
id: id || "",
|
|
393
|
+
text: text || "",
|
|
394
|
+
handle: sender || "",
|
|
395
|
+
chatId: chatIdentifier || "",
|
|
396
|
+
timestamp,
|
|
397
|
+
isFromMe,
|
|
398
|
+
hasAttachments: false,
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
return messages;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Parse tab-delimited AppleScript chats output.
|
|
405
|
+
* Expected format per line: "chat_identifier\tdisplay_name\tparticipant_count\tlast_message_date"
|
|
406
|
+
*/
|
|
407
|
+
export function parseChatsFromAppleScript(result) {
|
|
408
|
+
const chats = [];
|
|
409
|
+
if (!result || !result.trim()) {
|
|
410
|
+
return chats;
|
|
411
|
+
}
|
|
412
|
+
for (const line of result.split("\n")) {
|
|
413
|
+
const trimmed = line.trim();
|
|
414
|
+
if (!trimmed) {
|
|
415
|
+
continue;
|
|
416
|
+
}
|
|
417
|
+
const fields = trimmed.split("\t");
|
|
418
|
+
if (fields.length < 4) {
|
|
419
|
+
continue;
|
|
420
|
+
}
|
|
421
|
+
const [chatIdentifier, displayName, participantCountStr] = fields;
|
|
422
|
+
const participantCount = Number(participantCountStr) || 0;
|
|
423
|
+
const chatType = participantCount > 1 ? "group" : "direct";
|
|
424
|
+
chats.push({
|
|
425
|
+
chatId: chatIdentifier || "",
|
|
426
|
+
chatType,
|
|
427
|
+
displayName: displayName || undefined,
|
|
428
|
+
participants: [],
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
return chats;
|
|
432
|
+
}
|
|
433
|
+
//# sourceMappingURL=service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,IAA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 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for the iMessage plugin.
|
|
3
|
+
*/
|
|
4
|
+
import type { Service } from "@elizaos/core";
|
|
5
|
+
/** Maximum message length for iMessage */
|
|
6
|
+
export declare const MAX_IMESSAGE_MESSAGE_LENGTH = 4000;
|
|
7
|
+
/** Default poll interval in ms */
|
|
8
|
+
export declare const DEFAULT_POLL_INTERVAL_MS = 5000;
|
|
9
|
+
/** iMessage service name constant */
|
|
10
|
+
export declare const IMESSAGE_SERVICE_NAME = "imessage";
|
|
11
|
+
/**
|
|
12
|
+
* Event types emitted by the iMessage plugin
|
|
13
|
+
*/
|
|
14
|
+
export declare const IMessageEventTypes: {
|
|
15
|
+
readonly MESSAGE_RECEIVED: "IMESSAGE_MESSAGE_RECEIVED";
|
|
16
|
+
readonly MESSAGE_SENT: "IMESSAGE_MESSAGE_SENT";
|
|
17
|
+
readonly CONNECTION_READY: "IMESSAGE_CONNECTION_READY";
|
|
18
|
+
readonly ERROR: "IMESSAGE_ERROR";
|
|
19
|
+
};
|
|
20
|
+
export type IMessageEventType = (typeof IMessageEventTypes)[keyof typeof IMessageEventTypes];
|
|
21
|
+
/**
|
|
22
|
+
* iMessage chat types
|
|
23
|
+
*/
|
|
24
|
+
export type IMessageChatType = "direct" | "group";
|
|
25
|
+
/**
|
|
26
|
+
* Configuration settings for the iMessage plugin
|
|
27
|
+
*/
|
|
28
|
+
export interface IMessageSettings {
|
|
29
|
+
/** Path to iMessage CLI tool */
|
|
30
|
+
cliPath: string;
|
|
31
|
+
/** Path to iMessage database */
|
|
32
|
+
dbPath?: string;
|
|
33
|
+
/** Polling interval in ms */
|
|
34
|
+
pollIntervalMs: number;
|
|
35
|
+
/** DM policy */
|
|
36
|
+
dmPolicy: "open" | "pairing" | "allowlist" | "disabled";
|
|
37
|
+
/** Group policy */
|
|
38
|
+
groupPolicy: "open" | "allowlist" | "disabled";
|
|
39
|
+
/** Handles/phone numbers for allowlist */
|
|
40
|
+
allowFrom: string[];
|
|
41
|
+
/** Enable/disable the plugin */
|
|
42
|
+
enabled: boolean;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* iMessage contact
|
|
46
|
+
*/
|
|
47
|
+
export interface IMessageContact {
|
|
48
|
+
/** Handle (phone number or email) */
|
|
49
|
+
handle: string;
|
|
50
|
+
/** Display name */
|
|
51
|
+
displayName?: string;
|
|
52
|
+
/** Is this a phone number? */
|
|
53
|
+
isPhoneNumber: boolean;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* iMessage chat
|
|
57
|
+
*/
|
|
58
|
+
export interface IMessageChat {
|
|
59
|
+
/** Chat ID */
|
|
60
|
+
chatId: string;
|
|
61
|
+
/** Chat type */
|
|
62
|
+
chatType: IMessageChatType;
|
|
63
|
+
/** Display name */
|
|
64
|
+
displayName?: string;
|
|
65
|
+
/** Participants */
|
|
66
|
+
participants: IMessageContact[];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* iMessage message
|
|
70
|
+
*/
|
|
71
|
+
export interface IMessageMessage {
|
|
72
|
+
/** Message ID (ROWID) */
|
|
73
|
+
id: string;
|
|
74
|
+
/** Message text */
|
|
75
|
+
text: string;
|
|
76
|
+
/** Sender handle */
|
|
77
|
+
handle: string;
|
|
78
|
+
/** Chat ID */
|
|
79
|
+
chatId: string;
|
|
80
|
+
/** Timestamp */
|
|
81
|
+
timestamp: number;
|
|
82
|
+
/** Is from me */
|
|
83
|
+
isFromMe: boolean;
|
|
84
|
+
/** Has attachments */
|
|
85
|
+
hasAttachments: boolean;
|
|
86
|
+
/** Attachment paths */
|
|
87
|
+
attachmentPaths?: string[];
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Options for sending a message
|
|
91
|
+
*/
|
|
92
|
+
export interface IMessageSendOptions {
|
|
93
|
+
/** Media URL or path to attach */
|
|
94
|
+
mediaUrl?: string;
|
|
95
|
+
/** Max bytes for media */
|
|
96
|
+
maxBytes?: number;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Result from sending a message
|
|
100
|
+
*/
|
|
101
|
+
export interface IMessageSendResult {
|
|
102
|
+
success: boolean;
|
|
103
|
+
messageId?: string;
|
|
104
|
+
chatId?: string;
|
|
105
|
+
error?: string;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Service interface for iMessage
|
|
109
|
+
*/
|
|
110
|
+
export interface IIMessageService extends Service {
|
|
111
|
+
/** Check if the service is connected */
|
|
112
|
+
isConnected(): boolean;
|
|
113
|
+
/** Check if running on macOS */
|
|
114
|
+
isMacOS(): boolean;
|
|
115
|
+
/** Send a message */
|
|
116
|
+
sendMessage(to: string, text: string, options?: IMessageSendOptions): Promise<IMessageSendResult>;
|
|
117
|
+
/** Get recent messages */
|
|
118
|
+
getRecentMessages(limit?: number): Promise<IMessageMessage[]>;
|
|
119
|
+
/** Get chats */
|
|
120
|
+
getChats(): Promise<IMessageChat[]>;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* iMessage plugin errors
|
|
124
|
+
*/
|
|
125
|
+
export declare class IMessagePluginError extends Error {
|
|
126
|
+
readonly code: string;
|
|
127
|
+
readonly details?: Record<string, unknown> | undefined;
|
|
128
|
+
constructor(message: string, code: string, details?: Record<string, unknown> | undefined);
|
|
129
|
+
}
|
|
130
|
+
export declare class IMessageConfigurationError extends IMessagePluginError {
|
|
131
|
+
constructor(message: string, setting?: string);
|
|
132
|
+
}
|
|
133
|
+
export declare class IMessageNotSupportedError extends IMessagePluginError {
|
|
134
|
+
constructor(message?: string);
|
|
135
|
+
}
|
|
136
|
+
export declare class IMessageCliError extends IMessagePluginError {
|
|
137
|
+
constructor(message: string, exitCode?: number);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Check if a string looks like a phone number
|
|
141
|
+
*/
|
|
142
|
+
export declare function isPhoneNumber(input: string): boolean;
|
|
143
|
+
/**
|
|
144
|
+
* Check if a string looks like an email
|
|
145
|
+
*/
|
|
146
|
+
export declare function isEmail(input: string): boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Check if a string is a valid iMessage target (phone or email)
|
|
149
|
+
*/
|
|
150
|
+
export declare function isValidIMessageTarget(target: string): boolean;
|
|
151
|
+
/**
|
|
152
|
+
* Normalize an iMessage target
|
|
153
|
+
*/
|
|
154
|
+
export declare function normalizeIMessageTarget(target: string): string | null;
|
|
155
|
+
/**
|
|
156
|
+
* Format a phone number for iMessage
|
|
157
|
+
*/
|
|
158
|
+
export declare function formatPhoneNumber(phone: string): string;
|
|
159
|
+
/**
|
|
160
|
+
* Split text for iMessage
|
|
161
|
+
*/
|
|
162
|
+
export declare function splitMessageForIMessage(text: string, maxLength?: number): string[];
|
|
163
|
+
//# sourceMappingURL=types.d.ts.map
|