diff --git a/bot/.dev.vars.example b/bot/.dev.vars.example index 9254570..dfff161 100644 --- a/bot/.dev.vars.example +++ b/bot/.dev.vars.example @@ -1,4 +1,5 @@ # Copy to .dev.vars and fill for local wrangler dev (D-15). NEVER commit .dev.vars. BOT_TOKEN= WEBHOOK_SECRET= +# Full origin + path; set-webhook.mjs auto-appends /telegram/webhook if only an origin is set. WEBHOOK_URL= diff --git a/bot/scripts/set-webhook.mjs b/bot/scripts/set-webhook.mjs index 0ed1821..3684648 100644 --- a/bot/scripts/set-webhook.mjs +++ b/bot/scripts/set-webhook.mjs @@ -11,6 +11,10 @@ * Inputs come from bot/.dev.vars (gitignored, D-15): BOT_TOKEN, * WEBHOOK_URL, WEBHOOK_SECRET. The bot token is never echoed — on failure * only the API's error_code/description are printed (T-02-04). + * WEBHOOK_URL is normalized: if the configured origin points at the + * workers.dev root (no path), /telegram/webhook is appended automatically — + * a bare origin passed the 2026-10-22 deploy walkthrough caused Telegram to + * answer ok but deliver nothing (updates routed to "/" → 404). * Exit 0 only when Telegram answers ok:true. */ import { readFileSync } from "node:fs"; @@ -49,8 +53,27 @@ if (missing.length > 0) { process.exit(1); } +// Auto-append the route path when the URL has none — prevents the recurring +// misconfiguration where a bare workers.dev origin is registered and the +// Worker answers ok:true but Telegram updates land on "/" (404, silent drop). +const WEBHOOK_ROUTE = "/telegram/webhook"; +let normalizedUrl; +try { + const parsed = new URL(webhookUrl); + if (parsed.pathname === "/" || parsed.pathname === "") { + parsed.pathname = WEBHOOK_ROUTE; + normalizedUrl = parsed.toString(); + console.log(`WEBHOOK_URL had no path — normalized to ...${WEBHOOK_ROUTE}`); + } else { + normalizedUrl = webhookUrl; + } +} catch { + console.error(`WEBHOOK_URL is not a valid URL — check bot/.dev.vars (value never echoed).`); + process.exit(1); +} + const payload = { - url: webhookUrl, + url: normalizedUrl, secret_token: secret, allowed_updates: ["message"], };