@wahooks/channel 2.1.3 → 2.2.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 +50 -14
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -729,25 +729,61 @@ async function main() {
729
729
  claudeConnected = true;
730
730
  // Connect to real-time event stream
731
731
  connectWebSocket();
732
- // Process any pending reminders immediately
733
- await processPendingQueue();
734
- // Watch pending.json for changes (daemon writes to it)
732
+ // Process pending reminders via polling
735
733
  fs.mkdirSync(WAHOOKS_DIR, { recursive: true });
736
- // Ensure file exists for watching
737
734
  if (!fs.existsSync(PENDING_FILE)) {
738
735
  fs.writeFileSync(PENDING_FILE, "[]", { mode: 0o600 });
739
736
  }
740
- // Use both fs.watch and polling for robustness
741
- try {
742
- fs.watch(PENDING_FILE, () => {
743
- setTimeout(() => processPendingQueue(), 500); // debounce
744
- });
745
- }
746
- catch {
747
- // fs.watch not supported — fall back to polling only
737
+ async function pollPending() {
738
+ if (!claudeConnected)
739
+ return;
740
+ let pending;
741
+ try {
742
+ const raw = fs.readFileSync(PENDING_FILE, "utf-8");
743
+ pending = JSON.parse(raw);
744
+ }
745
+ catch {
746
+ return;
747
+ }
748
+ if (!pending || pending.length === 0)
749
+ return;
750
+ // Prune stale (>24h)
751
+ const cutoff = new Date(Date.now() - 24 * 60 * 60 * 1000);
752
+ const active = pending.filter((p) => new Date(p.addedAt) > cutoff);
753
+ if (active.length === 0) {
754
+ fs.writeFileSync(PENDING_FILE, "[]", { mode: 0o600 });
755
+ return;
756
+ }
757
+ console.error(`[wahooks-channel] Found ${active.length} pending reminder(s), delivering...`);
758
+ for (const item of active) {
759
+ console.error(`[wahooks-channel] Delivering: ${item.reminderId}`);
760
+ try {
761
+ await mcp.notification({
762
+ method: "notifications/claude/channel",
763
+ params: {
764
+ content: `[Scheduled Reminder] ${item.task}\n\nTarget chat: ${item.chatId}\nScheduled for: ${item.scheduledFor}\n\nPlease execute this task now and send the results to the target chat using wahooks_reply.`,
765
+ meta: {
766
+ from: item.chatId,
767
+ reminder_id: item.reminderId,
768
+ },
769
+ },
770
+ });
771
+ console.error(`[wahooks-channel] Delivered: ${item.reminderId}`);
772
+ }
773
+ catch (err) {
774
+ console.error(`[wahooks-channel] Delivery failed: ${err}`);
775
+ claudeConnected = false;
776
+ return;
777
+ }
778
+ }
779
+ // Clear queue after all delivered
780
+ fs.writeFileSync(PENDING_FILE, "[]", { mode: 0o600 });
781
+ console.error("[wahooks-channel] Pending queue cleared");
748
782
  }
749
- // Poll every 10s as fallback
750
- setInterval(() => processPendingQueue(), 10_000);
783
+ // Poll every 10s
784
+ setInterval(pollPending, 10_000);
785
+ // Also run once after 3s
786
+ setTimeout(pollPending, 3000);
751
787
  console.error("[wahooks-channel] Ready — WhatsApp messages will appear in Claude Code");
752
788
  }
753
789
  main().catch((err) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wahooks/channel",
3
- "version": "2.1.3",
3
+ "version": "2.2.0",
4
4
  "description": "WhatsApp channel for Claude Code — chat with Claude via WhatsApp",
5
5
  "type": "module",
6
6
  "bin": {