@elizaos/plugin-bluebubbles 2.0.0-alpha.3

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.
@@ -0,0 +1,260 @@
1
+ import { describe, expect, it, vi } from "vitest";
2
+
3
+ import blueBubblesPlugin, {
4
+ BLUEBUBBLES_SERVICE_NAME,
5
+ BlueBubblesService,
6
+ chatContextProvider,
7
+ sendMessageAction,
8
+ sendReactionAction,
9
+ } from "../src/index";
10
+
11
+ import {
12
+ normalizeHandle,
13
+ isHandleAllowed,
14
+ validateConfig,
15
+ } from "../src/environment";
16
+
17
+ import {
18
+ DEFAULT_WEBHOOK_PATH,
19
+ API_ENDPOINTS,
20
+ DM_POLICY_OPEN,
21
+ DM_POLICY_DISABLED,
22
+ DM_POLICY_PAIRING,
23
+ DM_POLICY_ALLOWLIST,
24
+ GROUP_POLICY_OPEN,
25
+ GROUP_POLICY_ALLOWLIST,
26
+ GROUP_POLICY_DISABLED,
27
+ } from "../src/constants";
28
+
29
+ // ----------------------------------------------------------------
30
+ // Plugin exports
31
+ // ----------------------------------------------------------------
32
+
33
+ describe("BlueBubbles plugin exports", () => {
34
+ it("exports plugin metadata", () => {
35
+ expect(blueBubblesPlugin.name).toBe(BLUEBUBBLES_SERVICE_NAME);
36
+ expect(blueBubblesPlugin.description).toContain("BlueBubbles");
37
+ expect(Array.isArray(blueBubblesPlugin.actions)).toBe(true);
38
+ expect(Array.isArray(blueBubblesPlugin.providers)).toBe(true);
39
+ expect(Array.isArray(blueBubblesPlugin.services)).toBe(true);
40
+ });
41
+
42
+ it("exports actions, providers, and service", () => {
43
+ expect(sendMessageAction).toBeDefined();
44
+ expect(sendReactionAction).toBeDefined();
45
+ expect(chatContextProvider).toBeDefined();
46
+ expect(BlueBubblesService).toBeDefined();
47
+ });
48
+
49
+ it("registers exactly 2 actions", () => {
50
+ expect(blueBubblesPlugin.actions).toHaveLength(2);
51
+ });
52
+
53
+ it("registers exactly 1 provider", () => {
54
+ expect(blueBubblesPlugin.providers).toHaveLength(1);
55
+ });
56
+ });
57
+
58
+ // ----------------------------------------------------------------
59
+ // normalizeHandle
60
+ // ----------------------------------------------------------------
61
+
62
+ describe("normalizeHandle", () => {
63
+ it("normalizes a formatted US phone number", () => {
64
+ expect(normalizeHandle("+1 (555) 123-4567")).toBe("+15551234567");
65
+ });
66
+
67
+ it("normalizes a phone number without plus prefix", () => {
68
+ expect(normalizeHandle("555-123-4567")).toBe("+5551234567");
69
+ });
70
+
71
+ it("normalizes an international phone number", () => {
72
+ expect(normalizeHandle("+44 7700 900000")).toBe("+447700900000");
73
+ });
74
+
75
+ it("lowercases an email address", () => {
76
+ expect(normalizeHandle("User@Example.COM")).toBe("user@example.com");
77
+ });
78
+
79
+ it("trims whitespace from an email", () => {
80
+ expect(normalizeHandle(" test@test.com ")).toBe("test@test.com");
81
+ });
82
+
83
+ it("handles short digit strings without adding plus", () => {
84
+ expect(normalizeHandle("12345")).toBe("12345");
85
+ });
86
+
87
+ it("handles a phone number with dots", () => {
88
+ expect(normalizeHandle("+1.555.123.4567")).toBe("+15551234567");
89
+ });
90
+ });
91
+
92
+ // ----------------------------------------------------------------
93
+ // isHandleAllowed
94
+ // ----------------------------------------------------------------
95
+
96
+ describe("isHandleAllowed", () => {
97
+ it("open policy allows any handle", () => {
98
+ expect(isHandleAllowed("anyone@example.com", [], DM_POLICY_OPEN)).toBe(true);
99
+ });
100
+
101
+ it("disabled policy denies all handles", () => {
102
+ expect(isHandleAllowed("anyone@example.com", [], DM_POLICY_DISABLED)).toBe(false);
103
+ });
104
+
105
+ it("pairing with empty allowlist allows first contact", () => {
106
+ expect(isHandleAllowed("first@contact.com", [], DM_POLICY_PAIRING)).toBe(true);
107
+ });
108
+
109
+ it("pairing with non-empty allowlist only allows listed handles", () => {
110
+ expect(isHandleAllowed("+15551234567", ["+15551234567"], DM_POLICY_PAIRING)).toBe(true);
111
+ expect(isHandleAllowed("+15559999999", ["+15551234567"], DM_POLICY_PAIRING)).toBe(false);
112
+ });
113
+
114
+ it("allowlist matches normalized handles", () => {
115
+ const allowList = ["+15551234567"];
116
+ expect(isHandleAllowed("+1 (555) 123-4567", allowList, DM_POLICY_ALLOWLIST)).toBe(true);
117
+ });
118
+
119
+ it("allowlist rejects non-matching handles", () => {
120
+ const allowList = ["+15551234567"];
121
+ expect(isHandleAllowed("+15559876543", allowList, DM_POLICY_ALLOWLIST)).toBe(false);
122
+ });
123
+
124
+ it("group open policy allows all", () => {
125
+ expect(isHandleAllowed("anyone", [], GROUP_POLICY_OPEN)).toBe(true);
126
+ });
127
+
128
+ it("group disabled policy denies all", () => {
129
+ expect(isHandleAllowed("anyone", [], GROUP_POLICY_DISABLED)).toBe(false);
130
+ });
131
+
132
+ it("group allowlist matches normalized handles", () => {
133
+ expect(isHandleAllowed("+1 555 123 4567", ["+15551234567"], GROUP_POLICY_ALLOWLIST)).toBe(true);
134
+ });
135
+ });
136
+
137
+ // ----------------------------------------------------------------
138
+ // validateConfig
139
+ // ----------------------------------------------------------------
140
+
141
+ describe("validateConfig", () => {
142
+ it("accepts a valid config", () => {
143
+ const config = validateConfig({
144
+ serverUrl: "http://localhost:1234",
145
+ password: "secret",
146
+ });
147
+ expect(config.serverUrl).toBe("http://localhost:1234");
148
+ expect(config.password).toBe("secret");
149
+ expect(config.webhookPath).toBe(DEFAULT_WEBHOOK_PATH);
150
+ expect(config.dmPolicy).toBe("pairing");
151
+ expect(config.groupPolicy).toBe("allowlist");
152
+ expect(config.sendReadReceipts).toBe(true);
153
+ expect(config.enabled).toBe(true);
154
+ });
155
+
156
+ it("rejects missing server URL", () => {
157
+ expect(() =>
158
+ validateConfig({ serverUrl: "", password: "secret" })
159
+ ).toThrow();
160
+ });
161
+
162
+ it("rejects missing password", () => {
163
+ expect(() =>
164
+ validateConfig({ serverUrl: "http://localhost:1234", password: "" })
165
+ ).toThrow();
166
+ });
167
+
168
+ it("rejects an invalid URL", () => {
169
+ expect(() =>
170
+ validateConfig({ serverUrl: "not-a-url", password: "secret" })
171
+ ).toThrow();
172
+ });
173
+
174
+ it("preserves custom webhook path", () => {
175
+ const config = validateConfig({
176
+ serverUrl: "http://localhost:1234",
177
+ password: "secret",
178
+ webhookPath: "/custom/webhook",
179
+ });
180
+ expect(config.webhookPath).toBe("/custom/webhook");
181
+ });
182
+ });
183
+
184
+ // ----------------------------------------------------------------
185
+ // Action definitions
186
+ // ----------------------------------------------------------------
187
+
188
+ describe("sendMessageAction", () => {
189
+ it("has the correct name", () => {
190
+ expect(sendMessageAction.name).toBe("SEND_BLUEBUBBLES_MESSAGE");
191
+ });
192
+
193
+ it("has a non-empty description", () => {
194
+ expect(sendMessageAction.description).toBeTruthy();
195
+ expect(sendMessageAction.description!.length).toBeGreaterThan(10);
196
+ });
197
+
198
+ it("has similes", () => {
199
+ expect(Array.isArray(sendMessageAction.similes)).toBe(true);
200
+ expect(sendMessageAction.similes!.length).toBeGreaterThan(0);
201
+ });
202
+
203
+ it("has at least one example", () => {
204
+ expect(Array.isArray(sendMessageAction.examples)).toBe(true);
205
+ expect(sendMessageAction.examples!.length).toBeGreaterThan(0);
206
+ });
207
+
208
+ it("validate rejects when service is missing", async () => {
209
+ const mockRuntime = {
210
+ getService: vi.fn().mockReturnValue(null),
211
+ } as any;
212
+ const mockMessage = { content: { source: "bluebubbles" } } as any;
213
+ const result = await sendMessageAction.validate!(mockRuntime, mockMessage);
214
+ expect(result).toBe(false);
215
+ });
216
+ });
217
+
218
+ describe("sendReactionAction", () => {
219
+ it("has the correct name", () => {
220
+ expect(sendReactionAction.name).toBe("BLUEBUBBLES_SEND_REACTION");
221
+ });
222
+
223
+ it("has a non-empty description", () => {
224
+ expect(sendReactionAction.description).toBeTruthy();
225
+ });
226
+
227
+ it("has similes including BLUEBUBBLES_REACT", () => {
228
+ expect(sendReactionAction.similes).toContain("BLUEBUBBLES_REACT");
229
+ });
230
+
231
+ it("validate rejects non-bluebubbles sources", async () => {
232
+ const mockRuntime = {} as any;
233
+ const mockMessage = { content: { source: "discord" } } as any;
234
+ const result = await sendReactionAction.validate!(mockRuntime, mockMessage);
235
+ expect(result).toBe(false);
236
+ });
237
+
238
+ it("validate accepts bluebubbles source", async () => {
239
+ const mockRuntime = {} as any;
240
+ const mockMessage = { content: { source: "bluebubbles" } } as any;
241
+ const result = await sendReactionAction.validate!(mockRuntime, mockMessage);
242
+ expect(result).toBe(true);
243
+ });
244
+ });
245
+
246
+ // ----------------------------------------------------------------
247
+ // Constants
248
+ // ----------------------------------------------------------------
249
+
250
+ describe("constants", () => {
251
+ it("has expected API endpoints", () => {
252
+ expect(API_ENDPOINTS.SEND_MESSAGE).toBeDefined();
253
+ expect(API_ENDPOINTS.REACT).toBeDefined();
254
+ expect(API_ENDPOINTS.SERVER_INFO).toBeDefined();
255
+ });
256
+
257
+ it("service name is bluebubbles", () => {
258
+ expect(BLUEBUBBLES_SERVICE_NAME).toBe("bluebubbles");
259
+ });
260
+ });
package/build.ts ADDED
@@ -0,0 +1,16 @@
1
+ import { execSync } from "node:child_process";
2
+ import { rmSync } from "node:fs";
3
+ import { join } from "node:path";
4
+
5
+ const distDir = join(import.meta.dirname, "dist");
6
+
7
+ // Clean
8
+ rmSync(distDir, { recursive: true, force: true });
9
+
10
+ // Build
11
+ execSync("npx tsc -p tsconfig.json", {
12
+ cwd: import.meta.dirname,
13
+ stdio: "inherit",
14
+ });
15
+
16
+ console.log("Build complete: plugin-bluebubbles");
package/dist/index.js ADDED
@@ -0,0 +1,46 @@
1
+ /**
2
+ * BlueBubbles Plugin for ElizaOS
3
+ *
4
+ * Provides iMessage integration via the BlueBubbles macOS app and REST API,
5
+ * supporting text messages, reactions, effects, and more.
6
+ */
7
+ import { logger } from "@elizaos/core";
8
+ import { sendMessageAction, sendReactionAction } from "./actions/index.js";
9
+ import { chatContextProvider } from "./providers/index.js";
10
+ import { BlueBubblesService } from "./service.js";
11
+ export * from "./constants.js";
12
+ // Re-export types and service
13
+ export * from "./types.js";
14
+ export { BlueBubblesService };
15
+ export { sendMessageAction, sendReactionAction };
16
+ export { chatContextProvider };
17
+ /**
18
+ * BlueBubbles plugin for ElizaOS agents.
19
+ */
20
+ const blueBubblesPlugin = {
21
+ name: "bluebubbles",
22
+ description: "BlueBubbles iMessage bridge plugin for ElizaOS agents",
23
+ services: [BlueBubblesService],
24
+ actions: [sendMessageAction, sendReactionAction],
25
+ providers: [chatContextProvider],
26
+ tests: [],
27
+ init: async (config, _runtime) => {
28
+ logger.info("Initializing BlueBubbles plugin...");
29
+ const hasServerUrl = Boolean(config.BLUEBUBBLES_SERVER_URL || process.env.BLUEBUBBLES_SERVER_URL);
30
+ const hasPassword = Boolean(config.BLUEBUBBLES_PASSWORD || process.env.BLUEBUBBLES_PASSWORD);
31
+ logger.info("BlueBubbles plugin configuration:");
32
+ logger.info(` - Server URL configured: ${hasServerUrl ? "Yes" : "No"}`);
33
+ logger.info(` - Password configured: ${hasPassword ? "Yes" : "No"}`);
34
+ logger.info(` - DM policy: ${config.BLUEBUBBLES_DM_POLICY || process.env.BLUEBUBBLES_DM_POLICY || "pairing"}`);
35
+ logger.info(` - Group policy: ${config.BLUEBUBBLES_GROUP_POLICY || process.env.BLUEBUBBLES_GROUP_POLICY || "allowlist"}`);
36
+ if (!hasServerUrl) {
37
+ logger.warn("BlueBubbles server URL not configured. Set BLUEBUBBLES_SERVER_URL.");
38
+ }
39
+ if (!hasPassword) {
40
+ logger.warn("BlueBubbles password not configured. Set BLUEBUBBLES_PASSWORD.");
41
+ }
42
+ logger.info("BlueBubbles plugin initialized");
43
+ },
44
+ };
45
+ export default blueBubblesPlugin;
46
+ //# sourceMappingURL=index.js.map
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@elizaos/plugin-bluebubbles",
3
+ "version": "2.0.0-alpha.3",
4
+ "type": "module",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "bun run build.ts",
9
+ "test": "vitest run",
10
+ "lint": "biome check --write --unsafe src"
11
+ },
12
+ "dependencies": {
13
+ "@elizaos/core": "2.0.0-alpha.3",
14
+ "zod": "^4.3.6"
15
+ },
16
+ "devDependencies": {
17
+ "@types/node": "^20.0.0",
18
+ "typescript": "^5.6.0",
19
+ "vitest": "^2.0.0"
20
+ },
21
+ "milaidy": {
22
+ "platforms": [
23
+ "node"
24
+ ],
25
+ "runtime": "node",
26
+ "platformDetails": {
27
+ "node": "Node.js via main entry point"
28
+ }
29
+ },
30
+ "publishConfig": {
31
+ "access": "public"
32
+ }
33
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * BlueBubbles actions export
3
+ */
4
+ export { sendMessageAction } from "./sendMessage";
5
+ export { sendReactionAction } from "./sendReaction";
@@ -0,0 +1,175 @@
1
+ /**
2
+ * Send message action for BlueBubbles
3
+ */
4
+ import {
5
+ type Action,
6
+ type ActionExample,
7
+ type ActionResult,
8
+ type Content,
9
+ composePromptFromState,
10
+ type HandlerCallback,
11
+ type IAgentRuntime,
12
+ logger,
13
+ type Memory,
14
+ ModelType,
15
+ type State,
16
+ } from "@elizaos/core";
17
+ import { BLUEBUBBLES_SERVICE_NAME } from "../constants";
18
+ import type { BlueBubblesService } from "../service";
19
+
20
+ const sendMessageTemplate = `
21
+ # Task: Generate a response to send via iMessage (BlueBubbles)
22
+ {{recentMessages}}
23
+
24
+ # Instructions: Write a response to send to the user via iMessage. Be conversational and friendly.
25
+ Your response should be appropriate for iMessage - keep it relatively concise but engaging.
26
+ `;
27
+
28
+ const examples: ActionExample[][] = [
29
+ [
30
+ {
31
+ name: "{{user1}}",
32
+ content: {
33
+ text: "Can you send a message to John saying I'll be late?",
34
+ },
35
+ },
36
+ {
37
+ name: "{{agentName}}",
38
+ content: {
39
+ text: "I'll send that message to John for you.",
40
+ action: "SEND_BLUEBUBBLES_MESSAGE",
41
+ },
42
+ },
43
+ ],
44
+ [
45
+ {
46
+ name: "{{user1}}",
47
+ content: {
48
+ text: "Reply to this iMessage for me",
49
+ },
50
+ },
51
+ {
52
+ name: "{{agentName}}",
53
+ content: {
54
+ text: "I'll compose and send a reply for you.",
55
+ action: "SEND_BLUEBUBBLES_MESSAGE",
56
+ },
57
+ },
58
+ ],
59
+ ];
60
+
61
+ export const sendMessageAction: Action = {
62
+ name: "SEND_BLUEBUBBLES_MESSAGE",
63
+ description: "Send a message via iMessage through BlueBubbles",
64
+ similes: [
65
+ "SEND_IMESSAGE",
66
+ "TEXT_MESSAGE",
67
+ "IMESSAGE_REPLY",
68
+ "BLUEBUBBLES_SEND",
69
+ "APPLE_MESSAGE",
70
+ ],
71
+ examples,
72
+
73
+ validate: async (
74
+ runtime: IAgentRuntime,
75
+ _message: Memory,
76
+ ): Promise<boolean> => {
77
+ const service = runtime.getService<BlueBubblesService>(
78
+ BLUEBUBBLES_SERVICE_NAME,
79
+ );
80
+ return service?.getIsRunning() ?? false;
81
+ },
82
+
83
+ handler: async (
84
+ runtime: IAgentRuntime,
85
+ message: Memory,
86
+ state: State | undefined,
87
+ _options: Record<string, unknown> | undefined,
88
+ callback?: HandlerCallback,
89
+ ): Promise<ActionResult> => {
90
+ const service = runtime.getService<BlueBubblesService>(
91
+ BLUEBUBBLES_SERVICE_NAME,
92
+ );
93
+ const currentState = state ?? (await runtime.composeState(message));
94
+
95
+ if (!service || !service.getIsRunning()) {
96
+ logger.error("BlueBubbles service is not available");
97
+ if (callback) {
98
+ await callback({
99
+ text: "Sorry, the iMessage service is currently unavailable.",
100
+ });
101
+ }
102
+ return { success: false, error: "BlueBubbles service not available" };
103
+ }
104
+
105
+ try {
106
+ // Get the room to find the target
107
+ const room = await runtime.getRoom(message.roomId);
108
+ if (!room?.channelId) {
109
+ logger.error("No channel ID found for room");
110
+ if (callback) {
111
+ await callback({
112
+ text: "Unable to determine the message recipient.",
113
+ });
114
+ }
115
+ return { success: false, error: "No channel ID" };
116
+ }
117
+
118
+ // Generate response if state is available
119
+ const prompt = composePromptFromState({
120
+ state: currentState,
121
+ template: sendMessageTemplate,
122
+ });
123
+
124
+ const response = await runtime.useModel(ModelType.TEXT_LARGE, {
125
+ prompt,
126
+ });
127
+
128
+ const responseText =
129
+ typeof response === "string"
130
+ ? response
131
+ : ((response as { text?: string }).text ?? "");
132
+
133
+ if (!responseText.trim()) {
134
+ logger.warn("Generated empty response, skipping send");
135
+ return { success: false, error: "Empty response generated" };
136
+ }
137
+
138
+ // Send the message
139
+ const result = await service.sendMessage(
140
+ room.channelId,
141
+ responseText,
142
+ message.content.inReplyTo as string | undefined,
143
+ );
144
+
145
+ logger.info(`Sent BlueBubbles message: ${result.guid}`);
146
+
147
+ const content: Content = {
148
+ text: responseText,
149
+ source: "bluebubbles",
150
+ metadata: {
151
+ messageGuid: result.guid,
152
+ chatGuid: room.channelId,
153
+ },
154
+ };
155
+
156
+ if (callback) {
157
+ await callback(content);
158
+ }
159
+
160
+ return { success: true, text: responseText };
161
+ } catch (error) {
162
+ const errorMessage =
163
+ error instanceof Error ? error.message : String(error);
164
+ logger.error(`Failed to send BlueBubbles message: ${errorMessage}`);
165
+
166
+ if (callback) {
167
+ await callback({
168
+ text: "Failed to send the iMessage. Please try again.",
169
+ });
170
+ }
171
+
172
+ return { success: false, error: errorMessage };
173
+ }
174
+ },
175
+ };