@dongdev/fca-unofficial 3.0.28 → 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 -7
  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/CHANGELOG.md CHANGED
@@ -1,196 +1,293 @@
1
1
  # Changelog
2
- Too lazy to write changelog, sorry! (will write changelog in the next release, through.)
3
- ## v1.0.10 - 2025-04-24
4
- - Hotfix / auto bump
5
2
 
6
- ## v1.0.11 - 2025-04-24
7
- - Hotfix / auto bump
3
+ All notable changes to this project are documented in this file.
8
4
 
9
- ## v1.0.12 - 2025-04-28
10
- - Hotfix / auto bump
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) where applicable.
11
6
 
12
- ## v1.0.13 - 2025-04-28
13
- - Hotfix / auto bump
7
+ ---
14
8
 
15
- ## v1.0.14 - 2025-04-28
16
- - Hotfix / auto bump
9
+ ## [3.0.29] - 2026-02-22
17
10
 
18
- ## v1.0.15 - 2025-05-03
19
- - Hotfix / auto bump
11
+ - Maintenance release (hotfix / version bump).
20
12
 
21
- ## v1.0.16 - 2025-05-07
22
- - Hotfix / auto bump
13
+ ## [3.0.30] - 2026-02-26
23
14
 
24
- ## v1.0.17 - 2025-05-07
25
- - Hotfix / auto bump
15
+ - **Security & supply chain**
16
+ - Removed legacy/self-dependency and old HTTP stack (`request`, `sqlite3`, `npmlog`), pinned `axios` to a secure version, and cleaned up `npm audit` findings (no Critical/High CVEs in runtime deps).
17
+ - Added `SECURITY.md`, restricted the published files via `package.json.files` (no Horizon refs, no bundled node_modules) and wired `npm publish --provenance` into CI for verifiable builds.
18
+ - **Event-driven core**
19
+ - Promoted the `api` object to an `EventEmitter` with lifecycle events: `sessionExpired`, `autoLoginSuccess`, `autoLoginFailed`, `checkpoint`/`checkpoint_282`/`checkpoint_956`, `loginBlocked`, `rateLimit`, `networkError`.
20
+ - Hooked these into `loginParser` and the HTTP layer so consumers can react to login, checkpoint, and network conditions without brittle error-string matching.
21
+ - **Thread/User info & DB-backed anti-get-info**
22
+ - Refactored `getThreadInfo` and `getUserInfo` to use GraphQL batch calls with optional SQLite caching (via Sequelize models), reducing repeated Facebook requests and aligning with Horizon-style anti-get-info behavior.
23
+ - Added configuration toggles in `fca-config.json` (`antiGetInfo.AntiGetThreadInfo`, `antiGetInfo.AntiGetUserInfo`) to switch between DB-backed and legacy behaviors when needed.
24
+ - **Remote control & analytics**
25
+ - Introduced a lightweight WebSocket **remote control client** (`src/remote/remoteClient.js`) driven by `remoteControl` config, emitting `remoteConnected`, `remoteDisconnected`, `remoteStop`, `remoteBroadcast`, and `remoteMessage` events for integration with external dashboards.
26
+ - Taught the MQTT layer to update per-thread statistics in SQLite via an atomic `Thread.increment("messageCount")` on each message, enabling future analytics (e.g. “most active threads”) without impacting message latency.
27
+ - **Docs & utilities**
28
+ - Updated `README.md`, `DOCS.md`, and `docs/ARCHITECTURE.md` to document the new event system, DB caching behavior, remote control, proxy configuration, and the optional `broadcast` helper.
26
29
 
27
- ## v1.0.18 - 2025-05-22
28
- - Hotfix / auto bump
30
+ ## [3.0.28] - 2026-02-22
29
31
 
30
- ## v1.0.19 - 2025-05-23
31
- - Hotfix / auto bump
32
+ - Maintenance release (hotfix / version bump).
32
33
 
33
- ## v2.0.0 - 2025-10-05
34
- - Hotfix / auto bump
34
+ ## [3.0.27] - 2026-02-22
35
35
 
36
- ## v2.0.1 - 2025-10-05
37
- - Hotfix / auto bump
36
+ - Maintenance release (hotfix / version bump).
38
37
 
39
- ## v2.0.2 - 2025-10-05
40
- - Hotfix / auto bump
38
+ ## [3.0.25] - 2026-02-05
41
39
 
42
- ## v2.0.3 - 2025-10-05
43
- - Hotfix / auto bump
40
+ - Maintenance release (hotfix / version bump).
44
41
 
45
- ## v2.0.4 - 2025-10-05
46
- - Hotfix / auto bump
42
+ ## [3.0.23] - 2026-01-30
47
43
 
48
- ## v2.0.5 - 2025-10-06
49
- - Now you can turn on/off autoLogin in config file.
50
- - Added autoUpdate feature.
51
- ## v2.0.6-beta - 2025-10-06
52
- - Hotfix / auto bump
44
+ - Maintenance release (hotfix / version bump).
53
45
 
54
- ## v2.0.7 - 2025-10-06
55
- - Hotfix / auto bump
46
+ ## [3.0.22] - 2026-01-07
56
47
 
57
- ## v2.0.8 - 2025-10-07
58
- - Hotfix / auto bump
48
+ - Maintenance release (hotfix / version bump).
59
49
 
60
- ## v2.0.9 - 2025-10-07
61
- - Hotfix / auto bump
50
+ ## [3.0.21] - 2025-12-31
62
51
 
63
- ## v2.0.9 - 2025-10-07
64
- - Hotfix / auto bump
52
+ - Maintenance release (hotfix / version bump).
65
53
 
66
- ## v2.0.10 - 2025-10-07
67
- - Hotfix / auto bump
54
+ ## [3.0.20] - 2025-12-31
68
55
 
69
- ## v2.0.10 - 2025-10-07
70
- - Hotfix / auto bump
56
+ - Maintenance release (hotfix / version bump).
71
57
 
72
- ## v2.0.11 - 2025-10-07
73
- - Hotfix / auto bump
58
+ ## [3.0.19] - 2025-12-31
74
59
 
75
- ## v2.0.12 - 2025-10-07
76
- - Hotfix / auto bump
60
+ - Maintenance release (hotfix / version bump).
77
61
 
78
- ## v2.0.13 - 2025-10-07
79
- - Hotfix / auto bump
62
+ ## [3.0.17] - 2025-12-16
80
63
 
81
- ## v2.0.14 - 2025-10-07
82
- - Hotfix / auto bump
64
+ - Maintenance release (hotfix / version bump).
83
65
 
84
- ## v2.0.15 - 2025-10-07
85
- - Hotfix / auto bump
66
+ ## [3.0.15] - 2025-12-12
86
67
 
87
- ## v2.0.16 - 2025-10-07
88
- - Hotfix / auto bump
68
+ - Maintenance release (hotfix / version bump).
89
69
 
90
- ## v2.0.17 - 2025-10-07
91
- - Hotfix / auto bump
70
+ ## [3.0.12] - 2025-12-05
92
71
 
93
- ## v2.0.18 - 2025-10-07
94
- - Hotfix / auto bump
72
+ - Maintenance release (hotfix / version bump).
95
73
 
96
- ## v2.0.19 - 2025-10-07
97
- - Hotfix / auto bump
74
+ ## [3.0.11] - 2025-12-05
98
75
 
99
- ## v2.0.20 - 2025-10-08
100
- - Hotfix / auto bump
76
+ - Maintenance release (hotfix / version bump).
101
77
 
102
- ## v2.0.21 - 2025-10-08
103
- - Hotfix / auto bump
78
+ ## [3.0.10] - 2025-12-05
104
79
 
105
- ## v2.0.22 - 2025-10-09
106
- - Hotfix / auto bump
80
+ - Maintenance release (hotfix / version bump).
107
81
 
108
- ## v2.0.23 - 2025-10-11
109
- - Hotfix / auto bump
82
+ ## [3.0.9] - 2025-12-05
110
83
 
111
- ## v2.0.24 - 2025-10-11
112
- - Hotfix / auto bump
84
+ - Maintenance release (hotfix / version bump).
113
85
 
114
- ## v2.0.25 - 2025-10-12
115
- - Hotfix / auto bump
86
+ ## [3.0.8] - 2025-11-27
116
87
 
117
- ## v2.0.26 - 2025-10-16
118
- - Hotfix / auto bump
88
+ - Maintenance release (hotfix / version bump).
119
89
 
120
- ## v2.0.27 - 2025-10-18
121
- - Hotfix / auto bump
90
+ ## [3.0.7] - 2025-11-27
122
91
 
123
- ## v2.0.28 - 2025-10-18
124
- - Hotfix / auto bump
92
+ - Maintenance release (hotfix / version bump).
125
93
 
126
- ## v2.0.29 - 2025-10-19
127
- - Hotfix / auto bump
94
+ ## [3.0.6] - 2025-11-27
128
95
 
129
- ## v2.0.30 - 2025-10-19
130
- - Hotfix / auto bump
96
+ - Maintenance release (hotfix / version bump).
131
97
 
132
- ## v2.0.31 - 2025-10-27
133
- - Hotfix / auto bump
98
+ ## [3.0.5] - 2025-11-27
134
99
 
135
- ## v2.0.32 - 2025-10-30
136
- - Hotfix / auto bump
100
+ - Maintenance release (hotfix / version bump).
137
101
 
138
- ## v3.0.2 - 2025-11-27
139
- - Hotfix / auto bump
102
+ ## [3.0.4] - 2025-11-27
140
103
 
141
- ## v3.0.3 - 2025-11-27
142
- - Hotfix / auto bump
104
+ - Maintenance release (hotfix / version bump).
143
105
 
144
- ## v3.0.4 - 2025-11-27
145
- - Hotfix / auto bump
106
+ ## [3.0.3] - 2025-11-27
146
107
 
147
- ## v3.0.5 - 2025-11-27
148
- - Hotfix / auto bump
108
+ - Maintenance release (hotfix / version bump).
149
109
 
150
- ## v3.0.6 - 2025-11-27
151
- - Hotfix / auto bump
110
+ ## [3.0.2] - 2025-11-27
152
111
 
153
- ## v3.0.7 - 2025-11-27
154
- - Hotfix / auto bump
112
+ - Maintenance release (hotfix / version bump).
155
113
 
156
- ## v3.0.8 - 2025-11-27
157
- - Hotfix / auto bump
114
+ ## [2.0.32] - 2025-10-30
158
115
 
159
- ## v3.0.9 - 2025-12-05
160
- - Hotfix / auto bump
116
+ - Maintenance release (hotfix / version bump).
161
117
 
162
- ## v3.0.10 - 2025-12-05
163
- - Hotfix / auto bump
118
+ ## [2.0.31] - 2025-10-27
164
119
 
165
- ## v3.0.11 - 2025-12-05
166
- - Hotfix / auto bump
120
+ - Maintenance release (hotfix / version bump).
167
121
 
168
- ## v3.0.12 - 2025-12-05
169
- - Hotfix / auto bump
122
+ ## [2.0.30] - 2025-10-19
170
123
 
171
- ## v3.0.15 - 2025-12-12
172
- - Hotfix / auto bump
124
+ - Maintenance release (hotfix / version bump).
173
125
 
174
- ## v3.0.17 - 2025-12-16
175
- - Hotfix / auto bump
126
+ ## [2.0.29] - 2025-10-19
176
127
 
177
- ## v3.0.19 - 2025-12-31
178
- - Hotfix / auto bump
128
+ - Maintenance release (hotfix / version bump).
179
129
 
180
- ## v3.0.20 - 2025-12-31
181
- - Hotfix / auto bump
130
+ ## [2.0.28] - 2025-10-18
182
131
 
183
- ## v3.0.21 - 2025-12-31
184
- - Hotfix / auto bump
132
+ - Maintenance release (hotfix / version bump).
185
133
 
186
- ## v3.0.22 - 2026-01-07
187
- - Hotfix / auto bump
134
+ ## [2.0.27] - 2025-10-18
188
135
 
189
- ## v3.0.23 - 2026-01-30
190
- - Hotfix / auto bump
136
+ - Maintenance release (hotfix / version bump).
191
137
 
192
- ## v3.0.25 - 2026-02-05
193
- - Hotfix / auto bump
138
+ ## [2.0.26] - 2025-10-16
194
139
 
195
- ## v3.0.27 - 2026-02-22
196
- - Hotfix / auto bump
140
+ - Maintenance release (hotfix / version bump).
141
+
142
+ ## [2.0.25] - 2025-10-12
143
+
144
+ - Maintenance release (hotfix / version bump).
145
+
146
+ ## [2.0.24] - 2025-10-11
147
+
148
+ - Maintenance release (hotfix / version bump).
149
+
150
+ ## [2.0.23] - 2025-10-11
151
+
152
+ - Maintenance release (hotfix / version bump).
153
+
154
+ ## [2.0.22] - 2025-10-09
155
+
156
+ - Maintenance release (hotfix / version bump).
157
+
158
+ ## [2.0.21] - 2025-10-08
159
+
160
+ - Maintenance release (hotfix / version bump).
161
+
162
+ ## [2.0.20] - 2025-10-08
163
+
164
+ - **Added:** Config option to enable/disable `autoLogin`.
165
+ - **Added:** Auto-update feature (configurable).
166
+
167
+ ## [2.0.19] - 2025-10-07
168
+
169
+ - Maintenance release (hotfix / version bump).
170
+
171
+ ## [2.0.18] - 2025-10-07
172
+
173
+ - Maintenance release (hotfix / version bump).
174
+
175
+ ## [2.0.17] - 2025-10-07
176
+
177
+ - Maintenance release (hotfix / version bump).
178
+
179
+ ## [2.0.16] - 2025-10-07
180
+
181
+ - Maintenance release (hotfix / version bump).
182
+
183
+ ## [2.0.15] - 2025-10-07
184
+
185
+ - Maintenance release (hotfix / version bump).
186
+
187
+ ## [2.0.14] - 2025-10-07
188
+
189
+ - Maintenance release (hotfix / version bump).
190
+
191
+ ## [2.0.13] - 2025-10-07
192
+
193
+ - Maintenance release (hotfix / version bump).
194
+
195
+ ## [2.0.12] - 2025-10-07
196
+
197
+ - Maintenance release (hotfix / version bump).
198
+
199
+ ## [2.0.11] - 2025-10-07
200
+
201
+ - Maintenance release (hotfix / version bump).
202
+
203
+ ## [2.0.10] - 2025-10-07
204
+
205
+ - Maintenance release (hotfix / version bump).
206
+
207
+ ## [2.0.9] - 2025-10-07
208
+
209
+ - Maintenance release (hotfix / version bump).
210
+
211
+ ## [2.0.8] - 2025-10-07
212
+
213
+ - Maintenance release (hotfix / version bump).
214
+
215
+ ## [2.0.7] - 2025-10-06
216
+
217
+ - Maintenance release (hotfix / version bump).
218
+
219
+ ## [2.0.6-beta] - 2025-10-06
220
+
221
+ - Beta release (hotfix / version bump).
222
+
223
+ ## [2.0.5] - 2025-10-06
224
+
225
+ - **Added:** Toggle for `autoLogin` in config.
226
+ - **Added:** Auto-update feature.
227
+
228
+ ## [2.0.4] - 2025-10-05
229
+
230
+ - Maintenance release (hotfix / version bump).
231
+
232
+ ## [2.0.3] - 2025-10-05
233
+
234
+ - Maintenance release (hotfix / version bump).
235
+
236
+ ## [2.0.2] - 2025-10-05
237
+
238
+ - Maintenance release (hotfix / version bump).
239
+
240
+ ## [2.0.1] - 2025-10-05
241
+
242
+ - Maintenance release (hotfix / version bump).
243
+
244
+ ## [2.0.0] - 2025-10-05
245
+
246
+ - Major version bump (hotfix / version bump).
247
+
248
+ ## [1.0.19] - 2025-05-23
249
+
250
+ - Maintenance release (hotfix / version bump).
251
+
252
+ ## [1.0.18] - 2025-05-22
253
+
254
+ - Maintenance release (hotfix / version bump).
255
+
256
+ ## [1.0.17] - 2025-05-07
257
+
258
+ - Maintenance release (hotfix / version bump).
259
+
260
+ ## [1.0.16] - 2025-05-07
261
+
262
+ - Maintenance release (hotfix / version bump).
263
+
264
+ ## [1.0.15] - 2025-05-03
265
+
266
+ - Maintenance release (hotfix / version bump).
267
+
268
+ ## [1.0.14] - 2025-04-28
269
+
270
+ - Maintenance release (hotfix / version bump).
271
+
272
+ ## [1.0.13] - 2025-04-28
273
+
274
+ - Maintenance release (hotfix / version bump).
275
+
276
+ ## [1.0.12] - 2025-04-28
277
+
278
+ - Maintenance release (hotfix / version bump).
279
+
280
+ ## [1.0.11] - 2025-04-24
281
+
282
+ - Maintenance release (hotfix / version bump).
283
+
284
+ ## [1.0.10] - 2025-04-24
285
+
286
+ - Maintenance release (hotfix / version bump).
287
+
288
+ ---
289
+
290
+ [3.0.29]: https://github.com/Donix-VN/fca-unofficial/compare/v3.0.28...v3.0.29
291
+ [3.0.28]: https://github.com/Donix-VN/fca-unofficial/compare/v3.0.27...v3.0.28
292
+ [3.0.27]: https://github.com/Donix-VN/fca-unofficial/compare/v3.0.25...v3.0.27
293
+ [1.0.10]: https://github.com/Donix-VN/fca-unofficial/releases/tag/v1.0.10
package/DOCS.md CHANGED
@@ -1,8 +1,24 @@
1
- # FCA-Unofficial - Complete API Documentation
1
+ # FCA-Unofficial API Documentation
2
2
 
3
3
  ## Introduction
4
4
 
5
- **@dongdev/fca-unofficial** is an unofficial Node.js library for interacting with Facebook Messenger by emulating browser behavior. This library allows you to create chat bots and automate tasks on Facebook Messenger.
5
+ **@dongdev/fca-unofficial** is an unofficial Node.js library for interacting with Facebook Messenger by emulating browser behavior. It lets you build chatbots and automate messaging on personal Facebook accounts (not just Pages).
6
+
7
+ ## Project structure
8
+
9
+ | Path | Description |
10
+ |------|--------------|
11
+ | `index.js` | Package entry point; exports `login`. |
12
+ | `index.d.ts` | TypeScript definitions for the public API. |
13
+ | `module/` | Login flow: `login.js`, `loginHelper.js`, `config.js`, `options.js`. |
14
+ | `src/api/` | API implementations: `messaging/`, `threads/`, `users/`, `action/`, `http/`, `socket/`. |
15
+ | `src/api/socket/` | MQTT/WebSocket real-time listening (`listenMqtt.js`, `core/`, `middleware/`). |
16
+ | `src/utils/` | Shared utilities: `request.js`, `client.js`, `format.js`, `headers.js`, `cookies.js`, `broadcast.js` (optional helper). |
17
+ | `src/database/` | Optional Sequelize models and data access for threads/users (used for caching and statistics). |
18
+ | `src/remote/` | Lightweight WebSocket client for remote control (dashboard/server). |
19
+ | `func/` | Logger, check-update, and other helpers. |
20
+
21
+ For a concise codebase overview, see [docs/ARCHITECTURE.md](./docs/ARCHITECTURE.md).
6
22
 
7
23
  ## Installation
8
24
 
@@ -123,12 +139,46 @@ login(credentials, (err, api) => {
123
139
  });
124
140
  ```
125
141
 
126
- **Note:** You can use [c3c-fbstate](https://github.com/c3cbot/c3c-fbstate) tool to get AppState from browser.
142
+ You can use the [c3c-fbstate](https://github.com/c3cbot/c3c-fbstate) tool to obtain AppState from your browser.
143
+
144
+ ### 1.4. Auto Login (session recovery)
145
+
146
+ When the session (AppState) expires, the library can automatically re-login using credentials from **`fca-config.json`**, so the bot can recover without manual restart.
147
+
148
+ 1. Create **`fca-config.json`** in your project root (the directory from which you run your bot):
149
+
150
+ ```json
151
+ {
152
+ "autoLogin": true,
153
+ "apiServer": "https://minhdong.site",
154
+ "apiKey": "",
155
+ "credentials": {
156
+ "email": "your_email_or_phone",
157
+ "password": "your_password",
158
+ "twofactor": ""
159
+ }
160
+ }
161
+ ```
162
+
163
+ 2. Log in with AppState as usual. When the session expires, the library will use these credentials (and optionally the external API at `apiServer`) to log in again and retry the failed request.
164
+
165
+ | Option | Description |
166
+ |--------|-------------|
167
+ | `autoLogin` | `true` (default) or `false`. Set to `false` to disable automatic re-login when session expires. |
168
+ | `apiServer` | Base URL for external login API (e.g. iOS-style login). Default: `https://minhdong.site`. |
169
+ | `apiKey` | Optional API key for the external login server (e.g. `x-api-key` header). |
170
+ | `credentials.email` | Facebook email or phone number. |
171
+ | `credentials.password` | Facebook password. |
172
+ | `credentials.twofactor` | Base32 secret for 2FA (TOTP). Leave empty if you do not use 2FA. Do not put the 6-digit code here. |
173
+
174
+ **Security:** Add `fca-config.json` to `.gitignore`; it contains sensitive credentials.
127
175
 
128
176
  ---
129
177
 
130
178
  ## 2. CONFIGURATION (Options)
131
179
 
180
+ ### 2.1. Runtime options (api.setOptions)
181
+
132
182
  After login, you can configure API options:
133
183
 
134
184
  ```javascript
@@ -153,6 +203,21 @@ api.setOptions({
153
203
  });
154
204
  ```
155
205
 
206
+ ### 2.2. File config (fca-config.json)
207
+
208
+ Optional config file in the project root (see [§ 1.4. Auto Login](#14-auto-login-session-recovery)):
209
+
210
+ | Key | Description |
211
+ |-----|-------------|
212
+ | `autoLogin` | Enable/disable automatic re-login when session expires (default: `true`). |
213
+ | `autoUpdate` | Check for package updates on startup (default: `true`). |
214
+ | `mqtt` | `{ enabled, reconnectInterval }` for MQTT. |
215
+ | `apiServer` | Base URL for external login API (default: `https://minhdong.site`). |
216
+ | `apiKey` | Optional API key for the login server. |
217
+ | `credentials` | `{ email, password, twofactor }` for auto-login and external API login. |
218
+ | `antiGetInfo` | `{ AntiGetThreadInfo, AntiGetUserInfo }` switches between DB-backed anti-get-info and legacy behavior. |
219
+ | `remoteControl` | `{ enabled, url, token, autoReconnect }` enables remote control over WebSocket. |
220
+
156
221
  ---
157
222
 
158
223
  ## 3. DETAILED API METHODS
@@ -634,6 +699,14 @@ api.getUserInfo(["100012345678901", "100012345678902"], (err, userInfo) => {
634
699
  });
635
700
  ```
636
701
 
702
+ #### Caching and Anti-Get-Info
703
+
704
+ - `getUserInfo` uses GraphQL to fetch profiles and stores normalized data in the `User` table (see `src/database/userData.js`).
705
+ - On each call:
706
+ - The library first checks the DB for existing entries.
707
+ - Missing or stale entries are fetched from Facebook and persisted back to SQLite.
708
+ - If `antiGetInfo.AntiGetUserInfo` is set to `true` in `fca-config.json`, the implementation falls back to the legacy `/chat/user_info/` endpoint and logs a Horizon-style warning when spam/limits are detected.
709
+
637
710
  ---
638
711
 
639
712
  ### 3.4. Message Scheduler - Schedule Messages
@@ -925,6 +998,12 @@ api.getThreadInfo("1234567890", (err, threadInfo) => {
925
998
  });
926
999
  ```
927
1000
 
1001
+ #### Caching and Anti-Get-Info
1002
+
1003
+ - `getThreadInfo` uses a GraphQL batch endpoint and caches responses in the `Thread` table (see `src/database/threadData.js`).
1004
+ - Subsequent calls within a short time window may be served from SQLite to reduce pressure on Facebook endpoints.
1005
+ - When Facebook signals spam/limits, a Horizon-style warning is logged and the error is surfaced to your callback/Promise.
1006
+
928
1007
  ---
929
1008
 
930
1009
  ### 3.5. changeThreadColor - Change Chat Color