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.
Files changed (184) hide show
  1. package/README.md +172 -210
  2. package/index.js +552 -0
  3. package/package.json +38 -75
  4. package/src/OldMessage.js +357 -0
  5. package/src/addExternalModule.js +25 -0
  6. package/src/{controllers/addUserToGroup.js → addUserToGroup.js} +27 -25
  7. package/src/changeAdminStatus.js +103 -0
  8. package/src/{controllers/changeArchivedStatus.js → changeArchivedStatus.js} +14 -14
  9. package/src/changeAvatar.js +136 -0
  10. package/src/changeAvatarV2.js +86 -0
  11. package/src/changeAvt.js +85 -0
  12. package/src/{controllers/changeBio.js → changeBio.js} +15 -16
  13. package/src/{controllers/changeBlockedStatus.js → changeBlockedStatus.js} +11 -9
  14. package/src/changeBlockedStatusMqtt.js +80 -0
  15. package/src/changeCover.js +72 -0
  16. package/src/{controllers/changeGroupImage.js → changeGroupImage.js} +34 -28
  17. package/src/changeName.js +79 -0
  18. package/src/{controllers/changeNickname.js → changeNickname.js} +13 -13
  19. package/src/changeThreadColor.js +65 -0
  20. package/src/{controllers/changeThreadEmoji.js → changeThreadEmoji.js} +14 -14
  21. package/src/changeUsername.js +59 -0
  22. package/src/createCommentPost.js +230 -0
  23. package/src/{controllers/createNewGroup.js → createNewGroup.js} +28 -26
  24. package/src/{controllers/createPoll.js → createPoll.js} +15 -15
  25. package/src/createPost.js +276 -0
  26. package/src/{controllers/deleteMessage.js → deleteMessage.js} +14 -14
  27. package/src/{controllers/deleteThread.js → deleteThread.js} +14 -14
  28. package/src/editMessage.js +68 -0
  29. package/src/editMessageOld.js +67 -0
  30. package/src/follow.js +74 -0
  31. package/src/{controllers/forwardAttachment.js → forwardAttachment.js} +15 -15
  32. package/src/friendList.js +103 -0
  33. package/src/getAccess.js +112 -0
  34. package/src/{controllers/getAvatarUser.js → getAvatarUser.js} +3 -2
  35. package/src/getCurrentUserID.js +7 -0
  36. package/src/getEmojiUrl.js +29 -0
  37. package/src/{controllers/getFriendsList.js → getFriendsList.js} +15 -16
  38. package/src/{controllers/getMessage.js → getMessage.js} +47 -33
  39. package/src/getRegion.js +7 -0
  40. package/src/{controllers/getThreadHistory.js → getThreadHistory.js} +129 -151
  41. package/src/{controllers/getThreadHistoryDeprecated.js → getThreadHistoryDeprecated.js} +20 -42
  42. package/src/getThreadInfo.js +232 -0
  43. package/src/getThreadInfoDeprecated.js +56 -0
  44. package/src/{controllers/getThreadList.js → getThreadList.js} +50 -111
  45. package/src/getThreadListDeprecated.js +46 -0
  46. package/src/getThreadPictures.js +59 -0
  47. package/src/getThreadTheme.js +82 -0
  48. package/src/getUID.js +119 -0
  49. package/src/{controllers/getUserID.js → getUserID.js} +9 -14
  50. package/src/{controllers/getUserInfo.js → getUserInfo.js} +12 -38
  51. package/src/{controllers/handleFriendRequest.js → handleFriendRequest.js} +11 -26
  52. package/src/handleMessageRequest.js +47 -0
  53. package/src/httpGet.js +49 -0
  54. package/src/httpPost.js +48 -0
  55. package/src/listenMqtt.js +763 -0
  56. package/src/logout.js +75 -0
  57. package/src/{controllers/markAsDelivered.js → markAsDelivered.js} +11 -22
  58. package/src/{controllers/markAsRead.js → markAsRead.js} +18 -40
  59. package/src/{controllers/markAsReadAll.js → markAsReadAll.js} +10 -20
  60. package/src/{controllers/markAsSeen.js → markAsSeen.js} +7 -18
  61. package/src/metaTheme.js +190 -0
  62. package/src/{controllers/muteThread.js → muteThread.js} +11 -18
  63. package/src/note.js +228 -0
  64. package/src/{controllers/refreshFb_dtsg.js → refreshFb_dtsg.js} +4 -4
  65. package/src/removeSuspiciousAccount.js +79 -0
  66. package/src/{controllers/removeUserFromGroup.js → removeUserFromGroup.js} +13 -13
  67. package/src/{controllers/resolvePhotoUrl.js → resolvePhotoUrl.js} +11 -11
  68. package/src/{controllers/searchForThread.js → searchForThread.js} +10 -10
  69. package/src/searchFriends.js +139 -0
  70. package/src/{controllers/searchStickers.js → searchStickers.js} +1 -1
  71. package/src/sendFriendRequest.js +113 -0
  72. package/src/sendMessage.js +258 -0
  73. package/src/sendMessageMqtt.js +322 -0
  74. package/src/sendTypingIndicator.js +45 -0
  75. package/src/setActiveStatus.js +93 -0
  76. package/src/{controllers/setMessageReaction.js → setMessageReaction.js} +22 -61
  77. package/src/setMessageReactionMqtt.js +62 -0
  78. package/src/setPostReaction.js +112 -0
  79. package/src/setProfileLock.js +98 -0
  80. package/src/setStoryReaction.js +134 -0
  81. package/src/setStorySeen.js +109 -0
  82. package/src/setThreadTheme.js +103 -0
  83. package/src/{controllers/setTitle.js → setTitle.js} +18 -14
  84. package/src/shareContact.js +110 -0
  85. package/src/shareLink.js +59 -0
  86. package/src/stopListenMqtt.js +23 -0
  87. package/src/storyManager.js +358 -0
  88. package/src/suggestFriend.js +108 -0
  89. package/src/threadColors.js +131 -0
  90. package/src/{controllers/unfriend.js → unfriend.js} +3 -3
  91. package/src/unsendMessage.js +45 -0
  92. package/src/uploadAttachment.js +93 -0
  93. package/utils.js +2962 -0
  94. package/.github/workflows/main.yml +0 -22
  95. package/jest.config.js +0 -10
  96. package/pnpm-workspace.yaml +0 -3
  97. package/scripts/discover-e2ee-jid.js +0 -266
  98. package/scripts/e2ee-send-debug.js +0 -218
  99. package/scripts/e2ee-send-smoke.js +0 -148
  100. package/scripts/listen-echo-all.js +0 -311
  101. package/src/controllers/addExternalModule.js +0 -34
  102. package/src/controllers/changeAdminStatus.js +0 -79
  103. package/src/controllers/changeThreadColor.js +0 -71
  104. package/src/controllers/connectE2EE.js +0 -47
  105. package/src/controllers/disconnectE2EE.js +0 -47
  106. package/src/controllers/downloadE2EEMedia.js +0 -52
  107. package/src/controllers/editMessage.js +0 -81
  108. package/src/controllers/getCurrentUserID.js +0 -11
  109. package/src/controllers/getE2EEDeviceData.js +0 -53
  110. package/src/controllers/getEmojiUrl.js +0 -37
  111. package/src/controllers/getRegion.js +0 -11
  112. package/src/controllers/getThreadInfo.js +0 -265
  113. package/src/controllers/getThreadInfoDeprecated.js +0 -80
  114. package/src/controllers/getThreadListDeprecated.js +0 -91
  115. package/src/controllers/getThreadPictures.js +0 -79
  116. package/src/controllers/handleMessageRequest.js +0 -65
  117. package/src/controllers/httpGet.js +0 -70
  118. package/src/controllers/httpPost.js +0 -70
  119. package/src/controllers/index.js +0 -75
  120. package/src/controllers/listenMqtt.js +0 -870
  121. package/src/controllers/logout.js +0 -144
  122. package/src/controllers/pinMessage.js +0 -86
  123. package/src/controllers/sendMediaE2EE.js +0 -105
  124. package/src/controllers/sendMessage.js +0 -566
  125. package/src/controllers/sendMessageE2EE.js +0 -77
  126. package/src/controllers/sendMessageMqtt.js +0 -235
  127. package/src/controllers/sendReactionE2EE.js +0 -65
  128. package/src/controllers/sendTypingE2EE.js +0 -71
  129. package/src/controllers/sendTypingIndicator.js +0 -59
  130. package/src/controllers/setMessageReactionMqtt.js +0 -72
  131. package/src/controllers/setPostReaction.js +0 -76
  132. package/src/controllers/stopListenMqtt.js +0 -79
  133. package/src/controllers/threadColors.js +0 -57
  134. package/src/controllers/unsendMessage.js +0 -65
  135. package/src/controllers/unsendMessageE2EE.js +0 -60
  136. package/src/e2ee/bridge.js +0 -488
  137. package/src/e2ee/thread.js +0 -12
  138. package/src/index.js +0 -768
  139. package/src/service/uploadAttachment.js +0 -318
  140. package/src/utils/base-parts/auth.js +0 -286
  141. package/src/utils/base-parts/formatters.js +0 -751
  142. package/src/utils/base-parts/identity.js +0 -169
  143. package/src/utils/base-parts/network.js +0 -159
  144. package/src/utils/base-parts/parsing.js +0 -53
  145. package/src/utils/base-parts/type.js +0 -9
  146. package/src/utils/base.js +0 -18
  147. package/src/utils/defaults.js +0 -10
  148. package/src/utils/format-attachments.js +0 -7
  149. package/src/utils/format-core.js +0 -8
  150. package/src/utils/format-events.js +0 -11
  151. package/src/utils/format-messages.js +0 -10
  152. package/src/utils/format-presence.js +0 -9
  153. package/src/utils/format-threads.js +0 -8
  154. package/src/utils/formatters.js +0 -18
  155. package/src/utils/identity.js +0 -12
  156. package/src/utils/index.js +0 -15
  157. package/src/utils/network.js +0 -12
  158. package/src/utils/parsing.js +0 -11
  159. package/src/utils.js +0 -3
  160. package/test/config.env.example +0 -30
  161. package/test/data/shareAttach.js +0 -146
  162. package/test/data/something.mov +0 -0
  163. package/test/data/test.png +0 -0
  164. package/test/data/test.txt +0 -7
  165. package/test/example-appstate.txt +0 -11
  166. package/test/integration/api.integration.test.js +0 -387
  167. package/test/integration/controllers.appstate.integration.test.js +0 -233
  168. package/test/integration/e2ee.appstate.integration.test.js +0 -290
  169. package/test/integration/env-test-config.js +0 -46
  170. package/test/integration/login.appstate.integration.test.js +0 -47
  171. package/test/integration/page.integration.test.js +0 -139
  172. package/test/jest.setup.js +0 -54
  173. package/test/unit/controllers/controllers.basic.test.js +0 -116
  174. package/test/unit/controllers/controllers.registry.test.js +0 -36
  175. package/test/unit/controllers/e2ee.controllers.test.js +0 -299
  176. package/test/unit/controllers/sendMessage.e2ee-auto.test.js +0 -111
  177. package/test/unit/controllers/sendMessage.transport-fallback.test.js +0 -177
  178. package/test/unit/index/index.test.js +0 -110
  179. package/test/unit/utils/base-parts/auth.test.js +0 -93
  180. package/test/unit/utils/base-parts/formatters.test.js +0 -53
  181. package/test/unit/utils/base-parts/identity.test.js +0 -43
  182. package/test/unit/utils/base-parts/parsing.test.js +0 -38
  183. package/test/unit/utils/base-parts/type.test.js +0 -23
  184. 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
- [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
1
+ # 🚀 SAGOR-FCA: Unofficial Facebook Chat API
6
2
 
7
- Facebook now has an official API for chat bots [here](https://developers.facebook.com/docs/messenger-platform).
3
+ ![npm](https://img.shields.io/npm/v/sagor-fca) ![License](https://img.shields.io/badge/License-MIT-green) ![GitHub issues](https://img.shields.io/github/issues/SAGOR-KINGx/sagor-fca)
8
4
 
9
- This API is the only way to automate chat functionalities on a user account. We do this by emulating the browser. This means doing the exact same GET/POST requests and tricking Facebook into thinking we're accessing the website normally. Because we're doing it this way, this API won't work with an auth token but requires the credentials of a Facebook account.
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
- _Disclaimer_: We are not responsible if your account gets banned for spammy activities such as sending lots of messages to people you don't know, sending messages very quickly, sending spammy looking URLs, logging in and out very quickly... Be responsible Facebook citizens.
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
- ## Install
18
- If you just want to use sagor-fca, you should use this command:
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
- ### Bleeding edge
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
- ## Testing your bots
31
- If you want to test your bots without creating another account on Facebook, you can use [Facebook Whitehat Accounts](https://www.facebook.com/whitehat/accounts/).
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
- // Create simple echo bot
38
- login({email: "FB_EMAIL", password: "FB_PASSWORD"}, (err, api) => {
39
- if(err) return console.error(err);
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
- api.listen((err, message) => {
42
- api.sendMessage(message.body, message.threadID);
44
+ // Echo back the received message
45
+ api.sendMessage(event.body, event.threadID);
43
46
  });
44
47
  });
45
48
  ```
46
49
 
47
- Result:
50
+ ### 2. Send Text Message
48
51
 
49
- <img width="517" alt="screen shot 2016-11-04 at 14 36 00" src="https://cloud.githubusercontent.com/assets/4534692/20023545/f8c24130-a29d-11e6-9ef7-47568bdbc1f2.png">
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
- ## Documentation
61
+ let yourID = "000000000000000"; // Replace with actual Facebook ID
62
+ let msg = "Hey!";
53
63
 
54
- You can see it [here](DOCS.md).
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
- ## Main Functionality
71
+ **Tip:** To find your Facebook ID, look inside the cookies under the name `c_user`
57
72
 
58
- ### Sending a message
59
- #### api.sendMessage(message, threadID[, callback][, messageID])
73
+ ### 3. Send File/Image
60
74
 
61
- Various types of message can be sent:
62
- * *Regular:* set field `body` to the desired message as a string.
63
- * *Sticker:* set a field `sticker` to the desired sticker ID.
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
- Note that 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.
79
+ login({ appState: [] }, (err, api) => {
80
+ if (err) {
81
+ console.error("Login Error:", err);
82
+ return;
83
+ }
69
84
 
70
- __Tip__: to find your own ID, you can look inside the cookies. The `userID` is under the name `c_user`.
85
+ let yourID = "000000000000000";
86
+ let imagePath = __dirname + "/image.jpg";
71
87
 
72
- __Example (Basic Message)__
73
- ```js
74
- const login = require("sagor-fca");
88
+ // Check if file exists
89
+ if (!fs.existsSync(imagePath)) {
90
+ console.error("Error: Image file not found!");
91
+ return;
92
+ }
75
93
 
76
- login({email: "FB_EMAIL", password: "FB_PASSWORD"}, (err, api) => {
77
- if(err) return console.error(err);
94
+ let msg = {
95
+ body: "Hey!",
96
+ attachment: fs.createReadStream(imagePath)
97
+ };
78
98
 
79
- var yourID = "000000000000000";
80
- var msg = "Hey!";
81
- api.sendMessage(msg, yourID);
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
- __Example (File upload)__
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
- // Note this example uploads an image called image.jpg
93
- var yourID = "000000000000000";
94
- var msg = {
95
- body: "Hey!",
96
- attachment: fs.createReadStream(__dirname + '/image.jpg')
97
- }
98
- api.sendMessage(msg, yourID);
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
- To avoid logging in every time you should save AppState (cookies etc.) to a file, then you can use it without having password in your scripts.
118
+ ## 💾 Saving AppState to Avoid Re-login
106
119
 
107
- __Example__
120
+ ### Save AppState
108
121
 
109
- ```js
122
+ ```javascript
110
123
  const fs = require("fs");
111
124
  const login = require("sagor-fca");
112
125
 
113
- var credentials = {email: "FB_EMAIL", password: "FB_PASSWORD"};
126
+ const credentials = { appState: [] };
114
127
 
115
128
  login(credentials, (err, api) => {
116
- if(err) return console.error(err);
129
+ if (err) {
130
+ console.error("Login Error:", err);
131
+ return;
132
+ }
117
133
 
118
- fs.writeFileSync('appstate.json', JSON.stringify(api.getAppState()));
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
- Alternative: Use [c3c-fbstate](https://github.com/lequanglam/c3c-fbstate) to get fbstate.json (appstate.json)
144
+ ### Use Saved AppState
123
145
 
124
- ------------------------------------
146
+ ```javascript
147
+ const fs = require("fs");
148
+ const login = require("sagor-fca");
125
149
 
126
- ### Listening to a chat
127
- #### api.listen(callback)
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
- Listen watches for messages sent in a chat. By default this won't receive events (joining/leaving a chat, title change etc…) but it can be activated with `api.setOptions({listenEvents: true})`. This will by default ignore messages sent by the current account, you can enable listening to your own messages with `api.setOptions({selfListen: true})`.
158
+ console.log("✅ Logged in successfully!");
159
+ // Your code here
160
+ }
161
+ );
162
+ ```
130
163
 
131
- __Example__
164
+ **Alternative:** Use [c3c-fbstate](https://github.com/c3cbot/c3c-fbstate) to get fbstate.json
132
165
 
133
- ```js
134
- const fs = require("fs");
135
- const login = require("sagor-fca");
166
+ ## 👂 Listening for Messages
136
167
 
137
- // Simple echo bot. It will repeat everything that you say.
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
- api.setOptions({listenEvents: true});
170
+ ```javascript
171
+ const fs = require("fs");
172
+ const login = require("sagor-fca");
143
173
 
144
- var stopListening = api.listenMqtt((err, event) => {
145
- if(err) return console.error(err);
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
- api.markAsRead(event.threadID, (err) => {
148
- if(err) console.error(err);
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
- switch(event.type) {
152
- case "message":
153
- if(event.body === '/stop') {
154
- api.sendMessage("Goodbye…", event.threadID);
155
- return stopListening();
156
- }
157
- api.sendMessage("TEST BOT: " + event.body, event.threadID);
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
- ### E2EE Support (meta-messenger bridge)
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
- `sagor-fca` supports receiving and sending E2EE messages by bridging to `meta-messenger.js`.
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
- if (event.type === "e2ee_message") {
187
- console.log("[E2EE]", event.body, event.e2ee.chatJid);
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
- Added E2EE APIs:
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