UNPKG

nowjs-web-telegram-api

Version:

NowCanDo Javascript Web Telegram Api [nowjs-web-telegram-api] is a library written by TypeScript code maintains under Apache 2.0 licence

561 lines (560 loc) 15.5 kB
/// <reference types="node" /> /// <reference types="request-promise-native" /> import { EventEmitter } from "events"; import { Stream } from "stream"; import * as request from "request-promise-native"; export declare function timeout<T>(ms: number, err: string | Error): Promise<T>; declare global { interface Promise<T> { timeout<T>(ms: number, err?: string | Error): Promise<T>; } interface PromiseConstructor { timeout<T>(ms: number, err?: string | Error): Promise<T>; } } export declare type idType = number | string; export declare type fileType = string | Buffer | IInputFile; export interface IJsonResponse<T> { ok: boolean; description?: string; error_code?: string; parameters?: IResponseParameters; result?: T; } export interface IUpdate { update_id: number; message?: IMessage; edited_message?: IMessage; channel_post?: IMessage; edited_channel_post?: IMessage; inline_query: any; chosen_inline_result?: any; callback_query?: ICallbackQuery; } export interface IUser { id: number; first_name: string; last_name?: string; username?: string; } export interface IChat { id: number; type: "private" | "group" | "supergroup" | "channel"; title?: string; first_name?: string; last_name?: string; username?: string; all_members_are_administrators?: boolean; } export interface IMessage { message_id: number; from?: IUser; date: number; chat: IChat; forward_from?: IUser; forward_from_chat?: IChat; forward_from_message_id?: number; forward_date?: number; reply_to_message?: IMessage; edit_date?: number; text?: string; entities?: IMessageEntity[]; audio?: IAudio; video?: IVideo; game?: any; photo?: IPhotoSize[]; sticker?: ISticker; voice?: IVoice; contact: IContact; caption?: string; location?: ILocation; venue?: IVenue; new_chat_member?: IUser; left_chat_member?: IUser; new_chat_title?: string; new_chat_photo?: IPhotoSize[]; delete_chat_photo?: boolean; group_chat_created?: boolean; supergroup_chat_created?: boolean; channel_chat_created: boolean; migrate_to_chat_id: number; migrate_from_chat_id: number; pinned_message: IMessage; } export interface IMessageEntity { type: string; offset: number; length: number; url?: string; user?: IUser; } export interface IPhotoSize { file_id: string; width: number; height: number; file_size?: number; } export interface IAudio { file_id: string; duration: number; performer?: string; title?: string; mime_type?: string; file_size?: number; } export interface IDocument { file_id: string; thumb?: IPhotoSize; file_name?: string; mime_type?: string; file_size?: number; } export interface IDocument { file_id: string; thumb?: IPhotoSize; file_name?: string; mime_type?: string; file_size?: number; } export interface ISticker { file_id: string; width: number; height: number; thumb?: IPhotoSize; emoji?: string; file_size?: number; } export interface IVideo { file_id: string; width: number; height: number; duration: number; thumb?: IPhotoSize; mime_type?: string; file_size?: number; } export interface IVoice { file_id: string; duration: number; mime_type?: string; file_size?: number; } export interface IContact { phone_number: string; first_name: string; last_name?: string; user_id?: number; } export interface ILocation { longitude: number; latitude: number; } export interface IVenue { location: ILocation; title: string; address: string; foursquare_id?: number; } export interface IUserProfilePhotos { total_count: number; photos: IPhotoSize[]; } export interface IGame { title: string; description: string; photo: IPhotoSize[]; text?: string; text_entities?: IMessageEntity[]; animation?: IAnimation; } export interface IAnimation { file_id: string; thumb: IPhotoSize; file_name?: string; mime_type?: string; file_size?: number; } export interface ICallbackGame { file_id: string; thumb: IPhotoSize; file_name?: string; mime_type?: string; file_size?: number; } export interface IGameHighScore { position: number; user: IUser; score: number; } export interface IFile { file_id: number; file_size?: number; file_path?: string; } export interface IReplyKeyboardMarkup { keyboard: IKeyboardButton[]; resize_keyboard?: boolean; one_time_keyboard?: boolean; selective?: boolean; } export interface IKeyboardButton { text: string; request_contact?: boolean; request_location?: boolean; } export interface IReplyKeyboardRemove { remove_keyboard: boolean; selective?: boolean; } export interface IInlineKeyboardMarkup { inline_keyboard: IInlineKeyboardButton[]; } export interface IInlineKeyboardButton { text: string; url?: string; callback_data?: string; switch_inline_query?: string; switch_inline_query_current_chat?: string; callback_game?: any; } export interface ICallbackQuery { id: string; from: IUser; message?: IMessage; inline_message_id?: string; chat_instance?: string; data?: string; game_short_name?: string; } export interface IForceReply { force_reply: boolean; selective?: boolean; } export interface IChatMember { user: IUser; status: "creator" | "administrator" | "member" | "left" | "kicked"; } export interface IResponseParameters { migrate_to_chat_id: number; retry_after: number; } export interface IInputFile extends Stream { } export interface ISendMessageOptions { chat_id: idType; text: string; parse_mode?: "HTML" | "MARKDOWN"; disable_web_page_preview?: boolean; disable_notification?: boolean; reply_to_message_id?: number; reply_markup?: string; } export interface IForwardMessageOptions { chat_id: idType; from_chat_id: idType; disable_notification?: boolean; message_id: number; } export interface ISendPhotoOptions { chat_id: idType; photo: fileType; caption?: string; disable_notification?: boolean; reply_to_message_id?: number; reply_markup?: string; } export interface ISendAudioOptions { chat_id: idType; audio: fileType; caption?: string; duration?: number; performer?: string; title?: string; disable_notification?: boolean; reply_to_message_id?: number; reply_markup?: string; } export interface ISendDocumentOptions { chat_id: idType; document: fileType; caption?: string; disable_notification?: boolean; reply_to_message_id?: number; reply_markup?: string; } export interface ISendStickerOptions { chat_id: idType; sticker: fileType; disable_notification?: boolean; reply_to_message_id?: number; reply_markup?: string; } export interface ISendVideoOptions { chat_id: idType; video: fileType; caption?: string; duration?: number; width?: number; height?: number; disable_notification?: boolean; reply_to_message_id?: number; reply_markup?: string; } export interface ISendVoiceOptions { chat_id: idType; voice: fileType; caption?: string; duration?: number; disable_notification?: boolean; reply_to_message_id?: number; reply_markup?: string; } export interface ISendLocationOptions { chat_id: idType; latitude: number; longitude: number; disable_notification?: boolean; reply_to_message_id?: number; reply_markup?: string; } export interface ISendVenueOptions { chat_id: idType; latitude: number; longitude: number; title: string; address: string; foursquare_id?: string; disable_notification?: boolean; reply_to_message_id?: number; reply_markup?: string; } export interface ISendContactOptions { chat_id: idType; phone_number: string; first_name: string; last_name?: string; disable_notification?: boolean; reply_to_message_id?: number; reply_markup?: string; } export interface ISendGameOptions { chat_id: idType; game_short_name: string; disable_notification?: boolean; reply_to_message_id?: number; reply_markup?: string; } export interface ISendChatActionOptions { chat_id: idType; action: string; } export interface IGetUserProfilePhotos { user_id: number; } export interface IGetFileOptions { file_id: string; } export interface IKickChatMemberOptions { chat_id: idType; user_id: number; } export interface ILeaveChatOptions { chat_id: idType; } export interface IUnBanChatMemberOptions { chat_id: idType; user_id: number; } export interface IGetChatOptions { chat_id: idType; } export interface IGetChatAdministratorsOptions { chat_id: idType; } export interface IGetChatMembersCountOptions { chat_id: idType; } export interface IGetChatMemberOptions { chat_id: idType; user_id: number; } export interface IAnswerCallbackQueryOptions { callback_query_id: string; text?: string; show_alert?: boolean; url?: string; cache_time?: number; } export interface IEditMessageTextOptions { chat_id: idType; message_id?: number; inline_message_id?: string; text?: string; parse_mode?: "HTML" | "MARKDOWN"; disable_web_page_preview?: boolean; reply_markup?: string; } export interface IEditMessageCaptionOptions { chat_id: idType; message_id?: number; inline_message_id?: string; caption?: string; reply_markup?: string; } export interface IEditMessageReplyMarkupOptions { chat_id: idType; message_id?: number; inline_message_id?: string; reply_markup?: string; } export interface ISetGameScoreOptions { user_id: number; score: number; force?: boolean; disable_edit_message?: boolean; chat_id?: number; message_id?: number; inline_message_id?: string; } export interface IGetGameHighScoresOptions { user_id: number; chat_id?: number; message_id?: number; inline_message_id?: string; } export interface IGetUpdatesOptions { offset?: number; limit?: number; timeout?: number; } export interface ISetWebhookOptions { url?: string; certificate?: IInputFile; } export interface IWebhookInfo { url: string; has_custom_certificate: boolean; pending_update_count: number; last_error_date?: number; last_error_message?: string; } export interface IAnswerInlineQueryOptions { inline_query_id: string; results?: any[]; cache_time?: number; is_personal?: boolean; next_offset?: string; switch_pm_text?: string; switch_pm_parameter?: string; } export interface TelegramBotApiOptions { token: string; onlyFirstMatch?: boolean; request?: request.RequestPromiseOptions; proxy?: { host: string; port?: number; username?: string; password?: string; https?: boolean; }; webhook?: { enabled: boolean; key: string; cert: string; }; polling?: { enabled: boolean; interval?: number; timeout?: number; }; } export declare class TelegramBotPolling { private token; private callback; private offset; private timeout; private limit; private interval; private lastUpdate; lastRequest: Promise<any>; abort: boolean; constructor(token: string, options: any, callback: Function); stopPolling(): Promise<any>; _polling(): void; _safeParse(json: string): any; _unsetWebHook(): Promise<any>; _getUpdates(): Promise<any>; } export declare class TelegramBotWebHook { private token; private callback; private regex; private _webServer; constructor(token: string, options: any, callback: Function); _safeParse(json: string): any; _parseBody: (err: any, body: any) => any; _requestListener: (req: any, res: any) => void; } export declare class TelegramBot extends EventEmitter { private textRegexpCallbacks; private onReplyToMessages; private onCommands; private onEvents; private _options; private _botUser; private _isRunning; private _baseurl; private _WebHook; private _polling; constructor(options: TelegramBotApiOptions); static readonly MessageTypes: string[]; private initPolling(); private stopPolling(); private safeParse(json); private fixReplyMarkup(obj); private formatSendData(type, data); private makeRequest<T>(urlpath, options?); protected processUpdate(update: IUpdate): void; private initBot(); start(): Promise<boolean>; stop(): Promise<boolean>; getUpdates(options: IGetUpdatesOptions): Promise<IUpdate[]>; setWebhook(options: ISetWebhookOptions): Promise<boolean>; getWebhookInfo(): Promise<IWebhookInfo>; getMe(): Promise<IUser>; sendMessage(options: ISendMessageOptions): Promise<IMessage>; forwardMessage(options: IForwardMessageOptions): Promise<IMessage>; sendPhoto(options: ISendPhotoOptions): Promise<IMessage>; sendAudio(options: ISendAudioOptions): Promise<IMessage>; sendDocument(options: ISendDocumentOptions, fileOpts: any): Promise<IMessage>; sendSticker(options: ISendStickerOptions): Promise<IMessage>; sendVideo(options: ISendVideoOptions): Promise<IMessage>; sendVoice(options: ISendVoiceOptions): Promise<IMessage>; sendLocation(options: ISendLocationOptions): Promise<IMessage>; sendVenue(options: ISendVenueOptions): Promise<IMessage>; sendContact(options: ISendContactOptions): Promise<IMessage>; sendChatAction(options: ISendChatActionOptions): Promise<boolean>; getUserProfilePhotos(options: IGetUserProfilePhotos): Promise<IUserProfilePhotos>; getFile(options: IGetFileOptions): Promise<IFile>; getFileLink(fileId: string): Promise<string>; downloadFile(fileId: string, downloadDir: string): void; kickChatMember(options: IKickChatMemberOptions): Promise<boolean>; leaveChat(options: ILeaveChatOptions): Promise<boolean>; unbanChatMember(options: IUnBanChatMemberOptions): Promise<boolean>; getChat(options: IGetChatOptions): Promise<IChat>; getChatAdministrators(options: IGetChatAdministratorsOptions): Promise<IChat>; getChatMembersCount(options: IGetChatMembersCountOptions): Promise<number>; getChatMember(options: IGetChatMemberOptions): Promise<IChatMember>; answerCallbackQuery(options: IAnswerCallbackQueryOptions): Promise<boolean>; editMessageText(options: IEditMessageTextOptions): Promise<boolean | IMessage>; editMessageCaption(options: IEditMessageCaptionOptions): Promise<boolean | IMessage>; editMessageReplyMarkup(options: IEditMessageReplyMarkupOptions): Promise<boolean | IMessage>; sendGame(options: ISendGameOptions): Promise<IMessage>; setGameScore(options: ISetGameScoreOptions): Promise<boolean | IMessage>; getGameHighScores(options: IGetGameHighScoresOptions): Promise<IGameHighScore[]>; answerInlineQuery(options: IAnswerInlineQueryOptions): Promise<any>; onText(command: RegExp | string): Promise<IMessage>; onCommand<T>(command: RegExp | string): Promise<T>; onReplyToMessage(chatId: number, messageId: number, callback: Function): void; }