@wahooks/channel 0.5.2 → 0.6.0

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 +28 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -353,8 +353,10 @@ function connectWebSocket() {
353
353
  // so the reply tool can use it directly as a chat ID
354
354
  const from = payload.from ?? "";
355
355
  const text = payload.body ?? payload.text ?? "";
356
+ const hasMedia = payload.hasMedia === true;
357
+ const media = payload.media;
356
358
  const messageId = payload.id?._serialized ?? payload.id ?? `msg_${Date.now()}`;
357
- if (!from || !text)
359
+ if (!from || (!text && !hasMedia))
358
360
  return;
359
361
  // Sender gating (compare bare number against allow list)
360
362
  const bareNumber = from.replace(/@.*$/, "");
@@ -377,18 +379,41 @@ function connectWebSocket() {
377
379
  console.error(`[wahooks-channel] Permission verdict: ${permMatch[1]} ${permMatch[2]}`);
378
380
  return;
379
381
  }
382
+ // Build message content for Claude
383
+ let content = text;
384
+ if (hasMedia && media?.url) {
385
+ // Download media and convert to base64 for Claude to see
386
+ try {
387
+ const mediaRes = await fetch(media.url, {
388
+ headers: { Authorization: `Bearer ${API_KEY}` },
389
+ });
390
+ if (mediaRes.ok) {
391
+ const buf = Buffer.from(await mediaRes.arrayBuffer());
392
+ const b64 = buf.toString("base64");
393
+ const mime = media.mimetype ?? "image/jpeg";
394
+ content = `${text ? text + "\n\n" : ""}[Media: ${mime}]\ndata:${mime};base64,${b64}`;
395
+ }
396
+ else {
397
+ content = `${text ? text + "\n\n" : ""}[Media attached but could not be downloaded: ${media.mimetype ?? "unknown type"}]`;
398
+ }
399
+ }
400
+ catch {
401
+ content = `${text ? text + "\n\n" : ""}[Media attached: ${media?.mimetype ?? "unknown type"}]`;
402
+ }
403
+ }
380
404
  // Forward to Claude Code
381
405
  await mcp.notification({
382
406
  method: "notifications/claude/channel",
383
407
  params: {
384
- content: text,
408
+ content,
385
409
  meta: {
386
410
  from,
387
411
  message_id: messageId,
412
+ ...(hasMedia ? { has_media: "true", media_type: media?.mimetype ?? "unknown" } : {}),
388
413
  },
389
414
  },
390
415
  });
391
- console.error(`[wahooks-channel] Message from ${from}: ${text.slice(0, 80)}`);
416
+ console.error(`[wahooks-channel] Message from ${from}: ${text.slice(0, 80)}${hasMedia ? " [+media]" : ""}`);
392
417
  }
393
418
  catch (err) {
394
419
  console.error("[wahooks-channel] Event parse error:", err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wahooks/channel",
3
- "version": "0.5.2",
3
+ "version": "0.6.0",
4
4
  "description": "WhatsApp channel for Claude Code — chat with Claude via WhatsApp",
5
5
  "type": "module",
6
6
  "bin": {