GramIO API Reference / @gramio/files/dist
@gramio/files/dist
Classes
| Class | Description |
|---|---|
| MediaInput | Class-helper with static methods that represents the content of a media message to be sent. |
| MediaUpload | Class-helper with static methods for file uploading. |
| TelegramFileDownload | Lazy, Response-like handle for downloading a Telegram file. |
Interfaces
| Interface | Description |
|---|---|
| FileDownloadBot | The minimal Bot-shaped object downloadFile needs. The GramIO Bot satisfies it structurally, so you just pass the instance — and a custom "without gramio" wrapper can pass any object of this shape. |
Type Aliases
| Type Alias | Description |
|---|---|
| DownloadFileInput | Anything downloadFile can turn into a file_id. |
| FileDownloadResolver | Lazily resolves the file metadata + where to read it from. |
| FileDownloadSource | A resolved file location used by TelegramFileDownload. |
| FileSource | Strategy for how downloadFile obtains file bytes — mainly relevant with a local Bot API server (--local), where getFile returns an absolute path on the server's disk instead of a URL. |
Variables
MEDIA_METHODS
constMEDIA_METHODS:MethodsWithMediaUpload
Defined in: files/index.d.ts:43
Methods which can carry Telegram file uploads.
Codegenerated
Functions
convertJsonToFormData()
convertJsonToFormData<
T>(method,params):Promise<FormData>
Defined in: files/index.d.ts:12
Helper to convert JSON to FormData that can accept Telegram Bot API. if File is not top-level property it will be “attach://<file_attach_name>”
Type Parameters
| Type Parameter |
|---|
T extends keyof APIMethods |
Parameters
| Parameter | Type |
|---|---|
method | T |
params | NonNullable<APIMethodParams<T>> |
Returns
Promise<FormData>
convertStreamToBuffer()
convertStreamToBuffer(
stream):Promise<Buffer<ArrayBufferLike>>
Defined in: files/index.d.ts:21
Helper for convert Readable stream to buffer
Parameters
| Parameter | Type |
|---|---|
stream | Readable |
Returns
Promise<Buffer<ArrayBufferLike>>
downloadFile()
Call Signature
downloadFile(
bot,attachment):TelegramFileDownload
Defined in: files/index.d.ts:282
Download a Telegram file. Returns a TelegramFileDownload handle (.bytes(), .text(), .json(), .blob(), .stream(), .toFile(), .link(), .info(); await it for an ArrayBuffer). Pass path to save straight to disk and get the path back.
Powers bot.downloadFile / context.download, and is re-exported from gramio so you can call it with a bot instance from anywhere.
Parameters
| Parameter | Type |
|---|---|
bot | FileDownloadBot |
attachment | DownloadFileInput |
Returns
Example
import { downloadFile } from "gramio";
const dl = downloadFile(bot, fileId);
await dl.toFile("./photo.jpg");
const text = await downloadFile(bot, fileId).text();Call Signature
downloadFile(
bot,attachment,path):Promise<string>
Defined in: files/index.d.ts:283
Download a Telegram file. Returns a TelegramFileDownload handle (.bytes(), .text(), .json(), .blob(), .stream(), .toFile(), .link(), .info(); await it for an ArrayBuffer). Pass path to save straight to disk and get the path back.
Powers bot.downloadFile / context.download, and is re-exported from gramio so you can call it with a bot instance from anywhere.
Parameters
| Parameter | Type |
|---|---|
bot | FileDownloadBot |
attachment | DownloadFileInput |
path | string |
Returns
Promise<string>
Example
import { downloadFile } from "gramio";
const dl = downloadFile(bot, fileId);
await dl.toFile("./photo.jpg");
const text = await downloadFile(bot, fileId).text();extractFilesToFormData()
extractFilesToFormData<
T>(method,params):Promise<[FormData,NonNullable<APIMethodParams<T>>]>
Defined in: files/index.d.ts:19
Helper to extract files from params and convert them to FormData. (Similar to convertJsonToFormData) if File is not top-level property it will be “attach://<file_attach_name>”
Type Parameters
| Type Parameter |
|---|
T extends keyof APIMethods |
Parameters
| Parameter | Type |
|---|---|
method | T |
params | NonNullable<APIMethodParams<T>> |
Returns
Promise<[FormData, NonNullable<APIMethodParams<T>>]>
isBlob()
isBlob(
blob?):boolean
Defined in: files/index.d.ts:41
Guard to check is it Blob or Promise.
Parameters
| Parameter | Type |
|---|---|
blob? | string | object | Blob |
Returns
boolean
isMediaUpload()
isMediaUpload<
T>(method,params):boolean
Defined in: files/index.d.ts:5
Guard to check is method used for File Uploading
Type Parameters
| Type Parameter |
|---|
T extends keyof APIMethods |
Parameters
| Parameter | Type |
|---|---|
method | T |
params | NonNullable<APIMethodParams<T>> |
Returns
boolean