@dongdev/fca-unofficial 3.0.29 → 3.0.30

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.
Files changed (61) hide show
  1. package/CHANGELOG.md +229 -132
  2. package/DOCS.md +82 -3
  3. package/README.md +524 -632
  4. package/func/logAdapter.js +33 -0
  5. package/index.d.ts +6 -0
  6. package/module/config.js +11 -1
  7. package/module/loginHelper.js +63 -4
  8. package/package.json +88 -81
  9. package/src/api/action/changeAvatar.js +1 -1
  10. package/src/api/action/changeBio.js +1 -1
  11. package/src/api/action/handleFriendRequest.js +1 -1
  12. package/src/api/action/logout.js +1 -1
  13. package/src/api/action/refreshFb_dtsg.js +1 -1
  14. package/src/api/action/setPostReaction.js +1 -1
  15. package/src/api/action/unfriend.js +1 -1
  16. package/src/api/http/postFormData.js +1 -1
  17. package/src/api/messaging/changeArchivedStatus.js +1 -1
  18. package/src/api/messaging/changeBlockedStatus.js +1 -1
  19. package/src/api/messaging/changeGroupImage.js +1 -1
  20. package/src/api/messaging/changeNickname.js +1 -1
  21. package/src/api/messaging/changeThreadEmoji.js +1 -1
  22. package/src/api/messaging/createNewGroup.js +1 -1
  23. package/src/api/messaging/createThemeAI.js +1 -1
  24. package/src/api/messaging/deleteMessage.js +1 -1
  25. package/src/api/messaging/deleteThread.js +1 -1
  26. package/src/api/messaging/getFriendsList.js +1 -1
  27. package/src/api/messaging/getMessage.js +1 -1
  28. package/src/api/messaging/getThemePictures.js +1 -1
  29. package/src/api/messaging/handleMessageRequest.js +1 -1
  30. package/src/api/messaging/markAsDelivered.js +1 -1
  31. package/src/api/messaging/markAsRead.js +1 -1
  32. package/src/api/messaging/markAsReadAll.js +1 -1
  33. package/src/api/messaging/markAsSeen.js +1 -1
  34. package/src/api/messaging/muteThread.js +1 -1
  35. package/src/api/messaging/resolvePhotoUrl.js +1 -1
  36. package/src/api/messaging/sendMessage.js +1 -1
  37. package/src/api/messaging/setTitle.js +1 -1
  38. package/src/api/messaging/unsendMessage.js +1 -1
  39. package/src/api/messaging/uploadAttachment.js +1 -1
  40. package/src/api/socket/core/connectMqtt.js +16 -8
  41. package/src/api/socket/core/emitAuth.js +4 -0
  42. package/src/api/socket/core/getSeqID.js +6 -8
  43. package/src/api/socket/core/getTaskResponseData.js +3 -0
  44. package/src/api/socket/core/parseDelta.js +9 -0
  45. package/src/api/socket/detail/buildStream.js +11 -4
  46. package/src/api/socket/detail/constants.js +4 -0
  47. package/src/api/socket/listenMqtt.js +11 -5
  48. package/src/api/threads/getThreadHistory.js +1 -1
  49. package/src/api/threads/getThreadInfo.js +245 -388
  50. package/src/api/threads/getThreadList.js +1 -1
  51. package/src/api/threads/getThreadPictures.js +1 -1
  52. package/src/api/users/getUserID.js +1 -1
  53. package/src/api/users/getUserInfo.js +80 -8
  54. package/src/database/models/thread.js +5 -0
  55. package/src/remote/remoteClient.js +123 -0
  56. package/src/utils/broadcast.js +51 -0
  57. package/src/utils/loginParser.js +19 -1
  58. package/src/utils/request.js +33 -6
  59. package/.gitattributes +0 -2
  60. package/Fca_Database/database.sqlite +0 -0
  61. package/LICENSE-MIT +0 -21
package/README.md CHANGED
@@ -1,632 +1,524 @@
1
- <div align="center">
2
-
3
- # 💬 @dongdev/fca-unofficial
4
-
5
- **Unofficial Facebook Chat API for Node.js** - Interact with Facebook Messenger programmatically
6
-
7
- [![npm version](https://img.shields.io/npm/v/@dongdev/fca-unofficial.svg?style=for-the-badge)](https://www.npmjs.com/package/@dongdev/fca-unofficial)
8
- [![npm downloads](https://img.shields.io/npm/dm/@dongdev/fca-unofficial.svg?style=for-the-badge)](https://www.npmjs.com/package/@dongdev/fca-unofficial)
9
- [![License](https://img.shields.io/badge/license-MIT-blue.svg?style=for-the-badge)](./LICENSE-MIT)
10
- [![Node.js](https://img.shields.io/badge/node-%3E%3D12.0.0-brightgreen.svg?style=for-the-badge)](https://nodejs.org/)
11
-
12
- [Features](#-features) • [Installation](#-installation) • [Quick Start](#-quick-start) • [Documentation](#-documentation) • [Support](#-support)
13
-
14
- </div>
15
-
16
- ---
17
-
18
- ## 📋 Table of Contents
19
-
20
- - [⚠️ Important Disclaimer](#️-important-disclaimer)
21
- - [ Features](#-features)
22
- - [🔍 Introduction](#-introduction)
23
- - [📦 Installation](#-installation)
24
- - [🚀 Quick Start](#-quick-start)
25
- - [📝 Message Types](#-message-types)
26
- - [💾 AppState Management](#-appstate-management)
27
- - [👂 Listening for Messages](#-listening-for-messages)
28
- - [🎯 API Quick Reference](#-api-quick-reference)
29
- - [📚 Documentation](#-documentation)
30
- - [🛠️ Projects Using This API](#️-projects-using-this-api)
31
- - [🤝 Contributing](#-contributing)
32
- - [📄 License](#-license)
33
- - [👨‍💻 Author & Support](#-author--support)
34
-
35
- ---
36
-
37
- ## ⚠️ Important Disclaimer
38
-
39
- <div align="center">
40
-
41
- **⚠️ Use at your own risk! We are not responsible for account bans.**
42
-
43
- </div>
44
-
45
- **We are not responsible if your account gets banned for spammy activities such as:**
46
-
47
- - Sending lots of messages to people you don't know
48
- - ❌ Sending messages very quickly
49
- - Sending spammy looking URLs
50
- - ❌ Logging in and out very quickly
51
-
52
- **💡 Recommendations:**
53
-
54
- - Use **Firefox browser** or visit [fca.dongdev.id.vn](https://fca.dongdev.id.vn) to reduce logout issues (especially for iOS users)
55
- - Use **AppState** instead of credentials when possible
56
- - Implement **rate limiting** in your bots
57
- - Follow Facebook's Terms of Service
58
-
59
- **🆘 Support:** If you encounter errors, contact us [here](https://www.facebook.com/mdong.dev)
60
-
61
- ---
62
-
63
- ## Features
64
-
65
- - **Full Messenger API** - Send messages, files, stickers, and more
66
- - ✅ **Real-time Events** - Listen to messages, reactions, and thread events
67
- - ✅ **User Account Support** - Works with personal Facebook accounts (not just Pages)
68
- - ✅ **AppState Support** - Save login state to avoid re-authentication
69
- - **MQTT Protocol** - Real-time messaging via MQTT
70
- - ✅ **TypeScript Support** - Includes TypeScript definitions
71
- - ✅ **Active Development** - Regularly updated and maintained
72
-
73
- ---
74
-
75
- ## 🔍 Introduction
76
-
77
- Facebook provides an [official API for chat bots](https://developers.facebook.com/docs/messenger-platform), but it's **only available for Facebook Pages**.
78
-
79
- `@dongdev/fca-unofficial` is the **only API** that allows you to automate chat functionalities on a **user account** by emulating the browser. This means:
80
-
81
- - 🔄 Making the exact same GET/POST requests as a browser
82
- - 🔐 Does not work with auth tokens
83
- - 📝 Requires Facebook account credentials (email/password) or AppState
84
-
85
- **Perfect for:**
86
- - 🤖 Building chatbots
87
- - 📱 Automating message responses
88
- - 🔔 Creating notification systems
89
- - 🎮 Building interactive games
90
- - 📊 Analytics and monitoring
91
-
92
- ---
93
-
94
- ## 📦 Installation
95
-
96
- ```bash
97
- npm install @dongdev/fca-unofficial@latest
98
- ```
99
-
100
- **Requirements:**
101
- - Node.js >= 12.0.0
102
- - Active Facebook account
103
-
104
- ---
105
-
106
- ## 🚀 Quick Start
107
-
108
- ### 1️⃣ Login and Simple Echo Bot
109
-
110
- ```javascript
111
- const login = require("@dongdev/fca-unofficial");
112
-
113
- login({ appState: [] }, (err, api) => {
114
- if (err) return console.error(err);
115
-
116
- api.listenMqtt((err, event) => {
117
- if (err) return console.error(err);
118
-
119
- // Echo back the received message
120
- api.sendMessage(event.body, event.threadID);
121
- });
122
- });
123
- ```
124
-
125
- ### 2️⃣ Send Text Message
126
-
127
- ```javascript
128
- const login = require("@dongdev/fca-unofficial");
129
-
130
- login({ appState: [] }, (err, api) => {
131
- if (err) {
132
- console.error("Login Error:", err);
133
- return;
134
- }
135
-
136
- const yourID = "000000000000000"; // Replace with actual Facebook ID
137
- const msg = "Hey! 👋";
138
-
139
- api.sendMessage(msg, yourID, err => {
140
- if (err) console.error("Message Sending Error:", err);
141
- else console.log("✅ Message sent successfully!");
142
- });
143
- });
144
- ```
145
-
146
- > **💡 Tip:** To find your Facebook ID, look inside the cookies under the name `c_user`
147
-
148
- ### 3️⃣ Send File/Image
149
-
150
- ```javascript
151
- const login = require("@dongdev/fca-unofficial");
152
- const fs = require("fs");
153
-
154
- login({ appState: [] }, (err, api) => {
155
- if (err) {
156
- console.error("Login Error:", err);
157
- return;
158
- }
159
-
160
- const yourID = "000000000000000";
161
- const imagePath = __dirname + "/image.jpg";
162
-
163
- // Check if file exists
164
- if (!fs.existsSync(imagePath)) {
165
- console.error("❌ Error: Image file not found!");
166
- return;
167
- }
168
-
169
- const msg = {
170
- body: "Check out this image! 📷",
171
- attachment: fs.createReadStream(imagePath)
172
- };
173
-
174
- api.sendMessage(msg, yourID, err => {
175
- if (err) console.error("Message Sending Error:", err);
176
- else console.log("✅ Image sent successfully!");
177
- });
178
- });
179
- ```
180
-
181
- ---
182
-
183
- ## 📝 Message Types
184
-
185
- | Type | Usage | Example |
186
- |------|-------|---------|
187
- | **Regular text** | `{ body: "message text" }` | `{ body: "Hello!" }` |
188
- | **Sticker** | `{ sticker: "sticker_id" }` | `{ sticker: "369239263222822" }` |
189
- | **File/Image** | `{ attachment: fs.createReadStream(path) }` | `{ attachment: fs.createReadStream("image.jpg") }` |
190
- | **URL** | `{ url: "https://example.com" }` | `{ url: "https://github.com" }` |
191
- | **Large emoji** | `{ emoji: "👍", emojiSize: "large" }` | `{ emoji: "👍", emojiSize: "large" }` |
192
-
193
- > **📌 Note:** A message can only be a regular message (which can be empty) and optionally **one of the following**: a sticker, an attachment, or a URL.
194
-
195
- **Emoji sizes:** `small` | `medium` | `large`
196
-
197
- ---
198
-
199
- ## 💾 AppState Management
200
-
201
- ### Save AppState
202
-
203
- Save your login session to avoid re-authentication:
204
-
205
- ```javascript
206
- const fs = require("fs");
207
- const login = require("@dongdev/fca-unofficial");
208
-
209
- const credentials = { appState: [] };
210
-
211
- login(credentials, (err, api) => {
212
- if (err) {
213
- console.error("Login Error:", err);
214
- return;
215
- }
216
-
217
- try {
218
- const appState = JSON.stringify(api.getAppState(), null, 2);
219
- fs.writeFileSync("appstate.json", appState);
220
- console.log("✅ AppState saved successfully!");
221
- } catch (error) {
222
- console.error("❌ Error saving AppState:", error);
223
- }
224
- });
225
- ```
226
-
227
- ### Use Saved AppState
228
-
229
- Load your saved AppState for faster login:
230
-
231
- ```javascript
232
- const fs = require("fs");
233
- const login = require("@dongdev/fca-unofficial");
234
-
235
- login(
236
- { appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) },
237
- (err, api) => {
238
- if (err) {
239
- console.error("Login Error:", err);
240
- return;
241
- }
242
-
243
- console.log("✅ Logged in successfully!");
244
- // Your code here
245
- }
246
- );
247
- ```
248
-
249
- **Alternative:** Use [c3c-fbstate](https://github.com/c3cbot/c3c-fbstate) to get `fbstate.json`
250
-
251
- ---
252
-
253
- ## 👂 Listening for Messages
254
-
255
- ### Echo Bot with Stop Command
256
-
257
- ```javascript
258
- const fs = require("fs");
259
- const login = require("@dongdev/fca-unofficial");
260
-
261
- login(
262
- { appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) },
263
- (err, api) => {
264
- if (err) {
265
- console.error("Login Error:", err);
266
- return;
267
- }
268
-
269
- // Enable listening to events (join/leave, title change, etc.)
270
- api.setOptions({ listenEvents: true });
271
-
272
- const stopListening = api.listenMqtt((err, event) => {
273
- if (err) {
274
- console.error("Listen Error:", err);
275
- return;
276
- }
277
-
278
- // Mark as read
279
- api.markAsRead(event.threadID, err => {
280
- if (err) console.error("Mark as read error:", err);
281
- });
282
-
283
- // Handle different event types
284
- switch (event.type) {
285
- case "message":
286
- if (event.body && event.body.trim().toLowerCase() === "/stop") {
287
- api.sendMessage("Goodbye… 👋", event.threadID);
288
- stopListening();
289
- return;
290
- }
291
- api.sendMessage(`🤖 BOT: ${event.body}`, event.threadID);
292
- break;
293
-
294
- case "event":
295
- console.log("📢 Event Received:", event);
296
- break;
297
- }
298
- });
299
- }
300
- );
301
- ```
302
-
303
- ### Listen Options
304
-
305
- Configure listening behavior:
306
-
307
- ```javascript
308
- api.setOptions({
309
- listenEvents: true, // Receive events (join/leave, rename, etc.)
310
- selfListen: true, // Receive messages from yourself
311
- logLevel: "silent" // Disable logs (silent/error/warn/info/verbose)
312
- });
313
- ```
314
-
315
- **Default values:**
316
- - `listenEvents`: `false` - won't receive events like joining/leaving chat, title changes
317
- - `selfListen`: `false` - will ignore messages sent by the current account
318
- - `logLevel`: `"info"` - default logging level
319
-
320
- ---
321
-
322
- ## 🎯 API Quick Reference
323
-
324
- ### 📨 Messaging Methods
325
-
326
- ```javascript
327
- // Send message
328
- api.sendMessage(message, threadID, callback);
329
-
330
- // Send typing indicator
331
- api.sendTypingIndicator(threadID, callback);
332
-
333
- // Get message
334
- api.getMessage(threadID, limit, callback);
335
-
336
- // Edit message
337
- api.editMessage(message, messageID, callback);
338
-
339
- // Delete message
340
- api.deleteMessage(messageID, callback);
341
-
342
- // Unsend message
343
- api.unsendMessage(messageID, callback);
344
-
345
- // Set message reaction
346
- api.setMessageReaction(reaction, messageID, threadID, callback, forceCustomReaction);
347
-
348
- // Forward attachment
349
- api.forwardAttachment(attachmentID, threadID, callback);
350
-
351
- // Upload attachment
352
- api.uploadAttachment(attachment, callback);
353
-
354
- // Create poll
355
- api.createPoll(question, options, threadID, callback);
356
-
357
- // Create theme AI
358
- api.createThemeAI(threadID, callback);
359
-
360
- // Get theme pictures
361
- api.getThemePictures(threadID, callback);
362
-
363
- // Get emoji URL
364
- api.getEmojiUrl(emoji, size, callback);
365
-
366
- // Resolve photo URL
367
- api.resolvePhotoUrl(photoID, callback);
368
- ```
369
-
370
- ### 📬 Read Receipt & Delivery
371
-
372
- ```javascript
373
- // Mark as read
374
- api.markAsRead(threadID, callback);
375
-
376
- // Mark as read all
377
- api.markAsReadAll(callback);
378
-
379
- // Mark as delivered
380
- api.markAsDelivered(threadID, callback);
381
-
382
- // Mark as seen
383
- api.markAsSeen(threadID, callback);
384
- ```
385
-
386
- ### 👥 Thread Management
387
-
388
- ```javascript
389
- // Get thread info
390
- api.getThreadInfo(threadID, callback);
391
-
392
- // Get thread list
393
- api.getThreadList(limit, timestamp, callback);
394
-
395
- // Get thread history
396
- api.getThreadHistory(threadID, amount, timestamp, callback);
397
-
398
- // Get thread pictures
399
- api.getThreadPictures(threadID, limit, callback);
400
-
401
- // Search for thread
402
- api.searchForThread(name, callback);
403
-
404
- // Delete thread
405
- api.deleteThread(threadID, callback);
406
- ```
407
-
408
- ### 🎨 Thread Customization
409
-
410
- ```javascript
411
- // Change thread color
412
- api.changeThreadColor(color, threadID, callback);
413
-
414
- // Change thread emoji
415
- api.changeThreadEmoji(emoji, threadID, callback);
416
-
417
- // Change group image
418
- api.changeGroupImage(image, threadID, callback);
419
-
420
- // Set title
421
- api.setTitle(title, threadID, callback);
422
-
423
- // Change nickname
424
- api.changeNickname(nickname, userID, threadID, callback);
425
- ```
426
-
427
- ### 👤 User Management
428
-
429
- ```javascript
430
- // Get user info
431
- api.getUserInfo(userID, callback);
432
-
433
- // Get user info V2
434
- api.getUserInfoV2(userID, callback);
435
-
436
- // Get user ID
437
- api.getUserID(username, callback);
438
-
439
- // Get friends list
440
- api.getFriendsList(callback);
441
-
442
- // Get current user ID
443
- api.getCurrentUserID(callback);
444
- ```
445
-
446
- ### 👥 Group Management
447
-
448
- ```javascript
449
- // Create new group
450
- api.createNewGroup(participantIDs, groupTitle, callback);
451
-
452
- // Add user to group
453
- api.addUserToGroup(userID, threadID, callback);
454
-
455
- // Remove user from group
456
- api.removeUserFromGroup(userID, threadID, callback);
457
-
458
- // Change admin status
459
- api.changeAdminStatus(userID, threadID, admin, callback);
460
- ```
461
-
462
- ### ⚙️ Thread Settings
463
-
464
- ```javascript
465
- // Mute thread
466
- api.muteThread(threadID, muteSeconds, callback);
467
-
468
- // Change archived status
469
- api.changeArchivedStatus(threadID, archived, callback);
470
-
471
- // Change blocked status
472
- api.changeBlockedStatus(userID, block, callback);
473
-
474
- // Handle message request
475
- api.handleMessageRequest(threadID, accept, callback);
476
- ```
477
-
478
- ### 🔗 Sharing & Contacts
479
-
480
- ```javascript
481
- // Share contact
482
- api.shareContact(contactID, threadID, callback);
483
- ```
484
-
485
- ### 🎭 User Actions
486
-
487
- ```javascript
488
- // Change avatar
489
- api.changeAvatar(image, callback);
490
-
491
- // Change bio
492
- api.changeBio(bio, callback);
493
-
494
- // Handle friend request
495
- api.handleFriendRequest(userID, accept, callback);
496
-
497
- // Unfriend
498
- api.unfriend(userID, callback);
499
-
500
- // Set post reaction
501
- api.setPostReaction(postID, reaction, callback);
502
-
503
- // Refresh fb_dtsg
504
- api.refreshFb_dtsg(callback);
505
- ```
506
-
507
- ### 🔐 Authentication
508
-
509
- ```javascript
510
- // Logout
511
- api.logout(callback);
512
-
513
- // Get app state
514
- api.getAppState();
515
-
516
- // Set options
517
- api.setOptions(options);
518
- ```
519
-
520
- ### 📡 Listening
521
-
522
- ```javascript
523
- // Listen to MQTT events
524
- api.listenMqtt(callback);
525
- ```
526
-
527
- ### Event Types
528
-
529
- - `message` - New message received
530
- - `event` - Thread events (join, leave, title change, etc.)
531
- - `typ` - Typing indicator
532
- - `read_receipt` - Read receipt
533
- - `presence` - User presence (online/offline)
534
- - `read` - Message read status
535
- - `delivery_receipt` - Message delivery receipt
536
-
537
- ---
538
-
539
- ## 📚 Documentation
540
-
541
- For detailed API documentation, see [DOCS.md](./DOCS.md)
542
-
543
- **Includes:**
544
- - 📖 All available API methods
545
- - 🔧 Parameters and options
546
- - 📨 Event types and structures
547
- - ⚠️ Error handling
548
- - 💡 Advanced usage examples
549
-
550
- ---
551
-
552
- ## 🛠️ Projects Using This API
553
-
554
- Here are some awesome projects built with `@dongdev/fca-unofficial`:
555
-
556
- | Project | Description |
557
- |---------|-------------|
558
- | **[c3c](https://github.com/lequanglam/c3c)** | Customizable bot with plugins, supports Facebook & Discord |
559
- | **[Miraiv2](https://github.com/miraiPr0ject/miraiv2)** | Simple Facebook Messenger Bot |
560
- | **[Messer](https://github.com/mjkaufer/Messer)** | Command-line messaging for Facebook Messenger |
561
- | **[messen](https://github.com/tomquirk/messen)** | Rapidly build Facebook Messenger apps in Node.js |
562
- | **[Concierge](https://github.com/concierge/Concierge)** | Highly modular chat bot with built-in package manager |
563
- | **[Marc Zuckerbot](https://github.com/bsansouci/marc-zuckerbot)** | Facebook chat bot |
564
- | **[Botyo](https://github.com/ivkos/botyo)** | Modular bot for group chat rooms |
565
- | **[matrix-puppet-facebook](https://github.com/matrix-hacks/matrix-puppet-facebook)** | Facebook bridge for Matrix |
566
- | **[Miscord](https://github.com/Bjornskjald/miscord)** | Easy-to-use Facebook bridge for Discord |
567
- | **[chat-bridge](https://github.com/rexx0520/chat-bridge)** | Messenger, Telegram and IRC chat bridge |
568
- | **[Botium](https://github.com/codeforequity-at/botium-core)** | The Selenium for Chatbots |
569
- | **[Messenger-CLI](https://github.com/AstroCB/Messenger-CLI)** | Command-line interface for Facebook Messenger |
570
- | **[BotCore](https://github.com/AstroCB/BotCore)** | Tools for writing and managing Facebook Messenger bots |
571
-
572
- [See more projects...](https://github.com/Donix-VN/fca-unofficial#projects-using-this-api)
573
-
574
- ---
575
-
576
- ## 🤝 Contributing
577
-
578
- Contributions are welcome! We love your input 💙
579
-
580
- **How to contribute:**
581
-
582
- 1. 🍴 Fork the repository
583
- 2. 🌿 Create a new branch (`git checkout -b feature/AmazingFeature`)
584
- 3. 💾 Commit your changes (`git commit -m 'Add some AmazingFeature'`)
585
- 4. 📤 Push to the branch (`git push origin feature/AmazingFeature`)
586
- 5. 🔄 Open a Pull Request
587
-
588
- **Guidelines:**
589
- - Follow the existing code style
590
- - Add tests for new features
591
- - Update documentation as needed
592
- - Be respectful and constructive
593
-
594
- ---
595
-
596
- ## 📄 License
597
-
598
- This project is licensed under the **MIT License** - see the [LICENSE-MIT](./LICENSE-MIT) file for details.
599
-
600
- ---
601
-
602
- ## 👨‍💻 Author & Support
603
-
604
- <div align="center">
605
-
606
- **Made with ❤️ by DongDev**
607
-
608
- [![Facebook](https://img.shields.io/badge/Facebook-1877F2?style=for-the-badge&logo=facebook&logoColor=white)](https://www.facebook.com/mdong.dev)
609
- [![GitHub](https://img.shields.io/badge/GitHub-181717?style=for-the-badge&logo=github&logoColor=white)](https://github.com/Donix-VN)
610
-
611
- </div>
612
-
613
- ### 🔗 Links
614
-
615
- - 📦 [NPM Package](https://www.npmjs.com/package/@dongdev/fca-unofficial)
616
- - 🐙 [GitHub Repository](https://github.com/Donix-VN/fca-unofficial)
617
- - 🐛 [Issue Tracker](https://github.com/Donix-VN/fca-unofficial/issues)
618
- - 📖 [Documentation](./DOCS.md)
619
-
620
- ### ⭐ Support
621
-
622
- If this project is helpful, please give it a ⭐ on GitHub!
623
-
624
- ---
625
-
626
- <div align="center">
627
-
628
- **⚠️ Disclaimer:** This is an unofficial API and is not officially supported by Facebook. Use responsibly and comply with [Facebook Terms of Service](https://www.facebook.com/terms.php).
629
-
630
- Made with ❤️ for the developer community
631
-
632
- </div>
1
+ <div align="center">
2
+
3
+ # 💬 @dongdev/fca-unofficial
4
+
5
+ **Unofficial Facebook Chat API for Node.js** - Interact with Facebook Messenger programmatically
6
+
7
+ [Features](#-features) • [Installation](#-installation) • [Quick Start](#-quick-start) • [Documentation](#-documentation) • [Support](#-author--support)
8
+
9
+ </div>
10
+
11
+ ---
12
+
13
+ ## 📋 Table of Contents
14
+
15
+ - [⚠️ Disclaimer & Support Policy](#️-disclaimer--support-policy)
16
+ - [⚡ Why this fork?](#-why-this-fork)
17
+ - [✨ Features](#-features)
18
+ - [🔍 Introduction](#-introduction)
19
+ - [📦 Installation](#-installation)
20
+ - [🚀 Quick Start](#-quick-start)
21
+ - [📝 Message Types](#-message-types)
22
+ - [💾 AppState Management](#-appstate-management)
23
+ - [🔄 Auto Login](#-auto-login)
24
+ - [👂 Listening for Messages](#-listening-for-messages)
25
+ - [🎯 API Quick Reference](#-api-quick-reference)
26
+ - [📚 Documentation](#-documentation)
27
+ - [🛠️ Projects Using This API](#️-projects-using-this-api)
28
+ - [🤝 Contributing](#-contributing)
29
+ - [📄 License](#-license)
30
+ - [👨‍💻 Author & Support](#-author--support)
31
+
32
+ ---
33
+
34
+ ## ⚠️ Disclaimer & Support Policy
35
+
36
+ <div align="center">
37
+
38
+ **READ THIS BEFORE USING OR OPENING AN ISSUE.**
39
+
40
+ </div>
41
+
42
+ This repository is provided **"AS IS"** and is entirely open-source. By using this project, you explicitly agree to the following terms:
43
+
44
+ 1. **Use at your own risk:** We are NOT responsible if your account gets banned for spammy activities (sending messages too fast, unsolicited mass messaging, suspicious URLs, or rapid login/logout).
45
+ 2. **No Spoon-Feeding:** This is a tool for developers. If you cannot read source code, navigate directories, or use basic search tools (`Ctrl + Shift + F`), you should not be using this library.
46
+ 3. **No Free Programming Lessons:** I maintain the core updates and security patches for the community for free. I do **not** provide free JavaScript/TypeScript tutorials, nor will I tell you exactly which line of code to edit for your specific bot.
47
+ 4. **Custom Features = Paid Service:** Brainpower and time are not free. If you need me to write custom logic, reverse-engineer specific endpoints, or provide 1-on-1 support for your personal project, **that is a paid service**.
48
+
49
+ If you don't like this policy, feel free to fork the repository and maintain it yourself.
50
+
51
+ **Recommendations to avoid bans:**
52
+
53
+ - Use **Firefox** or the [fca.dongdev.id.vn](https://fca.dongdev.id.vn) flow to reduce logout issues (especially on iOS).
54
+ - Prefer **AppState** over email/password when possible.
55
+ - Use strict **rate limiting** in your bots.
56
+
57
+ ---
58
+
59
+ ## Why this fork?
60
+
61
+ Unlike other outdated forks, `@dongdev/fca-unofficial` is built with a focus on **real-world practicality and performance**:
62
+
63
+ - **Performance First:** Stripped out legacy, redundant code that causes technical debt.
64
+ - **Modernized Architecture:** Adapted to the latest Facebook backend structure.
65
+ - **Clean Logic:** No messy wrappers. The codebase is straightforward and easy to navigate if you actually open the files.
66
+
67
+ ---
68
+
69
+ ## Features
70
+
71
+ - ✅ **Full Messenger API** - Send messages, files, stickers, and more
72
+ - ✅ **Real-time Events** - Listen to messages, reactions, and thread events
73
+ - ✅ **User Account Support** - Works with personal Facebook accounts (not just Pages)
74
+ - ✅ **AppState Support** - Save login state to avoid re-authentication
75
+ - **MQTT Protocol** - Real-time messaging via MQTT
76
+ - ✅ **TypeScript Support** - Includes TypeScript definitions
77
+ - **Active Development** - Regularly updated and maintained
78
+
79
+ ---
80
+
81
+ ## 🔍 Introduction
82
+
83
+ Facebook provides an [official API for chat bots](https://developers.facebook.com/docs/messenger-platform), but it's **only available for Facebook Pages**.
84
+
85
+ `@dongdev/fca-unofficial` is the API that allows you to automate chat functionalities on a **user account** by emulating the browser. This means:
86
+
87
+ - 🔄 Making the exact same GET/POST requests as a browser
88
+ - 🔐 Does not work with auth tokens
89
+ - 📝 Requires Facebook account credentials (email/password) or AppState
90
+
91
+ **Perfect for:**
92
+
93
+ - 🤖 Building chatbots
94
+ - 📱 Automating message responses
95
+ - 🔔 Creating notification systems
96
+ - 🎮 Building interactive games
97
+ - 📊 Analytics and monitoring
98
+
99
+ ---
100
+
101
+ ## 📦 Installation
102
+
103
+ ```bash
104
+ npm install @dongdev/fca-unofficial@latest
105
+ ```
106
+
107
+ **Requirements:**
108
+
109
+ - Node.js >= 12.0.0
110
+ - Active Facebook account
111
+
112
+ ---
113
+
114
+ ## 🚀 Quick Start
115
+
116
+ ### 1️⃣ Login and Simple Echo Bot
117
+
118
+ ```javascript
119
+ const login = require("@dongdev/fca-unofficial");
120
+
121
+ login({ appState: [] }, (err, api) => {
122
+ if (err) return console.error(err);
123
+
124
+ api.listenMqtt((err, event) => {
125
+ if (err) return console.error(err);
126
+
127
+ // Echo back the received message
128
+ if (event.type === "message") {
129
+ api.sendMessage(event.body, event.threadID);
130
+ }
131
+ });
132
+ });
133
+ ```
134
+
135
+ ### 2️⃣ Send Text Message
136
+
137
+ ```javascript
138
+ const login = require("@dongdev/fca-unofficial");
139
+
140
+ login({ appState: [] }, (err, api) => {
141
+ if (err) {
142
+ console.error("Login Error:", err);
143
+ return;
144
+ }
145
+
146
+ const yourID = "000000000000000"; // Replace with actual Facebook ID
147
+ const msg = "Hey! 👋";
148
+
149
+ api.sendMessage(msg, yourID, (err) => {
150
+ if (err) console.error("Message Sending Error:", err);
151
+ else console.log("✅ Message sent successfully!");
152
+ });
153
+ });
154
+ ```
155
+
156
+ > **💡 Tip:** To find your Facebook ID, look inside the cookies under the name `c_user`
157
+
158
+ ### 3️⃣ Send File/Image
159
+
160
+ ```javascript
161
+ const login = require("@dongdev/fca-unofficial");
162
+ const fs = require("fs");
163
+
164
+ login({ appState: [] }, (err, api) => {
165
+ if (err) {
166
+ console.error("Login Error:", err);
167
+ return;
168
+ }
169
+
170
+ const yourID = "000000000000000";
171
+ const imagePath = __dirname + "/image.jpg";
172
+
173
+ // Check if file exists
174
+ if (!fs.existsSync(imagePath)) {
175
+ console.error(" Error: Image file not found!");
176
+ return;
177
+ }
178
+
179
+ const msg = {
180
+ body: "Check out this image! 📷",
181
+ attachment: fs.createReadStream(imagePath),
182
+ };
183
+
184
+ api.sendMessage(msg, yourID, (err) => {
185
+ if (err) console.error("Message Sending Error:", err);
186
+ else console.log("✅ Image sent successfully!");
187
+ });
188
+ });
189
+ ```
190
+
191
+ ---
192
+
193
+ ## 📝 Message Types
194
+
195
+ | Type | Usage | Example |
196
+ | ---------------- | ------------------------------------------- | -------------------------------------------------- |
197
+ | **Regular text** | `{ body: "message text" }` | `{ body: "Hello!" }` |
198
+ | **Sticker** | `{ sticker: "sticker_id" }` | `{ sticker: "369239263222822" }` |
199
+ | **File/Image** | `{ attachment: fs.createReadStream(path) }` | `{ attachment: fs.createReadStream("image.jpg") }` |
200
+ | **URL** | `{ url: "https://example.com" }` | `{ url: "https://github.com" }` |
201
+ | **Large emoji** | `{ emoji: "👍", emojiSize: "large" }` | `{ emoji: "👍", emojiSize: "large" }` |
202
+
203
+ > **📌 Note:** A message can only be a regular message (which can be empty) and optionally **one of the following**: a sticker, an attachment, or a URL.
204
+
205
+ **Emoji sizes:** `small` | `medium` | `large`
206
+
207
+ ---
208
+
209
+ ## 💾 AppState Management
210
+
211
+ ### Save AppState
212
+
213
+ Save your login session to avoid re-authentication:
214
+
215
+ ```javascript
216
+ const fs = require("fs");
217
+ const login = require("@dongdev/fca-unofficial");
218
+
219
+ const credentials = { email: "YOUR_EMAIL", password: "YOUR_PASSWORD" }; // Or use existing appState
220
+
221
+ login(credentials, (err, api) => {
222
+ if (err) {
223
+ console.error("Login Error:", err);
224
+ return;
225
+ }
226
+
227
+ try {
228
+ const appState = JSON.stringify(api.getAppState(), null, 2);
229
+ fs.writeFileSync("appstate.json", appState);
230
+ console.log("✅ AppState saved successfully!");
231
+ } catch (error) {
232
+ console.error("❌ Error saving AppState:", error);
233
+ }
234
+ });
235
+ ```
236
+
237
+ ### Use Saved AppState
238
+
239
+ Load your saved AppState for faster login:
240
+
241
+ ```javascript
242
+ const fs = require("fs");
243
+ const login = require("@dongdev/fca-unofficial");
244
+
245
+ login(
246
+ { appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) },
247
+ (err, api) => {
248
+ if (err) {
249
+ console.error("Login Error:", err);
250
+ return;
251
+ }
252
+
253
+ console.log("✅ Logged in successfully!");
254
+ // Your code here
255
+ },
256
+ );
257
+ ```
258
+
259
+ ---
260
+
261
+ ## 🔄 Auto Login
262
+
263
+ When your session (AppState) expires, the library can **automatically re-login** using credentials from a config file, so your bot can keep running without manual intervention.
264
+
265
+ 1. Create **`fca-config.json`** in your project root (same folder as where you run `node`):
266
+
267
+ ```json
268
+ {
269
+ "autoLogin": true,
270
+ "apiServer": "https://minhdong.site",
271
+ "apiKey": "",
272
+ "credentials": {
273
+ "email": "YOUR_EMAIL_OR_PHONE",
274
+ "password": "YOUR_PASSWORD",
275
+ "twofactor": ""
276
+ }
277
+ }
278
+ ```
279
+
280
+ 2. **Log in with AppState** as usual. If the session later expires (e.g. Facebook invalidates cookies), the library will use `credentials` (and optionally the external `apiServer`) to log in again and retry the request.
281
+
282
+ - Set **`autoLogin`** to `false` to disable automatic re-login.
283
+ - **`twofactor`**: Base32 secret for 2FA (not the 6-digit code). Leave empty if you do not use 2FA.
284
+ - **`apiServer`** / **`apiKey`**: Optional; used for external iOS-style login. Default server is `https://minhdong.site`.
285
+
286
+ Keep **`fca-config.json`** out of version control (add it to `.gitignore`) since it contains credentials.
287
+
288
+ ---
289
+
290
+ ## 🔐 Security, Trust & Supply Chain
291
+
292
+ - Published via **GitHub Actions** using `npm publish --provenance`, so the tarball on npm can be cryptographically tied back to this repo.
293
+ - Core runtime code in `module/` and `src/` is **readable JavaScript** with no obfuscated logic.
294
+ - Legacy forks (such as Horizon) are kept only for reference and are **not** shipped in the npm package.
295
+ - No telemetry or hidden network calls:
296
+ - All HTTP traffic is implemented in `src/utils/request.js` and `module/loginHelper.js`.
297
+ - External URLs (such as `apiServer` or proxies) are fully user‑configurable.
298
+ - The npm publish account uses **2FA** and dedicated automation tokens.
299
+
300
+ See `SECURITY.md` for more details.
301
+
302
+ ---
303
+
304
+ ## 👂 Listening for Messages
305
+
306
+ ### Echo Bot with Stop Command
307
+
308
+ ```javascript
309
+ const fs = require("fs");
310
+ const login = require("@dongdev/fca-unofficial");
311
+
312
+ login(
313
+ { appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) },
314
+ (err, api) => {
315
+ if (err) return console.error("Login Error:", err);
316
+
317
+ // Enable listening to events (join/leave, title change, etc.)
318
+ api.setOptions({ listenEvents: true });
319
+
320
+ const stopListening = api.listenMqtt((err, event) => {
321
+ if (err) return console.error("Listen Error:", err);
322
+
323
+ // Mark as read
324
+ api.markAsRead(event.threadID, (err) => {
325
+ if (err) console.error("Mark as read error:", err);
326
+ });
327
+
328
+ // Handle different event types
329
+ switch (event.type) {
330
+ case "message":
331
+ if (event.body && event.body.trim().toLowerCase() === "/stop") {
332
+ api.sendMessage("Goodbye… 👋", event.threadID);
333
+ stopListening();
334
+ return;
335
+ }
336
+ api.sendMessage(`🤖 BOT: ${event.body}`, event.threadID);
337
+ break;
338
+
339
+ case "event":
340
+ console.log("📢 Event Received:", event);
341
+ break;
342
+ }
343
+ });
344
+ },
345
+ );
346
+ ```
347
+
348
+ ### Listen Options
349
+
350
+ Configure listening behavior:
351
+
352
+ ```javascript
353
+ api.setOptions({
354
+ listenEvents: true, // Receive events (join/leave, rename, etc.)
355
+ selfListen: true, // Receive messages from yourself
356
+ logLevel: "silent", // Disable logs (silent/error/warn/info/verbose)
357
+ });
358
+ ```
359
+
360
+ ---
361
+
362
+ ## 🎯 API Quick Reference
363
+
364
+ _(For full details, please read the source code or `DOCS.md`)_
365
+
366
+ ### 📨 Messaging
367
+
368
+ `sendMessage`, `sendTypingIndicator`, `getMessage`, `editMessage`, `deleteMessage`, `unsendMessage`, `setMessageReaction`, `forwardAttachment`, `uploadAttachment`, `createPoll`
369
+
370
+ ### 📬 Read Receipt & Delivery
371
+
372
+ `markAsRead`, `markAsReadAll`, `markAsDelivered`, `markAsSeen`
373
+
374
+ ### 👥 Thread Management
375
+
376
+ `getThreadInfo`, `getThreadList`, `getThreadHistory`, `deleteThread`, `changeThreadColor`, `changeThreadEmoji`, `changeGroupImage`, `setTitle`, `changeNickname`
377
+
378
+ ### 👤 User & Group Management
379
+
380
+ `getUserInfo`, `getFriendsList`, `getCurrentUserID`, `createNewGroup`, `addUserToGroup`, `removeUserFromGroup`, `changeAdminStatus`
381
+
382
+ ### ⚙️ Thread Settings & Actions
383
+
384
+ `muteThread`, `changeArchivedStatus`, `changeBlockedStatus`, `handleMessageRequest`, `changeAvatar`, `changeBio`, `handleFriendRequest`, `unfriend`
385
+
386
+ ### 🔐 Auth & Listening
387
+
388
+ `logout`, `getAppState`, `setOptions`, `listenMqtt`
389
+
390
+ ---
391
+ ## 🎛 Event Hooks & Remote Control (Advanced)
392
+
393
+ Starting from `3.x`, the API instance also behaves like an **EventEmitter** for lifecycle and remote‑control events:
394
+
395
+ - **Lifecycle events**:
396
+ - `sessionExpired` — login session is no longer valid, auto‑login will be attempted (if configured).
397
+ - `autoLoginSuccess` — auto‑login succeeded and the failed request will be retried.
398
+ - `autoLoginFailed` auto‑login could not recover the session.
399
+ - `checkpoint` — generic checkpoint, with subtype in `{ type: "282" | "956" | "scraping_warning" }`.
400
+ - `checkpoint_282`, `checkpoint_956` — more specific checkpoint events.
401
+ - `loginBlocked` Facebook actively blocked the login (error `1357001`).
402
+ - `rateLimit` — HTTP 429 detected on Facebook endpoints.
403
+ - `networkError` — network‑level failure (timeouts, DNS, connection reset, etc.).
404
+
405
+ Usage:
406
+
407
+ ```javascript
408
+ api.on("checkpoint_956", ({ res }) => {
409
+ console.error("Checkpoint 956 detected, manual action required.");
410
+ });
411
+
412
+ api.on("rateLimit", ({ url, method }) => {
413
+ console.warn("Rate limit hit on", method, url);
414
+ });
415
+ ```
416
+
417
+ - **Remote control events** (when `remoteControl.enabled` is `true` in `fca-config.json`):
418
+ - `remoteConnected` / `remoteDisconnected`
419
+ - `remoteStop`
420
+ - `remoteBroadcast`
421
+ - `remoteMessage` (raw messages from your WS backend)
422
+
423
+ See `examples/remote-control.js` for a concrete integration example.
424
+
425
+ ---
426
+
427
+ ## 🌐 Proxy Configuration & Broadcast Helper
428
+
429
+ - **Proxy support**:
430
+ - You can pass a proxy per‑login:
431
+
432
+ ```javascript
433
+ login({ appState }, (err, api) => {
434
+ if (err) return console.error(err);
435
+ api.setOptions({ proxy: "http://user:pass@host:port" });
436
+ });
437
+ ```
438
+
439
+ - Or define a default in `fca-config.json`:
440
+
441
+ ```json
442
+ {
443
+ "proxy": "http://user:pass@host:port"
444
+ }
445
+ ```
446
+
447
+ - All HTTP calls go through this proxy using `https-proxy-agent`.
448
+
449
+ - **Broadcast helper** (optional util):
450
+ - Not part of the public API surface on purpose (to avoid encouraging spam).
451
+ - You can use it manually:
452
+
453
+ ```javascript
454
+ const broadcast = require("@dongdev/fca-unofficial/src/utils/broadcast");
455
+
456
+ const threads = ["1000...", "2000..."];
457
+ await broadcast(api, threads, { body: "Hello!" }, {
458
+ delayMs: 1200,
459
+ skipBlocked: true
460
+ });
461
+ ```
462
+
463
+ ---
464
+
465
+ ## 📚 Documentation
466
+
467
+ - **[DOCS.md](./DOCS.md)** — Full API reference, examples, and best practices.
468
+ - **[docs/ARCHITECTURE.md](./docs/ARCHITECTURE.md)** Codebase structure and modules (for contributors).
469
+ - For implementation details, the `src/` folder is the authoritative reference.
470
+
471
+ ---
472
+
473
+ ## 🛠️ Projects Using This API
474
+
475
+ Here are some awesome projects built with `@dongdev/fca-unofficial`:
476
+ _(See [GitHub Repository](https://github.com/Donix-VN/fca-unofficial) for the full list)._
477
+
478
+ ---
479
+
480
+ ## 🤝 Contributing
481
+
482
+ Contributions are welcome! If you want to optimize something or fix a bug:
483
+
484
+ 1. 🍴 Fork the repository
485
+ 2. 🌿 Create a new branch
486
+ 3. 💾 Commit your changes
487
+ 4. 📤 Push to the branch
488
+ 5. 🔄 Open a Pull Request
489
+
490
+ **Rule:** Keep it clean, minimal, and performant. No bloated dependencies.
491
+
492
+ ---
493
+
494
+ ## 📄 License
495
+
496
+ This project is licensed under the **MIT License** - see the [LICENSE-MIT](./LICENSE-MIT) file for details.
497
+
498
+ ---
499
+
500
+ ## 👨‍💻 Author & Support
501
+
502
+ <div align="center">
503
+
504
+ **Maintained by DongDev (Donix)**
505
+
506
+ </div>
507
+
508
+ ### 🛠️ Need Custom Work?
509
+
510
+ If you have the budget and need specialized features, API reverse-engineering, or private bot development, reach out to me directly via Facebook. **Do not contact me for free coding lessons.**
511
+
512
+ ### 🔗 Links
513
+
514
+ - 📦 [NPM Package](https://www.npmjs.com/package/@dongdev/fca-unofficial)
515
+ - 🐙 [GitHub Repository](https://github.com/Donix-VN/fca-unofficial)
516
+ - 🐛 [Issue Tracker](https://github.com/Donix-VN/fca-unofficial/issues)
517
+
518
+ ---
519
+
520
+ <div align="center">
521
+
522
+ Made with ❤️ (and a lot of caffeine) for the developer community.
523
+
524
+ </div>