@wahooks/channel 0.4.1 → 0.5.1
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.js +7 -29
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -130,7 +130,6 @@ const mcp = new Server({ name: "wahooks-channel", version: "0.1.0" }, {
|
|
|
130
130
|
capabilities: {
|
|
131
131
|
experimental: {
|
|
132
132
|
"claude/channel": {},
|
|
133
|
-
"claude/channel/permission": {},
|
|
134
133
|
},
|
|
135
134
|
tools: {},
|
|
136
135
|
},
|
|
@@ -146,31 +145,6 @@ const mcp = new Server({ name: "wahooks-channel", version: "0.1.0" }, {
|
|
|
146
145
|
const PERMISSION_RE = /^\s*(y|yes|n|no)\s+([a-km-z]{5})\s*$/i;
|
|
147
146
|
// Track the last sender so we can forward permission requests
|
|
148
147
|
let lastSender = "";
|
|
149
|
-
// Listen for permission requests from Claude Code
|
|
150
|
-
const PermissionRequestSchema = {
|
|
151
|
-
method: "notifications/claude/channel/permission_request",
|
|
152
|
-
};
|
|
153
|
-
mcp.setNotificationHandler(PermissionRequestSchema, async (notification) => {
|
|
154
|
-
const params = notification.params;
|
|
155
|
-
if (!lastSender || !connectionId)
|
|
156
|
-
return;
|
|
157
|
-
// Forward the permission request to the WhatsApp user
|
|
158
|
-
const msg = [
|
|
159
|
-
`🔐 Claude wants to run: ${params.tool_name}`,
|
|
160
|
-
`${params.description}`,
|
|
161
|
-
``,
|
|
162
|
-
`Reply "yes ${params.request_id}" to allow or "no ${params.request_id}" to deny`,
|
|
163
|
-
].join("\n");
|
|
164
|
-
try {
|
|
165
|
-
await api("POST", `/connections/${connectionId}/send`, {
|
|
166
|
-
chatId: `${lastSender}@s.whatsapp.net`,
|
|
167
|
-
text: msg,
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
catch {
|
|
171
|
-
console.error("[wahooks-channel] Failed to forward permission request");
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
148
|
// ─── Tools ──────────────────────────────────────────────────────────────
|
|
175
149
|
mcp.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
176
150
|
tools: [
|
|
@@ -362,12 +336,16 @@ function connectWebSocket() {
|
|
|
362
336
|
const event = JSON.parse(data.toString());
|
|
363
337
|
const eventType = event.event ?? "";
|
|
364
338
|
const payload = event.payload ?? {};
|
|
365
|
-
// Only handle
|
|
366
|
-
if (
|
|
339
|
+
// Only handle "message" events (skip "message.any", "message.ack" to avoid duplicates)
|
|
340
|
+
if (eventType !== "message")
|
|
341
|
+
return;
|
|
342
|
+
// Skip outbound messages (sent by us)
|
|
343
|
+
if (payload.fromMe)
|
|
367
344
|
return;
|
|
368
345
|
const from = (payload.from ?? "")
|
|
369
346
|
.replace("@c.us", "")
|
|
370
|
-
.replace("@s.whatsapp.net", "")
|
|
347
|
+
.replace("@s.whatsapp.net", "")
|
|
348
|
+
.replace("@lid", "");
|
|
371
349
|
const text = payload.body ?? payload.text ?? "";
|
|
372
350
|
const messageId = payload.id?._serialized ?? payload.id ?? `msg_${Date.now()}`;
|
|
373
351
|
if (!from || !text)
|