From 296210636d89ad2987fe34b69b2f1ee063c8fe80 Mon Sep 17 00:00:00 2001 From: Harold Hunt Date: Thu, 26 Feb 2026 08:29:06 -0500 Subject: [PATCH] fix(telegram): Log bound port if ephemeral (0) is configured --- src/telegram/webhook.test.ts | 5 +++++ src/telegram/webhook.ts | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/telegram/webhook.test.ts b/src/telegram/webhook.test.ts index c3de0df5b60..80d25428011 100644 --- a/src/telegram/webhook.test.ts +++ b/src/telegram/webhook.test.ts @@ -304,6 +304,7 @@ describe("startTelegramWebhook", () => { it("registers webhook using the bound listening port when port is 0", async () => { setWebhookSpy.mockClear(); + const runtimeLog = vi.fn(); const abort = new AbortController(); const { server } = await startTelegramWebhook({ token: "tok", @@ -311,6 +312,7 @@ describe("startTelegramWebhook", () => { port: 0, abortSignal: abort.signal, path: "/hook", + runtime: { log: runtimeLog, error: vi.fn(), exit: vi.fn() }, }); try { const addr = server.address(); @@ -325,6 +327,9 @@ describe("startTelegramWebhook", () => { secret_token: "secret", }), ); + expect(runtimeLog).toHaveBeenCalledWith( + `webhook local listener on http://127.0.0.1:${addr.port}/hook`, + ); } finally { abort.abort(); } diff --git a/src/telegram/webhook.ts b/src/telegram/webhook.ts index bb48f6c09eb..a55720102dd 100644 --- a/src/telegram/webhook.ts +++ b/src/telegram/webhook.ts @@ -222,6 +222,8 @@ export async function startTelegramWebhook(opts: { port, host, }); + const boundAddress = server.address(); + const boundPort = boundAddress && typeof boundAddress !== "string" ? boundAddress.port : port; const publicUrl = resolveWebhookPublicUrl({ configuredPublicUrl: opts.publicUrl, @@ -250,7 +252,7 @@ export async function startTelegramWebhook(opts: { throw err; } - runtime.log?.(`webhook local listener on http://${host}:${port}${path}`); + runtime.log?.(`webhook local listener on http://${host}:${boundPort}${path}`); runtime.log?.(`webhook advertised to telegram on ${publicUrl}`); let shutDown = false;