meta-messenger.js 0.0.2 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1052 @@
1
+ /**
2
+ * Event types emitted by the client
3
+ */
4
+ type EventType = "ready" | "reconnected" | "disconnected" | "error" | "message" | "messageEdit" | "messageUnsend" | "reaction" | "typing" | "readReceipt" | "e2eeConnected" | "e2eeMessage" | "e2eeReaction" | "e2eeReceipt" | "deviceDataChanged";
5
+ /**
6
+ * Base event interface
7
+ */
8
+ interface BaseEvent {
9
+ type: EventType;
10
+ timestamp: number;
11
+ }
12
+ /**
13
+ * Ready event - emitted when connected to Messenger
14
+ */
15
+ interface ReadyEvent extends BaseEvent {
16
+ type: "ready";
17
+ data: {
18
+ isNewSession: boolean;
19
+ };
20
+ }
21
+ /**
22
+ * Reconnected event
23
+ */
24
+ interface ReconnectedEvent extends BaseEvent {
25
+ type: "reconnected";
26
+ }
27
+ /**
28
+ * Disconnected event
29
+ */
30
+ interface DisconnectedEvent extends BaseEvent {
31
+ type: "disconnected";
32
+ data?: {
33
+ isE2EE?: boolean;
34
+ };
35
+ }
36
+ /**
37
+ * Error event
38
+ */
39
+ interface ErrorEvent extends BaseEvent {
40
+ type: "error";
41
+ data: {
42
+ message: string;
43
+ code?: number;
44
+ };
45
+ }
46
+ /**
47
+ * Message event - new message received
48
+ */
49
+ interface MessageEvent extends BaseEvent {
50
+ type: "message";
51
+ data: Message;
52
+ }
53
+ /**
54
+ * Message edit event
55
+ */
56
+ interface MessageEditEvent extends BaseEvent {
57
+ type: "messageEdit";
58
+ data: {
59
+ messageId: string;
60
+ threadId: number;
61
+ newText: string;
62
+ editCount?: number;
63
+ timestampMs?: number;
64
+ };
65
+ }
66
+ /**
67
+ * Message unsend event
68
+ */
69
+ interface MessageUnsendEvent extends BaseEvent {
70
+ type: "messageUnsend";
71
+ data: {
72
+ messageId: string;
73
+ threadId: number;
74
+ };
75
+ }
76
+ /**
77
+ * Reaction event
78
+ */
79
+ interface ReactionEvent extends BaseEvent {
80
+ type: "reaction";
81
+ data: {
82
+ messageId: string;
83
+ threadId: number;
84
+ actorId: number;
85
+ reaction: string;
86
+ timestampMs: number;
87
+ };
88
+ }
89
+ /**
90
+ * Typing event
91
+ */
92
+ interface TypingEvent extends BaseEvent {
93
+ type: "typing";
94
+ data: {
95
+ threadId: number;
96
+ senderId: number;
97
+ isTyping: boolean;
98
+ };
99
+ }
100
+ /**
101
+ * Read receipt event
102
+ */
103
+ interface ReadReceiptEvent extends BaseEvent {
104
+ type: "readReceipt";
105
+ data: {
106
+ threadId: number;
107
+ readerId: number;
108
+ readWatermarkTimestampMs: number;
109
+ timestampMs?: number;
110
+ };
111
+ }
112
+ /**
113
+ * E2EE connected event
114
+ */
115
+ interface E2EEConnectedEvent extends BaseEvent {
116
+ type: "e2eeConnected";
117
+ }
118
+ /**
119
+ * E2EE message event
120
+ */
121
+ interface E2EEMessageEvent extends BaseEvent {
122
+ type: "e2eeMessage";
123
+ data: E2EEMessage;
124
+ }
125
+ /**
126
+ * E2EE reaction event
127
+ */
128
+ interface E2EEReactionEvent extends BaseEvent {
129
+ type: "e2eeReaction";
130
+ data: {
131
+ messageId: string;
132
+ chatJid: string;
133
+ senderJid: string;
134
+ reaction: string;
135
+ };
136
+ }
137
+ /**
138
+ * E2EE receipt event
139
+ */
140
+ interface E2EEReceiptEvent extends BaseEvent {
141
+ type: "e2eeReceipt";
142
+ data: {
143
+ type: string;
144
+ chat: string;
145
+ sender: string;
146
+ messageIds: string[];
147
+ };
148
+ }
149
+ /**
150
+ * Device data changed event - emitted when E2EE device data changes (only when using deviceData option)
151
+ */
152
+ interface DeviceDataChangedEvent extends BaseEvent {
153
+ type: "deviceDataChanged";
154
+ data: {
155
+ deviceData: string;
156
+ };
157
+ }
158
+ /**
159
+ * Union of all events
160
+ */
161
+ type ClientEvent = ReadyEvent | ReconnectedEvent | DisconnectedEvent | ErrorEvent | MessageEvent | MessageEditEvent | MessageUnsendEvent | ReactionEvent | TypingEvent | ReadReceiptEvent | E2EEConnectedEvent | E2EEMessageEvent | E2EEReactionEvent | E2EEReceiptEvent | DeviceDataChangedEvent;
162
+ /**
163
+ * User information
164
+ */
165
+ interface User {
166
+ id: number;
167
+ name: string;
168
+ username: string;
169
+ }
170
+ /**
171
+ * Thread/conversation
172
+ */
173
+ interface Thread {
174
+ id: number;
175
+ type: ThreadType;
176
+ name: string;
177
+ lastActivityTimestampMs: number;
178
+ snippet: string;
179
+ }
180
+ /**
181
+ * Thread types
182
+ */
183
+ declare enum ThreadType {
184
+ ONE_TO_ONE = 1,
185
+ GROUP = 2,
186
+ PAGE = 3,
187
+ MARKETPLACE = 4,
188
+ ENCRYPTED_ONE_TO_ONE = 7,
189
+ ENCRYPTED_GROUP = 8
190
+ }
191
+ /**
192
+ * Attachment type
193
+ */
194
+ type AttachmentType = "image" | "video" | "audio" | "file" | "sticker" | "gif" | "voice" | "location" | "link";
195
+ /**
196
+ * Media attachment
197
+ */
198
+ interface Attachment {
199
+ type: AttachmentType;
200
+ url?: string;
201
+ fileName?: string;
202
+ mimeType?: string;
203
+ fileSize?: number;
204
+ width?: number;
205
+ height?: number;
206
+ duration?: number;
207
+ stickerId?: number;
208
+ latitude?: number;
209
+ longitude?: number;
210
+ previewUrl?: string;
211
+ mediaKey?: string;
212
+ mediaSha256?: string;
213
+ directPath?: string;
214
+ }
215
+ /**
216
+ * Reply info
217
+ */
218
+ interface ReplyTo {
219
+ messageId: string;
220
+ senderId?: number;
221
+ text?: string;
222
+ }
223
+ /**
224
+ * Mention in message
225
+ */
226
+ interface Mention {
227
+ userId: number;
228
+ offset: number;
229
+ length: number;
230
+ type?: "user" | "page" | "group";
231
+ }
232
+ /**
233
+ * Message
234
+ */
235
+ interface Message {
236
+ id: string;
237
+ threadId: number;
238
+ senderId: number;
239
+ text: string;
240
+ timestampMs: number;
241
+ isE2EE?: boolean;
242
+ chatJid?: string;
243
+ senderJid?: string;
244
+ attachments?: Attachment[];
245
+ replyTo?: ReplyTo;
246
+ mentions?: Mention[];
247
+ isAdminMsg?: boolean;
248
+ }
249
+ /**
250
+ * E2EE Message
251
+ */
252
+ interface E2EEMessage {
253
+ id: string;
254
+ threadId: number;
255
+ chatJid: string;
256
+ senderJid: string;
257
+ senderId: number;
258
+ text: string;
259
+ timestampMs: number;
260
+ attachments?: Attachment[];
261
+ replyTo?: ReplyTo;
262
+ mentions?: Mention[];
263
+ }
264
+ /**
265
+ * Initial data received on connect
266
+ */
267
+ interface InitialData {
268
+ threads: Thread[];
269
+ messages: Message[];
270
+ }
271
+ /**
272
+ * Platform type
273
+ */
274
+ type Platform = "facebook" | "messenger" | "instagram";
275
+ /**
276
+ * Log level
277
+ */
278
+ type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "none";
279
+ /**
280
+ * Cookies required for authentication
281
+ */
282
+ interface Cookies {
283
+ c_user: string;
284
+ xs: string;
285
+ datr?: string;
286
+ fr?: string;
287
+ [key: string]: string | undefined;
288
+ }
289
+ /**
290
+ * Client options
291
+ */
292
+ interface ClientOptions {
293
+ /** Platform to connect to (Only tested on Facebook) */
294
+ platform?: Platform;
295
+ /** Path to E2EE device store (if not using deviceData) */
296
+ devicePath?: string;
297
+ /** E2EE device data as JSON string (takes priority over devicePath) */
298
+ deviceData?: string;
299
+ /** Log level */
300
+ logLevel?: LogLevel;
301
+ /** Enable E2EE */
302
+ enableE2EE?: boolean;
303
+ /** Auto reconnect on disconnect */
304
+ autoReconnect?: boolean;
305
+ }
306
+ /**
307
+ * Send message options
308
+ */
309
+ interface SendMessageOptions {
310
+ /** Text content */
311
+ text: string;
312
+ /** Reply to message ID */
313
+ replyToId?: string;
314
+ /** User IDs to mention */
315
+ mentions?: Array<{
316
+ userId: number;
317
+ offset: number;
318
+ length: number;
319
+ }>;
320
+ }
321
+ /**
322
+ * Send message result
323
+ */
324
+ interface SendMessageResult {
325
+ messageId: string;
326
+ timestampMs: number;
327
+ }
328
+ /**
329
+ * Upload media result
330
+ */
331
+ interface UploadMediaResult {
332
+ fbId: number;
333
+ filename: string;
334
+ }
335
+ /**
336
+ * Search user result
337
+ */
338
+ interface SearchUserResult {
339
+ id: number;
340
+ name: string;
341
+ username: string;
342
+ }
343
+ /**
344
+ * Create thread result (1:1 chat)
345
+ */
346
+ interface CreateThreadResult {
347
+ threadId: number;
348
+ }
349
+ /**
350
+ * User information
351
+ */
352
+ interface UserInfo {
353
+ id: number;
354
+ name: string;
355
+ firstName?: string;
356
+ username?: string;
357
+ profilePictureUrl?: string;
358
+ isMessengerUser?: boolean;
359
+ isVerified?: boolean;
360
+ gender?: number;
361
+ canViewerMessage?: boolean;
362
+ }
363
+
364
+ declare class TypedEventEmitter<T> {
365
+ on<K extends keyof T>(event: K, listener: (...args: T[K] extends unknown[] ? T[K] : never) => void): this;
366
+ once<K extends keyof T>(event: K, listener: (...args: T[K] extends unknown[] ? T[K] : never) => void): this;
367
+ off<K extends keyof T>(event: K, listener: (...args: T[K] extends unknown[] ? T[K] : never) => void): this;
368
+ emit<K extends keyof T>(event: K, ...args: T[K] extends unknown[] ? T[K] : never): boolean;
369
+ removeAllListeners<K extends keyof T>(event?: K): this;
370
+ }
371
+ interface ClientEventMap {
372
+ ready: [{
373
+ isNewSession: boolean;
374
+ }];
375
+ fullyReady: [];
376
+ reconnected: [];
377
+ disconnected: [{
378
+ isE2EE?: boolean;
379
+ }];
380
+ error: [Error];
381
+ message: [Message];
382
+ messageEdit: [{
383
+ messageId: string;
384
+ threadId: number;
385
+ newText: string;
386
+ editCount?: number;
387
+ timestampMs?: number;
388
+ }];
389
+ messageUnsend: [{
390
+ messageId: string;
391
+ threadId: number;
392
+ }];
393
+ reaction: [{
394
+ messageId: string;
395
+ threadId: number;
396
+ actorId: number;
397
+ reaction: string;
398
+ timestampMs?: number;
399
+ }];
400
+ typing: [{
401
+ threadId: number;
402
+ senderId: number;
403
+ isTyping: boolean;
404
+ }];
405
+ readReceipt: [{
406
+ threadId: number;
407
+ readerId: number;
408
+ readWatermarkTimestampMs: number;
409
+ timestampMs?: number;
410
+ }];
411
+ e2eeConnected: [];
412
+ e2eeMessage: [E2EEMessage];
413
+ e2eeReaction: [{
414
+ messageId: string;
415
+ chatJid: string;
416
+ senderJid: string;
417
+ senderId?: number;
418
+ reaction: string;
419
+ }];
420
+ e2eeReceipt: [{
421
+ type: string;
422
+ chat: string;
423
+ sender: string;
424
+ messageIds: string[];
425
+ }];
426
+ deviceDataChanged: [{
427
+ deviceData: string;
428
+ }];
429
+ }
430
+ declare const Client_base: new () => TypedEventEmitter<ClientEventMap>;
431
+ /**
432
+ * Demonstrates how to use the Client class to connect to Messenger and handle messages (E2EE disabled for simplicity).
433
+ *
434
+ * @example
435
+ * ```typescript
436
+ * import { Client } from 'meta-messenger.js'
437
+ *
438
+ * const client = new Client({
439
+ * c_user: 'your_user_id',
440
+ * xs: 'your_xs_cookie',
441
+ * datr: 'your_datr_cookie',
442
+ * fr: 'your_fr_cookie'
443
+ * })
444
+ *
445
+ * client.on('message', (message) => {
446
+ * console.log('New message:', message)
447
+ * if (message.text === 'ping') {
448
+ * client.sendMessage(message.threadId, { text: 'pong' })
449
+ * }
450
+ * })
451
+ *
452
+ * await client.connect()
453
+ * ```
454
+ */
455
+ declare class Client extends Client_base {
456
+ private handle;
457
+ private options;
458
+ private cookies;
459
+ private _user;
460
+ private _initialData;
461
+ private eventLoopRunning;
462
+ private eventLoopAbort;
463
+ private _socketReady;
464
+ private _e2eeConnected;
465
+ private _fullyReadyEmitted;
466
+ private pendingEvents;
467
+ /**
468
+ * Create a new Messenger client
469
+ *
470
+ * @param cookies - Authentication cookies
471
+ * @param options - Client options
472
+ */
473
+ constructor(cookies: Cookies, options?: ClientOptions);
474
+ /**
475
+ * Get the current user info
476
+ */
477
+ get user(): User | null;
478
+ /**
479
+ * Get the current user's Facebook ID
480
+ */
481
+ get currentUserId(): number | null;
482
+ /**
483
+ * Get initial sync data (threads and messages)
484
+ */
485
+ get initialData(): InitialData | null;
486
+ /**
487
+ * Check if client is fully ready (socket ready + E2EE connected if enabled)
488
+ */
489
+ get isFullyReady(): boolean;
490
+ /**
491
+ * Check if client is connected
492
+ */
493
+ get isConnected(): boolean;
494
+ /**
495
+ * Check if E2EE is connected
496
+ */
497
+ get isE2EEConnected(): boolean;
498
+ /**
499
+ * Connect to Messenger
500
+ *
501
+ * @returns User info and initial data
502
+ */
503
+ connect(): Promise<{
504
+ user: User;
505
+ initialData: InitialData;
506
+ }>;
507
+ /**
508
+ * Connect E2EE (end-to-end encryption)
509
+ * @warn This Promise is not resolved after the connection setup is completed; instead, it is resolved after the function finishes executing.\
510
+ * You should not rely on this Promise to wait for the E2EE connection to be fully established.
511
+ */
512
+ connectE2EE(): Promise<void>;
513
+ /**
514
+ * Disconnect from Messenger
515
+ */
516
+ disconnect(): Promise<void>;
517
+ /**
518
+ * Send a text message
519
+ *
520
+ * @param threadId - Thread ID to send to
521
+ * @param options - Message options (text, reply, mentions)
522
+ * @returns Send result with message ID
523
+ */
524
+ sendMessage(threadId: number, options: SendMessageOptions | string): Promise<SendMessageResult>;
525
+ /**
526
+ * Send / Remove a reaction to a message
527
+ *
528
+ * @param threadId - Thread ID
529
+ * @param messageId - Message ID to react to
530
+ * @param emoji - Reaction emoji (to remove, simply omit this parameter)
531
+ */
532
+ sendReaction(threadId: number, messageId: string, emoji?: string): Promise<void>;
533
+ /**
534
+ * Edit a message
535
+ *
536
+ * @param messageId - Message ID to edit
537
+ * @param newText - New text content
538
+ */
539
+ editMessage(messageId: string, newText: string): Promise<void>;
540
+ /**
541
+ * Unsend/delete a message
542
+ *
543
+ * @param messageId - Message ID to unsend
544
+ */
545
+ unsendMessage(messageId: string): Promise<void>;
546
+ /**
547
+ * Send typing indicator
548
+ *
549
+ * @param threadId - Thread ID
550
+ * @param isTyping - Whether typing or not
551
+ * @param isGroup - Whether it's a group chat
552
+ */
553
+ sendTypingIndicator(threadId: number, isTyping?: boolean, isGroup?: boolean): Promise<void>;
554
+ /**
555
+ * Mark messages as read
556
+ *
557
+ * @param threadId - Thread ID
558
+ * @param watermarkTs - Timestamp to mark read up to (optional)
559
+ */
560
+ markAsRead(threadId: number, watermarkTs?: number): Promise<void>;
561
+ /**
562
+ * Upload media to Messenger
563
+ *
564
+ * @param threadId - Thread ID
565
+ * @param data - File data as Buffer
566
+ * @param filename - Filename
567
+ * @param mimeType - MIME type
568
+ * @param isVoice - Whether it's a voice message
569
+ * @returns Upload result with Facebook ID
570
+ */
571
+ uploadMedia(threadId: number, data: Buffer, filename: string, mimeType: string, isVoice?: boolean): Promise<UploadMediaResult>;
572
+ /**
573
+ * Send an image
574
+ *
575
+ * @param threadId - Thread ID
576
+ * @param data - Image data as Buffer
577
+ * @param filename - Filename
578
+ * @param caption - Optional caption
579
+ */
580
+ sendImage(threadId: number, data: Buffer, filename: string, caption?: string): Promise<SendMessageResult>;
581
+ /**
582
+ * Send a video
583
+ *
584
+ * @param threadId - Thread ID
585
+ * @param data - Video data as Buffer
586
+ * @param filename - Filename
587
+ * @param caption - Optional caption
588
+ */
589
+ sendVideo(threadId: number, data: Buffer, filename: string, caption?: string): Promise<SendMessageResult>;
590
+ /**
591
+ * Send a voice message
592
+ *
593
+ * @param threadId - Thread ID
594
+ * @param data - Audio data as Buffer
595
+ * @param filename - Filename
596
+ */
597
+ sendVoice(threadId: number, data: Buffer, filename: string): Promise<SendMessageResult>;
598
+ /**
599
+ * Send a file
600
+ *
601
+ * @param threadId - Thread ID
602
+ * @param data - File data as Buffer
603
+ * @param filename - Filename
604
+ * @param mimeType - MIME type
605
+ * @param caption - Optional caption
606
+ */
607
+ sendFile(threadId: number, data: Buffer, filename: string, mimeType: string, caption?: string): Promise<SendMessageResult>;
608
+ /**
609
+ * Send a sticker
610
+ *
611
+ * @param threadId - Thread ID
612
+ * @param stickerId - Sticker ID
613
+ */
614
+ sendSticker(threadId: number, stickerId: number): Promise<SendMessageResult>;
615
+ /**
616
+ * Create a 1:1 thread with a user
617
+ *
618
+ * @param userId - User ID to create thread with
619
+ * @returns Created thread info
620
+ */
621
+ createThread(userId: number): Promise<CreateThreadResult>;
622
+ /**
623
+ * Get detailed information about a user
624
+ *
625
+ * @param userId - User ID
626
+ * @returns User info
627
+ */
628
+ getUserInfo(userId: number): Promise<UserInfo>;
629
+ /**
630
+ * Set group photo/avatar
631
+ *
632
+ * @param threadId - Thread ID
633
+ * @param data - Image data as Buffer or base64 string
634
+ * @param mimeType - MIME type (e.g., 'image/jpeg', 'image/png')
635
+ *
636
+ * @warn Cannot remove group photo. Messenger web doesn't have a remove option?
637
+ */
638
+ setGroupPhoto(threadId: number, data: Buffer | string, mimeType?: string): Promise<void>;
639
+ /**
640
+ * Rename a group thread
641
+ *
642
+ * @param threadId - Thread ID
643
+ * @param newName - New name
644
+ */
645
+ renameThread(threadId: number, newName: string): Promise<void>;
646
+ /**
647
+ * Mute a thread
648
+ *
649
+ * @param threadId - Thread ID
650
+ * @param muteSeconds - Duration in seconds (-1 for forever, 0 to unmute)
651
+ */
652
+ muteThread(threadId: number, muteSeconds?: number): Promise<void>;
653
+ /**
654
+ * Unmute a thread
655
+ *
656
+ * @param threadId - Thread ID
657
+ */
658
+ unmuteThread(threadId: number): Promise<void>;
659
+ /**
660
+ * Delete a thread
661
+ *
662
+ * @param threadId - Thread ID
663
+ */
664
+ deleteThread(threadId: number): Promise<void>;
665
+ /**
666
+ * Search for users
667
+ *
668
+ * @param query - Search query
669
+ * @returns List of matching users
670
+ */
671
+ searchUsers(query: string): Promise<SearchUserResult[]>;
672
+ /**
673
+ * Send an E2EE message
674
+ *
675
+ * @param chatJid - Chat JID
676
+ * @param text - Message text
677
+ * @param options - Optional: replyToId and replyToSenderJid for replies
678
+ */
679
+ sendE2EEMessage(chatJid: string, text: string, options?: {
680
+ replyToId?: string;
681
+ replyToSenderJid?: string;
682
+ }): Promise<SendMessageResult>;
683
+ /**
684
+ * Send / Remove an E2EE reaction
685
+ *
686
+ * @param chatJid - Chat JID
687
+ * @param messageId - Message ID
688
+ * @param senderJid - Sender JID
689
+ * @param emoji - Reaction emoji (To remove it, simply omit this parameter)
690
+ */
691
+ sendE2EEReaction(chatJid: string, messageId: string, senderJid: string, emoji?: string): Promise<void>;
692
+ /**
693
+ * Send E2EE typing indicator
694
+ *
695
+ * @param chatJid - Chat JID
696
+ * @param isTyping - Whether typing
697
+ */
698
+ sendE2EETyping(chatJid: string, isTyping?: boolean): Promise<void>;
699
+ /**
700
+ * Edit an E2EE message
701
+ *
702
+ * @param chatJid - Chat JID
703
+ * @param messageId - Message ID to edit
704
+ * @param newText - New message text
705
+ */
706
+ editE2EEMessage(chatJid: string, messageId: string, newText: string): Promise<void>;
707
+ /**
708
+ * Unsend/delete an E2EE message
709
+ *
710
+ * @param chatJid - Chat JID
711
+ * @param messageId - Message ID to unsend
712
+ */
713
+ unsendE2EEMessage(chatJid: string, messageId: string): Promise<void>;
714
+ /**
715
+ * Send an E2EE image
716
+ *
717
+ * @param chatJid - Chat JID
718
+ * @param data - Image data as Buffer
719
+ * @param mimeType - MIME type (e.g., image/jpeg, image/png)
720
+ * @param options - Optional caption, dimensions, and reply options
721
+ */
722
+ sendE2EEImage(chatJid: string, data: Buffer, mimeType?: string, options?: {
723
+ caption?: string;
724
+ width?: number;
725
+ height?: number;
726
+ replyToId?: string;
727
+ replyToSenderJid?: string;
728
+ }): Promise<SendMessageResult>;
729
+ /**
730
+ * Send an E2EE video
731
+ *
732
+ * @param chatJid - Chat JID
733
+ * @param data - Video data as Buffer
734
+ * @param mimeType - MIME type (default: video/mp4)
735
+ * @param options - Optional caption, dimensions, duration, and reply options
736
+ */
737
+ sendE2EEVideo(chatJid: string, data: Buffer, mimeType?: string, options?: {
738
+ caption?: string;
739
+ width?: number;
740
+ height?: number;
741
+ duration?: number;
742
+ replyToId?: string;
743
+ replyToSenderJid?: string;
744
+ }): Promise<SendMessageResult>;
745
+ /**
746
+ * Send an E2EE audio/voice message
747
+ *
748
+ * @param chatJid - Chat JID
749
+ * @param data - Audio data as Buffer
750
+ * @param mimeType - MIME type (default: audio/ogg)
751
+ * @param options - Optional PTT (push-to-talk/voice message), duration, and reply options
752
+ */
753
+ sendE2EEAudio(chatJid: string, data: Buffer, mimeType?: string, options?: {
754
+ ptt?: boolean;
755
+ duration?: number;
756
+ replyToId?: string;
757
+ replyToSenderJid?: string;
758
+ }): Promise<SendMessageResult>;
759
+ /**
760
+ * Send an E2EE document/file
761
+ *
762
+ * @param chatJid - Chat JID
763
+ * @param data - File data as Buffer
764
+ * @param filename - Filename
765
+ * @param mimeType - MIME type
766
+ * @param options - Optional reply options
767
+ */
768
+ sendE2EEDocument(chatJid: string, data: Buffer, filename: string, mimeType: string, options?: {
769
+ replyToId?: string;
770
+ replyToSenderJid?: string;
771
+ }): Promise<SendMessageResult>;
772
+ /**
773
+ * Send an E2EE sticker
774
+ *
775
+ * @param chatJid - Chat JID
776
+ * @param data - Sticker data as Buffer (WebP format)
777
+ * @param mimeType - MIME type (default: image/webp)
778
+ * @param options - Optional reply options
779
+ */
780
+ sendE2EESticker(chatJid: string, data: Buffer, mimeType?: string, options?: {
781
+ replyToId?: string;
782
+ replyToSenderJid?: string;
783
+ }): Promise<SendMessageResult>;
784
+ /**
785
+ * Get E2EE device data as JSON string
786
+ *
787
+ * Use this to persist device data externally (e.g., in a database)
788
+ *
789
+ * @returns Device data as JSON string
790
+ */
791
+ getDeviceData(): string;
792
+ private startEventLoop;
793
+ private stopEventLoop;
794
+ private checkFullyReady;
795
+ private handleEvent;
796
+ private emitEvent;
797
+ /**
798
+ * Unload the native library (for cleanup)
799
+ * @warn Any attempt to find or call a function from this library after unloading it will crash.
800
+ * @returns void
801
+ */
802
+ unloadLibrary(): void;
803
+ }
804
+
805
+ /**
806
+ * Utility class for cookie parsing and conversion
807
+ *
808
+ * Supports multiple cookie formats:
809
+ * - C3C UFC Utility / EditThisCookie (array of cookie objects)
810
+ * - Simple object format { name: value }
811
+ * - Netscape/HTTP cookie file format
812
+ * - Cookie header string format
813
+ * - Base64 encoded cookies
814
+ */
815
+
816
+ /**
817
+ * Cookie object format (C3C UFC Utility / EditThisCookie style)
818
+ */
819
+ interface CookieObject {
820
+ name: string;
821
+ value: string;
822
+ domain?: string;
823
+ path?: string;
824
+ expires?: number | string;
825
+ expirationDate?: number;
826
+ httpOnly?: boolean;
827
+ secure?: boolean;
828
+ sameSite?: string;
829
+ hostOnly?: boolean;
830
+ session?: boolean;
831
+ }
832
+ /**
833
+ * Static utility class for cookie operations
834
+ * @example
835
+ * ```typescript
836
+ * import { Utils } from 'meta-messenger.js'
837
+ *
838
+ * // Parse any cookie format
839
+ * const cookies = Utils.parseCookies(rawData)
840
+ *
841
+ * // Convert cookies to header string
842
+ * const header = Utils.toCookieString(cookies)
843
+ * ```
844
+ */
845
+ declare class Utils extends null {
846
+ /**
847
+ * Parse cookies from various formats
848
+ * Automatically detects the format and parses accordingly
849
+ *
850
+ * @param input - Cookie data in any supported format
851
+ * @returns Parsed cookies object
852
+ */
853
+ static parseCookies(input: string | CookieObject[] | Record<string, string>): Cookies;
854
+ /**
855
+ * Parse cookies from C3C UFC Utility / EditThisCookie array format
856
+ *
857
+ * @param cookies - Array of cookie objects
858
+ * @returns Parsed cookies object
859
+ *
860
+ * @example
861
+ * ```typescript
862
+ * const cookies = Utils.fromCookieArray([
863
+ * { name: 'c_user', value: '123456' },
864
+ * { name: 'xs', value: 'abc...' }
865
+ * ])
866
+ * ```
867
+ */
868
+ static fromCookieArray(cookies: CookieObject[]): Cookies;
869
+ /**
870
+ * Parse cookies from cookie header string format
871
+ *
872
+ * @param cookieString - Cookie string (e.g., "name1=value1; name2=value2")
873
+ * @returns Parsed cookies object
874
+ *
875
+ * @example
876
+ * ```typescript
877
+ * const cookies = Utils.fromCookieString('c_user=123456; xs=abc...; datr=xyz...')
878
+ * ```
879
+ */
880
+ static fromCookieString(cookieString: string): Cookies;
881
+ /**
882
+ * Parse cookies from Netscape/HTTP cookie file format
883
+ *
884
+ * @param content - Netscape cookie file content
885
+ * @returns Parsed cookies object
886
+ *
887
+ * @example
888
+ * ```typescript
889
+ * const cookies = Utils.fromNetscape(`
890
+ * # Netscape HTTP Cookie File
891
+ * .facebook.com TRUE / TRUE 1234567890 c_user 123456
892
+ * .facebook.com TRUE / TRUE 1234567890 xs abc...
893
+ * `)
894
+ * ```
895
+ */
896
+ static fromNetscape(content: string): Cookies;
897
+ /**
898
+ * Parse cookies from Base64 encoded string
899
+ *
900
+ * @param base64 - Base64 encoded cookie data
901
+ * @returns Parsed cookies object
902
+ */
903
+ static fromBase64(base64: string): Cookies;
904
+ /**
905
+ * Convert cookies object to cookie header string
906
+ *
907
+ * @param cookies - Cookies object
908
+ * @returns Cookie header string
909
+ *
910
+ * @example
911
+ * ```typescript
912
+ * const header = Utils.toCookieString({ c_user: '123456', xs: 'abc...' })
913
+ * // Returns: "c_user=123456; xs=abc..."
914
+ * ```
915
+ */
916
+ static toCookieString(cookies: Cookies): string;
917
+ /**
918
+ * Convert cookies object to array format (C3C UFC Utility style)
919
+ *
920
+ * @param cookies - Cookies object
921
+ * @param domain - Cookie domain (default: .facebook.com)
922
+ * @returns Array of cookie objects
923
+ *
924
+ * @example
925
+ * ```typescript
926
+ * const arr = Utils.toCookieArray({ c_user: '123456', xs: 'abc...' })
927
+ * ```
928
+ */
929
+ static toCookieArray(cookies: Cookies, domain?: string): CookieObject[];
930
+ /**
931
+ * Convert cookies object to Netscape format
932
+ *
933
+ * @param cookies - Cookies object
934
+ * @param domain - Cookie domain (default: .facebook.com)
935
+ * @returns Netscape cookie file content
936
+ */
937
+ static toNetscape(cookies: Cookies, domain?: string): string;
938
+ /**
939
+ * Convert cookies to Base64 encoded JSON
940
+ *
941
+ * @param cookies - Cookies object
942
+ * @returns Base64 encoded string
943
+ */
944
+ static toBase64(cookies: Cookies): string;
945
+ /**
946
+ * Filter cookies to only essential ones for Facebook/Messenger
947
+ *
948
+ * @param cookies - Cookies object
949
+ * @returns Filtered cookies with only essential keys
950
+ */
951
+ static filterEssential(cookies: Cookies): Cookies;
952
+ /**
953
+ * Validate that cookies contain required fields
954
+ *
955
+ * @param cookies - Cookies object
956
+ * @returns True if cookies are valid
957
+ */
958
+ static validate(cookies: Cookies): boolean;
959
+ /**
960
+ * Get missing required cookies
961
+ *
962
+ * @param cookies - Cookies object
963
+ * @returns Array of missing cookie names
964
+ */
965
+ static getMissing(cookies: Cookies): string[];
966
+ /**
967
+ * Check if a string is valid Base64
968
+ */
969
+ private static isBase64;
970
+ }
971
+
972
+ /**
973
+ * meta-messenger.js - TypeScript wrapper for Facebook Messenger with E2EE support
974
+ *
975
+ * @example
976
+ * ```typescript
977
+ * import { Client, login } from 'meta-messenger.js'
978
+ *
979
+ * // Method 1: Using Client class directly
980
+ * const client = new Client({
981
+ * c_user: 'your_user_id',
982
+ * xs: 'your_xs_cookie',
983
+ * datr: 'your_datr_cookie',
984
+ * fr: 'your_fr_cookie'
985
+ * })
986
+ *
987
+ * client.on('message', (message) => {
988
+ * console.log('New message:', message)
989
+ * if (message.text === 'ping') {
990
+ * client.sendMessage(message.threadId, 'pong')
991
+ * }
992
+ * })
993
+ *
994
+ * await client.connect()
995
+ *
996
+ * // Method 2: Using login function (facebook-chat-api style)
997
+ * const api = await login({
998
+ * c_user: 'your_user_id',
999
+ * xs: 'your_xs_cookie',
1000
+ * datr: 'your_datr_cookie',
1001
+ * fr: 'your_fr_cookie'
1002
+ * })
1003
+ *
1004
+ * api.on('message', (message) => {
1005
+ * console.log('Got message:', message.text)
1006
+ * })
1007
+ * ```
1008
+ *
1009
+ * @packageDocumentation
1010
+ */
1011
+
1012
+ /**
1013
+ * Login to Facebook Messenger (E2EE disabled for simplicity)
1014
+ *
1015
+ * @param cookies - Authentication cookies
1016
+ * @param options - Client options
1017
+ * @returns Connected client instance
1018
+ *
1019
+ * @example
1020
+ * ```typescript
1021
+ * const api = await login({
1022
+ * c_user: 'your_user_id',
1023
+ * xs: 'your_xs_cookie',
1024
+ * datr: 'your_datr_cookie',
1025
+ * fr: 'your_fr_cookie'
1026
+ * })
1027
+ *
1028
+ * console.log('Logged in as:', api.user?.name)
1029
+ *
1030
+ * api.on('message', async (message) => {
1031
+ * if (message.senderId !== api.currentUserId) {
1032
+ * await api.sendMessage(message.threadId, 'Hello!')
1033
+ * }
1034
+ * })
1035
+ * ```
1036
+ */
1037
+ declare function login(cookies: Cookies, options?: ClientOptions): Promise<Client>;
1038
+ /**
1039
+ * Create a client without connecting
1040
+ *
1041
+ * @param cookies - Authentication cookies
1042
+ * @param options - Client options
1043
+ * @returns Client instance (not connected)
1044
+ */
1045
+ declare function createClient(cookies: Cookies, options?: ClientOptions): Client;
1046
+ declare const _default: {
1047
+ Client: typeof Client;
1048
+ login: typeof login;
1049
+ createClient: typeof createClient;
1050
+ };
1051
+
1052
+ export { type BaseEvent, Client, type ClientEvent, type ClientEventMap, type ClientOptions, type CookieObject, type Cookies, type CreateThreadResult, type DisconnectedEvent, type E2EEConnectedEvent, type E2EEMessage, type E2EEMessageEvent, type E2EEReactionEvent, type E2EEReceiptEvent, type ErrorEvent, type EventType, type InitialData, type LogLevel, type Message, type MessageEditEvent, type MessageEvent, type MessageUnsendEvent, type Platform, type ReactionEvent, type ReadyEvent, type ReconnectedEvent, type SearchUserResult, type SendMessageOptions, type SendMessageResult, type Thread, ThreadType, type TypingEvent, type UploadMediaResult, type User, type UserInfo, Utils, createClient, _default as default, login };