/** * Telegram Data Service * * API layer for storing Telegram data on backend. * Sends extracted dialogs and messages to /platform-data/store endpoint. * * MATCHES ChatGPT implementation pattern * - Uses format: { platform, data, metadata } * - Platform: "mobile-telegram" * * ============================================================ * TELEGRAM MTProto API REFERENCE * ============================================================ * * Method: messages.getDialogs * @see https://core.telegram.org/method/messages.getDialogs * * Parameters: * - flags (#): Flags for conditional fields * - exclude_pinned (flags.0? true): Exclude pinned dialogs * - folder_id (flags.1? int): Peer folder ID (archived = 1) * - offset_date (int): Offset for pagination (date-based) * - offset_id (int): Offset for pagination (top message ID) * - offset_peer (InputPeer): Offset peer for pagination * - limit (int): Number of dialogs to return * - hash (long): Hash for caching and efficient pagination * * Returns: messages.Dialogs containing dialogs, messages, chats, users * * Method: messages.getHistory * @see https://core.telegram.org/method/messages.getHistory * * Authorization: * - Requires api_id and api_hash from https://my.telegram.org/apps * - User must authenticate with phone number + code + optional 2FA * * Libraries: * - Python: Telethon, Pyrogram * - Multi-language: TDLib (official) * - C#/.NET: WTelegramClient * * ============================================================ */ /** * Telegram Dialog entity types * Matches MTProto entity types returned by messages.getDialogs */ export type TelegramEntityType = 'User' | 'Chat' | 'Channel' | 'Supergroup'; /** * Structure of a Telegram dialog/chat * Based on messages.Dialogs response from MTProto API * * @see https://core.telegram.org/constructor/dialog */ export interface TelegramDialogData { /** Peer ID (can be user_id, chat_id, or channel_id) */ id: string | number; /** Chat/User/Channel title or name */ title: string; /** Entity type: User, Chat, Channel, Supergroup */ type: TelegramEntityType | 'chat' | 'group' | 'channel' | 'user'; /** Number of unread messages */ unreadCount?: number; /** Pinned flag from dialog */ pinned?: boolean; /** Folder ID (0 = main, 1 = archived) */ folderId?: number; /** Top message ID in this dialog */ topMessageId?: number; /** Read inbox max ID */ readInboxMaxId?: number; /** Read outbox max ID */ readOutboxMaxId?: number; /** Date of last message (Unix timestamp) */ lastMessageDate?: number | string; /** Photo URL if available */ photoUrl?: string; } /** * Structure of a Telegram message * Based on messages.getHistory response from MTProto API * * @see https://core.telegram.org/constructor/message */ export interface TelegramMessageData { /** Message ID */ id: string | number; /** Peer/Chat ID this message belongs to */ chatId?: string | number; /** Message text content */ text: string; /** Unix timestamp or ISO date */ timestamp?: string | number; /** Date (Unix timestamp from MTProto) */ date?: number; /** Message type */ type: 'text' | 'photo' | 'video' | 'document' | 'sticker' | 'voice' | 'audio' | 'other'; /** From ID (sender) */ fromId?: string | number; /** Is outgoing message (sent by user) */ out?: boolean; /** Media URL if applicable */ mediaUrl?: string; /** Reply to message ID */ replyToMsgId?: number; /** Forward info if forwarded */ fwdFrom?: { fromId?: string | number; fromName?: string; date?: number; }; } /** * Combined Telegram data to store * Matches structure returned by messages.getDialogs + messages.getHistory */ export interface TelegramStorageData { dialogs: TelegramDialogData[]; messages: TelegramMessageData[]; /** Telegram user ID */ userId?: string | number; /** Additional users/chats metadata from API response */ users?: Array<{ id: number; firstName?: string; lastName?: string; username?: string; }>; chats?: Array<{ id: number; title?: string; type?: string; }>; } /** * Response from backend endpoint */ export interface StoreTelegramDataResponse { success: boolean; message?: string; error?: string; data?: any; } /** * Store Telegram data on backend * * @param userId - Username or identifier * @param data - Telegram dialogs and messages data * @returns Response indicating success/failure with metadata */ export declare const storeTelegramData: (userId: string, data: TelegramStorageData) => Promise; /** * Telegram MTProto API Configuration * * REQUIRED: Register at https://my.telegram.org/apps to get: * - api_id (integer) * - api_hash (string, 32 hex chars) * * @see https://core.telegram.org/api/obtaining_api_id */ export interface TelegramMTProtoConfig { /** Application ID from my.telegram.org (integer) */ apiId: number; /** Application hash from my.telegram.org (32 hex string) */ apiHash: string; /** User's phone number for authentication */ phoneNumber?: string; /** Session string for persistent auth (optional) */ sessionString?: string; } /** * MTProto API Method Parameters * Based on Layer 214+ schema */ export declare const TELEGRAM_MTPROTO_API: { getDialogs: { method: string; description: string; parameters: { flags: string; exclude_pinned: string; folder_id: string; offset_date: string; offset_id: string; offset_peer: string; limit: string; hash: string; }; returns: string; errors: string[]; }; getHistory: { method: string; description: string; parameters: { peer: string; offset_id: string; offset_date: string; add_offset: string; limit: string; max_id: string; min_id: string; hash: string; }; returns: string; errors: string[]; }; search: { method: string; description: string; parameters: { peer: string; q: string; from_id: string; filter: string; min_date: string; max_date: string; offset_id: string; add_offset: string; limit: string; max_id: string; min_id: string; hash: string; }; returns: string; }; }; /** * Recommended Libraries for MTProto Implementation */ export declare const TELEGRAM_LIBRARIES: { python: { telethon: { name: string; install: string; github: string; docs: string; example: string; }; pyrogram: { name: string; install: string; github: string; docs: string; }; }; nodejs: { gramjs: { name: string; install: string; github: string; example: string; }; tdl: { name: string; install: string; github: string; }; }; multiPlatform: { tdlib: { name: string; description: string; github: string; docs: string; platforms: string[]; }; }; dotnet: { wtelegramclient: { name: string; install: string; github: string; }; }; }; /** * Backend API endpoints for Telegram integration * These should be implemented on your backend server */ export declare const TELEGRAM_BACKEND_ENDPOINTS: { initAuth: { method: string; path: string; body: { phoneNumber: string; }; response: { codeHash: string; phoneCodeHash: string; }; }; verifyCode: { method: string; path: string; body: { phoneNumber: string; code: string; phoneCodeHash: string; }; response: { sessionString: string; user: string; }; }; verify2FA: { method: string; path: string; body: { password: string; sessionString: string; }; response: { sessionString: string; user: string; }; }; getDialogs: { method: string; path: string; query: { limit: string; folderId: string; offsetDate: string; }; response: { dialogs: string; users: string; chats: string; }; }; getMessages: { method: string; path: string; query: { limit: string; offsetId: string; }; response: { messages: string; }; }; storeData: { method: string; path: string; body: { platform: string; data: string; }; response: { success: string; message: string; }; }; }; /** * Rate Limiting Guidelines * Telegram has strict rate limits - handle FLOOD_WAIT errors */ export declare const TELEGRAM_RATE_LIMITS: { requests_per_second: number; flood_wait_handling: string; batch_size: number; telethon_config: { flood_sleep_threshold: number; }; }; //# sourceMappingURL=telegramDataService.d.ts.map