@cexy/hoonfca 1.0.4 → 1.0.6
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/CHANGELOG.md +181 -0
- package/DOCS.md +2636 -0
- package/LICENSE-MIT +21 -21
- package/README.md +632 -0
- package/func/checkUpdate.js +231 -0
- package/func/logger.js +48 -0
- package/index.d.ts +731 -605
- package/index.js +6 -774
- package/module/config.js +67 -0
- package/module/login.js +154 -0
- package/module/loginHelper.js +1034 -0
- package/module/options.js +54 -0
- package/package.json +54 -19
- package/src/api/action/addExternalModule.js +25 -0
- package/src/api/action/changeAvatar.js +137 -0
- package/src/{changeBio.js → api/action/changeBio.js} +75 -76
- package/src/api/action/enableAutoSaveAppState.js +73 -0
- package/src/{getCurrentUserID.js → api/action/getCurrentUserID.js} +7 -7
- package/src/{handleFriendRequest.js → api/action/handleFriendRequest.js} +57 -57
- package/src/api/action/logout.js +76 -0
- package/src/api/action/refreshFb_dtsg.js +48 -0
- package/src/api/action/setPostReaction.js +106 -0
- package/src/api/action/unfriend.js +54 -0
- package/src/api/http/httpGet.js +46 -0
- package/src/api/http/httpPost.js +52 -0
- package/src/api/http/postFormData.js +47 -0
- package/src/api/messaging/addUserToGroup.js +68 -0
- package/src/api/messaging/changeAdminStatus.js +122 -0
- package/src/api/messaging/changeArchivedStatus.js +55 -0
- package/src/api/messaging/changeBlockedStatus.js +48 -0
- package/src/api/messaging/changeGroupImage.js +90 -0
- package/src/api/messaging/changeNickname.js +70 -0
- package/src/api/messaging/changeThreadColor.js +79 -0
- package/src/api/messaging/changeThreadEmoji.js +106 -0
- package/src/{createNewGroup.js → api/messaging/createNewGroup.js} +88 -88
- package/src/api/messaging/createPoll.js +43 -0
- package/src/api/messaging/createThemeAI.js +98 -0
- package/src/{deleteMessage.js → api/messaging/deleteMessage.js} +56 -56
- package/src/{deleteThread.js → api/messaging/deleteThread.js} +56 -56
- package/src/api/messaging/editMessage.js +68 -0
- package/src/api/messaging/forwardAttachment.js +51 -0
- package/src/{getEmojiUrl.js → api/messaging/getEmojiUrl.js} +8 -8
- package/src/{getFriendsList.js → api/messaging/getFriendsList.js} +82 -84
- package/src/api/messaging/getMessage.js +829 -0
- package/src/api/messaging/getThemePictures.js +62 -0
- package/src/api/messaging/handleMessageRequest.js +65 -0
- package/src/{markAsDelivered.js → api/messaging/markAsDelivered.js} +57 -58
- package/src/{markAsRead.js → api/messaging/markAsRead.js} +88 -88
- package/src/{markAsReadAll.js → api/messaging/markAsReadAll.js} +49 -50
- package/src/api/messaging/markAsSeen.js +61 -0
- package/src/{muteThread.js → api/messaging/muteThread.js} +50 -52
- package/src/api/messaging/removeUserFromGroup.js +106 -0
- package/src/{resolvePhotoUrl.js → api/messaging/resolvePhotoUrl.js} +43 -45
- package/src/api/messaging/scheduler.js +264 -0
- package/src/{searchForThread.js → api/messaging/searchForThread.js} +52 -53
- package/src/api/messaging/sendMessage.js +272 -0
- package/src/api/messaging/sendTypingIndicator.js +67 -0
- package/src/api/messaging/setMessageReaction.js +76 -0
- package/src/api/messaging/setTitle.js +119 -0
- package/src/{shareContact.js → api/messaging/shareContact.js} +49 -53
- package/src/api/messaging/threadColors.js +128 -0
- package/src/api/messaging/unsendMessage.js +81 -0
- package/src/api/messaging/uploadAttachment.js +94 -0
- package/src/api/socket/core/connectMqtt.js +255 -0
- package/src/api/socket/core/emitAuth.js +106 -0
- package/src/api/socket/core/getSeqID.js +40 -0
- package/src/api/socket/core/getTaskResponseData.js +22 -0
- package/src/api/socket/core/markDelivery.js +12 -0
- package/src/api/socket/core/parseDelta.js +391 -0
- package/src/api/socket/detail/buildStream.js +208 -0
- package/src/api/socket/detail/constants.js +24 -0
- package/src/api/socket/listenMqtt.js +364 -0
- package/src/api/socket/middleware/index.js +216 -0
- package/src/{getThreadHistory.js → api/threads/getThreadHistory.js} +664 -647
- package/src/api/threads/getThreadInfo.js +438 -0
- package/src/{getThreadList.js → api/threads/getThreadList.js} +293 -292
- package/src/{getThreadPictures.js → api/threads/getThreadPictures.js} +78 -79
- package/src/{getUserID.js → api/users/getUserID.js} +65 -66
- package/src/api/users/getUserInfo.js +327 -0
- package/src/api/users/getUserInfoV2.js +134 -0
- package/src/core/sendReqMqtt.js +96 -0
- package/src/database/models/index.js +87 -0
- package/src/database/models/thread.js +45 -0
- package/src/database/models/user.js +46 -0
- package/src/database/threadData.js +98 -0
- package/src/database/userData.js +89 -0
- package/src/utils/client.js +320 -0
- package/src/utils/constants.js +23 -0
- package/{utils.js → src/utils/format.js} +1115 -1447
- package/src/utils/headers.js +115 -0
- package/src/utils/request.js +305 -0
- package/.travis.yml +0 -6
- package/src/addExternalModule.js +0 -23
- package/src/addUserToGroup.js +0 -113
- package/src/changeAdminStatus.js +0 -95
- package/src/changeApprovalMode.js +0 -79
- package/src/changeArchivedStatus.js +0 -55
- package/src/changeBlockedStatus.js +0 -47
- package/src/changeBlockedStatusMqtt.js +0 -86
- package/src/changeGroupImage.js +0 -133
- package/src/changeNickname.js +0 -59
- package/src/changeThreadColor.js +0 -71
- package/src/changeThreadEmoji.js +0 -55
- package/src/createPoll.js +0 -130
- package/src/editMessage.js +0 -63
- package/src/forwardAttachment.js +0 -60
- package/src/forwardMessage.js +0 -63
- package/src/getGroupsList.js +0 -83
- package/src/getMarketplace.js +0 -84
- package/src/getNotifications.js +0 -86
- package/src/getPagesList.js +0 -83
- package/src/getStories.js +0 -88
- package/src/getThreadInfo.js +0 -222
- package/src/getUserInfo.js +0 -128
- package/src/handleMessageRequest.js +0 -65
- package/src/httpGet.js +0 -58
- package/src/httpPost.js +0 -58
- package/src/listenMqtt.js +0 -1018
- package/src/logout.js +0 -75
- package/src/markAsSeen.js +0 -61
- package/src/pinMessage.js +0 -61
- package/src/removeUserFromGroup.js +0 -79
- package/src/searchUsers.js +0 -89
- package/src/sendComment.js +0 -161
- package/src/sendMessage.js +0 -457
- package/src/sendTypingIndicator.js +0 -179
- package/src/setBio.js +0 -86
- package/src/setMessageReaction.js +0 -186
- package/src/setPostReaction.js +0 -71
- package/src/setTheme.js +0 -313
- package/src/setTitle.js +0 -90
- package/src/shareLink.js +0 -62
- package/src/threadColors.js +0 -57
- package/src/unfriend.js +0 -53
- package/src/unsendMessage.js +0 -104
package/LICENSE-MIT
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Copyright (c)
|
|
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
|
|
13
|
-
|
|
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
|
|
21
|
-
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 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
ADDED
|
@@ -0,0 +1,632 @@
|
|
|
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
|
+
[](https://www.npmjs.com/package/@dongdev/fca-unofficial)
|
|
8
|
+
[](https://www.npmjs.com/package/@dongdev/fca-unofficial)
|
|
9
|
+
[](./LICENSE-MIT)
|
|
10
|
+
[](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, callback);
|
|
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
|
+
[](https://www.facebook.com/mdong.dev)
|
|
609
|
+
[](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>
|