/**
 * Telegram Service
 *
 * Core service for Telegram Bot API integration with long-polling
 * for incoming messages. Manages bot lifecycle, incoming message
 * polling, and outgoing message delivery.
 *
 * @module services/telegram/telegram
 */
import { EventEmitter } from 'events';
import type { TelegramConfig } from './telegram-credentials.service.js';
/**
 * Telegram Bot API Update object (simplified).
 */
export interface TelegramUpdate {
    /** Unique update identifier */
    update_id: number;
    /** Incoming message (present when a text message is received) */
    message?: TelegramMessage;
}
/**
 * Telegram Bot API Message object (simplified).
 */
export interface TelegramMessage {
    /** Unique message identifier */
    message_id: number;
    /** Sender information */
    from?: {
        id: number;
        is_bot: boolean;
        first_name: string;
        last_name?: string;
        username?: string;
    };
    /** Chat information */
    chat: {
        id: number;
        type: 'private' | 'group' | 'supergroup' | 'channel';
        title?: string;
        first_name?: string;
        last_name?: string;
        username?: string;
    };
    /** Date the message was sent (Unix timestamp) */
    date: number;
    /** Message text */
    text?: string;
    /** If the message is a reply, the original message */
    reply_to_message?: TelegramMessage;
}
/**
 * Incoming message event payload emitted by TelegramService.
 */
export interface TelegramIncomingMessage {
    /** Telegram chat ID */
    chatId: string;
    /** Telegram message ID */
    messageId: number;
    /** Sender user ID */
    userId: string;
    /** Sender display name */
    userName: string;
    /** Message text content */
    text: string;
    /** Unix timestamp */
    timestamp: number;
    /** Reply-to message ID (if replying) */
    replyToMessageId?: number;
}
/**
 * TelegramService manages the Telegram Bot API connection, incoming
 * message polling via getUpdates, and outgoing message delivery.
 *
 * Events:
 * - 'message' — Emitted when a text message is received
 * - 'error' — Emitted on polling errors
 * - 'connected' — Emitted when polling starts
 * - 'disconnected' — Emitted when polling stops
 *
 * @example
 * ```typescript
 * const service = getTelegramService();
 * await service.initialize({ botToken: 'BOT_TOKEN' });
 * service.on('message', (msg) => console.log(msg.text));
 * service.startPolling();
 * ```
 */
export declare class TelegramService extends EventEmitter {
    private logger;
    private config;
    private botInfo;
    private polling;
    private pollTimer;
    private lastUpdateOffset;
    private consecutiveFailures;
    private connected;
    constructor();
    /**
     * Initialize the Telegram service by validating the bot token.
     *
     * @param config - Telegram configuration with bot token
     * @throws Error if token is invalid or validation fails
     */
    initialize(config: TelegramConfig): Promise<void>;
    /**
     * Start long-polling for incoming messages.
     * Emits 'message' events for each incoming text message.
     */
    startPolling(): void;
    /**
     * Stop polling for incoming messages.
     */
    stopPolling(): void;
    /**
     * Send a text message to a Telegram chat.
     *
     * @param chatId - Telegram chat ID
     * @param text - Message content
     * @param replyToMessageId - Optional message ID to reply to
     * @returns The sent message ID
     * @throws Error if service is not initialized or send fails
     */
    sendMessage(chatId: string, text: string, replyToMessageId?: number): Promise<number>;
    /**
     * Check if the service is currently connected and polling.
     *
     * @returns True if polling is active
     */
    isConnected(): boolean;
    /**
     * Get the current service status.
     *
     * @returns Status object with connection state and bot info
     */
    getStatus(): Record<string, unknown>;
    /**
     * Disconnect the service and stop polling.
     */
    disconnect(): Promise<void>;
    /**
     * Get the bot's username.
     *
     * @returns Bot username or null if not initialized
     */
    getBotUsername(): string | null;
    /**
     * Internal polling loop. Calls getUpdates and schedules next poll.
     */
    private poll;
    /**
     * Call the Telegram getUpdates API with long polling.
     *
     * @returns Array of updates
     */
    private getUpdates;
    /**
     * Process a single Telegram update and emit events.
     *
     * @param update - The update to process
     */
    private processUpdate;
}
/**
 * Get the TelegramService singleton.
 *
 * @returns The service instance
 */
export declare function getTelegramService(): TelegramService;
/**
 * Reset the TelegramService singleton (for testing).
 */
export declare function resetTelegramService(): void;
//# sourceMappingURL=telegram.service.d.ts.map