import * as http from "node:http"; import * as https from "node:https"; import { Collection, type ReadonlyCollection } from "@telegram.ts/collection"; import { ApiMethods as Methods, Chat as ApiChat, User as ApiUser, ParseMode, Update, } from "@telegram.ts/types"; import { BodyInit, Headers, HeadersInit, RequestInit, Response, } from "node-fetch"; import { Blob, Buffer } from "node:buffer"; import { EventEmitter } from "node:events"; import { ReadStream } from "node:fs"; import { IncomingMessage, RequestListener, ServerResponse } from "node:http"; import { Agent } from "node:https"; import { Stream } from "node:stream"; import { TlsOptions } from "node:tls"; import { SandwichStream } from "sandwich-stream"; import { PassportElementError, MessageEntity, ReplyParameters, InlineKeyboardMarkup, KeyboardButton, KeyboardButtonPollType, KeyboardButtonRequestChat, KeyboardButtonRequestUsers, KeyboardButtonRequestManagedBot, SwitchInlineQueryChosenChat, BotCommandScope, BotCommand, WebAppInfo, InlineQueryResult, InputPollOption, InputPaidMedia, InputMedia, LoginUrl, ApiMethods, ShippingOption, LabeledPrice, ForceReply, ReplyKeyboardRemove, ReplyKeyboardMarkup, CopyTextButton, InputMediaVideo, InputMediaPhoto, InputMediaDocument, InputMediaLivePhoto, InputMediaAudio, InlineKeyboardButton, InlineQueryResultsButton, LanguageCode, InputContactMessageContent, InputInvoiceMessageContent, InputLocationMessageContent, InputTextMessageContent, InputVenueMessageContent, InputRichMessageContent, InlineQueryResultCachedAudio, InlineQueryResultCachedDocument, InlineQueryResultCachedGif, InlineQueryResultCachedMpeg4Gif, InlineQueryResultCachedPhoto, InlineQueryResultCachedSticker, InlineQueryResultCachedVideo, InlineQueryResultCachedVoice, InlineQueryResultArticle, InlineQueryResultAudio, InlineQueryResultContact, InlineQueryResultDocument, InlineQueryResultGame, InlineQueryResultGif, InlineQueryResultLocation, InlineQueryResultMpeg4Gif, InlineQueryResultPhoto, InlineQueryResultVenue, InlineQueryResultVideo, InlineQueryResultVoice, InputMessageContent, MediaDataParam, InputStoryContent, SuggestedPostParameters, InputChecklist, InputProfilePhoto, InputRichMessage, } from "./telegram/index"; /** * Type representing the string literals for chat permissions. */ export type ChatPermissionString = | "isAnonymous" | "editTag" | "sendMessages" | "sendAudios" | "sendDocuments" | "sendPhotos" | "sendVideos" | "sendVideoNotes" | "sendVoiceNotes" | "sendPolls" | "sendOtherMessages" | "addWebPagePreviews" | "changeInfo" | "inviteUsers" | "pinMessages" | "manageTopics" | "manageTags" | "reactToMessages" | "manageDirectMessages" | "welcomeMessages"; /** * Interface representing the chat permission flags. */ export interface ChatPermissionFlags { isAnonymous?: boolean; editTag?: boolean; sendMessages?: boolean; sendAudios?: boolean; sendDocuments?: boolean; sendPhotos?: boolean; sendVideos?: boolean; sendVideoNotes?: boolean; sendVoiceNotes?: boolean; sendPolls?: boolean; sendOtherMessages?: boolean; addWebPagePreviews?: boolean; changeInfo?: boolean; inviteUsers?: boolean; pinMessages?: boolean; manageTopics?: boolean; manageTags?: boolean; reactToMessages?: boolean; manageDirectMessages?: boolean; welcomeMessages?: boolean; } /** * Represents a set of chat permissions and provides methods to manage them. */ export declare class ChatPermissions extends PermissionManager< ChatPermissionString, ChatPermissionFlags > { /** * Constructs a new instance of ChatPermissions with optional initial data. * @param data - An object containing the initial permissions. */ constructor(data?: ChatPermissionFlags); /** * Checks if the provided permission is valid. * @param permission - The permission to validate. * @returns `true` if the permission is valid, otherwise `false`. */ static isValid(permission: string): boolean; /** * A mapping of chat permission strings to their numeric equivalents. */ static Flags: Record; } /** * Type representing a value that can be resolved to chat permissions. */ export type ChatPermissionResolvable = ChatPermissionString | ChatPermissionFlags | ChatPermissions; /** * A class representing a multipart stream for composing HTTP multipart requests. * Extends SandwichStream. */ export declare class MultipartStream extends SandwichStream { /** * Constructs a new MultipartStream instance with the specified boundary. * @param boundary - The boundary string used to separate parts in the multipart stream. */ constructor(boundary: string); /** * Adds a part to the multipart stream with optional headers and body. * @param part - An object representing the part to add to the multipart stream. * May include headers and body. */ addPart(part?: { headers?: { [key: string]: string; }; body?: any; }): void; /** * Checks if the provided object is a stream. * @param stream - The object to check. * @returns A boolean indicating whether the object is a stream. */ static isStream(stream: any): stream is Stream; } /** * Interface representing the configuration for an API request. */ export interface IApiConfig { method: string; compress: boolean; headers: HeadersInit; body: MultipartStream | BodyInit; agent?: RequestInit["agent"]; } /** * A class for handling media data and preparing configuration for API requests. */ export declare class MediaData { /** * Mapping of media type extensions. */ readonly extensions: Record; /** * Fields in the form data that should be JSON-encoded. */ readonly formDataJsonFields: string[]; /** * Parameters that can contain media data. */ readonly sourceParametersMedia: string[]; /** * Checks if the given value is a media-related object. * This function determines if the provided value is an object associated with media data types such as Buffer, ArrayBuffer, Blob, FormData, Uint8Array, or DataView. * * @param value - The value to check. * @returns `true` if the value is a media-related object; otherwise, `false`. */ isMediaType(value: any): boolean; /** * Checks if the payload contains media data. * @param payload - The data to check. * @returns `true` if media is found, otherwise `false`. */ hasMedia(payload: Record): boolean; /** * Builds the configuration for a JSON request. * @param payload - The data to be sent in the request. * @param requestOptions - Additional options for the request. * @returns The configuration for the request. */ buildJSONConfig( payload: Record, requestOptions?: RequestInit, ): IApiConfig; /** * Builds the configuration for a form-data request. * @param apiPayload - The data to be sent in the request. * @param requestOptions - Additional options for the request. * @returns The configuration for the request. */ buildFormDataConfig( apiPayload: Record, requestOptions?: RequestInit, ): Promise; /** * Attaches a value to the form data. * @param form - The form to which the value should be attached. * @param id - The name of the form field. * @param value - The value to attach to the form. * @param agent - The agent to use for fetching external resources. */ attachFormValue( form: MultipartStream, id: string, value: any, agent: RequestInit["agent"], ): Promise; /** * Attaches media to the form data. * @param form - The form to which the media should be attached. * @param media - The media to attach, can be a string path, buffer, or read stream. * @param options - The options of the form field. */ attachFormMedia( form: MultipartStream, media: string | Buffer | ReadStream, options: { id: string; filename?: string }, ): Promise; } export interface IRateLimitData { /** The API method of this request */ method: keyof ApiMethods; /** In case of exceeding flood control, the number of seconds left to wait before the request can be repeated */ retryAfter?: number; /** The group has been migrated to a supergroup with the specified identifier */ migrateToChatId?: string; } export interface IRestEventHandlers { rateLimit: (rateLimitData: IRateLimitData) => PossiblyAsync; apiRequest: (method: string, options: RequestInit) => PossiblyAsync; apiResponse: ( method: string, response: IRequestSuccess | IRequestFailt, ) => PossiblyAsync; } export type IRestOptions = { enableRateLimit?: boolean; } & Omit; /** * Handles API requests to the Telegram Bot API. */ export declare class Rest extends EventEmitter { readonly options?: IRestOptions; media: MediaData; /** * @param authToken - The authentication token for the Telegram Bot API. * @param requestOptions - Options for the fetch request. */ constructor(authToken: string, requestOptions?: IRestOptions); /** * Adds a typed listener for the specified event. * @param event - The event name. * @param listener - The listener function. * @returns The Rest instance. */ on( event: T, listener: IRestEventHandlers[T], ): this; /** * Adds a typed one-time listener for the specified event. * @param event - The event name. * @param listener - The listener function. * @returns The Rest instance. */ once( event: T, listener: IRestEventHandlers[T], ): this; /** * Prepares the configuration for the fetch request based on the provided options. * @param options - The options to include in the request. * @returns The configuration for the fetch request. */ transferDataToServer(options: Record): Promise; /** * Makes a request to the Telegram Bot API. * Handles rate limits and retries the request if necessary. * @param method - The API method to call. * @param options - The options to include in the request. * @returns The result from the API response. * @throws {HTTPResponseError} If the API response indicates an error. */ request( method: keyof ApiMethods, options?: Record, ): Promise; } export declare class InputFile extends Base { /** * @param client - The client that instantiated this * @param data - Data about the file object from the Telegram API */ constructor( client: TelegramClient | BaseClient, data: import("@telegram.ts/types").File, ); /** * The unique identifier for this file */ id: string; /** * The unique identifier for this file, which is supposed to be consistent across different bots */ uniqueId: string; /** * The size of the file in bytes, if available */ size: number | null; /** * The path to the file on the Telegram server, if available */ path: string | null; /** * Gets the URL to access the file on the Telegram server. */ get url(): string | null; /** * Fetch about the file */ fetch(): Promise; /** * Downloads the file from the Telegram server. * @returns A promise that resolves with the file data as a Buffer. */ download(): Promise; /** * Writes the file to the specified path. * @param path - The path where the file should be written. * @param writeType - The type of write operation. * @param options - Additional options for writing the file. * @returns A promise that resolves when the file has been written. */ write( path: string, writeType?: "promise", options?: { encoding?: BufferEncoding; flag?: string; signal?: AbortSignal; }, ): Promise; /** * Writes the file to the specified path. * @param path - The path where the file should be written. * @param writeType - The type of write operation. * @param options - Additional options for writing the file. * @returns A promise that resolves when the file has been written. */ write( path: string, writeType: "stream", options?: { encoding?: BufferEncoding; autoClose?: boolean; emitClose?: boolean; start?: number; highWaterMark?: number; flush?: boolean; }, ): Promise; /** * Writes the file to the specified path. * @param path - The path where the file should be written. * @param writeType - The type of write operation. * @param options - Additional options for writing the file. * @returns A promise that resolves when the file has been written. */ write( path: string, writeType?: "promise" | "stream", options?: undefined, ): Promise; } export declare class Photo extends InputFile { /** * @param client - The client that instantiated this * @param data - Data about the represents one size of a photo or a file / sticker thumbnail */ constructor( client: TelegramClient | BaseClient, data: import("@telegram.ts/types").PhotoSize, ); /** Photo width */ width: number; /** Photo height */ height: number; } export declare class UserProfileAudios extends Base { /** * @param client - The client that instantiated this * @param data - Data about the audios displayed on a user's profile */ constructor( client: TelegramClient | BaseClient, data: import("@telegram.ts/types").UserProfileAudios, ); /** Total number of profile audios for the target user */ count: number; /** Requested profile audios */ audios: Collection; /** * Makes the class iterable, returning each `Audio` object. */ [Symbol.iterator](): IterableIterator