import EventEmitter, { EventEmitter as EventEmitter$1 } from 'node:events'; import { AxiosInstance } from 'axios'; import io from 'socket.io-client'; type LogLevel = "debug" | "info" | "warn" | "error"; declare class Logger extends EventEmitter { tag: string; private logLevel; private logFile?; constructor(tag: string, level?: LogLevel, logToFile?: boolean); setLogLevel(level: LogLevel): void; private shouldLog; private formatMessage; private writeLog; info(message: string): void; debug(message: string): void; error(message: string | Error): void; warn(message: string): void; log(message: string, level?: LogLevel): void; } interface SendAttachmentOptions { chatGuid: string; filePath: string; fileName?: string; isAudioMessage?: boolean; selectedMessageGuid?: string; } interface Attachment { guid: string; originalROWID: number; transferName: string; totalBytes: number; mimeType?: string; filePath?: string; } type AttachmentResponse = { originalROWID: number; guid: string; messages?: string[]; data?: string; blurhash?: string; height?: number; width?: number; uti: string; mimeType: string; transferState?: number; totalBytes: number; isOutgoing?: boolean; transferName: string; isSticker?: boolean; hideAttachment?: boolean; originalGuid?: string; metadata?: { [key: string]: string | boolean | number; }; hasLivePhoto?: boolean; }; interface TextStyle { start: number; end: number; bold?: boolean; italic?: boolean; underline?: boolean; strikethrough?: boolean; } type TextAnimation = "big" | "small" | "shake" | "nod" | "explode" | "ripple" | "bloom" | "jitter"; type BubbleEffect = "slam" | "loud" | "gentle" | "invisibleInk" | "confetti" | "lasers" | "fireworks" | "balloons" | "hearts" | "shootingStar" | "celebration" | "echo" | "spotlight"; interface SendMessageOptions { chatGuid: string; message: string; tempGuid?: string; subject?: string; selectedMessageGuid?: string; partIndex?: number; richLink?: boolean; textStyles?: TextStyle[]; textAnimation?: TextAnimation; bubbleEffect?: BubbleEffect; } type SendMultipartMessagePart = { partIndex?: number; text: string; mention?: Record; } | { partIndex?: number; filePath: string; fileName?: string; }; interface SendMultipartMessageOptions { chatGuid: string; parts: SendMultipartMessagePart[]; tempGuid?: string; subject?: string; effectId?: string; selectedMessageGuid?: string; partIndex?: number; ddScan?: boolean; attributedBody?: Record | Record[]; } interface SendIMessageAppOptions { chatGuid: string; balloonBundleId: string; appName: string; url: string; ldtext?: string; layoutClass?: string; userInfo?: { caption?: string; subcaption?: string; "secondary-subcaption"?: string; "tertiary-subcaption"?: string; "image-title"?: string; "image-subtitle"?: string; }; appId?: number; imageBase64?: string; sessionIdentifier?: string; } interface MessageData { guid: string; text?: string; subject?: string; dateCreated: number; dateRead?: number; dateDelivered?: number; isFromMe: boolean; handle?: Handle; chats?: Chat[]; attachments?: Attachment[]; } interface Message { guid: string; text: string; service?: string; handle?: Handle | null; chats?: Chat[]; attachments?: Attachment[]; subject: string; error: number; dateCreated: number; dateRead: number | null; dateDelivered: number | null; isFromMe: boolean; isDelivered?: boolean; isArchived: boolean; isAudioMessage?: boolean; datePlayed?: number | null; itemType: number; groupTitle: string | null; groupActionType: number; dateEdited?: number | null; } type MessageResponse = { originalROWID: number; tempGuid?: string; guid: string; text: string; attributedBody?: any[]; messageSummaryInfo?: NodeJS.Dict[]; handle?: HandleResponse | null; handleId: number; otherHandle: number; chats?: ChatResponse[]; attachments?: AttachmentResponse[]; subject: string; country?: string; error: number; dateCreated: number; dateRead: number | null; dateDelivered: number | null; isFromMe: boolean; isDelayed?: boolean; isDelivered?: boolean; isAutoReply?: boolean; isSystemMessage?: boolean; isServiceMessage?: boolean; isForward?: boolean; isArchived: boolean; hasDdResults?: boolean; cacheRoomnames?: string | null; isAudioMessage?: boolean; datePlayed?: number | null; itemType: number; groupTitle: string | null; groupActionType: number; isExpired?: boolean; balloonBundleId: string | null; associatedMessageGuid: string | null; associatedMessageType: string | null; expressiveSendStyleId: string | null; timeExpressiveSendPlayed?: number | null; replyToGuid?: string | null; isCorrupt?: boolean; isSpam?: boolean; threadOriginatorGuid?: string | null; threadOriginatorPart?: string | null; dateRetracted?: number | null; dateEdited?: number | null; partCount?: number | null; payloadData?: NodeJS.Dict[]; hasPayloadData?: boolean; isPoll?: boolean; wasDeliveredQuietly?: boolean; didNotifyRecipient?: boolean; shareStatus?: number | null; shareDirection?: number | null; receivingFrom?: string | null; }; interface Handle { address: string; id: string; country?: string; service?: string; } type HandleResponse = { originalROWID: number; messages?: MessageResponse[]; chats?: ChatResponse[]; address: string; service: string; country?: string; uncanonicalizedId?: string; }; interface Chat { guid: string; chatIdentifier: string; displayName?: string; participants?: Handle[]; style?: number; } type ChatResponse = { originalROWID: number; guid: string; participants?: HandleResponse[]; messages?: MessageResponse[]; lastMessage?: MessageResponse; properties?: NodeJS.Dict[] | null; style: number; chatIdentifier: string; isArchived: boolean; isFiltered?: boolean; displayName: string; groupId?: string; lastAddressedHandle?: string | null; }; interface ClientConfig { serverUrl?: string; apiKey?: string; logLevel?: "debug" | "info" | "warn" | "error"; logToFile?: boolean; } interface FaceTimeStatusData { uuid: string; status_id: number; status: string; ended_error: string; ended_reason: string; address: string; handle?: HandleResponse | null; image_url: string; is_outgoing: boolean; is_audio: boolean; is_video: boolean; url?: string | null; } interface FindMyLocationItem { handle: string | null; coordinates: [number, number]; long_address: string | null; short_address: string | null; subtitle: string | null; title: string | null; last_updated: number; is_locating_in_progress: 0 | 1 | boolean; status: "legacy" | "live" | "shallow"; expiry?: number | null; } interface ScheduledMessageData { id: number; chatGuid: string; message: string; scheduledFor: number; createdAt: number; type: string; payload?: Record; } interface ServerMetadataResponse { os_version: string; server_version: string; private_api: boolean; helper_connected: boolean; detected_icloud?: string; detected_icloud_name?: string; detected_imessage?: string; macos_time_sync?: number | null; local_ipv4s?: string[]; local_ipv6s?: string[]; computer_id?: string; } interface ServerUpdateData { version: string; releaseDate?: string; releaseNotes?: string; } interface BackupData { name: string; path?: string; createdAt?: number; } interface PhotonEventMap { "new-message": MessageResponse; "updated-message": MessageResponse; "message-updated": MessageResponse; "message-send-error": MessageResponse; "chat-read-status-changed": { chatGuid: string; read: boolean; }; "group-name-change": MessageResponse; "participant-added": MessageResponse; "participant-removed": MessageResponse; "participant-left": MessageResponse; "group-icon-changed": MessageResponse; "group-icon-removed": MessageResponse; "typing-indicator": { display: boolean; guid: string; }; "new-server": string; "server-update": ServerUpdateData; "server-update-downloading": ServerUpdateData; "server-update-installing": ServerUpdateData; "config-update": Record; "incoming-facetime": string; "ft-call-status-changed": FaceTimeStatusData; "new-findmy-location": FindMyLocationItem; "scheduled-message-created": ScheduledMessageData; "scheduled-message-updated": ScheduledMessageData; "scheduled-message-deleted": ScheduledMessageData; "scheduled-message-sent": ScheduledMessageData; "scheduled-message-error": ScheduledMessageData; "settings-backup-created": BackupData; "settings-backup-updated": BackupData; "settings-backup-deleted": BackupData; "theme-backup-created": BackupData; "theme-backup-updated": BackupData; "theme-backup-deleted": BackupData; "imessage-aliases-removed": string[]; "hello-world": undefined; connect: undefined; disconnect: undefined; ready: undefined; error: Error; log: { level: string; message: string; tag?: string; }; } type PhotonEventName = keyof PhotonEventMap; interface TypedEventEmitter { emit(event: K, ...args: PhotonEventMap[K] extends undefined ? [] : [PhotonEventMap[K]]): boolean; emit(event: string | symbol, ...args: unknown[]): boolean; on(event: K, listener: PhotonEventMap[K] extends undefined ? () => void : (data: PhotonEventMap[K]) => void): this; on(event: string | symbol, listener: (...args: unknown[]) => void): this; once(event: K, listener: PhotonEventMap[K] extends undefined ? () => void : (data: PhotonEventMap[K]) => void): this; once(event: string | symbol, listener: (...args: unknown[]) => void): this; off(event: K, listener: PhotonEventMap[K] extends undefined ? () => void : (data: PhotonEventMap[K]) => void): this; off(event: string | symbol, listener: (...args: unknown[]) => void): this; addListener(event: K, listener: PhotonEventMap[K] extends undefined ? () => void : (data: PhotonEventMap[K]) => void): this; addListener(event: string | symbol, listener: (...args: unknown[]) => void): this; removeListener(event: K, listener: PhotonEventMap[K] extends undefined ? () => void : (data: PhotonEventMap[K]) => void): this; removeListener(event: string | symbol, listener: (...args: unknown[]) => void): this; } interface CreatePollOptions { chatGuid: string; title?: string; options: string[]; } interface VotePollOptions { chatGuid: string; pollMessageGuid: string; optionIdentifier: string; } interface AddPollOptionOptions { chatGuid: string; pollMessageGuid: string; optionText: string; } interface PollOption { optionIdentifier: string; text: string; attributedText: string; creatorHandle: string; canBeEdited: boolean; } interface PollVote { voteOptionIdentifier: string; participantHandle: string; serverVoteTime?: number; } interface PollDefinition { version: number; item: { title: string; orderedPollOptions: PollOption[]; creatorHandle: string; }; } interface PollVoteResponse { version: number; item: { votes: PollVote[]; }; } type PollMessageResponse = MessageResponse; interface SendStickerOptions { chatGuid: string; filePath: string; fileName?: string; selectedMessageGuid?: string; stickerX?: number; stickerY?: number; stickerScale?: number; stickerRotation?: number; stickerWidth?: number; } type ValidTapback = "love" | "like" | "dislike" | "laugh" | "emphasize" | "question"; type ValidRemoveTapback = "-love" | "-like" | "-dislike" | "-laugh" | "-emphasize" | "-question"; declare class AttachmentModule { private readonly http; private readonly enqueueSend; constructor(http: AxiosInstance, enqueueSend?: (task: () => Promise) => Promise); getAttachmentCount(): Promise; getAttachment(guid: string): Promise; downloadAttachment(guid: string, options?: { original?: boolean; force?: boolean; height?: number; width?: number; quality?: number; }): Promise; downloadAttachmentLive(guid: string): Promise; getAttachmentBlurhash(guid: string, options?: { height?: number; width?: number; quality?: number; }): Promise; /** * Ensures the chat exists by creating it if it doesn't already exist. */ private ensureChatExists; sendAttachment(options: SendAttachmentOptions): Promise; sendSticker(options: SendStickerOptions): Promise; } declare class ChatModule { private readonly http; constructor(http: AxiosInstance); getChats(options?: { withLastMessage?: boolean; withArchived?: boolean; offset?: number; limit?: number; sort?: string; }): Promise; createChat(options: { addresses: string[]; message?: string; method?: "apple-script" | "private-api"; service?: "iMessage" | "SMS"; tempGuid?: string; subject?: string; bubbleEffect?: BubbleEffect; attributedBody?: Record; }): Promise; getChat(guid: string, options?: { with?: string[]; }): Promise; updateChat(guid: string, options: { displayName?: string; }): Promise; deleteChat(guid: string): Promise; markChatRead(guid: string): Promise; markChatUnread(guid: string): Promise; leaveChat(guid: string): Promise; addParticipant(chatGuid: string, address: string): Promise; removeParticipant(chatGuid: string, address: string): Promise; getChatMessages(chatGuid: string, options?: { offset?: number; limit?: number; sort?: "ASC" | "DESC"; before?: number; after?: number; with?: string[]; }): Promise; setGroupIcon(chatGuid: string, filePath: string): Promise; removeGroupIcon(chatGuid: string): Promise; getGroupIcon(chatGuid: string): Promise; getChatCount(options?: { includeArchived?: boolean; }): Promise<{ total: number; breakdown: Record; }>; startTyping(chatGuid: string): Promise; stopTyping(chatGuid: string): Promise; getBackground(chatGuid: string): Promise<{ hasBackground: boolean; backgroundChannelGUID?: string | null; imageUrl?: string | null; backgroundId?: string | null; }>; setBackground(chatGuid: string, options: string | { imageUrl?: string; filePath?: string; fileData?: string; }): Promise; removeBackground(chatGuid: string): Promise; } declare class ContactModule { private readonly http; constructor(http: AxiosInstance); getContacts(): Promise; getContactCard(address: string): Promise; shareContactCard(chatGuid: string): Promise; shouldShareContact(chatGuid: string): Promise; } declare class FaceTimeModule { private readonly http; constructor(http: AxiosInstance); createFaceTimeLink(): Promise; } declare class HandleModule { private readonly http; constructor(http: AxiosInstance); getHandleCount(): Promise; queryHandles(options?: { address?: string; with?: string[]; offset?: number; limit?: number; }): Promise<{ data: any[]; metadata: { total: number; offset: number; limit: number; count: number; }; }>; getHandle(guid: string): Promise; getHandleAvailability(address: string, type: "imessage" | "facetime"): Promise; getHandleFocusStatus(guid: string): Promise; } declare class ICloudModule { private readonly http; constructor(http: AxiosInstance); getFindMyFriends(): Promise; refreshFindMyFriends(): Promise; getLocationForHandle(handle: string): Promise; isHandleSharingLocation(handle: string): Promise; } declare class MessageModule { private readonly http; private readonly enqueueSend; constructor(http: AxiosInstance, enqueueSend?: (task: () => Promise) => Promise); private uploadMultipartAttachment; sendMessage(options: SendMessageOptions): Promise; sendMultipartMessage(options: SendMultipartMessageOptions): Promise; getMessage(guid: string, options?: { with?: string[]; }): Promise; getMessages(options?: { chatGuid?: string; offset?: number; limit?: number; sort?: "ASC" | "DESC"; before?: number; after?: number; with?: string[]; }): Promise; getMessageCount(options?: { after?: number; before?: number; chatGuid?: string; minRowId?: number; maxRowId?: number; }): Promise; getUpdatedMessageCount(options?: { after?: number; before?: number; chatGuid?: string; minRowId?: number; maxRowId?: number; }): Promise; getSentMessageCount(options?: { after?: number; before?: number; chatGuid?: string; minRowId?: number; maxRowId?: number; }): Promise; editMessage(options: { messageGuid: string; editedMessage: string; backwardsCompatibilityMessage?: string; partIndex?: number; }): Promise; sendReaction(options: { chatGuid: string; messageGuid: string; reaction: string; partIndex?: number; }): Promise; unsendMessage(options: { messageGuid: string; partIndex?: number; }): Promise; notifyMessage(guid: string): Promise; getEmbeddedMedia(guid: string): Promise<{ path?: string; data?: string; }>; searchMessages(options: { query: string; chatGuid?: string; offset?: number; limit?: number; sort?: "ASC" | "DESC"; before?: number; after?: number; }): Promise; } declare class PollModule { private readonly http; constructor(http: AxiosInstance); create(options: CreatePollOptions): Promise; vote(options: VotePollOptions): Promise; unvote(options: VotePollOptions): Promise; addOption(options: AddPollOptionOptions): Promise; } declare class ScheduledMessageModule { private readonly http; constructor(http: AxiosInstance); createScheduledMessage(options: any): Promise; getScheduledMessages(): Promise; updateScheduledMessage(id: string, options: any): Promise; deleteScheduledMessage(id: string): Promise; } declare class ServerModule { private readonly http; constructor(http: AxiosInstance); getServerInfo(): Promise; getMessageStats(): Promise; getServerLogs(count?: number): Promise; getMediaStatistics(options?: { only?: string[]; }): Promise; getMediaStatisticsByChat(options?: { only?: string[]; }): Promise; } declare class AdvancedIMessageKit extends EventEmitter$1 implements TypedEventEmitter { private static getGlobalSdk; private static setGlobalSdk; static getInstance(config?: ClientConfig): AdvancedIMessageKit; readonly config: ClientConfig; readonly logger: Logger; readonly http: AxiosInstance; readonly socket: ReturnType; readonly attachments: AttachmentModule; readonly messages: MessageModule; readonly chats: ChatModule; readonly contacts: ContactModule; readonly handles: HandleModule; readonly facetime: FaceTimeModule; readonly icloud: ICloudModule; readonly polls: PollModule; readonly scheduledMessages: ScheduledMessageModule; readonly server: ServerModule; private processedMessages; private lastMessageTime; private sendQueue; private readyEmitted; private listenersAttached; constructor(config?: ClientConfig); emit(event: K, ...args: PhotonEventMap[K] extends undefined ? [] : [PhotonEventMap[K]]): boolean; on(event: K, listener: PhotonEventMap[K] extends undefined ? () => void : (data: PhotonEventMap[K]) => void): this; once(event: K, listener: PhotonEventMap[K] extends undefined ? () => void : (data: PhotonEventMap[K]) => void): this; off(event: K, listener: PhotonEventMap[K] extends undefined ? () => void : (data: PhotonEventMap[K]) => void): this; addListener(event: K, listener: PhotonEventMap[K] extends undefined ? () => void : (data: PhotonEventMap[K]) => void): this; removeListener(event: K, listener: PhotonEventMap[K] extends undefined ? () => void : (data: PhotonEventMap[K]) => void): this; connect(): Promise; private attachSocketListeners; close(): Promise; private recoverMissedMessages; /** * Clear processed message records (prevent memory leaks) * @param maxSize Maximum number of messages to retain, default 1000 */ clearProcessedMessages(maxSize?: number): void; /** * Get the count of processed messages */ getProcessedMessageCount(): number; /** * Enqueue a send operation to ensure sequential delivery. * All send operations (messages, attachments, stickers) should use this method * to guarantee order for a single user. * @param task The async send operation to enqueue * @returns Promise that resolves with the task result */ enqueueSend(task: () => Promise): Promise; } declare const SDK: typeof AdvancedIMessageKit.getInstance; declare const SCHEDULED_MESSAGE_ERROR = "scheduled-message-error"; declare const SCHEDULED_MESSAGE_SENT = "scheduled-message-sent"; declare const SCHEDULED_MESSAGE_DELETED = "scheduled-message-deleted"; declare const SCHEDULED_MESSAGE_UPDATED = "scheduled-message-updated"; declare const SCHEDULED_MESSAGE_CREATED = "scheduled-message-created"; declare const NEW_MESSAGE = "new-message"; declare const MESSAGE_SEND_ERROR = "message-send-error"; declare const MESSAGE_UPDATED = "updated-message"; declare const NEW_SERVER = "new-server"; declare const PARTICIPANT_REMOVED = "participant-removed"; declare const PARTICIPANT_ADDED = "participant-added"; declare const PARTICIPANT_LEFT = "participant-left"; declare const GROUP_ICON_CHANGED = "group-icon-changed"; declare const GROUP_ICON_REMOVED = "group-icon-removed"; declare const CHAT_READ_STATUS_CHANGED = "chat-read-status-changed"; declare const HELLO_WORLD = "hello-world"; declare const TYPING_INDICATOR = "typing-indicator"; declare const SERVER_UPDATE = "server-update"; declare const SERVER_UPDATE_DOWNLOADING = "server-update-downloading"; declare const SERVER_UPDATE_INSTALLING = "server-update-installing"; declare const GROUP_NAME_CHANGE = "group-name-change"; declare const INCOMING_FACETIME = "incoming-facetime"; declare const SETTINGS_BACKUP_CREATED = "settings-backup-created"; declare const SETTINGS_BACKUP_DELETED = "settings-backup-deleted"; declare const SETTINGS_BACKUP_UPDATED = "settings-backup-updated"; declare const THEME_BACKUP_CREATED = "theme-backup-created"; declare const THEME_BACKUP_DELETED = "theme-backup-deleted"; declare const THEME_BACKUP_UPDATED = "theme-backup-updated"; declare const IMESSAGE_ALIASES_REMOVED = "imessage-aliases-removed"; declare const FT_CALL_STATUS_CHANGED = "ft-call-status-changed"; declare const NEW_FINDMY_LOCATION = "new-findmy-location"; declare const setGlobalLogLevel: (level: LogLevel) => void; declare const setGlobalLogToFile: (logToFile: boolean) => void; declare const getLogger: (tag: string) => Logger; declare function getOptionTextById(optionId: string): string | null; declare function isPollMessage(message: MessageResponse): boolean; declare function isPollVote(message: MessageResponse): boolean; interface ParsedPoll { title: string; creatorHandle: string; options: PollOption[]; } interface ParsedPollVote { votes: PollVote[]; } declare function parsePollDefinition(message: MessageResponse): ParsedPoll | null; declare function parsePollVotes(message: MessageResponse): ParsedPollVote | null; declare function getPollSummary(message: MessageResponse): string; declare function getPollOneLiner(message: MessageResponse): string; export { type AddPollOptionOptions, AdvancedIMessageKit, type Attachment, type AttachmentResponse, type BackupData, type BubbleEffect, CHAT_READ_STATUS_CHANGED, type Chat, type ChatResponse, type ClientConfig, type CreatePollOptions, FT_CALL_STATUS_CHANGED, type FaceTimeStatusData, type FindMyLocationItem, GROUP_ICON_CHANGED, GROUP_ICON_REMOVED, GROUP_NAME_CHANGE, HELLO_WORLD, type Handle, type HandleResponse, IMESSAGE_ALIASES_REMOVED, INCOMING_FACETIME, MESSAGE_SEND_ERROR, MESSAGE_UPDATED, type Message, type MessageData, type MessageResponse, NEW_FINDMY_LOCATION, NEW_MESSAGE, NEW_SERVER, PARTICIPANT_ADDED, PARTICIPANT_LEFT, PARTICIPANT_REMOVED, type ParsedPoll, type ParsedPollVote, type PhotonEventMap, type PhotonEventName, type PollDefinition, type PollMessageResponse, type PollOption, type PollVote, type PollVoteResponse, SCHEDULED_MESSAGE_CREATED, SCHEDULED_MESSAGE_DELETED, SCHEDULED_MESSAGE_ERROR, SCHEDULED_MESSAGE_SENT, SCHEDULED_MESSAGE_UPDATED, SDK, SERVER_UPDATE, SERVER_UPDATE_DOWNLOADING, SERVER_UPDATE_INSTALLING, SETTINGS_BACKUP_CREATED, SETTINGS_BACKUP_DELETED, SETTINGS_BACKUP_UPDATED, type ScheduledMessageData, type SendAttachmentOptions, type SendIMessageAppOptions, type SendMessageOptions, type SendMultipartMessageOptions, type SendMultipartMessagePart, type SendStickerOptions, type ServerMetadataResponse, type ServerUpdateData, THEME_BACKUP_CREATED, THEME_BACKUP_DELETED, THEME_BACKUP_UPDATED, TYPING_INDICATOR, type TextAnimation, type TextStyle, type TypedEventEmitter, type ValidRemoveTapback, type ValidTapback, type VotePollOptions, getLogger, getOptionTextById, getPollOneLiner, getPollSummary, isPollMessage, isPollVote, parsePollDefinition, parsePollVotes, setGlobalLogLevel, setGlobalLogToFile };