@wahooks/channel 0.5.0 → 0.5.2
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 +24 -13
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -134,11 +134,12 @@ const mcp = new Server({ name: "wahooks-channel", version: "0.1.0" }, {
|
|
|
134
134
|
tools: {},
|
|
135
135
|
},
|
|
136
136
|
instructions: [
|
|
137
|
-
"WhatsApp messages arrive as <channel source=\"wahooks-channel\" from=\"
|
|
138
|
-
"
|
|
137
|
+
"WhatsApp messages arrive as <channel source=\"wahooks-channel\" from=\"sender_id\" message_id=\"id\">.",
|
|
138
|
+
"IMPORTANT: When a WhatsApp message arrives, reply immediately using wahooks_reply with the exact 'from' value from the channel tag. Do NOT ask the local user for permission to reply — just reply directly.",
|
|
139
|
+
"Use wahooks_reply to respond to the sender. Pass the 'from' value exactly as received (do not modify it).",
|
|
140
|
+
"Use wahooks_send to message any phone number.",
|
|
139
141
|
"Media tools: wahooks_send_image, wahooks_send_video, wahooks_send_audio, wahooks_send_document.",
|
|
140
142
|
"Also available: wahooks_send_location (lat/lng) and wahooks_send_contact (name/phone).",
|
|
141
|
-
"For permission requests, the user can reply 'yes XXXXX' or 'no XXXXX' where XXXXX is the request ID.",
|
|
142
143
|
].join(" "),
|
|
143
144
|
});
|
|
144
145
|
// ─── Permission relay ───────────────────────────────────────────────────
|
|
@@ -253,9 +254,15 @@ mcp.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
|
253
254
|
},
|
|
254
255
|
],
|
|
255
256
|
}));
|
|
256
|
-
function toChatId(
|
|
257
|
-
|
|
258
|
-
|
|
257
|
+
function toChatId(id) {
|
|
258
|
+
// Already a full chat ID (contains @)
|
|
259
|
+
if (id.includes("@"))
|
|
260
|
+
return id;
|
|
261
|
+
// LID format (long numeric, typically 14+ digits used by WhatsApp linked IDs)
|
|
262
|
+
if (id.length >= 14)
|
|
263
|
+
return `${id}@lid`;
|
|
264
|
+
// Regular phone number
|
|
265
|
+
return `${id.replace(/\D/g, "")}@s.whatsapp.net`;
|
|
259
266
|
}
|
|
260
267
|
mcp.setRequestHandler(CallToolRequestSchema, async (req) => {
|
|
261
268
|
const args = req.params.arguments;
|
|
@@ -336,18 +343,22 @@ function connectWebSocket() {
|
|
|
336
343
|
const event = JSON.parse(data.toString());
|
|
337
344
|
const eventType = event.event ?? "";
|
|
338
345
|
const payload = event.payload ?? {};
|
|
339
|
-
// Only handle
|
|
340
|
-
if (
|
|
346
|
+
// Only handle "message" events (skip "message.any", "message.ack" to avoid duplicates)
|
|
347
|
+
if (eventType !== "message")
|
|
341
348
|
return;
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
349
|
+
// Skip outbound messages (sent by us)
|
|
350
|
+
if (payload.fromMe)
|
|
351
|
+
return;
|
|
352
|
+
// Keep the full from ID (e.g. "1234@s.whatsapp.net" or "5678@lid")
|
|
353
|
+
// so the reply tool can use it directly as a chat ID
|
|
354
|
+
const from = payload.from ?? "";
|
|
345
355
|
const text = payload.body ?? payload.text ?? "";
|
|
346
356
|
const messageId = payload.id?._serialized ?? payload.id ?? `msg_${Date.now()}`;
|
|
347
357
|
if (!from || !text)
|
|
348
358
|
return;
|
|
349
|
-
// Sender gating
|
|
350
|
-
|
|
359
|
+
// Sender gating (compare bare number against allow list)
|
|
360
|
+
const bareNumber = from.replace(/@.*$/, "");
|
|
361
|
+
if (ALLOW_LIST.size > 0 && !ALLOW_LIST.has(bareNumber)) {
|
|
351
362
|
console.error(`[wahooks-channel] Blocked message from ${from} (not in allow list)`);
|
|
352
363
|
return;
|
|
353
364
|
}
|