UNPKG

@gramio/files

Version:

Set of utils to work with files uploading to Telegram Bot API

33 lines (30 loc) 955 B
import { APIMethods, APIMethodParams } from '@gramio/types'; type MiddlewareContext = { [M in keyof APIMethods]: { method: M; params: APIMethodParams<M>; formData?: FormData; }; }[keyof APIMethods]; /** * Middleware that automatically detects file uploads in API params * and converts them to `FormData`, enabling `Blob`/`File` support for all media methods. * * @example * ```ts * import { Telegram } from "wrappergram"; * import { filesMiddleware } from "@gramio/files/middleware"; * import { MediaUpload } from "@gramio/files"; * * const telegram = new Telegram("BOT_TOKEN", { * middlewares: [filesMiddleware], * }); * * await telegram.api.sendPhoto({ * chat_id: 123, * photo: await MediaUpload.url("https://example.com/image.jpg"), * }); * ``` */ declare const filesMiddleware: (context: MiddlewareContext, next: () => Promise<unknown>) => Promise<unknown>; export { filesMiddleware };