@lizzythelizard/whatsapp-mcp 0.1.6 → 0.1.7
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/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +58 -14
- package/dist/index.js.map +1 -1
- package/dist/tools/authTools.d.ts +5 -0
- package/dist/tools/authTools.d.ts.map +1 -0
- package/dist/tools/authTools.js +44 -0
- package/dist/tools/authTools.js.map +1 -0
- package/dist/tools/chatTools.d.ts.map +1 -1
- package/dist/tools/chatTools.js +4 -20
- package/dist/tools/chatTools.js.map +1 -1
- package/dist/tools/common.d.ts +7 -4
- package/dist/tools/common.d.ts.map +1 -1
- package/dist/tools/common.js +30 -11
- package/dist/tools/common.js.map +1 -1
- package/dist/tools/contactTools.d.ts +2 -1
- package/dist/tools/contactTools.d.ts.map +1 -1
- package/dist/tools/contactTools.js +2 -2
- package/dist/tools/contactTools.js.map +1 -1
- package/dist/tools/messageTools.d.ts.map +1 -1
- package/dist/tools/messageTools.js +3 -11
- package/dist/tools/messageTools.js.map +1 -1
- package/package.json +68 -60
- package/dist/syncManager.d.ts +0 -29
- package/dist/syncManager.d.ts.map +0 -1
- package/dist/syncManager.js +0 -79
- package/dist/syncManager.js.map +0 -1
- package/dist/tools.d.ts +0 -2
- package/dist/tools.d.ts.map +0 -1
- package/dist/tools.js +0 -65
- package/dist/tools.js.map +0 -1
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAgBA,OAAO,EAAE,SAAS,EAAE,MAAM,+CAA+C,CAAA;AAWzE,wBAAsB,WAAW,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,CAcpF"}
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,40 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
3
|
+
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
3
4
|
import pkg from '../package.json' with { type: 'json' };
|
|
4
5
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
5
6
|
import { createStore } from './store.js';
|
|
6
7
|
import { createHandler } from './sync.js';
|
|
7
8
|
import { promises as fsp } from 'fs';
|
|
9
|
+
import { createServer } from 'node:http';
|
|
10
|
+
import { randomUUID } from 'node:crypto';
|
|
11
|
+
import { parseArgs } from 'node:util';
|
|
8
12
|
import { registerContactResources } from './tools/contactTools.js';
|
|
9
13
|
import { registerChatTools } from './tools/chatTools.js';
|
|
10
14
|
import { registerMessageTools } from './tools/messageTools.js';
|
|
15
|
+
import { registerAuthTools } from './tools/authTools.js';
|
|
16
|
+
import { fileURLToPath } from 'node:url';
|
|
17
|
+
import { resolve } from 'node:path';
|
|
11
18
|
const dataDir = process.env.DATA_DIR ?? './data';
|
|
19
|
+
const cliOptions = {
|
|
20
|
+
host: { type: 'string', short: 'h', multiple: false },
|
|
21
|
+
port: { type: 'string', short: 'p', multiple: false },
|
|
22
|
+
};
|
|
23
|
+
export async function startServer(transport) {
|
|
24
|
+
const inputData = await readDataFromFile();
|
|
25
|
+
const store = createStore(writeDataToFile, inputData);
|
|
26
|
+
const sync = createHandler(store);
|
|
27
|
+
const server = new McpServer({ name: pkg.name, version: pkg.version });
|
|
28
|
+
registerContactResources(server, store, sync);
|
|
29
|
+
registerChatTools(server, store, sync);
|
|
30
|
+
registerMessageTools(server, store, sync);
|
|
31
|
+
registerAuthTools(server, store, sync);
|
|
32
|
+
await server.connect(transport);
|
|
33
|
+
return async () => {
|
|
34
|
+
sync.close();
|
|
35
|
+
await server.close();
|
|
36
|
+
};
|
|
37
|
+
}
|
|
12
38
|
async function readDataFromFile() {
|
|
13
39
|
const canAccess = await fsp.access(dataDir).then(() => true).catch(() => false);
|
|
14
40
|
if (!canAccess)
|
|
@@ -27,19 +53,37 @@ async function writeDataToFile(data) {
|
|
|
27
53
|
await fsp.writeFile(`${dataDir}/auth.json`, data.auth, 'utf-8');
|
|
28
54
|
}
|
|
29
55
|
async function main() {
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
56
|
+
const { values } = parseArgs({
|
|
57
|
+
options: cliOptions,
|
|
58
|
+
args: process.argv.slice(2),
|
|
59
|
+
allowPositionals: false,
|
|
60
|
+
});
|
|
61
|
+
if (values.host || values.port) {
|
|
62
|
+
const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: () => randomUUID() });
|
|
63
|
+
const httpServer = createServer((req, res) => { void transport.handleRequest(req, res); });
|
|
64
|
+
const closeCB = await startServer(transport);
|
|
65
|
+
httpServer.on('close', () => { void closeCB(); });
|
|
66
|
+
const port = values.port ? parseInt(values.port, 10) : 3100;
|
|
67
|
+
if (Number.isNaN(port)) {
|
|
68
|
+
console.error('Invalid port number');
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
71
|
+
const host = (values.host ?? 'localhost');
|
|
72
|
+
httpServer.listen(port, host);
|
|
73
|
+
console.info(`whatsapp-mcp server running on http://${host}:${String(port)}`);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
const transport = new StdioServerTransport();
|
|
77
|
+
const closeCB = await startServer(transport);
|
|
78
|
+
process.on('exit', () => { void closeCB(); });
|
|
79
|
+
console.info('whatsapp-mcp server running on stdio');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const isMain = resolve(fileURLToPath(import.meta.url)) === resolve(process.argv[1]);
|
|
83
|
+
if (isMain) {
|
|
84
|
+
main().catch((error) => {
|
|
85
|
+
console.error('Server error:', error);
|
|
86
|
+
process.exit(1);
|
|
87
|
+
});
|
|
40
88
|
}
|
|
41
|
-
main().catch((error) => {
|
|
42
|
-
console.error('Server error:', error);
|
|
43
|
-
process.exit(1);
|
|
44
|
-
});
|
|
45
89
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAA;AAChF,OAAO,GAAG,MAAM,iBAAiB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAA;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACnE,OAAO,EAAE,WAAW,EAAa,MAAM,YAAY,CAAA;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,QAAQ,IAAI,GAAG,EAAE,MAAM,IAAI,CAAA;AACpC,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAA;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAA;AAChF,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAA;AAClG,OAAO,GAAG,MAAM,iBAAiB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAA;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACnE,OAAO,EAAE,WAAW,EAAa,MAAM,YAAY,CAAA;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AACzC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elcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { WhatsAppStore } from '../store.js';
|
|
3
|
+
import { WhatsAppHandler } from '../sync.js';
|
|
4
|
+
export declare function registerAuthTools(server: McpServer, store: WhatsAppStore, sync: WhatsAppHandler): void;
|
|
5
|
+
//# sourceMappingURL=authTools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authTools.d.ts","sourceRoot":"","sources":["../../src/tools/authTools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AAEnE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAI5C,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,eAAe,QAqC/F"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { toCallError } from './common.js';
|
|
2
|
+
import QRCode from 'qrcode';
|
|
3
|
+
export function registerAuthTools(server, store, sync) {
|
|
4
|
+
server.registerTool('get_auth_qr', { description: 'Get a QR code for WhatsApp authentication.' }, async () => {
|
|
5
|
+
try {
|
|
6
|
+
const status = sync.getStatus();
|
|
7
|
+
if (status.type !== 'needAuth')
|
|
8
|
+
throw new Error('Authentication is not required at this time.');
|
|
9
|
+
const pngBuffer = await QRCode.toBuffer(status.qr, { type: 'png', width: 400, margin: 2 });
|
|
10
|
+
return {
|
|
11
|
+
content: [
|
|
12
|
+
{ type: 'text', text: qrExplanation },
|
|
13
|
+
{ type: 'image', data: pngBuffer.toString('base64'), mimeType: 'image/png' },
|
|
14
|
+
{ type: 'text', text: status.qr },
|
|
15
|
+
],
|
|
16
|
+
isError: false,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
return toCallError(e);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
server.registerTool('get_status', { description: 'Get the current server status.' }, () => {
|
|
24
|
+
try {
|
|
25
|
+
const status = sync.getStatus();
|
|
26
|
+
return { content: [{ type: 'text', text: status.type }], isError: false };
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
return toCallError(e);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
const qrExplanation = `⚠️ Authentication Required
|
|
34
|
+
|
|
35
|
+
To use this WhatsApp MCP server, you need to link it to your WhatsApp account.
|
|
36
|
+
|
|
37
|
+
1. Open WhatsApp on your phone
|
|
38
|
+
2. Tap the three dots menu (⋮) or Settings
|
|
39
|
+
3. Select "Linked Devices"
|
|
40
|
+
4. Tap "Link a Device"
|
|
41
|
+
5. Scan the QR code below with your phone
|
|
42
|
+
|
|
43
|
+
The raw QR code string is also provided below for clients that render QR codes themselves.`;
|
|
44
|
+
//# sourceMappingURL=authTools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authTools.js","sourceRoot":"","sources":["../../src/tools/authTools.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAGzC,OAAO,MAAM,MAAM,QAAQ,CAAA;AAG3B,MAAM,UAAU,iBAAiB,CAAC,MAAiB,EAAE,KAAoB,EAAE,IAAqB;IAC9F,MAAM,CAAC,YAAY,CACjB,aAAa,EACb,EAAE,WAAW,EAAE,4CAA4C,EAAE,EAC7D,KAAK,IAAI,EAAE;QACT,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAA;YAC/B,IAAI,MAAM,CAAC,IAAI,KAAK,UAAU;gBAAE,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAA;YAC/F,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,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BAAiB,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"chatTools.d.ts","sourceRoot":"","sources":["../../src/tools/chatTools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACnE,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAI5C,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,eAAe,QA2B/F"}
|
package/dist/tools/chatTools.js
CHANGED
|
@@ -1,25 +1,9 @@
|
|
|
1
1
|
import z from 'zod';
|
|
2
|
-
import { JidSchema, registerEntityResources,
|
|
2
|
+
import { JidSchema, registerEntityResources, registerTool } from './common.js';
|
|
3
3
|
export function registerChatTools(server, store, sync) {
|
|
4
|
-
registerEntityResources(server, 'chats', 'chat', () => store.getChats(), id => store.getChat(id), c => `chats://app/${c.id}`, c => c.name ?? c.id);
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
await sync.setArchived(args.jid, args.archived);
|
|
8
|
-
return toCallResult(`Chat ${args.jid} archived status set to ${String(args.archived)}`);
|
|
9
|
-
}
|
|
10
|
-
catch (error) {
|
|
11
|
-
return toCallError(error);
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
server.registerTool('set_chat_read', { description: 'Set a WhatsApp chat as read or unread.', inputSchema: ReadChatSchema }, async (args) => {
|
|
15
|
-
try {
|
|
16
|
-
await sync.setRead(args.jid, args.read);
|
|
17
|
-
return toCallResult(`Chat ${args.jid} read status set to ${String(args.read)}`);
|
|
18
|
-
}
|
|
19
|
-
catch (error) {
|
|
20
|
-
return toCallError(error);
|
|
21
|
-
}
|
|
22
|
-
});
|
|
4
|
+
registerEntityResources(server, 'chats', 'chat', () => store.getChats(), id => store.getChat(id), c => `chats://app/${c.id}`, c => c.name ?? c.id, () => sync.getStatus());
|
|
5
|
+
registerTool(server, 'set_chat_archived', ArchiveChatSchema, 'Set a WhatsApp chat as archived or unarchived.', async (args) => { await sync.setArchived(args.jid, args.archived); return `Chat ${args.jid} archived status set to ${String(args.archived)}`; }, () => sync.getStatus());
|
|
6
|
+
registerTool(server, 'set_chat_read', ReadChatSchema, 'Set a WhatsApp chat as read or unread.', async (args) => { await sync.setRead(args.jid, args.read); return `Chat ${args.jid} read status set to ${String(args.read)}`; }, () => sync.getStatus());
|
|
23
7
|
}
|
|
24
8
|
const ArchiveChatSchema = z.object({
|
|
25
9
|
jid: JidSchema,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatTools.js","sourceRoot":"","sources":["../../src/tools/chatTools.ts"],"names":[],"mappings":"AAGA,OAAO,CAAC,MAAM,KAAK,CAAA;AACnB,OAAO,EAAE,SAAS,EAAE,uBAAuB,EAAE,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"chatTools.js","sourceRoot":"","sources":["../../src/tools/chatTools.ts"],"names":[],"mappings":"AAGA,OAAO,CAAC,MAAM,KAAK,CAAA;AACnB,OAAO,EAAE,SAAS,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE9E,MAAM,UAAU,iBAAiB,CAAC,MAAiB,EAAE,KAAoB,EAAE,IAAqB;IAC9F,uBAAuB,CACrB,MAAM,EAAE,OAAO,EAAE,MAAM,EACvB,GAAG,EAAE,CAAC,KAAK,CAAC,QAAQ,EAAE,EACtB,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,EACvB,CAAC,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC,EAAE,EAAE,EAC1B,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,EACnB,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,EAAE,CACvB,CAAA;IAED,YAAY,CACV,MAAM,EACN,mBAAmB,EACnB,iBAAiB,EACjB,gDAAgD,EAChD,KAAK,EAAE,IAAI,EAAE,EAAE,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,QAAQ,IAAI,CAAC,GAAG,2BAA2B,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAA,CAAC,CAAC,EAC9I,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,EAAE,CACvB,CAAA;IAED,YAAY,CACV,MAAM,EACN,eAAe,EACf,cAAc,EACd,wCAAwC,EACxC,KAAK,EAAE,IAAI,EAAE,EAAE,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,QAAQ,IAAI,CAAC,GAAG,uBAAuB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAA,CAAC,CAAC,EAC9H,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,EAAE,CACvB,CAAA;AACH,CAAC;AAED,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC,GAAG,EAAE,SAAS;IACd,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE;SAClB,QAAQ,CAAC,mEAAmE,CAAC;CACjF,CAAC,CAAA;AAEF,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9B,GAAG,EAAE,SAAS;IACd,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE;SACd,QAAQ,CAAC,qEAAqE,CAAC;CACnF,CAAC,CAAA"}
|
package/dist/tools/common.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
2
|
import { type CallToolResult, type ListResourcesResult, type ReadResourceResult } from '@modelcontextprotocol/sdk/types.js';
|
|
3
|
-
import
|
|
3
|
+
import { type SyncStatus } from '../sync.js';
|
|
4
|
+
import z, { ZodType } from 'zod';
|
|
5
|
+
export declare const JidSchema: z.ZodUnion<readonly [z.ZodString, z.ZodString]>;
|
|
6
|
+
export declare function registerEntityResources<T>(server: McpServer, pluralType: string, singularType: string, getAll: () => T[], get: (id: string) => T | undefined, toUri: (entity: T) => string, toName: (entity: T) => string, getStatus: () => SyncStatus): void;
|
|
7
|
+
export declare function registerTool<I>(server: McpServer, name: string, inputSchema: ZodType<I>, description: string, action: (args: I) => Promise<string>, getStatus: () => SyncStatus): void;
|
|
8
|
+
export declare function withErrorHandling<R>(getStatus: () => SyncStatus, action: () => R | Promise<R>, onError: (error: Error) => R | Promise<R>): Promise<R>;
|
|
9
|
+
export declare const toCallError: (error: Error) => CallToolResult;
|
|
4
10
|
export declare const toReadResource: (contents: ReadResourceResult["contents"]) => {
|
|
5
11
|
contents: ({
|
|
6
12
|
uri: string;
|
|
@@ -43,7 +49,4 @@ export declare const toListResource: (resources: ListResourcesResult["resources"
|
|
|
43
49
|
}[];
|
|
44
50
|
};
|
|
45
51
|
export declare const toCallResult: (text: string) => CallToolResult;
|
|
46
|
-
export declare const toCallError: (error: Error) => CallToolResult;
|
|
47
|
-
export declare function registerEntityResources<T>(server: McpServer, pluralType: string, singularType: string, getAll: () => T[], get: (id: string) => T | undefined, toUri: (entity: T) => string, toName: (entity: T) => string): void;
|
|
48
|
-
export declare const JidSchema: z.ZodUnion<readonly [z.ZodString, z.ZodString]>;
|
|
49
52
|
//# sourceMappingURL=common.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/tools/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAoB,MAAM,yCAAyC,CAAA;AACrF,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,mBAAmB,EAAE,KAAK,kBAAkB,EAAE,MAAM,oCAAoC,CAAA;A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AC,CAAC,CAAC,GACxC,OAAO,CAAC,CAAC,CAAC,CAWZ;AAED,eAAO,MAAM,WAAW,GAAI,OAAO,KAAK,KAAG,cAAmG,CAAA;AAC9I,eAAO,MAAM,cAAc,GAAI,UAAU,kBAAkB,CAAC,UAAU,CAAC;;;;;;;;;;;;;;;;CAAmB,CAAA;AAC1F,eAAO,MAAM,cAAc,GAAI,WAAW,mBAAmB,CAAC,WAAW,CAAC;;;;;;;;;;;;;;;;;;;;;;;CAAoB,CAAA;AAC9F,eAAO,MAAM,YAAY,GAAI,MAAM,MAAM,KAAG,cAAyE,CAAA"}
|
package/dist/tools/common.js
CHANGED
|
@@ -1,18 +1,37 @@
|
|
|
1
1
|
import { ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
2
|
import z from 'zod';
|
|
3
|
-
export const toReadResource = (contents) => ({ contents });
|
|
4
|
-
export const toListResource = (resources) => ({ resources });
|
|
5
|
-
export const toCallResult = (text) => ({ content: [{ type: 'text', text }], isError: false });
|
|
6
|
-
export const toCallError = (error) => ({ content: [{ type: 'text', text: `Error: ${error.message}` }], isError: true });
|
|
7
|
-
export function registerEntityResources(server, pluralType, singularType, getAll, get, toUri, toName) {
|
|
8
|
-
const toResource = (entity) => entity ? [{ uri: toUri(entity), mimeType: 'application/json', text: JSON.stringify(entity) }] : [];
|
|
9
|
-
server.registerResource(pluralType, `${pluralType}://app`, { title: `All WhatsApp ${pluralType}`, description: `List WhatsApp ${pluralType}`, mimeType: 'application/json' }, () => toReadResource(getAll().flatMap(toResource)));
|
|
10
|
-
server.registerResource(singularType, new ResourceTemplate(`${pluralType}://app/{${singularType}Id}`, {
|
|
11
|
-
list: () => toListResource(getAll().map(e => ({ uri: toUri(e), name: toName(e) }))),
|
|
12
|
-
}), { title: `A single WhatsApp ${singularType}`, description: `Details of a single WhatsApp ${singularType}`, mimeType: 'application/json' }, (_, params) => toReadResource(toResource(get(params[`${singularType}Id`]))));
|
|
13
|
-
}
|
|
14
3
|
export const JidSchema = z.union([
|
|
15
4
|
z.string().min(1, 'JID is required').endsWith('@s.whatsapp.net', 'JID not a valid WhatsApp JID)'),
|
|
16
5
|
z.string().min(1, 'JID is required').endsWith('@g.us', 'JID not a valid WhatsApp JID)'),
|
|
17
6
|
]).describe('The JID of the recipient or chat. For example 41791234567@s.whatsapp.net for an individual or 1234567890-1234567890@g.us for a group');
|
|
7
|
+
export function registerEntityResources(server, pluralType, singularType, getAll, get, toUri, toName, getStatus) {
|
|
8
|
+
const toResource = (entity) => entity ? [{ uri: toUri(entity), mimeType: 'application/json', text: JSON.stringify(entity) }] : [];
|
|
9
|
+
server.registerResource(pluralType, `${pluralType}://app`, { title: `All WhatsApp ${pluralType}`, description: `List WhatsApp ${pluralType}`, mimeType: 'application/json' }, async () => withErrorHandling(getStatus, () => toReadResource(getAll().flatMap(e => toResource(e))), (error) => { throw error; }));
|
|
10
|
+
const resourceTemplate = new ResourceTemplate(`${pluralType}://app/{${singularType}Id}`, {
|
|
11
|
+
list: async () => withErrorHandling(getStatus, () => toListResource(getAll().map(e => ({ uri: toUri(e), name: toName(e) }))), (error) => { throw error; }),
|
|
12
|
+
});
|
|
13
|
+
server.registerResource(singularType, resourceTemplate, { title: `A single WhatsApp ${singularType}`, description: `Details of a single WhatsApp ${singularType}`, mimeType: 'application/json' }, async (_, params) => withErrorHandling(getStatus, () => toReadResource(toResource(get(params[`${singularType}Id`]))), (error) => { throw error; }));
|
|
14
|
+
}
|
|
15
|
+
export function registerTool(server, name, inputSchema, description, action, getStatus) {
|
|
16
|
+
server.registerTool(name, { description, inputSchema }, async (args) => withErrorHandling(() => getStatus(), () => action(args).then(toCallResult), e => toCallError(e)));
|
|
17
|
+
}
|
|
18
|
+
export async function withErrorHandling(getStatus, action, onError) {
|
|
19
|
+
try {
|
|
20
|
+
const status = getStatus();
|
|
21
|
+
if (status.type === 'needAuth')
|
|
22
|
+
throw new Error('Authentication required, please call the "get_auth_qr" tool to get a QR code for authentication');
|
|
23
|
+
if (status.type === 'connecting')
|
|
24
|
+
throw new Error('Server still connecting, please wait');
|
|
25
|
+
if (status.type === 'closed')
|
|
26
|
+
throw new Error('Connection closed, please restart server');
|
|
27
|
+
return await action();
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
return await onError(error);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export const toCallError = (error) => ({ content: [{ type: 'text', text: `Error: ${error.message}` }], isError: true });
|
|
34
|
+
export const toReadResource = (contents) => ({ contents });
|
|
35
|
+
export const toListResource = (resources) => ({ resources });
|
|
36
|
+
export const toCallResult = (text) => ({ content: [{ type: 'text', text }], isError: false });
|
|
18
37
|
//# sourceMappingURL=common.js.map
|
package/dist/tools/common.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/tools/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,gBAAgB,EAAE,MAAM,yCAAyC,CAAA;
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/tools/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,gBAAgB,EAAE,MAAM,yCAAyC,CAAA;AAGrF,OAAO,CAAc,MAAM,KAAK,CAAA;AAGhC,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC;IAC/B,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,iBAAiB,CAAC,CAAC,QAAQ,CAAC,iBAAiB,EAAE,+BAA+B,CAAC;IACjG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,iBAAiB,CAAC,CAAC,QAAQ,CAAC,OAAO,EAAE,+BAA+B,CAAC;CACxF,CAAC,CAAC,QAAQ,CAAC,sIAAsI,CAAC,CAAA;AAEnJ,MAAM,UAAU,uBAAuB,CACrC,MAAiB,EACjB,UAAkB,EAClB,YAAoB,EACpB,MAAiB,EACjB,GAAkC,EACl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CAAC,CAAA;QACzF,OAAO,MAAM,MAAM,EAAE,CAAA;IACvB,CAAC;IACD,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,MAAM,OAAO,CAAC,KAAc,CAAC,CAAA;IACtC,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAY,EAAkB,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAA;AAC9I,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,QAAwC,EAAE,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAA;AAC1F,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,SAA2C,EAAE,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAA;AAC9F,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAY,EAAkB,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
2
|
import { type WhatsAppStore } from '../store.js';
|
|
3
|
-
|
|
3
|
+
import { type WhatsAppHandler } from '../sync.js';
|
|
4
|
+
export declare function registerContactResources(server: McpServer, store: WhatsAppStore, sync: WhatsAppHandler): void;
|
|
4
5
|
//# sourceMappingURL=contactTools.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contactTools.d.ts","sourceRoot":"","sources":["../../src/tools/contactTools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACnE,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"contactTools.d.ts","sourceRoot":"","sources":["../../src/tools/contactTools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACnE,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAA;AAGjD,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,eAAe,QAOtG"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { registerEntityResources } from './common.js';
|
|
2
|
-
export function registerContactResources(server, store) {
|
|
3
|
-
registerEntityResources(server, 'contacts', 'contact', () => store.getContacts(), id => store.getContact(id), c => `contacts://app/${c.id}`, c => c.name ?? c.id);
|
|
2
|
+
export function registerContactResources(server, store, sync) {
|
|
3
|
+
registerEntityResources(server, 'contacts', 'contact', () => store.getContacts(), id => store.getContact(id), c => `contacts://app/${c.id}`, c => c.name ?? c.id, () => sync.getStatus());
|
|
4
4
|
}
|
|
5
5
|
//# sourceMappingURL=contactTools.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contactTools.js","sourceRoot":"","sources":["../../src/tools/contactTools.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"contactTools.js","sourceRoot":"","sources":["../../src/tools/contactTools.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAErD,MAAM,UAAU,wBAAwB,CAAC,MAAiB,EAAE,KAAoB,EAAE,IAAqB;IACrG,uBAAuB,CACrB,MAAM,EAAE,UAAU,EAAE,SAAS,EAC7B,GAAG,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,EACrD,CAAC,CAAC,EAAE,CAAC,kBAAkB,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,EAClD,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,EAAE,CACvB,CAAA;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messageTools.d.ts","sourceRoot":"","sources":["../../src/tools/messageTools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACnE,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"messageTools.d.ts","sourceRoot":"","sources":["../../src/tools/messageTools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACnE,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAI5C,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,eAAe,QAgBlG"}
|
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
import z from 'zod';
|
|
2
|
-
import { JidSchema, registerEntityResources,
|
|
2
|
+
import { JidSchema, registerEntityResources, registerTool } from './common.js';
|
|
3
3
|
export function registerMessageTools(server, store, sync) {
|
|
4
|
-
registerEntityResources(server, 'messages', 'message', () => store.getMessages(), id => store.getMessage(id), m => `messages://app/${m.key.id}`, m => m.key.id);
|
|
5
|
-
|
|
6
|
-
try {
|
|
7
|
-
const message = await sync.sendMessage(args.jid, args.message);
|
|
8
|
-
return toCallResult(`Message sent to ${message.key.remoteJid ?? 'unknown'}: "${message.message?.conversation ?? 'unknown'}"`);
|
|
9
|
-
}
|
|
10
|
-
catch (error) {
|
|
11
|
-
return toCallError(error);
|
|
12
|
-
}
|
|
13
|
-
});
|
|
4
|
+
registerEntityResources(server, 'messages', 'message', () => store.getMessages(), id => store.getMessage(id), m => `messages://app/${m.key.id}`, m => m.key.id, () => sync.getStatus());
|
|
5
|
+
registerTool(server, 'send_message', SendMessageSchema, 'Send a WhatsApp-Message to a given JID.', async (args) => { await sync.sendMessage(args.jid, args.message); return `Message sent to ${args.jid}: "${args.message}"`; }, () => sync.getStatus());
|
|
14
6
|
}
|
|
15
7
|
const SendMessageSchema = z.object({
|
|
16
8
|
jid: JidSchema,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messageTools.js","sourceRoot":"","sources":["../../src/tools/messageTools.ts"],"names":[],"mappings":"AAGA,OAAO,CAAC,MAAM,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"messageTools.js","sourceRoot":"","sources":["../../src/tools/messageTools.ts"],"names":[],"mappings":"AAGA,OAAO,CAAC,MAAM,KAAK,CAAA;AACnB,OAAO,EAAE,SAAS,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE9E,MAAM,UAAU,oBAAoB,CAAC,MAAiB,EAAE,KAAoB,EAAE,IAAqB;IACjG,uBAAuB,CACrB,MAAM,EAAE,UAAU,EAAE,SAAS,EAC7B,GAAG,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,EACrD,CAAC,CAAC,EAAE,CAAC,kBAAkB,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAChD,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,EAAE,CACvB,CAAA;IAED,YAAY,CACV,MAAM,EACN,cAAc,EACd,iBAAiB,EACjB,yCAAyC,EACzC,KAAK,EAAE,IAAI,EAAE,EAAE,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,mBAAmB,IAAI,CAAC,GAAG,MAAM,IAAI,CAAC,OAAO,GAAG,CAAA,CAAC,CAAC,EAC3H,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,EAAE,CACvB,CAAA;AACH,CAAC;AAED,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC,GAAG,EAAE,SAAS;IACd,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;SAChB,GAAG,CAAC,CAAC,EAAE,0BAA0B,CAAC;SAClC,QAAQ,CAAC,iFAAiF,CAAC;CAC/F,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,60 +1,68 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@lizzythelizard/whatsapp-mcp",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "MCP server for WhatsApp integration",
|
|
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
|
-
"@eslint
|
|
51
|
-
"@
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@lizzythelizard/whatsapp-mcp",
|
|
3
|
+
"version": "0.1.7",
|
|
4
|
+
"description": "MCP server for WhatsApp integration",
|
|
5
|
+
"author": { "name": "Matthias Graf" },
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=20"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/lizzyTheLizard/whatsapp-mcp.git"
|
|
17
|
+
},
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/lizzyTheLizard/whatsapp-mcp/issues"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/lizzyTheLizard/whatsapp-mcp#readme",
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"bin": {
|
|
26
|
+
"whatsapp-mcp": "dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsc",
|
|
30
|
+
"start": "node dist/index.js",
|
|
31
|
+
"dev": "tsx watch src/index.ts",
|
|
32
|
+
"dev:http": "tsx watch src/index.ts -h localhost",
|
|
33
|
+
"test": "vitest run",
|
|
34
|
+
"test:watch": "vitest",
|
|
35
|
+
"lint": "eslint src/",
|
|
36
|
+
"lint:fix": "eslint src/ --fix",
|
|
37
|
+
"typecheck": "tsc --noEmit",
|
|
38
|
+
"mcpb:manifest": "node scripts/create-mcpb-manifest.mjs",
|
|
39
|
+
"mcpb:pack": "npx mcpb pack",
|
|
40
|
+
"mcpb": "npm run mcpb:manifest && npm run mcpb:pack"
|
|
41
|
+
},
|
|
42
|
+
"keywords": [
|
|
43
|
+
"mcp",
|
|
44
|
+
"whatsapp",
|
|
45
|
+
"model-context-protocol"
|
|
46
|
+
],
|
|
47
|
+
"license": "MIT",
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
50
|
+
"@stylistic/eslint-plugin": "^5.10.0",
|
|
51
|
+
"@whiskeysockets/baileys": "^7.0.0-rc13",
|
|
52
|
+
"qrcode": "^1.5.4",
|
|
53
|
+
"zod": "^4.4.3"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@anthropic-ai/mcpb": "^2.1.2",
|
|
57
|
+
"@eslint/js": "^10.0.1",
|
|
58
|
+
"@types/node": "^26.0.1",
|
|
59
|
+
"@types/qrcode": "^1.5.6",
|
|
60
|
+
"@typescript-eslint/eslint-plugin": "^8.62.0",
|
|
61
|
+
"eslint": "^10.5.0",
|
|
62
|
+
"eslint-plugin-import-x": "^4.17.0",
|
|
63
|
+
"tsx": "^4.22.4",
|
|
64
|
+
"typescript": "^6.0.3",
|
|
65
|
+
"typescript-eslint": "^8.62.0",
|
|
66
|
+
"vitest": "^4.1.9"
|
|
67
|
+
}
|
|
68
|
+
}
|
package/dist/syncManager.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { UserSession } from '@/app/shared/auth/auth';
|
|
2
|
-
import { SyncHandler } from './sync';
|
|
3
|
-
import { Mutex } from 'async-mutex';
|
|
4
|
-
export type RunningSyncStatus = {
|
|
5
|
-
state: 'connecting';
|
|
6
|
-
} | {
|
|
7
|
-
state: 'qr';
|
|
8
|
-
data: string;
|
|
9
|
-
} | {
|
|
10
|
-
state: 'initialsync';
|
|
11
|
-
} | {
|
|
12
|
-
state: 'ready';
|
|
13
|
-
} | {
|
|
14
|
-
state: 'failed';
|
|
15
|
-
data: string;
|
|
16
|
-
};
|
|
17
|
-
interface RunningSync {
|
|
18
|
-
status: RunningSyncStatus;
|
|
19
|
-
timeout: NodeJS.Timeout;
|
|
20
|
-
handler: SyncHandler;
|
|
21
|
-
}
|
|
22
|
-
declare global {
|
|
23
|
-
var runningSyncs: Map<string, RunningSync> | undefined;
|
|
24
|
-
var mutex: Mutex | undefined;
|
|
25
|
-
}
|
|
26
|
-
export declare function getRunningSyncData(user: UserSession): RunningSyncStatus;
|
|
27
|
-
export declare function triggerWhatsappSync(user: UserSession): Promise<void>;
|
|
28
|
-
export {};
|
|
29
|
-
//# sourceMappingURL=syncManager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"syncManager.d.ts","sourceRoot":"","sources":["../src/syncManager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAIpD,OAAO,EAAa,WAAW,EAAE,MAAM,QAAQ,CAAA;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAEnC,MAAM,MAAM,iBAAiB,GAAG;IAAE,KAAK,EAAE,YAAY,CAAA;CAAE,GACnD;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC7B;IAAE,KAAK,EAAE,aAAa,CAAA;CAAE,GACxB;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,GAClB;IAAE,KAAK,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAA;AAErC,UAAU,WAAW;IACnB,MAAM,EAAE,iBAAiB,CAAA;IACzB,OAAO,EAAE,MAAM,CAAC,OAAO,CAAA;IACvB,OAAO,EAAE,WAAW,CAAA;CACrB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,SAAS,CAAA;IACtD,IAAI,KAAK,EAAE,KAAK,GAAG,SAAS,CAAA;CAC7B;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,WAAW,GAAG,iBAAiB,CAEvE;AAED,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAwB1E"}
|
package/dist/syncManager.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
'use server';
|
|
2
|
-
import { logger } from '@/app/shared/logger';
|
|
3
|
-
import { transactional } from '@/app/shared/_external/db/access';
|
|
4
|
-
import { logEvent } from '@/app/shared/_data/Event';
|
|
5
|
-
import { startSync } from './sync';
|
|
6
|
-
import { Mutex } from 'async-mutex';
|
|
7
|
-
export function getRunningSyncData(user) {
|
|
8
|
-
return getSync(user).status;
|
|
9
|
-
}
|
|
10
|
-
export async function triggerWhatsappSync(user) {
|
|
11
|
-
globalThis.mutex ??= new Mutex();
|
|
12
|
-
await globalThis.mutex.runExclusive(async () => {
|
|
13
|
-
globalThis.runningSyncs ??= new Map();
|
|
14
|
-
const existing = globalThis.runningSyncs.get(user.email);
|
|
15
|
-
if (existing) {
|
|
16
|
-
clearTimeout(existing.timeout);
|
|
17
|
-
existing.timeout = setTimeout(() => { existing.handler.close(); }, 5 * 1000);
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
logger.debug(`Start whatsapp sync for ${user.email}`);
|
|
21
|
-
const handler = await startSync(user.email);
|
|
22
|
-
handler.onQrCode((qr) => { qrCallback(user, qr); });
|
|
23
|
-
handler.onAuth(() => { authCallback(user); });
|
|
24
|
-
handler.onReady(() => { readyCallback(user); });
|
|
25
|
-
handler.onFinished((error) => { finishedCallback(user, error); });
|
|
26
|
-
handler.start();
|
|
27
|
-
const runningSync = {
|
|
28
|
-
status: { state: 'connecting' },
|
|
29
|
-
timeout: setTimeout(() => { closeSync(user); }, 5 * 1000),
|
|
30
|
-
handler,
|
|
31
|
-
};
|
|
32
|
-
globalThis.runningSyncs.set(user.email, runningSync);
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
function qrCallback(user, qr) {
|
|
36
|
-
const message = `WhatsApp authentication requires QR code for user ${user.email}`;
|
|
37
|
-
logger.info(message);
|
|
38
|
-
void transactional(async (c) => { await logEvent(c, 'INFO', message); });
|
|
39
|
-
const runningSync = getSync(user);
|
|
40
|
-
runningSync.status = { state: 'qr', data: qr };
|
|
41
|
-
}
|
|
42
|
-
function authCallback(user) {
|
|
43
|
-
const message = `WhatsApp authentication successful for user ${user.email}`;
|
|
44
|
-
logger.info(message);
|
|
45
|
-
void transactional(async (c) => { await logEvent(c, 'INFO', message); });
|
|
46
|
-
const runningSync = getSync(user);
|
|
47
|
-
runningSync.status = { state: 'initialsync' };
|
|
48
|
-
}
|
|
49
|
-
function readyCallback(user) {
|
|
50
|
-
logger.debug(`WhatsApp is ready for user ${user.email}`);
|
|
51
|
-
const runningSync = getSync(user);
|
|
52
|
-
runningSync.status = { state: 'ready' };
|
|
53
|
-
}
|
|
54
|
-
function finishedCallback(user, error) {
|
|
55
|
-
if (!error) {
|
|
56
|
-
logger.debug('Closing WhatsApp sync handler after successful completion');
|
|
57
|
-
globalThis.runningSyncs?.delete(user.email);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
61
|
-
const message = `WhatsApp sync failed for user ${user.email}: ${errorMessage}`;
|
|
62
|
-
logger.error(message, error);
|
|
63
|
-
void transactional(async (c) => { await logEvent(c, 'ERROR', message); });
|
|
64
|
-
const runningSync = getSync(user);
|
|
65
|
-
runningSync.status = { state: 'failed', data: message };
|
|
66
|
-
}
|
|
67
|
-
function closeSync(user) {
|
|
68
|
-
logger.info('WhatsApp sync timeout reached, closing sync handler');
|
|
69
|
-
const runningSync = getSync(user);
|
|
70
|
-
globalThis.runningSyncs?.delete(user.email);
|
|
71
|
-
runningSync.handler.close();
|
|
72
|
-
}
|
|
73
|
-
function getSync(user) {
|
|
74
|
-
const runningSync = globalThis.runningSyncs?.get(user.email);
|
|
75
|
-
if (!runningSync)
|
|
76
|
-
throw new Error(`No running WhatsApp sync found for user ${user.email}`);
|
|
77
|
-
return runningSync;
|
|
78
|
-
}
|
|
79
|
-
//# sourceMappingURL=syncManager.js.map
|
package/dist/syncManager.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"syncManager.js","sourceRoot":"","sources":["../src/syncManager.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAA;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AACnD,OAAO,EAAE,SAAS,EAAe,MAAM,QAAQ,CAAA;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAmBnC,MAAM,UAAU,kBAAkB,CAAC,IAAiB;IAClD,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CAAA;AAC7B,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,IAAiB;IACzD,UAAU,CAAC,KAAK,KAAK,IAAI,KAAK,EAAE,CAAA;IAChC,MAAM,UAAU,CAAC,KAAK,CAAC,YAAY,CAAC,KAAK,IAAI,EAAE;QAC7C,UAAU,CAAC,YAAY,KAAK,IAAI,GAAG,EAAE,CAAA;QACrC,MAAM,QAAQ,GAAG,UAAU,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACxD,IAAI,QAAQ,EAAE,CAAC;YACb,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;YAC9B,QAAQ,CAAC,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,CAAA,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAA;YAC3E,OAAM;QACR,CAAC;QACD,MAAM,CAAC,KAAK,CAAC,2BAA2B,IAAI,CAAC,KAAK,EAAE,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,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IAC5B,KAAK,aAAa,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,GAAG,MAAM,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA,CAAC,CAAC,CAAC,CAAA;IACxE,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACjC,WAAW,CAAC,MAAM,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,CAAA;AACzD,CAAC;AAED,SAAS,SAAS,CAAC,IAAiB;IAClC,MAAM,CAAC,IAAI,CAAC,qDAAqD,CAAC,CAAA;IAClE,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACjC,UAAU,CAAC,YAAY,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAC3C,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,CAAA;AAC7B,CAAC;AAED,SAAS,OAAO,CAAC,IAAiB;IAChC,MAAM,WAAW,GAAG,UAAU,CAAC,YAAY,EAAE,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAC5D,IAAI,CAAC,WAAW;QAAE,MAAM,IAAI,KAAK,CAAC,2CAA2C,IAAI,CAAC,KAAK,EAAE,CAAC,CAAA;IAC1F,OAAO,WAAW,CAAA;AACpB,CAAC"}
|
package/dist/tools.d.ts
DELETED
package/dist/tools.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":""}
|
package/dist/tools.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
export {};
|
|
2
|
-
/*
|
|
3
|
-
const SendMessageSchema = z.object({
|
|
4
|
-
to: z.string().min(1, "Recipient is required"),
|
|
5
|
-
message: z.string().min(1, "Message body is required"),
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
const ListChatsSchema = z.object({
|
|
9
|
-
limit: z.number().int().positive().optional().default(20),
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
const ReadMessagesSchema = z.object({
|
|
13
|
-
chatId: z.string().min(1, "Chat ID is required"),
|
|
14
|
-
limit: z.number().int().positive().optional().default(50),
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
server.registerTool(
|
|
18
|
-
"send_message",
|
|
19
|
-
{
|
|
20
|
-
description: "Send a WhatsApp message to a recipient",
|
|
21
|
-
inputSchema: SendMessageSchema,
|
|
22
|
-
},
|
|
23
|
-
async ({ to, message }) => ({
|
|
24
|
-
content: [
|
|
25
|
-
{
|
|
26
|
-
type: "text" as const,
|
|
27
|
-
text: `Message would be sent to ${to}: "${message}" (not yet implemented)`,
|
|
28
|
-
},
|
|
29
|
-
],
|
|
30
|
-
}),
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
server.registerTool(
|
|
34
|
-
"list_chats",
|
|
35
|
-
{
|
|
36
|
-
description: "List recent WhatsApp chats",
|
|
37
|
-
inputSchema: ListChatsSchema,
|
|
38
|
-
},
|
|
39
|
-
async ({ limit }) => ({
|
|
40
|
-
content: [
|
|
41
|
-
{
|
|
42
|
-
type: "text" as const,
|
|
43
|
-
text: `Listing up to ${limit} chats (not yet implemented)`,
|
|
44
|
-
},
|
|
45
|
-
],
|
|
46
|
-
}),
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
server.registerTool(
|
|
50
|
-
"read_messages",
|
|
51
|
-
{
|
|
52
|
-
description: "Read messages from a WhatsApp chat",
|
|
53
|
-
inputSchema: ReadMessagesSchema,
|
|
54
|
-
},
|
|
55
|
-
async ({ chatId, limit }) => ({
|
|
56
|
-
content: [
|
|
57
|
-
{
|
|
58
|
-
type: "text" as const,
|
|
59
|
-
text: `Reading up to ${limit} messages from ${chatId} (not yet implemented)`,
|
|
60
|
-
},
|
|
61
|
-
],
|
|
62
|
-
}),
|
|
63
|
-
);
|
|
64
|
-
*/
|
|
65
|
-
//# sourceMappingURL=tools.js.map
|
package/dist/tools.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8DE"}
|