2026-01-21 17:29:39 +00:00
|
|
|
import { resolveFetch } from "../infra/fetch.js";
|
2026-01-21 16:46:49 +00:00
|
|
|
|
2026-01-08 10:31:16 +01:00
|
|
|
// Bun-only: force native fetch to avoid grammY's Node shim under Bun.
|
2026-01-14 14:31:43 +00:00
|
|
|
export function resolveTelegramFetch(proxyFetch?: typeof fetch): typeof fetch | undefined {
|
2026-01-21 17:29:39 +00:00
|
|
|
if (proxyFetch) return resolveFetch(proxyFetch);
|
2026-01-08 08:39:55 +01:00
|
|
|
const isBun = "Bun" in globalThis || Boolean(process?.versions?.bun);
|
2026-01-08 10:31:16 +01:00
|
|
|
if (!isBun) return undefined;
|
2026-01-21 17:29:39 +00:00
|
|
|
const fetchImpl = resolveFetch();
|
2026-01-08 04:40:29 +01:00
|
|
|
if (!fetchImpl) {
|
2026-01-14 14:31:43 +00:00
|
|
|
throw new Error("fetch is not available; set channels.telegram.proxy in config");
|
2026-01-08 04:40:29 +01:00
|
|
|
}
|
2026-01-21 17:29:39 +00:00
|
|
|
return fetchImpl;
|
2026-01-08 04:40:29 +01:00
|
|
|
}
|