const isDeno = typeof Deno !== "undefined";
import { type InputFileProxy } from "https://esm.sh/@grammyjs/types@2.8.0";import { basename } from "https://deno.land/std@0.144.0/path/mod.ts";import { iterateReader } from "https://deno.land/std@0.144.0/streams/mod.ts";
export * from "https://esm.sh/@grammyjs/types@2.8.0";
import d from "https://cdn.skypack.dev/debug@4.3.4";export { d as debug };const DEBUG = "DEBUG";if (isDeno) { d.useColors = () => !Deno.noColor; const env = { name: "env", variable: DEBUG } as const; const res = await Deno.permissions.query(env); if (res.state === "granted") { const val = Deno.env.get(DEBUG); if (val) d.enable(val); }}const debug = d("grammy:warn");
export { readableStreamFromIterable as itrToStream } from "https://deno.land/std@0.144.0/streams/mod.ts";
export const baseFetchConfig = (_apiRoot: string) => ({});
interface URLLike { url: string;}
export const toRaw = Symbol("InputFile data");
export class InputFile { private consumed = false; private readonly fileData: ConstructorParameters<typeof InputFile>[0]; public readonly filename?: string; constructor( file: | string | Blob | Deno.FsFile | URL | URLLike | Uint8Array | ReadableStream<Uint8Array> | Iterable<Uint8Array> | AsyncIterable<Uint8Array>, filename?: string, ) { this.fileData = file; filename ??= this.guessFilename(file); this.filename = filename; if ( typeof file === "string" && (file.startsWith("http:") || file.startsWith("https:")) ) { debug( `InputFile received the local file path '${file}' that looks like a URL. Is this a mistake?`, ); } } private guessFilename( file: ConstructorParameters<typeof InputFile>[0], ): string | undefined { if (typeof file === "string") return basename(file); if (typeof file !== "object") return undefined; if ("url" in file) return basename(file.url); if (!(file instanceof URL)) return undefined; return basename(file.pathname) || basename(file.hostname); } async [toRaw](): Promise< Uint8Array | Iterable<Uint8Array> | AsyncIterable<Uint8Array> > { if (this.consumed) { throw new Error("Cannot reuse InputFile data source!"); } const data = this.fileData; if (typeof data === "string") { if (!isDeno) { throw new Error( "Reading files by path requires a Deno environment", ); } const file = await Deno.open(data); return iterateReader(file); } if (data instanceof Blob) return data.stream(); if (isDenoFile(data)) return iterateReader(data); if (data instanceof URL) return fetchFile(data); if ("url" in data) return fetchFile(data.url); if (!(data instanceof Uint8Array)) this.consumed = true; return data; }}
async function* fetchFile(url: string | URL): AsyncIterable<Uint8Array> { const { body } = await fetch(url instanceof URL ? url.href : url); if (body === null) { throw new Error(`Download failed, no response body from '${url}'`); } yield* body;}function isDenoFile(data: unknown): data is Deno.FsFile { return isDeno && data instanceof Deno.FsFile;}
type GrammyTypes = InputFileProxy<InputFile>;
export type Telegram = GrammyTypes["Telegram"];
export type Opts<M extends keyof GrammyTypes["Telegram"]> = GrammyTypes["Opts"][M];
export type InputMedia = GrammyTypes["InputMedia"];export type InputMediaPhoto = GrammyTypes["InputMediaPhoto"];export type InputMediaVideo = GrammyTypes["InputMediaVideo"];export type InputMediaAnimation = GrammyTypes["InputMediaAnimation"];export type InputMediaAudio = GrammyTypes["InputMediaAudio"];export type InputMediaDocument = GrammyTypes["InputMediaDocument"];