fix: normalize abort signals for telegram fetch

This commit is contained in:
Peter Steinberger
2026-01-21 16:46:49 +00:00
parent fb164b321e
commit 0e003cb7f1
7 changed files with 88 additions and 24 deletions

View File

@@ -1,11 +1,13 @@
import { wrapFetchWithAbortSignal } from "../infra/fetch.js";
// Bun-only: force native fetch to avoid grammY's Node shim under Bun.
export function resolveTelegramFetch(proxyFetch?: typeof fetch): typeof fetch | undefined {
if (proxyFetch) return proxyFetch;
if (proxyFetch) return wrapFetchWithAbortSignal(proxyFetch);
const fetchImpl = globalThis.fetch;
const isBun = "Bun" in globalThis || Boolean(process?.versions?.bun);
if (!isBun) return undefined;
if (!fetchImpl) {
throw new Error("fetch is not available; set channels.telegram.proxy in config");
}
return fetchImpl;
return wrapFetchWithAbortSignal(fetchImpl);
}