@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.
Files changed (2) hide show
  1. package/dist/index.js +24 -13
  2. 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=\"phone\" message_id=\"id\">.",
138
- "Use wahooks_reply to respond to the sender. Use wahooks_send to message any phone.",
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(phone) {
257
- const digits = phone.replace(/\D/g, "");
258
- return digits.includes("@") ? digits : `${digits}@s.whatsapp.net`;
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 incoming messages
340
- if (!eventType.startsWith("message"))
346
+ // Only handle "message" events (skip "message.any", "message.ack" to avoid duplicates)
347
+ if (eventType !== "message")
341
348
  return;
342
- const from = (payload.from ?? "")
343
- .replace("@c.us", "")
344
- .replace("@s.whatsapp.net", "");
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
- if (ALLOW_LIST.size > 0 && !ALLOW_LIST.has(from)) {
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wahooks/channel",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "WhatsApp channel for Claude Code — chat with Claude via WhatsApp",
5
5
  "type": "module",
6
6
  "bin": {