@dongdev/fca-unofficial 3.0.31 → 4.0.1
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.
- package/LICENSE +191 -0
- package/README.md +238 -398
- package/dist/cjs.cjs +9 -0
- package/dist/index.d.mts +1250 -0
- package/dist/index.d.ts +1250 -0
- package/dist/index.js +27772 -0
- package/dist/index.mjs +27735 -0
- package/docs/ARCHITECTURE.md +467 -0
- package/docs/DOCS.md +709 -0
- package/fca-config.example.json +33 -0
- package/package.json +32 -22
- package/test/fca.test.cjs +540 -0
- package/CHANGELOG.md +0 -296
- package/DOCS.md +0 -2712
- package/func/checkUpdate.js +0 -222
- package/func/logAdapter.js +0 -33
- package/func/logger.js +0 -48
- package/index.d.ts +0 -751
- package/index.js +0 -8
- package/module/config.js +0 -40
- package/module/login.js +0 -133
- package/module/loginHelper.js +0 -1296
- package/module/options.js +0 -44
- package/src/api/action/addExternalModule.js +0 -25
- package/src/api/action/changeAvatar.js +0 -137
- package/src/api/action/changeBio.js +0 -75
- package/src/api/action/enableAutoSaveAppState.js +0 -73
- package/src/api/action/getCurrentUserID.js +0 -7
- package/src/api/action/handleFriendRequest.js +0 -57
- package/src/api/action/logout.js +0 -76
- package/src/api/action/refreshFb_dtsg.js +0 -48
- package/src/api/action/setPostReaction.js +0 -106
- package/src/api/action/unfriend.js +0 -54
- package/src/api/http/httpGet.js +0 -46
- package/src/api/http/httpPost.js +0 -52
- package/src/api/http/postFormData.js +0 -47
- package/src/api/messaging/addUserToGroup.js +0 -68
- package/src/api/messaging/changeAdminStatus.js +0 -126
- package/src/api/messaging/changeArchivedStatus.js +0 -55
- package/src/api/messaging/changeBlockedStatus.js +0 -48
- package/src/api/messaging/changeGroupImage.js +0 -91
- package/src/api/messaging/changeNickname.js +0 -70
- package/src/api/messaging/changeThreadColor.js +0 -79
- package/src/api/messaging/changeThreadEmoji.js +0 -111
- package/src/api/messaging/createNewGroup.js +0 -88
- package/src/api/messaging/createPoll.js +0 -46
- package/src/api/messaging/createThemeAI.js +0 -98
- package/src/api/messaging/deleteMessage.js +0 -136
- package/src/api/messaging/deleteThread.js +0 -56
- package/src/api/messaging/editMessage.js +0 -68
- package/src/api/messaging/forwardAttachment.js +0 -57
- package/src/api/messaging/getEmojiUrl.js +0 -29
- package/src/api/messaging/getFriendsList.js +0 -82
- package/src/api/messaging/getMessage.js +0 -829
- package/src/api/messaging/getThemePictures.js +0 -62
- package/src/api/messaging/handleMessageRequest.js +0 -65
- package/src/api/messaging/markAsDelivered.js +0 -57
- package/src/api/messaging/markAsRead.js +0 -88
- package/src/api/messaging/markAsReadAll.js +0 -49
- package/src/api/messaging/markAsSeen.js +0 -61
- package/src/api/messaging/muteThread.js +0 -50
- package/src/api/messaging/removeUserFromGroup.js +0 -62
- package/src/api/messaging/resolvePhotoUrl.js +0 -43
- package/src/api/messaging/scheduler.js +0 -264
- package/src/api/messaging/searchForThread.js +0 -53
- package/src/api/messaging/sendMessage.js +0 -270
- package/src/api/messaging/sendTypingIndicator.js +0 -74
- package/src/api/messaging/setMessageReaction.js +0 -90
- package/src/api/messaging/setTitle.js +0 -124
- package/src/api/messaging/shareContact.js +0 -49
- package/src/api/messaging/threadColors.js +0 -128
- package/src/api/messaging/unsendMessage.js +0 -81
- package/src/api/messaging/uploadAttachment.js +0 -492
- package/src/api/socket/core/connectMqtt.js +0 -258
- package/src/api/socket/core/emitAuth.js +0 -103
- package/src/api/socket/core/getSeqID.js +0 -320
- package/src/api/socket/core/getTaskResponseData.js +0 -25
- package/src/api/socket/core/parseDelta.js +0 -377
- package/src/api/socket/detail/buildStream.js +0 -215
- package/src/api/socket/detail/constants.js +0 -28
- package/src/api/socket/listenMqtt.js +0 -377
- package/src/api/socket/middleware/index.js +0 -216
- package/src/api/threads/getThreadHistory.js +0 -664
- package/src/api/threads/getThreadInfo.js +0 -296
- package/src/api/threads/getThreadList.js +0 -293
- package/src/api/threads/getThreadPictures.js +0 -78
- package/src/api/users/getUserID.js +0 -65
- package/src/api/users/getUserInfo.js +0 -402
- package/src/api/users/getUserInfoV2.js +0 -134
- package/src/core/sendReqMqtt.js +0 -96
- package/src/database/helpers.js +0 -53
- package/src/database/models/index.js +0 -88
- package/src/database/models/thread.js +0 -50
- package/src/database/models/user.js +0 -46
- package/src/database/threadData.js +0 -94
- package/src/database/userData.js +0 -98
- package/src/remote/remoteClient.js +0 -123
- package/src/utils/broadcast.js +0 -51
- package/src/utils/client.js +0 -10
- package/src/utils/constants.js +0 -23
- package/src/utils/cookies.js +0 -68
- package/src/utils/format/attachment.js +0 -357
- package/src/utils/format/cookie.js +0 -9
- package/src/utils/format/date.js +0 -50
- package/src/utils/format/decode.js +0 -44
- package/src/utils/format/delta.js +0 -194
- package/src/utils/format/ids.js +0 -64
- package/src/utils/format/index.js +0 -64
- package/src/utils/format/message.js +0 -88
- package/src/utils/format/presence.js +0 -132
- package/src/utils/format/readTyp.js +0 -44
- package/src/utils/format/thread.js +0 -42
- package/src/utils/format/utils.js +0 -141
- package/src/utils/headers.js +0 -115
- package/src/utils/loginParser/autoLogin.js +0 -125
- package/src/utils/loginParser/helpers.js +0 -43
- package/src/utils/loginParser/index.js +0 -10
- package/src/utils/loginParser/parseAndCheckLogin.js +0 -220
- package/src/utils/loginParser/textUtils.js +0 -28
- package/src/utils/request/client.js +0 -26
- package/src/utils/request/config.js +0 -23
- package/src/utils/request/defaults.js +0 -46
- package/src/utils/request/helpers.js +0 -46
- package/src/utils/request/index.js +0 -17
- package/src/utils/request/methods.js +0 -163
- package/src/utils/request/proxy.js +0 -21
- package/src/utils/request/retry.js +0 -77
- package/src/utils/request/sanitize.js +0 -49
package/README.md
CHANGED
|
@@ -1,524 +1,364 @@
|
|
|
1
|
-
|
|
1
|
+
# @dongdev/fca-unofficial
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An **unofficial** Node.js library for interacting with **Facebook Messenger** through user-session emulation. It speaks the same HTTP/GraphQL and MQTT protocols the browser client uses, giving you programmatic access to messages, threads, reactions, typing indicators, and more — all in TypeScript with full type definitions.
|
|
4
4
|
|
|
5
|
-
**
|
|
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.
|
|
5
|
+
> **Disclaimer:** This library operates by emulating a logged-in browser session. Using it may violate Facebook / Meta's Terms of Service and could result in account restrictions or bans. The author assumes **no responsibility** for how you use this software. Use it only for lawful purposes and at your own risk.
|
|
66
6
|
|
|
67
7
|
---
|
|
68
8
|
|
|
69
|
-
##
|
|
9
|
+
## Table of Contents
|
|
70
10
|
|
|
71
|
-
-
|
|
72
|
-
-
|
|
73
|
-
-
|
|
74
|
-
-
|
|
75
|
-
-
|
|
76
|
-
-
|
|
77
|
-
-
|
|
11
|
+
- [Installation](#installation)
|
|
12
|
+
- [Quick Start](#quick-start)
|
|
13
|
+
- [Authentication](#authentication)
|
|
14
|
+
- [API Styles](#api-styles)
|
|
15
|
+
- [MessengerBot (Event-Driven)](#messengerbot-event-driven)
|
|
16
|
+
- [Configuration](#configuration)
|
|
17
|
+
- [Features Overview](#features-overview)
|
|
18
|
+
- [Project Documentation](#project-documentation)
|
|
19
|
+
- [Requirements](#requirements)
|
|
20
|
+
- [License](#license)
|
|
21
|
+
- [Links](#links)
|
|
78
22
|
|
|
79
23
|
---
|
|
80
24
|
|
|
81
|
-
##
|
|
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
|
|
25
|
+
## Installation
|
|
98
26
|
|
|
99
|
-
|
|
27
|
+
```bash
|
|
28
|
+
npm install @dongdev/fca-unofficial@latest
|
|
29
|
+
```
|
|
100
30
|
|
|
101
|
-
|
|
31
|
+
If you clone the repository and want to work with the source directly:
|
|
102
32
|
|
|
103
33
|
```bash
|
|
104
|
-
|
|
34
|
+
git clone https://github.com/dongp06/fca-unofficial.git
|
|
35
|
+
cd fca-unofficial
|
|
36
|
+
npm install
|
|
37
|
+
npm run build
|
|
105
38
|
```
|
|
106
39
|
|
|
107
|
-
|
|
40
|
+
The build produces these artifacts in `dist/`:
|
|
108
41
|
|
|
109
|
-
|
|
110
|
-
|
|
42
|
+
| File | Format / role |
|
|
43
|
+
|-------------------|----------------------------------------------------|
|
|
44
|
+
| `dist/cjs.cjs` | **CommonJS entry** — `require()` resolves here; the export **is** the `login` function (Mirai / classic FCA). |
|
|
45
|
+
| `dist/index.js` | Internal CJS bundle (required by `cjs.cjs`) |
|
|
46
|
+
| `dist/index.mjs` | ES Modules (ESM) |
|
|
47
|
+
| `dist/index.d.ts` | TypeScript typings |
|
|
111
48
|
|
|
112
49
|
---
|
|
113
50
|
|
|
114
|
-
##
|
|
51
|
+
## Quick Start
|
|
115
52
|
|
|
116
|
-
###
|
|
53
|
+
### Event-driven bot (recommended)
|
|
117
54
|
|
|
118
55
|
```javascript
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
56
|
+
const { createMessengerBot } = require("@dongdev/fca-unofficial");
|
|
57
|
+
|
|
58
|
+
async function main() {
|
|
59
|
+
const bot = await createMessengerBot(
|
|
60
|
+
{ appState: require("./appstate.json") },
|
|
61
|
+
{
|
|
62
|
+
listenEvents: true,
|
|
63
|
+
stopOnSignals: true,
|
|
64
|
+
commandPrefix: "/"
|
|
65
|
+
}
|
|
66
|
+
);
|
|
123
67
|
|
|
124
|
-
|
|
125
|
-
if (err) return console.error(err);
|
|
68
|
+
bot.on("error", (err) => console.error("Bot error:", err));
|
|
126
69
|
|
|
127
|
-
|
|
128
|
-
if (event.
|
|
129
|
-
|
|
70
|
+
bot.on("messageCreate", (event) => {
|
|
71
|
+
if (event.body) {
|
|
72
|
+
console.log(`[${event.threadID}] ${event.body}`);
|
|
130
73
|
}
|
|
131
74
|
});
|
|
132
|
-
});
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
### 2️⃣ Send Text Message
|
|
136
75
|
|
|
137
|
-
|
|
138
|
-
|
|
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!");
|
|
76
|
+
bot.command("ping", async (ctx) => {
|
|
77
|
+
await ctx.replyAsync("pong");
|
|
152
78
|
});
|
|
153
|
-
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
main();
|
|
154
82
|
```
|
|
155
83
|
|
|
156
|
-
|
|
84
|
+
### Classic `require` (default export = `login`)
|
|
157
85
|
|
|
158
|
-
|
|
86
|
+
Same pattern as older FCA forks: the required module **is** `login`. Callback gets **`api`**, not `ctx`.
|
|
159
87
|
|
|
160
88
|
```javascript
|
|
161
89
|
const login = require("@dongdev/fca-unofficial");
|
|
162
|
-
const fs = require("fs");
|
|
163
90
|
|
|
164
|
-
login({ appState:
|
|
165
|
-
if (err)
|
|
166
|
-
|
|
167
|
-
|
|
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!");
|
|
91
|
+
login({ appState: require("./appstate.json") }, (err, api) => {
|
|
92
|
+
if (err) return console.error(err);
|
|
93
|
+
api.setOptions({ listenEvents: true });
|
|
94
|
+
api.listenMqtt((e, ev) => {
|
|
95
|
+
if (e) return console.error(e);
|
|
96
|
+
if (ev.type === "message") api.sendMessage(ev.body, ev.threadID);
|
|
187
97
|
});
|
|
188
98
|
});
|
|
189
99
|
```
|
|
190
100
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
## 📝 Message Types
|
|
101
|
+
Optional FCA options before the callback: `login(credentials, { listenEvents: true }, (err, api) => { ... })`.
|
|
194
102
|
|
|
195
|
-
|
|
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:
|
|
103
|
+
### Async / Promise style
|
|
214
104
|
|
|
215
105
|
```javascript
|
|
216
|
-
const
|
|
217
|
-
const login = require("@dongdev/fca-unofficial");
|
|
106
|
+
const { login } = require("@dongdev/fca-unofficial");
|
|
218
107
|
|
|
219
|
-
|
|
108
|
+
async function main() {
|
|
109
|
+
const ctx = await login({ appState: require("./appstate.json") });
|
|
110
|
+
const api = ctx.api;
|
|
220
111
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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;
|
|
112
|
+
api.listenMqtt((err, event) => {
|
|
113
|
+
if (err) return console.error(err);
|
|
114
|
+
if (event.type === "message") {
|
|
115
|
+
api.sendMessage(`Echo: ${event.body}`, event.threadID);
|
|
251
116
|
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
252
119
|
|
|
253
|
-
|
|
254
|
-
// Your code here
|
|
255
|
-
},
|
|
256
|
-
);
|
|
120
|
+
main();
|
|
257
121
|
```
|
|
258
122
|
|
|
259
123
|
---
|
|
260
124
|
|
|
261
|
-
##
|
|
125
|
+
## Authentication
|
|
262
126
|
|
|
263
|
-
|
|
127
|
+
With **`require("@dongdev/fca-unofficial")`**, you get the **`login`** function directly (see [Quick Start](#quick-start)). With **named** imports / ESM, use `import { login } from "..."` or `import login from "..."`.
|
|
264
128
|
|
|
265
|
-
|
|
129
|
+
The library supports multiple credential strategies. Pass **one** of the following to `login()` or `createMessengerBot()`:
|
|
266
130
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
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
|
-
---
|
|
131
|
+
| Credential | Description |
|
|
132
|
+
|----------------|-------------------------------------------------------------------------------------------------------------|
|
|
133
|
+
| `appState` | An array of cookie objects (`{ key, value, domain, path, ... }`) exported from a browser extension or tool. **Recommended for bots.** |
|
|
134
|
+
| `Cookie` | A raw cookie header string, e.g. `"c_user=...; xs=...; ..."`. |
|
|
135
|
+
| `email` + `password` | Web login credentials. Prone to checkpoints and CAPTCHAs; **not recommended** for long-running bots. |
|
|
289
136
|
|
|
290
|
-
|
|
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.
|
|
137
|
+
You can also use `loginViaAPI` / `tokensViaAPI` for token-based authentication through an external API server (see `fca-config.json` → `apiServer`).
|
|
301
138
|
|
|
302
139
|
---
|
|
303
140
|
|
|
304
|
-
##
|
|
305
|
-
|
|
306
|
-
### Echo Bot with Stop Command
|
|
307
|
-
|
|
308
|
-
```javascript
|
|
309
|
-
const fs = require("fs");
|
|
310
|
-
const login = require("@dongdev/fca-unofficial");
|
|
141
|
+
## API Styles
|
|
311
142
|
|
|
312
|
-
|
|
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
|
-
```
|
|
143
|
+
After authentication, you get an `FcaContext` object. The library offers two ways to call Messenger functions:
|
|
347
144
|
|
|
348
|
-
###
|
|
145
|
+
### 1. Flat API (legacy-compatible)
|
|
349
146
|
|
|
350
|
-
|
|
147
|
+
Every method lives directly on `ctx.api`:
|
|
351
148
|
|
|
352
149
|
```javascript
|
|
353
|
-
api.
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
logLevel: "silent", // Disable logs (silent/error/warn/info/verbose)
|
|
357
|
-
});
|
|
150
|
+
api.sendMessage("Hello!", threadID);
|
|
151
|
+
api.getThreadInfo(threadID, (err, info) => { ... });
|
|
152
|
+
api.setMessageReaction(":heart:", messageID);
|
|
358
153
|
```
|
|
359
154
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
## 🎯 API Quick Reference
|
|
363
|
-
|
|
364
|
-
_(For full details, please read the source code or `DOCS.md`)_
|
|
365
|
-
|
|
366
|
-
### 📨 Messaging
|
|
155
|
+
### 2. Namespaced client facade
|
|
367
156
|
|
|
368
|
-
|
|
157
|
+
Group related methods under domain namespaces for cleaner code:
|
|
369
158
|
|
|
370
|
-
|
|
159
|
+
```typescript
|
|
160
|
+
import { createFcaClient } from "@dongdev/fca-unofficial";
|
|
371
161
|
|
|
372
|
-
|
|
162
|
+
const client = createFcaClient(ctx.api);
|
|
373
163
|
|
|
374
|
-
|
|
164
|
+
await client.messages.send("Hello!", threadID);
|
|
165
|
+
await client.threads.getInfo(threadID);
|
|
166
|
+
await client.users.getInfo(userID);
|
|
167
|
+
```
|
|
375
168
|
|
|
376
|
-
|
|
169
|
+
Available namespaces: `messages`, `threads`, `users`, `account`, `realtime`, `http`, `scheduler`.
|
|
377
170
|
|
|
378
|
-
|
|
171
|
+
---
|
|
379
172
|
|
|
380
|
-
|
|
173
|
+
## MessengerBot (Event-Driven)
|
|
381
174
|
|
|
382
|
-
|
|
175
|
+
`MessengerBot` provides a high-level, event-driven interface inspired by Discord.js and Telegraf.
|
|
383
176
|
|
|
384
|
-
|
|
177
|
+
### Creating a bot
|
|
385
178
|
|
|
386
|
-
|
|
179
|
+
```typescript
|
|
180
|
+
import { createMessengerBot } from "@dongdev/fca-unofficial";
|
|
387
181
|
|
|
388
|
-
|
|
182
|
+
const bot = await createMessengerBot(
|
|
183
|
+
{ appState: require("./appstate.json") },
|
|
184
|
+
{
|
|
185
|
+
listenEvents: true,
|
|
186
|
+
stopOnSignals: true,
|
|
187
|
+
commandPrefix: "/",
|
|
188
|
+
maxEventListeners: 64,
|
|
189
|
+
enableComposer: true
|
|
190
|
+
}
|
|
191
|
+
);
|
|
192
|
+
```
|
|
389
193
|
|
|
390
|
-
|
|
391
|
-
## 🎛 Event Hooks & Remote Control (Advanced)
|
|
194
|
+
### Events
|
|
392
195
|
|
|
393
|
-
|
|
196
|
+
| Event | Trigger |
|
|
197
|
+
|----------------------|----------------------------------------------|
|
|
198
|
+
| `message` | Any incoming message (including replies) |
|
|
199
|
+
| `messageCreate` | Alias for `message` |
|
|
200
|
+
| `message_reply` | A reply to an existing message |
|
|
201
|
+
| `messageReactionAdd` | A reaction is added to a message |
|
|
202
|
+
| `messageDelete` | A message is unsent/deleted |
|
|
203
|
+
| `typingStart` | A user starts typing |
|
|
204
|
+
| `typingStop` | A user stops typing |
|
|
205
|
+
| `threadUpdate` | Thread metadata changes (title, participants) |
|
|
206
|
+
| `ready` | MQTT connection established |
|
|
207
|
+
| `raw` / `update` | Every MQTT delta (unfiltered) |
|
|
208
|
+
| `error` | Any error during listening |
|
|
394
209
|
|
|
395
|
-
|
|
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.).
|
|
210
|
+
### Composer middleware
|
|
404
211
|
|
|
405
|
-
|
|
212
|
+
The composer pipeline processes `message` and `message_reply` events through a chain of middleware functions:
|
|
406
213
|
|
|
407
214
|
```javascript
|
|
408
|
-
|
|
409
|
-
|
|
215
|
+
// Global middleware
|
|
216
|
+
bot.use(async (ctx, next) => {
|
|
217
|
+
console.log(`[${ctx.threadID}] ${ctx.text}`);
|
|
218
|
+
await next();
|
|
410
219
|
});
|
|
411
220
|
|
|
412
|
-
|
|
413
|
-
|
|
221
|
+
// Command handler — matches "/ping" at the start of a message
|
|
222
|
+
bot.command("ping", async (ctx) => {
|
|
223
|
+
await ctx.replyAsync("pong");
|
|
414
224
|
});
|
|
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
225
|
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
## 🌐 Proxy Configuration & Broadcast Helper
|
|
226
|
+
// Pattern matching — regex or substring
|
|
227
|
+
bot.hears(/hello/i, async (ctx) => {
|
|
228
|
+
await ctx.replyAsync("Hi there!");
|
|
229
|
+
});
|
|
428
230
|
|
|
429
|
-
|
|
430
|
-
|
|
231
|
+
bot.hears("goodbye", async (ctx) => {
|
|
232
|
+
ctx.reply("See you later!");
|
|
233
|
+
});
|
|
431
234
|
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
api.setOptions({ proxy: "http://user:pass@host:port" });
|
|
235
|
+
// Error handler for the composer chain
|
|
236
|
+
bot.catch((err, ctx) => {
|
|
237
|
+
console.error("Composer error:", err);
|
|
436
238
|
});
|
|
437
239
|
```
|
|
438
240
|
|
|
439
|
-
|
|
241
|
+
### MessengerContext
|
|
440
242
|
|
|
441
|
-
|
|
442
|
-
{
|
|
443
|
-
"proxy": "http://user:pass@host:port"
|
|
444
|
-
}
|
|
445
|
-
```
|
|
243
|
+
Each composer handler receives a `MessengerContext` with:
|
|
446
244
|
|
|
447
|
-
|
|
245
|
+
| Property / Method | Description |
|
|
246
|
+
|-----------------------|-----------------------------------------------|
|
|
247
|
+
| `ctx.text` | Trimmed message body |
|
|
248
|
+
| `ctx.body` | Raw message body |
|
|
249
|
+
| `ctx.threadID` | Thread the message belongs to |
|
|
250
|
+
| `ctx.senderID` | User who sent the message |
|
|
251
|
+
| `ctx.messageID` | Unique message identifier |
|
|
252
|
+
| `ctx.event` | Full `MessageEvent` object |
|
|
253
|
+
| `ctx.reply(payload)` | Send a reply (callback-style) |
|
|
254
|
+
| `ctx.replyAsync(payload)` | Send a reply (returns a `Promise`) |
|
|
448
255
|
|
|
449
|
-
|
|
450
|
-
- Not part of the public API surface on purpose (to avoid encouraging spam).
|
|
451
|
-
- You can use it manually:
|
|
256
|
+
### Lifecycle
|
|
452
257
|
|
|
453
258
|
```javascript
|
|
454
|
-
|
|
259
|
+
await bot.launch({ stopOnSignals: true });
|
|
455
260
|
|
|
456
|
-
|
|
457
|
-
await
|
|
458
|
-
delayMs: 1200,
|
|
459
|
-
skipBlocked: true
|
|
460
|
-
});
|
|
261
|
+
// Graceful shutdown
|
|
262
|
+
await bot.stop();
|
|
461
263
|
```
|
|
462
264
|
|
|
463
|
-
|
|
265
|
+
When `stopOnSignals` is `true`, the bot automatically calls `stop()` on `SIGINT` / `SIGTERM`.
|
|
464
266
|
|
|
465
|
-
|
|
267
|
+
---
|
|
466
268
|
|
|
467
|
-
|
|
468
|
-
- **[docs/ARCHITECTURE.md](./docs/ARCHITECTURE.md)** — Codebase structure and modules (for contributors).
|
|
469
|
-
- For implementation details, the `src/` folder is the authoritative reference.
|
|
269
|
+
## Configuration
|
|
470
270
|
|
|
471
|
-
|
|
271
|
+
Copy the example config and edit it:
|
|
472
272
|
|
|
473
|
-
|
|
273
|
+
```bash
|
|
274
|
+
cp fca-config.example.json fca-config.json
|
|
275
|
+
```
|
|
474
276
|
|
|
475
|
-
|
|
476
|
-
|
|
277
|
+
### Configuration blocks
|
|
278
|
+
|
|
279
|
+
| Block | Purpose |
|
|
280
|
+
|-----------------|-------------------------------------------------------------------------------|
|
|
281
|
+
| `checkUpdate` | Automatic npm version check on startup |
|
|
282
|
+
| `mqtt` | MQTT reconnect interval, enable/disable realtime |
|
|
283
|
+
| `autoLogin` | Re-authenticate automatically when the session expires |
|
|
284
|
+
| `credentials` | Email / password / 2FA secret for auto-login |
|
|
285
|
+
| `antiGetInfo` | Toggle SQLite-backed caching for `getThreadInfo` / `getUserInfo` |
|
|
286
|
+
| `remoteControl` | WebSocket-based remote control for external dashboards |
|
|
287
|
+
| `apiServer` | External API server URL for token-based login |
|
|
288
|
+
|
|
289
|
+
### Login options (`FcaOptions`)
|
|
290
|
+
|
|
291
|
+
| Option | Type | Default | Description |
|
|
292
|
+
|-------------------|-----------|-----------|--------------------------------------------------|
|
|
293
|
+
| `listenEvents` | `boolean` | `false` | Receive thread events (not just messages) |
|
|
294
|
+
| `selfListen` | `boolean` | `false` | Receive your own messages |
|
|
295
|
+
| `selfListenEvent` | `boolean` | `false` | Receive your own thread events |
|
|
296
|
+
| `listenTyping` | `boolean` | `false` | Receive typing indicators |
|
|
297
|
+
| `updatePresence` | `boolean` | `false` | Receive presence/online status updates |
|
|
298
|
+
| `forceLogin` | `boolean` | `false` | Force login even if already logged in |
|
|
299
|
+
| `autoMarkRead` | `boolean` | `false` | Automatically mark messages as read |
|
|
300
|
+
| `autoReconnect` | `boolean` | `false` | Reconnect MQTT automatically on disconnect |
|
|
301
|
+
| `online` | `boolean` | `false` | Appear online to other users |
|
|
302
|
+
| `emitReady` | `boolean` | `false` | Emit a `ready` event when MQTT connects |
|
|
303
|
+
| `userAgent` | `string` | Chrome UA | Custom User-Agent header |
|
|
304
|
+
| `proxy` | `string` | — | HTTP/SOCKS proxy URL |
|
|
305
|
+
| `pageID` | `string` | — | Act as a Facebook Page instead of a user |
|
|
306
|
+
| `logLevel` | `string` | `"info"` | Logging verbosity (`silly`, `info`, `warn`, `error`, `silent`) |
|
|
477
307
|
|
|
478
308
|
---
|
|
479
309
|
|
|
480
|
-
##
|
|
310
|
+
## Features Overview
|
|
481
311
|
|
|
482
|
-
|
|
312
|
+
### Messaging
|
|
313
|
+
Send text, attachments, stickers; edit, unsend, delete messages; forward attachments; upload files; set reactions; share contacts; send typing indicators; mark as read/delivered/seen.
|
|
483
314
|
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
3. 💾 Commit your changes
|
|
487
|
-
4. 📤 Push to the branch
|
|
488
|
-
5. 🔄 Open a Pull Request
|
|
315
|
+
### Threads
|
|
316
|
+
Get thread info and history; list threads; search threads; create groups; add/remove participants; change admin status; change group name, image, color, emoji; create polls; archive/mute/delete threads; handle message requests.
|
|
489
317
|
|
|
490
|
-
|
|
318
|
+
### Users
|
|
319
|
+
Look up user info (single and batch); resolve user IDs from vanity URLs; get friends list.
|
|
491
320
|
|
|
492
|
-
|
|
321
|
+
### Account
|
|
322
|
+
Change avatar, bio, blocked status; handle friend requests; unfriend; set post reactions; refresh `fb_dtsg`; logout; manage external modules; auto-save app state.
|
|
493
323
|
|
|
494
|
-
|
|
324
|
+
### Realtime (MQTT)
|
|
325
|
+
Persistent WebSocket connection to Facebook's MQTT broker. Receives messages, reactions, typing indicators, presence, thread events, read receipts, and more in real time. Automatic reconnection with debounce and jitter.
|
|
495
326
|
|
|
496
|
-
|
|
327
|
+
### Database (optional)
|
|
328
|
+
SQLite-backed caching via Sequelize. Thread and user data are cached locally to reduce API calls. Thread cache is kept in sync with realtime events through `attachThreadInfoRealtimeSync`.
|
|
329
|
+
|
|
330
|
+
### Scheduler
|
|
331
|
+
Built-in scheduling domain for deferred or periodic tasks.
|
|
497
332
|
|
|
498
333
|
---
|
|
499
334
|
|
|
500
|
-
##
|
|
335
|
+
## Project Documentation
|
|
501
336
|
|
|
502
|
-
|
|
337
|
+
| Document | Contents |
|
|
338
|
+
|------------------------------------------------|---------------------------------------------------------|
|
|
339
|
+
| [docs/DOCS.md](./docs/DOCS.md) | Full API reference: login, facade, MessengerBot, MQTT, caching |
|
|
340
|
+
| [docs/ARCHITECTURE.md](./docs/ARCHITECTURE.md) | Source tree layout, bootstrap flow, module design |
|
|
341
|
+
| [CHANGELOG](https://github.com/dongp06/fca-unofficial/blob/main/CHANGELOG.md) | Version history (repository only; not in the npm package) |
|
|
342
|
+
| [fca-config.example.json](./fca-config.example.json) | Sample configuration file |
|
|
503
343
|
|
|
504
|
-
|
|
344
|
+
---
|
|
505
345
|
|
|
506
|
-
|
|
346
|
+
## Requirements
|
|
507
347
|
|
|
508
|
-
|
|
348
|
+
- **Node.js** >= 14.0.0 (LTS recommended)
|
|
349
|
+
- **npm** or any compatible package manager
|
|
509
350
|
|
|
510
|
-
|
|
351
|
+
---
|
|
511
352
|
|
|
512
|
-
|
|
353
|
+
## License
|
|
513
354
|
|
|
514
|
-
|
|
515
|
-
- 🐙 [GitHub Repository](https://github.com/Donix-VN/fca-unofficial)
|
|
516
|
-
- 🐛 [Issue Tracker](https://github.com/Donix-VN/fca-unofficial/issues)
|
|
355
|
+
This project is licensed under the **Apache License, Version 2.0**. See the [LICENSE](./LICENSE) file for the full text.
|
|
517
356
|
|
|
518
357
|
---
|
|
519
358
|
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
Made with ❤️ (and a lot of caffeine) for the developer community.
|
|
359
|
+
## Links
|
|
523
360
|
|
|
524
|
-
|
|
361
|
+
- **npm:** [@dongdev/fca-unofficial](https://www.npmjs.com/package/@dongdev/fca-unofficial)
|
|
362
|
+
- **GitHub:** [dongp06/fca-unofficial](https://github.com/dongp06/fca-unofficial)
|
|
363
|
+
- **Issues:** [GitHub Issues](https://github.com/dongp06/fca-unofficial/issues)
|
|
364
|
+
- **Author:** DongDev — [GitHub](https://github.com/dongp06)
|