import { Evogram } from '../Client'; import { BusinessConnectionContext, BusinessMessagesDeletedContext, CallbackQueryContext, ChatJoinRequestContext, ChosenInlineResultContext, InlineQueryContext, MessageContext, PollAnswerContext, PollContext, ServiceMessage, ShippingQueryContext } from '../migrated'; import { Polling } from '../transports'; import { TelegramChatBoostRemoved, TelegramChatBoostUpdated, TelegramChatMemberUpdated, TelegramMessageReactionCountUpdated, TelegramMessageReactionUpdated, TelegramPreCheckoutQuery, TelegramUpdateType } from '../types'; export type UpdateHandler = (data: { context: T; client: Evogram; }) => any; export type UpdateHandlerMap = { [updateName in TelegramUpdateType]?: UpdateHandler[]; }; export declare class Updates { private client; constructor(client: Evogram); static handlers: UpdateHandlerMap; handlers: UpdateHandlerMap; polling: Polling; /** * Method for registering update handlers * @param {TelegramUpdateType} update Name of the update to be processed * @param {TelegramUpdateType} handler Callback function, which will be called on a new update * @return {Updates} Return this * * @example * client.updates.on("message", message => { * message.send("Hello, world!"); * }); */ on(update: 'message' | 'edited_message' | 'channel_post' | 'edited_channel_post' | 'business_message' | 'edited_business_message', handler: UpdateHandler): this; on(update: 'service_message', handler: UpdateHandler): this; on(update: 'business_connection', handler: UpdateHandler): this; on(update: 'deleted_business_messages', handler: UpdateHandler): this; on(update: 'message_reaction', handler: UpdateHandler): this; on(update: 'message_reaction_count', handler: UpdateHandler): this; on(update: 'inline_query', handler: UpdateHandler): this; on(update: 'chosen_inline_result', handler: UpdateHandler): this; on(update: 'callback_query', handler: UpdateHandler): this; on(update: 'shipping_query', handler: UpdateHandler): this; on(update: 'pre_checkout_query', handler: UpdateHandler): this; on(update: 'poll', handler: UpdateHandler): this; on(update: 'poll_answer', handler: UpdateHandler): this; on(update: 'my_chat_member' | 'chat_member', handler: UpdateHandler): this; on(update: 'chat_join_request', handler: UpdateHandler): this; on(update: 'chat_boost', handler: UpdateHandler): this; on(update: 'removed_chat_boost', handler: UpdateHandler): this; static on(update: TelegramUpdateType, handler: UpdateHandler): void; /** * Контролируемый метод once - выполняется только один раз, но останавливается по команде * @param {TelegramUpdateType} update Тип обновления для прослушивания * @param {Function} callback Функция-коллбэк, которая получает данные и метод остановки * @returns {Function} Функция для принудительной остановки (если коллбэк еще не выполнился) * * @example * const stopOnce = client.updates.onceControlled('message', (data, stop) => { * console.log('Получено сообщение:', data.context.text); * if (data.context.text === 'cancel') { * stop(); // Останавливаем коллбэк изнутри * } * }); * * // Можно принудительно остановить до выполнения * stopOnce(); */ onceControlled(update: TelegramUpdateType, callback: (data: any, stop: () => void) => void): () => void; /** * Вспомогательный метод для удаления обработчика * @private */ private removeHandler; }