From 4a7cfbcc7c3f79839f4d6ea70e424098b9cc5642 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 24 Nov 2025 14:43:50 +0100 Subject: [PATCH] Rename setup->up (alias kept) and keep process alive --- src/index.ts | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 35fd8972c..f6caade40 100644 --- a/src/index.ts +++ b/src/index.ts @@ -685,6 +685,11 @@ async function ensureFunnel(port: number) { console.error( "Failed to enable Tailscale Funnel. Is it allowed on your tailnet?", ); + console.error( + info( + "Tip: you can fall back to polling (no webhooks needed): `pnpm warelay poll --interval 5 --lookback 10`", + ), + ); if (globalVerbose) { if (stdout.trim()) console.error(chalk.gray(`stdout: ${stdout.trim()}`)); if (stderr.trim()) console.error(chalk.gray(`stderr: ${stderr.trim()}`)); @@ -801,6 +806,11 @@ async function updateWebhook( "Double-check your sender SID and credentials; you can set TWILIO_SENDER_SID to force a specific sender.", ), ); + console.error( + info( + "Tip: if webhooks are blocked, use polling instead: `pnpm warelay poll --interval 5 --lookback 10`", + ), + ); process.exit(1); } @@ -941,6 +951,36 @@ Examples: await monitor(intervalSeconds, lookbackMinutes); }); +program + .command("poll") + .description("Poll Twilio for inbound WhatsApp messages (non-webhook mode)") + .option("-i, --interval ", "Polling interval in seconds", "5") + .option("-l, --lookback ", "Initial lookback window in minutes", "5") + .option("--verbose", "Verbose logging during polling", false) + .addHelpText( + "after", + ` +Examples: + warelay poll # poll every 5s, look back 5 minutes + warelay poll --interval 2 --lookback 30 --verbose`, + ) + .action(async (opts) => { + setVerbose(Boolean(opts.verbose)); + const intervalSeconds = Number.parseInt(opts.interval, 10); + const lookbackMinutes = Number.parseInt(opts.lookback, 10); + + if (Number.isNaN(intervalSeconds) || intervalSeconds <= 0) { + console.error("Interval must be a positive integer"); + process.exit(1); + } + if (Number.isNaN(lookbackMinutes) || lookbackMinutes < 0) { + console.error("Lookback must be >= 0 minutes"); + process.exit(1); + } + + await monitor(intervalSeconds, lookbackMinutes); + }); + program .command("webhook") .description( @@ -998,9 +1038,9 @@ With Tailscale: }); program - .command("setup") + .command("up") .description( - "Auto-setup webhook + Tailscale Funnel + Twilio callback with sensible defaults", + "Bring up webhook + Tailscale Funnel + Twilio callback (default webhook mode)", ) .option("-p, --port ", "Port to listen on", "42873") .option("--path ", "Webhook path", "/webhook/whatsapp") @@ -1063,6 +1103,7 @@ program "\nSetup complete. Leave this process running to keep the webhook online. Ctrl+C to stop.", ); await waitForever(); - }); + }) + .alias("setup"); program.parseAsync(process.argv);