fix(telegram): gate native fetch to bun

This commit is contained in:
Peter Steinberger
2026-01-08 08:10:10 +01:00
parent c1e97fab80
commit c241cb25bd
5 changed files with 27 additions and 19 deletions

View File

@@ -1,6 +1,11 @@
// BAN compatibility: force native fetch to avoid grammY's node-fetch shim under Bun.
export function resolveTelegramFetch(proxyFetch?: typeof fetch): typeof fetch {
const fetchImpl = proxyFetch ?? globalThis.fetch;
// BAN compatibility: force native fetch under Bun; keep grammY defaults on Node.
export function resolveTelegramFetch(
proxyFetch?: typeof fetch,
): typeof fetch | undefined {
if (proxyFetch) return proxyFetch;
const isBun = "Bun" in globalThis || Boolean(process?.versions?.bun);
if (!isBun) return undefined;
const fetchImpl = globalThis.fetch;
if (!fetchImpl) {
throw new Error("fetch is not available; set telegram.proxy in config");
}