telegramx.js

REST

class

Low-level transport to the Telegram Bot API. Handles auth, JSON vs. multipart bodies, file uploads (including nested attach:// references), timeouts, and 429 retries.

rest.api is a fully-typed proxy exposing every Bot API method — e.g. rest.api.sendMessage({ chat_id, text }).

Declaration

declare class REST 

Properties

apiproperty#
readonly api: ApiMethods;

Fully-typed access to every Bot API method.

optionsproperty#
readonly options: RESTOptions;

Methods

(constructor)constructor#
constructor(token: string, options?: Partial<RESTOptions>);

Constructs a new instance of the REST class

downloadmethod#
download(filePath: string): Promise<Buffer>;
ParameterType
filePathstring
Returns Promise<Buffer>

Download a file previously obtained via getFile. Returns the raw bytes. filePath is the file_path field of a Telegram File object.

requestmethod#
request<T = unknown>(method: string, params?: Record<string, unknown>): Promise<T>;
ParameterType
methodstring
params?Record<string, unknown>
Returns Promise<T>

Call a Bot API method by name with an optional params object.

setTokenmethod#
setToken(token: string): this;
ParameterType
tokenstring
Returns this

Update the bot token used for authentication.