sagor-fca 0.0.14 → 0.0.15
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/README.md +172 -210
- package/index.js +552 -0
- package/package.json +38 -75
- package/src/OldMessage.js +357 -0
- package/src/addExternalModule.js +25 -0
- package/src/{controllers/addUserToGroup.js → addUserToGroup.js} +27 -25
- package/src/changeAdminStatus.js +103 -0
- package/src/{controllers/changeArchivedStatus.js → changeArchivedStatus.js} +14 -14
- package/src/changeAvatar.js +136 -0
- package/src/changeAvatarV2.js +86 -0
- package/src/changeAvt.js +85 -0
- package/src/{controllers/changeBio.js → changeBio.js} +15 -16
- package/src/{controllers/changeBlockedStatus.js → changeBlockedStatus.js} +11 -9
- package/src/changeBlockedStatusMqtt.js +80 -0
- package/src/changeCover.js +72 -0
- package/src/{controllers/changeGroupImage.js → changeGroupImage.js} +34 -28
- package/src/changeName.js +79 -0
- package/src/{controllers/changeNickname.js → changeNickname.js} +13 -13
- package/src/changeThreadColor.js +65 -0
- package/src/{controllers/changeThreadEmoji.js → changeThreadEmoji.js} +14 -14
- package/src/changeUsername.js +59 -0
- package/src/createCommentPost.js +230 -0
- package/src/{controllers/createNewGroup.js → createNewGroup.js} +28 -26
- package/src/{controllers/createPoll.js → createPoll.js} +15 -15
- package/src/createPost.js +276 -0
- package/src/{controllers/deleteMessage.js → deleteMessage.js} +14 -14
- package/src/{controllers/deleteThread.js → deleteThread.js} +14 -14
- package/src/editMessage.js +68 -0
- package/src/editMessageOld.js +67 -0
- package/src/follow.js +74 -0
- package/src/{controllers/forwardAttachment.js → forwardAttachment.js} +15 -15
- package/src/friendList.js +103 -0
- package/src/getAccess.js +112 -0
- package/src/{controllers/getAvatarUser.js → getAvatarUser.js} +3 -2
- package/src/getCurrentUserID.js +7 -0
- package/src/getEmojiUrl.js +29 -0
- package/src/{controllers/getFriendsList.js → getFriendsList.js} +15 -16
- package/src/{controllers/getMessage.js → getMessage.js} +47 -33
- package/src/getRegion.js +7 -0
- package/src/{controllers/getThreadHistory.js → getThreadHistory.js} +129 -151
- package/src/{controllers/getThreadHistoryDeprecated.js → getThreadHistoryDeprecated.js} +20 -42
- package/src/getThreadInfo.js +232 -0
- package/src/getThreadInfoDeprecated.js +56 -0
- package/src/{controllers/getThreadList.js → getThreadList.js} +50 -111
- package/src/getThreadListDeprecated.js +46 -0
- package/src/getThreadPictures.js +59 -0
- package/src/getThreadTheme.js +82 -0
- package/src/getUID.js +119 -0
- package/src/{controllers/getUserID.js → getUserID.js} +9 -14
- package/src/{controllers/getUserInfo.js → getUserInfo.js} +12 -38
- package/src/{controllers/handleFriendRequest.js → handleFriendRequest.js} +11 -26
- package/src/handleMessageRequest.js +47 -0
- package/src/httpGet.js +49 -0
- package/src/httpPost.js +48 -0
- package/src/listenMqtt.js +763 -0
- package/src/logout.js +75 -0
- package/src/{controllers/markAsDelivered.js → markAsDelivered.js} +11 -22
- package/src/{controllers/markAsRead.js → markAsRead.js} +18 -40
- package/src/{controllers/markAsReadAll.js → markAsReadAll.js} +10 -20
- package/src/{controllers/markAsSeen.js → markAsSeen.js} +7 -18
- package/src/metaTheme.js +190 -0
- package/src/{controllers/muteThread.js → muteThread.js} +11 -18
- package/src/note.js +228 -0
- package/src/{controllers/refreshFb_dtsg.js → refreshFb_dtsg.js} +4 -4
- package/src/removeSuspiciousAccount.js +79 -0
- package/src/{controllers/removeUserFromGroup.js → removeUserFromGroup.js} +13 -13
- package/src/{controllers/resolvePhotoUrl.js → resolvePhotoUrl.js} +11 -11
- package/src/{controllers/searchForThread.js → searchForThread.js} +10 -10
- package/src/searchFriends.js +139 -0
- package/src/{controllers/searchStickers.js → searchStickers.js} +1 -1
- package/src/sendFriendRequest.js +113 -0
- package/src/sendMessage.js +258 -0
- package/src/sendMessageMqtt.js +322 -0
- package/src/sendTypingIndicator.js +45 -0
- package/src/setActiveStatus.js +93 -0
- package/src/{controllers/setMessageReaction.js → setMessageReaction.js} +22 -61
- package/src/setMessageReactionMqtt.js +62 -0
- package/src/setPostReaction.js +112 -0
- package/src/setProfileLock.js +98 -0
- package/src/setStoryReaction.js +134 -0
- package/src/setStorySeen.js +109 -0
- package/src/setThreadTheme.js +103 -0
- package/src/{controllers/setTitle.js → setTitle.js} +18 -14
- package/src/shareContact.js +110 -0
- package/src/shareLink.js +59 -0
- package/src/stopListenMqtt.js +23 -0
- package/src/storyManager.js +358 -0
- package/src/suggestFriend.js +108 -0
- package/src/threadColors.js +131 -0
- package/src/{controllers/unfriend.js → unfriend.js} +3 -3
- package/src/unsendMessage.js +45 -0
- package/src/uploadAttachment.js +93 -0
- package/utils.js +2962 -0
- package/.github/workflows/main.yml +0 -22
- package/jest.config.js +0 -10
- package/pnpm-workspace.yaml +0 -3
- package/scripts/discover-e2ee-jid.js +0 -266
- package/scripts/e2ee-send-debug.js +0 -218
- package/scripts/e2ee-send-smoke.js +0 -148
- package/scripts/listen-echo-all.js +0 -311
- package/src/controllers/addExternalModule.js +0 -34
- package/src/controllers/changeAdminStatus.js +0 -79
- package/src/controllers/changeThreadColor.js +0 -71
- package/src/controllers/connectE2EE.js +0 -47
- package/src/controllers/disconnectE2EE.js +0 -47
- package/src/controllers/downloadE2EEMedia.js +0 -52
- package/src/controllers/editMessage.js +0 -81
- package/src/controllers/getCurrentUserID.js +0 -11
- package/src/controllers/getE2EEDeviceData.js +0 -53
- package/src/controllers/getEmojiUrl.js +0 -37
- package/src/controllers/getRegion.js +0 -11
- package/src/controllers/getThreadInfo.js +0 -265
- package/src/controllers/getThreadInfoDeprecated.js +0 -80
- package/src/controllers/getThreadListDeprecated.js +0 -91
- package/src/controllers/getThreadPictures.js +0 -79
- package/src/controllers/handleMessageRequest.js +0 -65
- package/src/controllers/httpGet.js +0 -70
- package/src/controllers/httpPost.js +0 -70
- package/src/controllers/index.js +0 -75
- package/src/controllers/listenMqtt.js +0 -870
- package/src/controllers/logout.js +0 -144
- package/src/controllers/pinMessage.js +0 -86
- package/src/controllers/sendMediaE2EE.js +0 -105
- package/src/controllers/sendMessage.js +0 -566
- package/src/controllers/sendMessageE2EE.js +0 -77
- package/src/controllers/sendMessageMqtt.js +0 -235
- package/src/controllers/sendReactionE2EE.js +0 -65
- package/src/controllers/sendTypingE2EE.js +0 -71
- package/src/controllers/sendTypingIndicator.js +0 -59
- package/src/controllers/setMessageReactionMqtt.js +0 -72
- package/src/controllers/setPostReaction.js +0 -76
- package/src/controllers/stopListenMqtt.js +0 -79
- package/src/controllers/threadColors.js +0 -57
- package/src/controllers/unsendMessage.js +0 -65
- package/src/controllers/unsendMessageE2EE.js +0 -60
- package/src/e2ee/bridge.js +0 -488
- package/src/e2ee/thread.js +0 -12
- package/src/index.js +0 -768
- package/src/service/uploadAttachment.js +0 -318
- package/src/utils/base-parts/auth.js +0 -286
- package/src/utils/base-parts/formatters.js +0 -751
- package/src/utils/base-parts/identity.js +0 -169
- package/src/utils/base-parts/network.js +0 -159
- package/src/utils/base-parts/parsing.js +0 -53
- package/src/utils/base-parts/type.js +0 -9
- package/src/utils/base.js +0 -18
- package/src/utils/defaults.js +0 -10
- package/src/utils/format-attachments.js +0 -7
- package/src/utils/format-core.js +0 -8
- package/src/utils/format-events.js +0 -11
- package/src/utils/format-messages.js +0 -10
- package/src/utils/format-presence.js +0 -9
- package/src/utils/format-threads.js +0 -8
- package/src/utils/formatters.js +0 -18
- package/src/utils/identity.js +0 -12
- package/src/utils/index.js +0 -15
- package/src/utils/network.js +0 -12
- package/src/utils/parsing.js +0 -11
- package/src/utils.js +0 -3
- package/test/config.env.example +0 -30
- package/test/data/shareAttach.js +0 -146
- package/test/data/something.mov +0 -0
- package/test/data/test.png +0 -0
- package/test/data/test.txt +0 -7
- package/test/example-appstate.txt +0 -11
- package/test/integration/api.integration.test.js +0 -387
- package/test/integration/controllers.appstate.integration.test.js +0 -233
- package/test/integration/e2ee.appstate.integration.test.js +0 -290
- package/test/integration/env-test-config.js +0 -46
- package/test/integration/login.appstate.integration.test.js +0 -47
- package/test/integration/page.integration.test.js +0 -139
- package/test/jest.setup.js +0 -54
- package/test/unit/controllers/controllers.basic.test.js +0 -116
- package/test/unit/controllers/controllers.registry.test.js +0 -36
- package/test/unit/controllers/e2ee.controllers.test.js +0 -299
- package/test/unit/controllers/sendMessage.e2ee-auto.test.js +0 -111
- package/test/unit/controllers/sendMessage.transport-fallback.test.js +0 -177
- package/test/unit/index/index.test.js +0 -110
- package/test/unit/utils/base-parts/auth.test.js +0 -93
- package/test/unit/utils/base-parts/formatters.test.js +0 -53
- package/test/unit/utils/base-parts/identity.test.js +0 -43
- package/test/unit/utils/base-parts/parsing.test.js +0 -38
- package/test/unit/utils/base-parts/type.test.js +0 -23
- package/test/unit/utils/base.test.js +0 -35
package/README.md
CHANGED
|
@@ -1,282 +1,244 @@
|
|
|
1
|
-
# Unofficial Facebook Chat API
|
|
2
|
-
<a href="https://www.npmjs.com/package/sagor-fca"><img alt="npm version" src="https://img.shields.io/npm/v/sagor-fca.svg?style=flat-square"></a>
|
|
3
|
-
<img alt="version" src="https://img.shields.io/github/package-json/v/VangBanLaNhat/sagor-fca?label=github&style=flat-square">
|
|
4
|
-
<a href="https://www.npmjs.com/package/sagor-fca"><img src="https://img.shields.io/npm/dm/sagor-fca.svg?style=flat-square" alt="npm downloads"></a>
|
|
5
|
-
[](https://github.com/prettier/prettier)
|
|
1
|
+
# 🚀 SAGOR-FCA: Unofficial Facebook Chat API
|
|
6
2
|
|
|
7
|
-
|
|
3
|
+
  
|
|
8
4
|
|
|
9
|
-
|
|
5
|
+
**A lightweight, fast, and unofficial API to interact with Facebook Chat programmatically — ideal for building bots, automation systems, and custom messaging tools.**
|
|
10
6
|
|
|
11
|
-
|
|
7
|
+
**This project is customized and enhanced for improved performance and stability.**
|
|
12
8
|
|
|
13
|
-
See [below](#projects-using-this-api) for projects using this API.
|
|
14
9
|
|
|
15
|
-
See the [full changelog](/CHANGELOG.md) for release details.
|
|
16
10
|
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
# 🌟 What's New in SAGOR-FCA
|
|
12
|
+
|
|
13
|
+
- ✨ Enhanced MQTT connection logging
|
|
14
|
+
- 🔄 Auto-reconnect with configurable intervals
|
|
15
|
+
- 📊 Better connection status indicators
|
|
16
|
+
- 🎨 Improved console output with colors
|
|
17
|
+
- 🔐 Enhanced security and stability
|
|
18
|
+
- 🚀 Automatic update checking and installation
|
|
19
|
+
- 💡 Better error handling and debugging
|
|
20
|
+
|
|
21
|
+
## 📦 Installation
|
|
19
22
|
```bash
|
|
20
|
-
npm install sagor-fca
|
|
23
|
+
npm install sagor-fca@latest
|
|
21
24
|
```
|
|
22
|
-
It will download `sagor-fca` from NPM repositories
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
If you want to use bleeding edge (directly from github) to test new features or submit bug report, this is the command for you:
|
|
26
|
+
Or
|
|
26
27
|
```bash
|
|
27
28
|
npm install sagor-fca
|
|
28
29
|
```
|
|
29
30
|
|
|
30
|
-
##
|
|
31
|
-
|
|
31
|
+
## 🚀 Basic Usage
|
|
32
|
+
|
|
33
|
+
### 1. Login and Simple Echo Bot
|
|
32
34
|
|
|
33
|
-
## Example Usage
|
|
34
35
|
```javascript
|
|
35
36
|
const login = require("sagor-fca");
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
login({ appState: [] }, (err, api) => {
|
|
39
|
+
if (err) return console.error(err);
|
|
40
|
+
|
|
41
|
+
api.listenMqtt((err, event) => {
|
|
42
|
+
if (err) return console.error(err);
|
|
40
43
|
|
|
41
|
-
|
|
42
|
-
api.sendMessage(
|
|
44
|
+
// Echo back the received message
|
|
45
|
+
api.sendMessage(event.body, event.threadID);
|
|
43
46
|
});
|
|
44
47
|
});
|
|
45
48
|
```
|
|
46
49
|
|
|
47
|
-
|
|
50
|
+
### 2. Send Text Message
|
|
48
51
|
|
|
49
|
-
|
|
52
|
+
```javascript
|
|
53
|
+
const login = require("sagor-fca");
|
|
50
54
|
|
|
55
|
+
login({ appState: [] }, (err, api) => {
|
|
56
|
+
if (err) {
|
|
57
|
+
console.error("Login Error:", err);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
51
60
|
|
|
52
|
-
|
|
61
|
+
let yourID = "000000000000000"; // Replace with actual Facebook ID
|
|
62
|
+
let msg = "Hey!";
|
|
53
63
|
|
|
54
|
-
|
|
64
|
+
api.sendMessage(msg, yourID, err => {
|
|
65
|
+
if (err) console.error("Message Sending Error:", err);
|
|
66
|
+
else console.log("Message sent successfully!");
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
```
|
|
55
70
|
|
|
56
|
-
|
|
71
|
+
**Tip:** To find your Facebook ID, look inside the cookies under the name `c_user`
|
|
57
72
|
|
|
58
|
-
###
|
|
59
|
-
#### api.sendMessage(message, threadID[, callback][, messageID])
|
|
73
|
+
### 3. Send File/Image
|
|
60
74
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
* *File or image:* Set field `attachment` to a readable stream or an array of readable streams.
|
|
65
|
-
* *URL:* set a field `url` to the desired URL.
|
|
66
|
-
* *Emoji:* set field `emoji` to the desired emoji as a string and set field `emojiSize` with size of the emoji (`small`, `medium`, `large`)
|
|
75
|
+
```javascript
|
|
76
|
+
const login = require("sagor-fca");
|
|
77
|
+
const fs = require("fs");
|
|
67
78
|
|
|
68
|
-
|
|
79
|
+
login({ appState: [] }, (err, api) => {
|
|
80
|
+
if (err) {
|
|
81
|
+
console.error("Login Error:", err);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
69
84
|
|
|
70
|
-
|
|
85
|
+
let yourID = "000000000000000";
|
|
86
|
+
let imagePath = __dirname + "/image.jpg";
|
|
71
87
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
88
|
+
// Check if file exists
|
|
89
|
+
if (!fs.existsSync(imagePath)) {
|
|
90
|
+
console.error("Error: Image file not found!");
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
75
93
|
|
|
76
|
-
|
|
77
|
-
|
|
94
|
+
let msg = {
|
|
95
|
+
body: "Hey!",
|
|
96
|
+
attachment: fs.createReadStream(imagePath)
|
|
97
|
+
};
|
|
78
98
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
99
|
+
api.sendMessage(msg, yourID, err => {
|
|
100
|
+
if (err) console.error("Message Sending Error:", err);
|
|
101
|
+
else console.log("Message sent successfully!");
|
|
102
|
+
});
|
|
82
103
|
});
|
|
83
104
|
```
|
|
84
105
|
|
|
85
|
-
|
|
86
|
-
```js
|
|
87
|
-
const login = require("sagor-fca");
|
|
88
|
-
|
|
89
|
-
login({email: "FB_EMAIL", password: "FB_PASSWORD"}, (err, api) => {
|
|
90
|
-
if(err) return console.error(err);
|
|
106
|
+
## 📝 Message Types
|
|
91
107
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
});
|
|
100
|
-
```
|
|
108
|
+
| Type | Usage |
|
|
109
|
+
| ---------------------- | ----------------------------------------------------------------- |
|
|
110
|
+
| **Regular text** | `{ body: "message text" }` |
|
|
111
|
+
| **Sticker** | `{ sticker: "sticker_id" }` |
|
|
112
|
+
| **File/Image** | `{ attachment: fs.createReadStream(path) }` or array of streams |
|
|
113
|
+
| **URL** | `{ url: "https://example.com" }` |
|
|
114
|
+
| **Large emoji** | `{ emoji: "👍", emojiSize: "large" }` (small/medium/large) |
|
|
101
115
|
|
|
102
|
-
|
|
103
|
-
### Saving session.
|
|
116
|
+
**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.
|
|
104
117
|
|
|
105
|
-
|
|
118
|
+
## 💾 Saving AppState to Avoid Re-login
|
|
106
119
|
|
|
107
|
-
|
|
120
|
+
### Save AppState
|
|
108
121
|
|
|
109
|
-
```
|
|
122
|
+
```javascript
|
|
110
123
|
const fs = require("fs");
|
|
111
124
|
const login = require("sagor-fca");
|
|
112
125
|
|
|
113
|
-
|
|
126
|
+
const credentials = { appState: [] };
|
|
114
127
|
|
|
115
128
|
login(credentials, (err, api) => {
|
|
116
|
-
if(err)
|
|
129
|
+
if (err) {
|
|
130
|
+
console.error("Login Error:", err);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
117
133
|
|
|
118
|
-
|
|
134
|
+
try {
|
|
135
|
+
const appState = JSON.stringify(api.getAppState(), null, 2);
|
|
136
|
+
fs.writeFileSync("appstate.json", appState);
|
|
137
|
+
console.log("✅ AppState saved successfully!");
|
|
138
|
+
} catch (error) {
|
|
139
|
+
console.error("Error saving AppState:", error);
|
|
140
|
+
}
|
|
119
141
|
});
|
|
120
142
|
```
|
|
121
143
|
|
|
122
|
-
|
|
144
|
+
### Use Saved AppState
|
|
123
145
|
|
|
124
|
-
|
|
146
|
+
```javascript
|
|
147
|
+
const fs = require("fs");
|
|
148
|
+
const login = require("sagor-fca");
|
|
125
149
|
|
|
126
|
-
|
|
127
|
-
|
|
150
|
+
login(
|
|
151
|
+
{ appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) },
|
|
152
|
+
(err, api) => {
|
|
153
|
+
if (err) {
|
|
154
|
+
console.error("Login Error:", err);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
128
157
|
|
|
129
|
-
|
|
158
|
+
console.log("✅ Logged in successfully!");
|
|
159
|
+
// Your code here
|
|
160
|
+
}
|
|
161
|
+
);
|
|
162
|
+
```
|
|
130
163
|
|
|
131
|
-
|
|
164
|
+
**Alternative:** Use [c3c-fbstate](https://github.com/c3cbot/c3c-fbstate) to get fbstate.json
|
|
132
165
|
|
|
133
|
-
|
|
134
|
-
const fs = require("fs");
|
|
135
|
-
const login = require("sagor-fca");
|
|
166
|
+
## 👂 Listening for Messages
|
|
136
167
|
|
|
137
|
-
|
|
138
|
-
// Will stop when you say '/stop'
|
|
139
|
-
login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
|
|
140
|
-
if(err) return console.error(err);
|
|
168
|
+
### Echo Bot with Stop Command
|
|
141
169
|
|
|
142
|
-
|
|
170
|
+
```javascript
|
|
171
|
+
const fs = require("fs");
|
|
172
|
+
const login = require("sagor-fca");
|
|
143
173
|
|
|
144
|
-
|
|
145
|
-
|
|
174
|
+
login(
|
|
175
|
+
{ appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) },
|
|
176
|
+
(err, api) => {
|
|
177
|
+
if (err) {
|
|
178
|
+
console.error("Login Error:", err);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
146
181
|
|
|
147
|
-
|
|
148
|
-
|
|
182
|
+
// Enable listening to events (join/leave, title change, etc.)
|
|
183
|
+
api.setOptions({ listenEvents: true });
|
|
184
|
+
|
|
185
|
+
const stopListening = api.listenMqtt((err, event) => {
|
|
186
|
+
if (err) {
|
|
187
|
+
console.error("Listen Error:", err);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Mark as read
|
|
192
|
+
api.markAsRead(event.threadID, err => {
|
|
193
|
+
if (err) console.error("Mark as read error:", err);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
// Handle different event types
|
|
197
|
+
switch (event.type) {
|
|
198
|
+
case "message":
|
|
199
|
+
if (event.body && event.body.trim().toLowerCase() === "/stop") {
|
|
200
|
+
api.sendMessage("Goodbye…", event.threadID);
|
|
201
|
+
stopListening();
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
api.sendMessage(`TEST BOT: ${event.body}`, event.threadID);
|
|
205
|
+
break;
|
|
206
|
+
|
|
207
|
+
case "event":
|
|
208
|
+
console.log("Event Received:", event);
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
149
211
|
});
|
|
212
|
+
}
|
|
213
|
+
);
|
|
214
|
+
```
|
|
150
215
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
break;
|
|
159
|
-
case "event":
|
|
160
|
-
console.log(event);
|
|
161
|
-
break;
|
|
162
|
-
}
|
|
163
|
-
});
|
|
216
|
+
### Listen Options
|
|
217
|
+
|
|
218
|
+
```javascript
|
|
219
|
+
api.setOptions({
|
|
220
|
+
listenEvents: true, // Receive events (join/leave, rename, etc.)
|
|
221
|
+
selfListen: true, // Receive messages from yourself
|
|
222
|
+
logLevel: "silent" // Disable logs (silent/error/warn/info/verbose)
|
|
164
223
|
});
|
|
165
224
|
```
|
|
166
225
|
|
|
167
|
-
|
|
226
|
+
**By default:**
|
|
168
227
|
|
|
169
|
-
|
|
228
|
+
- `listenEvents` is `false` - won't receive events like joining/leaving chat, title changes
|
|
229
|
+
- `selfListen` is `false` - will ignore messages sent by the current account
|
|
170
230
|
|
|
171
|
-
|
|
231
|
+
### ⚠️ Disclaime
|
|
232
|
+
> Note: This is an unofficial Facebook API.
|
|
233
|
+
Use at your own risk.
|
|
234
|
+
This project is not affiliated with or endorsed by Meta / Facebook in any way.
|
|
172
235
|
|
|
173
|
-
Enable E2EE at login:
|
|
174
236
|
|
|
175
|
-
```js
|
|
176
|
-
login({ appState }, {
|
|
177
|
-
enableE2EE: true,
|
|
178
|
-
e2eeMemoryOnly: false,
|
|
179
|
-
e2eeDevicePath: "./e2ee_device.json"
|
|
180
|
-
}, (err, api) => {
|
|
181
|
-
if (err) return console.error(err);
|
|
182
237
|
|
|
183
|
-
api.listenMqtt((listenErr, event) => {
|
|
184
|
-
if (listenErr) return console.error(listenErr);
|
|
185
238
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
});
|
|
191
|
-
```
|
|
239
|
+
🚀 **DEVELOPMENT APPROACH**
|
|
240
|
+
- 💻 **Copy-paste techniques with customizations**
|
|
241
|
+
- 🤝 **Collaborative development with friends**
|
|
242
|
+
- 🤖 **AI-powered using ChatGPT and other advanced tools**
|
|
192
243
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
- `api.connectE2EE(callback)`
|
|
196
|
-
- `api.disconnectE2EE(callback)`
|
|
197
|
-
- `api.getE2EEDeviceData(callback)`
|
|
198
|
-
- `api.sendMessageE2EE(chatJid, message, callback)`
|
|
199
|
-
- `api.sendMediaE2EE(chatJid, mediaType, data, options, callback)`
|
|
200
|
-
- `api.sendReactionE2EE(chatJid, messageID, senderJid, reaction, callback)`
|
|
201
|
-
- `api.sendTypingE2EE(chatJid, isTyping, callback)`
|
|
202
|
-
- `api.unsendMessageE2EE(chatJid, messageID, callback)`
|
|
203
|
-
- `api.downloadE2EEMedia(options, callback)`
|
|
204
|
-
|
|
205
|
-
Auto routing behavior:
|
|
206
|
-
|
|
207
|
-
- `api.sendMessage(...)` auto-selects normal or E2EE by `threadID` format.
|
|
208
|
-
- `api.sendTypingIndicator(...)`, `api.unsendMessage(...)`, and `api.setMessageReaction(...)` also support auto routing when E2EE metadata is provided.
|
|
209
|
-
- E2EE-specific APIs (`sendMessageE2EE`, `sendMediaE2EE`, `sendReactionE2EE`, `sendTypingE2EE`, `unsendMessageE2EE`) auto-fallback to normal transport when target is not an E2EE chat JID.
|
|
210
|
-
- For non-E2EE threads, MQTT is now the default transport when MQTT client is connected (`listenMqtt` active).
|
|
211
|
-
- Dedicated files `sendMessageMqtt.js` and `setMessageReactionMqtt.js` were removed; legacy method names are still aliased for backward compatibility.
|
|
212
|
-
|
|
213
|
-
## FAQS
|
|
214
|
-
|
|
215
|
-
1. How do I run tests?
|
|
216
|
-
> For tests, create a `test-config.json` file that resembles `example-config.json` and put it in the `test` directory. From the root >directory, run `npm test`.
|
|
217
|
-
|
|
218
|
-
2. Why doesn't `sendMessage` always work when I'm logged in as a page?
|
|
219
|
-
> Pages can't start conversations with users directly; this is to prevent pages from spamming users.
|
|
220
|
-
|
|
221
|
-
3. What do I do when `login` doesn't work?
|
|
222
|
-
> First check that you can login to Facebook using the website. If login approvals are enabled, you might be logging in incorrectly. For how to handle login approvals, read our docs on [`login`](DOCS.md#login).
|
|
223
|
-
|
|
224
|
-
4. How can I avoid logging in every time? Can I log into a previous session?
|
|
225
|
-
> We support caching everything relevant for you to bypass login. `api.getAppState()` returns an object that you can save and pass into login as `{appState: mySavedAppState}` instead of the credentials object. If this fails, your session has expired.
|
|
226
|
-
|
|
227
|
-
5. Do you support sending messages as a page?
|
|
228
|
-
> Yes, set the pageID option on login (this doesn't work if you set it using api.setOptions, it affects the login process).
|
|
229
|
-
> ```js
|
|
230
|
-
> login(credentials, {pageID: "000000000000000"}, (err, api) => { … }
|
|
231
|
-
> ```
|
|
232
|
-
|
|
233
|
-
6. I'm getting some crazy weird syntax error like `SyntaxError: Unexpected token [`!!!
|
|
234
|
-
> Please try to update your version of node.js before submitting an issue of this nature. We like to use new language features.
|
|
235
|
-
|
|
236
|
-
7. I don't want all of these logging messages!
|
|
237
|
-
> You can use `api.setOptions` to silence the logging. You get the `api` object from `login` (see example above). Do
|
|
238
|
-
> ```js
|
|
239
|
-
> api.setOptions({
|
|
240
|
-
> logLevel: "silent"
|
|
241
|
-
> });
|
|
242
|
-
> ```
|
|
243
|
-
|
|
244
|
-
8. If my project installs `sagor-fca` as a dependency, do I need to run `pnpm run build:e2ee` in that project?
|
|
245
|
-
> Usually no. That script lives in `sagor-fca` itself, so it is only available when you run it inside the package that defines it. For consuming projects, the normal flow is to install dependencies and let `meta-messenger.js` download its prebuilt bridge during install.
|
|
246
|
-
>
|
|
247
|
-
> If you want your own app to expose a wrapper, you can add a script like this in your app's `package.json`:
|
|
248
|
-
> ```json
|
|
249
|
-
> "scripts": {
|
|
250
|
-
> "build:e2ee": "node -e \"const cp=require('child_process');const fs=require('fs');const path=require('path');const {createRequire}=require('module');const fcaPkg=require.resolve('sagor-fca/package.json');const fcaRequire=createRequire(fcaPkg);let metaPkg;try{metaPkg=fcaRequire.resolve('meta-messenger.js/package.json');}catch(e){console.error('meta-messenger.js not found from sagor-fca context. Run: pnpm add meta-messenger.js');process.exit(1);}const p=path.dirname(metaPkg);cp.execSync('pnpm install --force --ignore-scripts=false',{cwd:p,stdio:'inherit',shell:true});cp.execSync('node scripts/postinstall.mjs',{cwd:p,stdio:'inherit',shell:true});let ext='so';if(process.platform==='win32') ext='dll';if(process.platform==='darwin') ext='dylib';const out=path.join(p,'build','messagix.'+ext);if(!fs.existsSync(out)){console.error('E2EE native bridge was not created: '+out);console.error('Try: MESSAGIX_BUILD_FROM_SOURCE=true pnpm run build:e2ee (requires Go)');process.exit(1);}console.log('E2EE bridge ready: '+out);\""
|
|
251
|
-
> }
|
|
252
|
-
> ```
|
|
253
|
-
> If the bridge is still missing, rebuild from source with `MESSAGIX_BUILD_FROM_SOURCE=true` and Go 1.24+.
|
|
254
|
-
|
|
255
|
-
<a name="projects-using-this-api"></a>
|
|
256
|
-
## Projects using this API:
|
|
257
|
-
|
|
258
|
-
- [c3c](https://github.com/lequanglam/c3c) - A bot that can be customizable using plugins. Support Facebook & Discord.
|
|
259
|
-
|
|
260
|
-
## Projects using this API (original repository, facebook-chat-api):
|
|
261
|
-
|
|
262
|
-
- [Messer](https://github.com/mjkaufer/Messer) - Command-line messaging for Facebook Messenger
|
|
263
|
-
- [messen](https://github.com/tomquirk/messen) - Rapidly build Facebook Messenger apps in Node.js
|
|
264
|
-
- [Concierge](https://github.com/concierge/Concierge) - Concierge is a highly modular, easily extensible general purpose chat bot with a built in package manager
|
|
265
|
-
- [Marc Zuckerbot](https://github.com/bsansouci/marc-zuckerbot) - Facebook chat bot
|
|
266
|
-
- [Marc Thuckerbot](https://github.com/bsansouci/lisp-bot) - Programmable lisp bot
|
|
267
|
-
- [MarkovsInequality](https://github.com/logicx24/MarkovsInequality) - Extensible chat bot adding useful functions to Facebook Messenger
|
|
268
|
-
- [AllanBot](https://github.com/AllanWang/AllanBot-Public) - Extensive module that combines the facebook api with firebase to create numerous functions; no coding experience is required to implement this.
|
|
269
|
-
- [Larry Pudding Dog Bot](https://github.com/Larry850806/facebook-chat-bot) - A facebook bot you can easily customize the response
|
|
270
|
-
- [fbash](https://github.com/avikj/fbash) - Run commands on your computer's terminal over Facebook Messenger
|
|
271
|
-
- [Klink](https://github.com/KeNt178/klink) - This Chrome extension will 1-click share the link of your active tab over Facebook Messenger
|
|
272
|
-
- [Botyo](https://github.com/ivkos/botyo) - Modular bot designed for group chat rooms on Facebook
|
|
273
|
-
- [matrix-puppet-facebook](https://github.com/matrix-hacks/matrix-puppet-facebook) - A facebook bridge for [matrix](https://matrix.org)
|
|
274
|
-
- [facebot](https://github.com/Weetbix/facebot) - A facebook bridge for Slack.
|
|
275
|
-
- [Botium](https://github.com/codeforequity-at/botium-core) - The Selenium for Chatbots
|
|
276
|
-
- [Messenger-CLI](https://github.com/AstroCB/Messenger-CLI) - A command-line interface for sending and receiving messages through Facebook Messenger.
|
|
277
|
-
- [AssumeZero-Bot](https://github.com/AstroCB/AssumeZero-Bot) – A highly customizable Facebook Messenger bot for group chats.
|
|
278
|
-
- [Miscord](https://github.com/Bjornskjald/miscord) - An easy-to-use Facebook bridge for Discord.
|
|
279
|
-
- [chat-bridge](https://github.com/rexx0520/chat-bridge) - A Messenger, Telegram and IRC chat bridge.
|
|
280
|
-
- [messenger-auto-reply](https://gitlab.com/theSander/messenger-auto-reply) - An auto-reply service for Messenger.
|
|
281
|
-
- [BotCore](https://github.com/AstroCB/BotCore) – A collection of tools for writing and managing Facebook Messenger bots.
|
|
282
|
-
- [mnotify](https://github.com/AstroCB/mnotify) – A command-line utility for sending alerts and notifications through Facebook Messenger.
|
|
244
|
+
## Thanks for using FCA
|