sagor-fca 0.0.9 → 0.0.10

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 (76) hide show
  1. package/.gitattributes +2 -0
  2. package/.github/workflows/SaGor.yml +22 -0
  3. package/LICENSE-MIT +21 -0
  4. package/README.md +365 -64
  5. package/Sagor_Database/sagor.sqlite +0 -0
  6. package/docs/ARCHITECTURE.md +142 -0
  7. package/examples/remote-control.js +85 -0
  8. package/func/checkUpdate.js +219 -10
  9. package/func/logAdapter.js +19 -16
  10. package/func/logger.js +29 -47
  11. package/index.d.ts +1 -1
  12. package/index.js +5 -14
  13. package/module/config.js +22 -20
  14. package/module/login.js +100 -78
  15. package/module/options.js +33 -26
  16. package/package.json +14 -20
  17. package/src/api/action/addExternalModule.js +16 -10
  18. package/src/api/action/changeBio.js +45 -18
  19. package/src/api/action/enableAutoSaveAppState.js +53 -52
  20. package/src/api/action/getCurrentUserID.js +0 -4
  21. package/src/api/action/refreshFb_dtsg.js +37 -51
  22. package/src/api/http/httpGet.js +33 -14
  23. package/src/api/http/httpPost.js +37 -16
  24. package/src/api/http/postFormData.js +39 -14
  25. package/src/api/messaging/sendMessage.js +1 -1
  26. package/src/api/socket/core/connectMqtt.js +174 -181
  27. package/src/api/socket/core/emitAuth.js +74 -50
  28. package/src/api/socket/core/getSeqID.js +267 -115
  29. package/src/api/socket/core/getTaskResponseData.js +7 -9
  30. package/src/api/socket/detail/constants.js +4 -5
  31. package/src/api/socket/listenMqtt.js +1 -1
  32. package/src/api/socket/middleware/index.js +181 -45
  33. package/src/api/threads/getThreadHistory.js +3 -3
  34. package/src/api/threads/getThreadInfo.js +1 -1
  35. package/src/api/threads/getThreadPictures.js +0 -4
  36. package/src/api/users/getUserID.js +46 -29
  37. package/src/api/users/getUserInfo.js +2 -2
  38. package/src/core/sendReqMqtt.js +56 -29
  39. package/src/database/models/thread.js +0 -4
  40. package/src/database/models/user.js +0 -4
  41. package/src/remote/remoteClient.js +88 -36
  42. package/src/utils/broadcast.js +34 -44
  43. package/src/utils/client.js +7 -7
  44. package/src/utils/constants.js +5 -35
  45. package/src/utils/cookies.js +49 -54
  46. package/src/utils/headers.js +96 -75
  47. package/src/utils/request/client.js +10 -16
  48. package/src/utils/request/config.js +11 -13
  49. package/src/utils/request/defaults.js +26 -20
  50. package/src/utils/request/helpers.js +27 -12
  51. package/src/utils/request/index.js +13 -8
  52. package/src/utils/request/methods.js +91 -20
  53. package/src/utils/request/proxy.js +8 -10
  54. package/src/utils/request/retry.js +41 -51
  55. package/src/utils/request/sanitize.js +25 -17
  56. package/func/utils.js +0 -5
  57. package/src/api/feed/commentOnPost.js +0 -120
  58. package/src/api/feed/getPostInfo.js +0 -98
  59. package/src/api/groups/getGroupJoinRequests.js +0 -126
  60. package/src/api/groups/handleGroupJoinRequest.js +0 -134
  61. package/src/api/live/getLiveStreamInfo.js +0 -35
  62. package/src/api/live/reactLiveStream.js +0 -31
  63. package/src/api/marketplace/getMarketplaceItemDetail.js +0 -35
  64. package/src/api/marketplace/getMarketplaceItems.js +0 -30
  65. package/src/api/messaging/notes.js +0 -98
  66. package/src/api/messaging/sendVoiceMessage.js +0 -173
  67. package/src/api/privacy/getPrivacySettings.js +0 -32
  68. package/src/api/privacy/setPrivacySettings.js +0 -31
  69. package/src/api/professional/getProfessionalInfo.js +0 -35
  70. package/src/api/professional/toggleProfessionalMode.js +0 -31
  71. package/src/api/reels/getReels.js +0 -30
  72. package/src/api/reels/reactReel.js +0 -31
  73. package/src/utils/format/s +0 -0
  74. package/src/utils/loginParser/s +0 -0
  75. package/src/utils/sessionKeeper.js +0 -275
  76. package/src/utils/userAgent.js +0 -28
package/.gitattributes ADDED
@@ -0,0 +1,2 @@
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
@@ -0,0 +1,22 @@
1
+ name: "publish npm by SaGor"
2
+
3
+ on: push
4
+
5
+ jobs:
6
+ publish:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - name: Checkout
10
+ uses: actions/checkout@v2
11
+
12
+ - name: Setup Node.js
13
+ uses: actions/setup-node@v2
14
+ with:
15
+ node-version: 16
16
+ registry-url: https://registry.npmjs.org
17
+
18
+ - name: Publish to NPM
19
+ run: npm publish --access public
20
+ env:
21
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
22
+
package/LICENSE-MIT ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Phạm Minh Đồng (DongDev)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,8 +1,10 @@
1
- # 💬 sagor-fca
2
-
3
1
  <div align="center">
4
2
 
5
- **Unofficial Facebook Chat API for Node.js**
3
+ # sagor-nx-fca
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)
6
8
 
7
9
  </div>
8
10
 
@@ -11,15 +13,21 @@
11
13
  ## 📋 Table of Contents
12
14
 
13
15
  - [⚠️ Disclaimer & Support Policy](#️-disclaimer--support-policy)
16
+ - [⚡ Why this fork?](#-why-this-fork)
14
17
  - [✨ Features](#-features)
18
+ - [🔍 Introduction](#-introduction)
19
+ - [📦 Installation](#-installation)
15
20
  - [🚀 Quick Start](#-quick-start)
16
- - [📚 API Reference](#-api-reference)
21
+ - [📝 Message Types](#-message-types)
17
22
  - [💾 AppState Management](#-appstate-management)
18
23
  - [🔄 Auto Login](#-auto-login)
19
- - [🔐 Security & Anti-Ban](#-security--anti-ban)
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)
20
28
  - [🤝 Contributing](#-contributing)
21
29
  - [📄 License](#-license)
22
- - [👨‍💻 Author](#-author)
30
+ - [👨‍💻 Author & Support](#-author--support)
23
31
 
24
32
  ---
25
33
 
@@ -33,60 +41,82 @@
33
41
 
34
42
  This repository is provided **"AS IS"** and is entirely open-source. By using this project, you explicitly agree to the following terms:
35
43
 
36
- 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).
37
- 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.
38
- 3. **No Free Programming Lessons:** The maintainers provide core updates and security patches for the community for free. We do **not** provide free JavaScript/TypeScript tutorials, nor will we tell you exactly which line of code to edit for your specific bot.
39
- 4. **Custom Features = Paid Service:** Brainpower and time are not free. If you need custom logic, reverse-engineer specific endpoints, or 1-on-1 support for your personal project, **that is a paid service**.
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**.
40
48
 
41
- If you do not agree with this policy, you are free to fork the repository and maintain it yourself.
49
+ If you don't like this policy, feel free to fork the repository and maintain it yourself.
42
50
 
43
- **Recommendations to minimize ban risks:**
51
+ **Recommendations to avoid bans:**
44
52
 
45
- - Utilize **AppState** over direct email/password authentication whenever possible.
46
- - Implement strict **rate limiting** within your bot's operations.
47
- - Ensure your application adheres to Facebook's platform policies.
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.
48
56
 
49
57
  ---
50
58
 
51
- ## Features
59
+ ## Why this fork?
52
60
 
53
- This **sagor-fca** extends the base functionality with advanced features for a more robust and versatile Facebook automation experience:
61
+ Unlike other outdated forks, `@sagor/fca-unofficial` is built with a focus on **real-world practicality and performance**:
54
62
 
55
- | Category | Feature | Description |
56
- | :--- | :--- | :--- |
57
- | **Core Messenger** | Full Messenger API | Send messages, files, stickers, and more. |
58
- | | Real-time Events | Listen to messages, reactions, and thread events. |
59
- | | User Account Support | Works with personal Facebook accounts (not just Pages). |
60
- | | AppState Support | Save login state to avoid re-authentication. |
61
- | | MQTT Protocol | Real-time messaging via MQTT. |
62
- | | TypeScript Support | Includes TypeScript definitions. |
63
- | **Story Interaction** | `getStories`, `reactStory`, `viewStory` | Friends' stories can be viewed, reacted to, and marked as 'Seen'. |
64
- | **Group Management** | `getGroupJoinRequests`, `handleGroupJoinRequest` | View and manage pending group join requests. |
65
- | **Feed Interaction** | `getPostInfo`, `commentOnPost` | Retrieve detailed information about a specific post and comment on it. |
66
- | **Advanced Messaging** | `sendVoiceMessage` | Send audio files as native voice notes. |
67
- | **Reels Interaction** | `getReels`, `reactReel` | Fetch and react to Facebook Reels. |
68
- | **Professional Mode** | `getProfessionalInfo`, `toggleProfessionalMode` | View professional profile information and toggle Professional Mode. |
69
- | **Security & Anti-Ban** | Request Throttling | Configurable delay between requests to avoid detection. |
70
- | | User-Agent Rotation | Automatic rotation of User-Agents for each request. |
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.
71
66
 
72
67
  ---
73
68
 
74
- ## 🚀 Quick Start
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
75
82
 
76
- ### Installation
83
+ Facebook provides an [official API for chat bots](https://developers.facebook.com/docs/messenger-platform), but it's **only available for Facebook Pages**.
77
84
 
78
- To install `sagor-fca`, ensure you have Node.js (version 12.0.0 or higher) installed. Then, use npm:
85
+ `@sagor/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
79
102
 
80
103
  ```bash
81
- npm install sagor-fca
104
+ npm install @sagor/fca-unofficial@latest
82
105
  ```
83
106
 
84
- ### Basic Usage (Echo Bot)
107
+ **Requirements:**
108
+
109
+ - Node.js >= 12.0.0
110
+ - Active Facebook account
85
111
 
86
- Here's a simple example to get started with an echo bot:
112
+ ---
113
+
114
+ ## 🚀 Quick Start
115
+
116
+ ### 1️⃣ Login and Simple Echo Bot
87
117
 
88
118
  ```javascript
89
- const login = require("sagor-fca");
119
+ const login = require("@sagor/fca-unofficial");
90
120
 
91
121
  login({ appState: [] }, (err, api) => {
92
122
  if (err) return console.error(err);
@@ -94,6 +124,7 @@ login({ appState: [] }, (err, api) => {
94
124
  api.listenMqtt((err, event) => {
95
125
  if (err) return console.error(err);
96
126
 
127
+ // Echo back the received message
97
128
  if (event.type === "message") {
98
129
  api.sendMessage(event.body, event.threadID);
99
130
  }
@@ -101,10 +132,10 @@ login({ appState: [] }, (err, api) => {
101
132
  });
102
133
  ```
103
134
 
104
- ### Sending a Text Message
135
+ ### 2️⃣ Send Text Message
105
136
 
106
137
  ```javascript
107
- const login = require("sagor-fca");
138
+ const login = require("@sagor/fca-unofficial");
108
139
 
109
140
  login({ appState: [] }, (err, api) => {
110
141
  if (err) {
@@ -113,7 +144,7 @@ login({ appState: [] }, (err, api) => {
113
144
  }
114
145
 
115
146
  const yourID = "000000000000000"; // Replace with actual Facebook ID
116
- const msg = "Hello I'm SaGor bot👋";
147
+ const msg = "Hey! 👋";
117
148
 
118
149
  api.sendMessage(msg, yourID, (err) => {
119
150
  if (err) console.error("Message Sending Error:", err);
@@ -122,25 +153,72 @@ login({ appState: [] }, (err, api) => {
122
153
  });
123
154
  ```
124
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("@sagor/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
+
125
191
  ---
126
192
 
127
- ## 📚 API Reference
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" }` |
128
202
 
129
- Detailed documentation for each API endpoint, including parameters and return types, can be found within the `src/api` directory of this repository. Key modules include `action`, `messaging`, `threads`, `users`, `stories`, `groups`, `feed`, `reels`, and `professional`.
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`
130
206
 
131
207
  ---
132
208
 
133
209
  ## 💾 AppState Management
134
210
 
135
- AppState is crucial for maintaining login sessions without re-authenticating with email/password. It helps prevent frequent logouts and reduces the risk of account flags.
211
+ ### Save AppState
136
212
 
137
- ### Saving AppState
213
+ Save your login session to avoid re-authentication:
138
214
 
139
215
  ```javascript
140
216
  const fs = require("fs");
141
- const login = require("sagor-fca");
217
+ const login = require("@sagor/fca-unofficial");
218
+
219
+ const credentials = { email: "YOUR_EMAIL", password: "YOUR_PASSWORD" }; // Or use existing appState
142
220
 
143
- login({ email: "YOUR_EMAIL", password: "YOUR_PASSWORD" }, (err, api) => {
221
+ login(credentials, (err, api) => {
144
222
  if (err) {
145
223
  console.error("Login Error:", err);
146
224
  return;
@@ -156,11 +234,13 @@ login({ email: "YOUR_EMAIL", password: "YOUR_PASSWORD" }, (err, api) => {
156
234
  });
157
235
  ```
158
236
 
159
- ### Using Saved AppState
237
+ ### Use Saved AppState
238
+
239
+ Load your saved AppState for faster login:
160
240
 
161
241
  ```javascript
162
242
  const fs = require("fs");
163
- const login = require("sagor-fca");
243
+ const login = require("@sagor/fca-unofficial");
164
244
 
165
245
  login(
166
246
  { appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) },
@@ -170,8 +250,8 @@ login(
170
250
  return;
171
251
  }
172
252
 
173
- console.log("✅ Logged in successfully using AppState!");
174
- // Your bot logic here
253
+ console.log("✅ Logged in successfully!");
254
+ // Your code here
175
255
  },
176
256
  );
177
257
  ```
@@ -180,44 +260,265 @@ login(
180
260
 
181
261
  ## 🔄 Auto Login
182
262
 
183
- This library supports automatic re-login if your session expires, ensuring continuous operation of your bot. Configure `fca-config.json` in your project root:
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`):
184
266
 
185
267
  ```json
186
268
  {
187
269
  "autoLogin": true,
270
+ "apiServer": "https://minhdong.site",
271
+ "apiKey": "",
188
272
  "credentials": {
189
273
  "email": "YOUR_EMAIL_OR_PHONE",
190
274
  "password": "YOUR_PASSWORD",
191
- "twofactor": "" // Base32 secret for 2FA, leave empty if not used
275
+ "twofactor": ""
192
276
  }
193
277
  }
194
278
  ```
195
279
 
196
- If `autoLogin` is `true` and credentials are provided, the library will attempt to re-authenticate if the current session becomes invalid.
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("@sagor/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("@sagor/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
+ ```
197
462
 
198
463
  ---
199
464
 
200
- ## 🔐 Security & Anti-Ban
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
+ ---
201
472
 
202
- To enhance the longevity and stability of your bot, `sagor-fca` includes built-in anti-ban measures:
473
+ ## 🛠️ Projects Using This API
203
474
 
204
- - **Request Throttling:** A default delay of 500ms is introduced between API requests. This can be configured in `src/utils/request/config.js` via `requestThrottlingMs`.
205
- - **User-Agent Rotation:** The library automatically rotates through a list of up-to-date browser User-Agents (as of March 2026) to mimic legitimate browser traffic, reducing the likelihood of detection and blocking by Facebook.
475
+ Here are some awesome projects built with `@sagor/fca-unofficial`:
476
+ _(See [GitHub Repository](https://github.com/SAGOR-KINGx/fca-unofficial) for the full list)._
206
477
 
207
478
  ---
208
479
 
209
480
  ## 🤝 Contributing
210
481
 
211
- Contributions are welcome! If you have suggestions for improvements, new features, or bug fixes, please feel free to open an issue or submit a pull request to the repository.
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.
212
491
 
213
492
  ---
214
493
 
215
494
  ## 📄 License
216
495
 
217
- This project is open-source and available under the [MIT License](LICENSE).
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 SaGor**
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/@sagor/fca-unofficial)
515
+ - 🐙 [GitHub Repository](https://github.com/SAGOR- KINGx/fca-unofficial)
516
+ - 🐛 [Issue Tracker](https://github.com/SAGOR-KINGx/fca-unofficial/issues)
218
517
 
219
518
  ---
220
519
 
221
- ## 👨‍💻 Author
520
+ <div align="center">
521
+
522
+ Made with ❤️ (and a lot of caffeine) for the developer community.
222
523
 
223
- Developed and maintained by **SAGOR**.
524
+ </div>
Binary file