stfca 1.0.0

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 (82) hide show
  1. package/LICENSE-MIT +4 -0
  2. package/README.md +325 -0
  3. package/index.d.ts +615 -0
  4. package/index.js +1 -0
  5. package/module/config.js +33 -0
  6. package/module/login.js +48 -0
  7. package/module/loginHelper.js +722 -0
  8. package/module/options.js +44 -0
  9. package/package.json +69 -0
  10. package/src/api/action/addExternalModule.js +25 -0
  11. package/src/api/action/changeAvatar.js +137 -0
  12. package/src/api/action/changeBio.js +75 -0
  13. package/src/api/action/getCurrentUserID.js +7 -0
  14. package/src/api/action/handleFriendRequest.js +57 -0
  15. package/src/api/action/logout.js +76 -0
  16. package/src/api/action/refreshFb_dtsg.js +71 -0
  17. package/src/api/action/setPostReaction.js +106 -0
  18. package/src/api/action/unfriend.js +54 -0
  19. package/src/api/http/httpGet.js +46 -0
  20. package/src/api/http/httpPost.js +52 -0
  21. package/src/api/http/postFormData.js +47 -0
  22. package/src/api/messaging/addUserToGroup.js +68 -0
  23. package/src/api/messaging/changeAdminStatus.js +122 -0
  24. package/src/api/messaging/changeArchivedStatus.js +55 -0
  25. package/src/api/messaging/changeBlockedStatus.js +48 -0
  26. package/src/api/messaging/changeGroupImage.js +90 -0
  27. package/src/api/messaging/changeNickname.js +70 -0
  28. package/src/api/messaging/changeThreadColor.js +79 -0
  29. package/src/api/messaging/changeThreadEmoji.js +106 -0
  30. package/src/api/messaging/createNewGroup.js +88 -0
  31. package/src/api/messaging/createPoll.js +43 -0
  32. package/src/api/messaging/deleteMessage.js +56 -0
  33. package/src/api/messaging/deleteThread.js +56 -0
  34. package/src/api/messaging/editMessage.js +68 -0
  35. package/src/api/messaging/forwardAttachment.js +51 -0
  36. package/src/api/messaging/getEmojiUrl.js +29 -0
  37. package/src/api/messaging/getFriendsList.js +82 -0
  38. package/src/api/messaging/getMessage.js +829 -0
  39. package/src/api/messaging/handleMessageRequest.js +65 -0
  40. package/src/api/messaging/markAsDelivered.js +57 -0
  41. package/src/api/messaging/markAsRead.js +88 -0
  42. package/src/api/messaging/markAsReadAll.js +49 -0
  43. package/src/api/messaging/markAsSeen.js +61 -0
  44. package/src/api/messaging/muteThread.js +50 -0
  45. package/src/api/messaging/removeUserFromGroup.js +105 -0
  46. package/src/api/messaging/resolvePhotoUrl.js +43 -0
  47. package/src/api/messaging/searchForThread.js +52 -0
  48. package/src/api/messaging/sendMessage.js +379 -0
  49. package/src/api/messaging/sendMessageMqtt.js +323 -0
  50. package/src/api/messaging/sendTypingIndicator.js +67 -0
  51. package/src/api/messaging/setMessageReaction.js +75 -0
  52. package/src/api/messaging/setTitle.js +119 -0
  53. package/src/api/messaging/shareContact.js +49 -0
  54. package/src/api/messaging/threadColors.js +128 -0
  55. package/src/api/messaging/unsendMessage.js +81 -0
  56. package/src/api/messaging/uploadAttachment.js +95 -0
  57. package/src/api/socket/core/connectMqtt.js +179 -0
  58. package/src/api/socket/core/getSeqID.js +25 -0
  59. package/src/api/socket/core/getTaskResponseData.js +22 -0
  60. package/src/api/socket/core/markDelivery.js +12 -0
  61. package/src/api/socket/core/parseDelta.js +351 -0
  62. package/src/api/socket/detail/buildStream.js +208 -0
  63. package/src/api/socket/detail/constants.js +24 -0
  64. package/src/api/socket/listenMqtt.js +133 -0
  65. package/src/api/threads/getThreadHistory.js +664 -0
  66. package/src/api/threads/getThreadInfo.js +358 -0
  67. package/src/api/threads/getThreadList.js +248 -0
  68. package/src/api/threads/getThreadPictures.js +78 -0
  69. package/src/api/users/getUserID.js +65 -0
  70. package/src/api/users/getUserInfo.js +319 -0
  71. package/src/api/users/getUserInfoV2.js +133 -0
  72. package/src/core/sendReqMqtt.js +63 -0
  73. package/src/database/models/index.js +49 -0
  74. package/src/database/models/thread.js +31 -0
  75. package/src/database/models/user.js +32 -0
  76. package/src/database/threadData.js +98 -0
  77. package/src/database/userData.js +89 -0
  78. package/src/utils/client.js +214 -0
  79. package/src/utils/constants.js +23 -0
  80. package/src/utils/format.js +1111 -0
  81. package/src/utils/headers.js +41 -0
  82. package/src/utils/request.js +215 -0
package/LICENSE-MIT ADDED
@@ -0,0 +1,4 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 ST | Sheikh Tamim (@sheikhtamimlover/fca-unofficial)
4
+
package/README.md ADDED
@@ -0,0 +1,325 @@
1
+ # @sheikhtamimlover/fca-unofficial
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@sheikhtamimlover/fca-unofficial.svg)](https://www.npmjs.com/package/@sheikhtamimlover/fca-unofficial)
4
+ [![npm downloads](https://img.shields.io/npm/dm/@sheikhtamimlover/fca-unofficial.svg)](https://www.npmjs.com/package/@sheikhtamimlover/fca-unofficial)
5
+
6
+ > **Unofficial Facebook Chat API for Node.js** - Interact with Facebook Messenger programmatically
7
+
8
+ ## ⚠️ Important Disclaimer
9
+
10
+ **We are not responsible if your account gets banned for spammy activities such as:**
11
+
12
+ - Sending lots of messages to people you don't know
13
+ - Sending messages very quickly
14
+ - Sending spammy looking URLs
15
+ - Logging in and out very quickly
16
+
17
+ **Recommendation:** Use Firefox browser or [this website](https://fca.dongdev.id.vn) to reduce logout issues, especially for iOS users.
18
+
19
+ **Support:** If you encounter errors, contact us [here](https://www.facebook.com/mdong.dev)
20
+
21
+ ## 🔍 Introduction
22
+
23
+ Facebook now has an [official API for chat bots](https://developers.facebook.com/docs/messenger-platform), however it's only available for Facebook Pages.
24
+
25
+ `@sheikhtamimlover/fca-unofficial` is the only API that allows you to automate chat functionalities on a **user account** by emulating the browser. This means:
26
+
27
+ - Making the exact same GET/POST requests as a browser
28
+ - Does not work with auth tokens
29
+ - Requires Facebook account credentials (email/password) or AppState
30
+
31
+ ## 📦 Installation
32
+
33
+ ```bash
34
+ npm install @sheikhtamimlover/fca-unofficial@latest
35
+ ```
36
+
37
+ ## 🚀 Basic Usage
38
+
39
+ ### 1. Login and Simple Echo Bot
40
+
41
+ ```javascript
42
+ const login = require("@sheikhtamimlover/fca-unofficial");
43
+
44
+ login({ appState: [] }, (err, api) => {
45
+ if (err) return console.error(err);
46
+
47
+ api.listenMqtt((err, event) => {
48
+ if (err) return console.error(err);
49
+
50
+ // Echo back the received message
51
+ api.sendMessage(event.body, event.threadID);
52
+ });
53
+ });
54
+ ```
55
+
56
+ ### 2. Send Text Message
57
+
58
+ ```javascript
59
+ const login = require("@sheikhtamimlover/fca-unofficial");
60
+
61
+ login({ appState: [] }, (err, api) => {
62
+ if (err) {
63
+ console.error("Login Error:", err);
64
+ return;
65
+ }
66
+
67
+ let yourID = "000000000000000"; // Replace with actual Facebook ID
68
+ let msg = "Hey!";
69
+
70
+ api.sendMessage(msg, yourID, err => {
71
+ if (err) console.error("Message Sending Error:", err);
72
+ else console.log("Message sent successfully!");
73
+ });
74
+ });
75
+ ```
76
+
77
+ **Tip:** To find your Facebook ID, look inside the cookies under the name `c_user`
78
+
79
+ ### 3. Send File/Image
80
+
81
+ ```javascript
82
+ const login = require("@sheikhtamimlover/fca-unofficial");
83
+ const fs = require("fs");
84
+
85
+ login({ appState: [] }, (err, api) => {
86
+ if (err) {
87
+ console.error("Login Error:", err);
88
+ return;
89
+ }
90
+
91
+ let yourID = "000000000000000";
92
+ let imagePath = __dirname + "/image.jpg";
93
+
94
+ // Check if file exists
95
+ if (!fs.existsSync(imagePath)) {
96
+ console.error("Error: Image file not found!");
97
+ return;
98
+ }
99
+
100
+ let msg = {
101
+ body: "Hey!",
102
+ attachment: fs.createReadStream(imagePath)
103
+ };
104
+
105
+ api.sendMessage(msg, yourID, err => {
106
+ if (err) console.error("Message Sending Error:", err);
107
+ else console.log("Message sent successfully!");
108
+ });
109
+ });
110
+ ```
111
+
112
+ ## 📝 Message Types
113
+
114
+ | Type | Usage |
115
+ | ---------------------- | ----------------------------------------------------------------- |
116
+ | **Regular text** | `{ body: "message text" }` |
117
+ | **Sticker** | `{ sticker: "sticker_id" }` |
118
+ | **File/Image** | `{ attachment: fs.createReadStream(path) }` or array of streams |
119
+ | **URL** | `{ url: "https://example.com" }` |
120
+ | **Large emoji** | `{ emoji: "👍", emojiSize: "large" }` (small/medium/large) |
121
+
122
+ **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.
123
+
124
+ ## 💾 Saving AppState to Avoid Re-login
125
+
126
+ ### Save AppState
127
+
128
+ ```javascript
129
+ const fs = require("fs");
130
+ const login = require("@sheikhtamimlover/fca-unofficial");
131
+
132
+ const credentials = { appState: [] };
133
+
134
+ login(credentials, (err, api) => {
135
+ if (err) {
136
+ console.error("Login Error:", err);
137
+ return;
138
+ }
139
+
140
+ try {
141
+ const appState = JSON.stringify(api.getAppState(), null, 2);
142
+ fs.writeFileSync("appstate.json", appState);
143
+ console.log("✅ AppState saved successfully!");
144
+ } catch (error) {
145
+ console.error("Error saving AppState:", error);
146
+ }
147
+ });
148
+ ```
149
+
150
+ ### Use Saved AppState
151
+
152
+ ```javascript
153
+ const fs = require("fs");
154
+ const login = require("@sheikhtamimlover/fca-unofficial");
155
+
156
+ login(
157
+ { appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) },
158
+ (err, api) => {
159
+ if (err) {
160
+ console.error("Login Error:", err);
161
+ return;
162
+ }
163
+
164
+ console.log("✅ Logged in successfully!");
165
+ // Your code here
166
+ }
167
+ );
168
+ ```
169
+
170
+ **Alternative:** Use [c3c-fbstate](https://github.com/c3cbot/c3c-fbstate) to get fbstate.json
171
+
172
+ ## 👂 Listening for Messages
173
+
174
+ ### Echo Bot with Stop Command
175
+
176
+ ```javascript
177
+ const fs = require("fs");
178
+ const login = require("@sheikhtamimlover/fca-unofficial");
179
+
180
+ login(
181
+ { appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) },
182
+ (err, api) => {
183
+ if (err) {
184
+ console.error("Login Error:", err);
185
+ return;
186
+ }
187
+
188
+ // Enable listening to events (join/leave, title change, etc.)
189
+ api.setOptions({ listenEvents: true });
190
+
191
+ const stopListening = api.listenMqtt((err, event) => {
192
+ if (err) {
193
+ console.error("Listen Error:", err);
194
+ return;
195
+ }
196
+
197
+ // Mark as read
198
+ api.markAsRead(event.threadID, err => {
199
+ if (err) console.error("Mark as read error:", err);
200
+ });
201
+
202
+ // Handle different event types
203
+ switch (event.type) {
204
+ case "message":
205
+ if (event.body && event.body.trim().toLowerCase() === "/stop") {
206
+ api.sendMessage("Goodbye…", event.threadID);
207
+ stopListening();
208
+ return;
209
+ }
210
+ api.sendMessage(`TEST BOT: ${event.body}`, event.threadID);
211
+ break;
212
+
213
+ case "event":
214
+ console.log("Event Received:", event);
215
+ break;
216
+ }
217
+ });
218
+ }
219
+ );
220
+ ```
221
+
222
+ ### Listen Options
223
+
224
+ ```javascript
225
+ api.setOptions({
226
+ listenEvents: true, // Receive events (join/leave, rename, etc.)
227
+ selfListen: true, // Receive messages from yourself
228
+ logLevel: "silent" // Disable logs (silent/error/warn/info/verbose)
229
+ });
230
+ ```
231
+
232
+ **By default:**
233
+
234
+ - `listenEvents` is `false` - won't receive events like joining/leaving chat, title changes
235
+ - `selfListen` is `false` - will ignore messages sent by the current account
236
+
237
+ ## 🛠️ Projects Using This API
238
+
239
+ - **[c3c](https://github.com/lequanglam/c3c)** - Customizable bot with plugins, supports Facebook & Discord
240
+ - **[Miraiv2](https://github.com/miraiPr0ject/miraiv2)** - Simple Facebook Messenger Bot
241
+ - **[Messer](https://github.com/mjkaufer/Messer)** - Command-line messaging for Facebook Messenger
242
+ - **[messen](https://github.com/tomquirk/messen)** - Rapidly build Facebook Messenger apps in Node.js
243
+ - **[Concierge](https://github.com/concierge/Concierge)** - Highly modular chat bot with built-in package manager
244
+ - **[Marc Zuckerbot](https://github.com/bsansouci/marc-zuckerbot)** - Facebook chat bot
245
+ - **[Botyo](https://github.com/ivkos/botyo)** - Modular bot for group chat rooms
246
+ - **[matrix-puppet-facebook](https://github.com/matrix-hacks/matrix-puppet-facebook)** - Facebook bridge for Matrix
247
+ - **[Miscord](https://github.com/Bjornskjald/miscord)** - Easy-to-use Facebook bridge for Discord
248
+ - **[chat-bridge](https://github.com/rexx0520/chat-bridge)** - Messenger, Telegram and IRC chat bridge
249
+ - **[Botium](https://github.com/codeforequity-at/botium-core)** - The Selenium for Chatbots
250
+ - **[Messenger-CLI](https://github.com/AstroCB/Messenger-CLI)** - Command-line interface for Facebook Messenger
251
+ - **[BotCore](https://github.com/AstroCB/BotCore)** - Tools for writing and managing Facebook Messenger bots
252
+
253
+ [See more projects...](https://github.com/Donix-VN/fca-unofficial#projects-using-this-api)
254
+
255
+ ## 📚 Full API Documentation
256
+
257
+ See [DOCS.md](./DOCS.md) for detailed information about:
258
+
259
+ - All available API methods
260
+ - Parameters and options
261
+ - Event types
262
+ - Error handling
263
+ - Advanced usage examples
264
+
265
+ ## 🎯 Quick Reference
266
+
267
+ ### Common API Methods
268
+
269
+ ```javascript
270
+ // Send message
271
+ api.sendMessage(message, threadID, callback);
272
+
273
+ // Send typing indicator
274
+ api.sendTypingIndicator(threadID, callback);
275
+
276
+ // Mark as read
277
+ api.markAsRead(threadID, callback);
278
+
279
+ // Get user info
280
+ api.getUserInfo(userID, callback);
281
+
282
+ // Get thread info
283
+ api.getThreadInfo(threadID, callback);
284
+
285
+ // Change thread color
286
+ api.changeThreadColor(color, threadID, callback);
287
+
288
+ // Change thread emoji
289
+ api.changeThreadEmoji(emoji, threadID, callback);
290
+
291
+ // Set message reaction
292
+ api.setMessageReaction(reaction, messageID, callback);
293
+ ```
294
+
295
+ ## 🤝 Contributing
296
+
297
+ Contributions are welcome! Please:
298
+
299
+ 1. Fork the repository
300
+ 2. Create a new branch (`git checkout -b feature/AmazingFeature`)
301
+ 3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
302
+ 4. Push to the branch (`git push origin feature/AmazingFeature`)
303
+ 5. Open a Pull Request
304
+
305
+ ## 📄 License
306
+
307
+ MIT License - See [LICENSE](./LICENSE) for details.
308
+
309
+ ## 👨‍💻 Author
310
+
311
+ **ST | Sheikh Tamim** - [Facebook](https://www.facebook.com/hamza.chudena)
312
+
313
+ ## ⭐ Support
314
+
315
+ If this project is helpful, please give it a ⭐ on GitHub!
316
+
317
+ ## 🔗 Links
318
+
319
+ - [NPM Package](https://www.npmjs.com/package/@sheikhtamimlover/fca-unofficial)
320
+ - [GitHub Repository](https://github.com/sheikhtamimlover/fca-unofficial)
321
+ - [Issue Tracker](https://github.com/sheikhtamimlover/fca-unofficial/issues)
322
+
323
+ ---
324
+
325
+ **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).