fix(telegram): Log bound port if ephemeral (0) is configured

This commit is contained in:
Harold Hunt
2026-02-26 08:29:06 -05:00
committed by Ayaan Zaidi
parent 840b768d97
commit 296210636d
2 changed files with 8 additions and 1 deletions

View File

@@ -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();
}

View File

@@ -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;