sagor-fca 0.0.13 → 0.0.14

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 (222) hide show
  1. package/.github/workflows/main.yml +22 -0
  2. package/README.md +282 -0
  3. package/jest.config.js +10 -0
  4. package/package.json +71 -68
  5. package/pnpm-workspace.yaml +3 -0
  6. package/scripts/discover-e2ee-jid.js +266 -0
  7. package/scripts/e2ee-send-debug.js +218 -0
  8. package/scripts/e2ee-send-smoke.js +148 -0
  9. package/scripts/listen-echo-all.js +311 -0
  10. package/src/controllers/addExternalModule.js +34 -0
  11. package/src/controllers/addUserToGroup.js +113 -0
  12. package/src/controllers/changeAdminStatus.js +79 -0
  13. package/src/{api/messaging → controllers}/changeArchivedStatus.js +13 -13
  14. package/src/{api/action → controllers}/changeBio.js +23 -21
  15. package/src/controllers/changeBlockedStatus.js +47 -0
  16. package/src/controllers/changeGroupImage.js +129 -0
  17. package/src/controllers/changeNickname.js +59 -0
  18. package/src/controllers/changeThreadColor.js +71 -0
  19. package/src/controllers/changeThreadEmoji.js +55 -0
  20. package/src/controllers/connectE2EE.js +47 -0
  21. package/src/{api/messaging → controllers}/createNewGroup.js +23 -25
  22. package/src/controllers/createPoll.js +71 -0
  23. package/src/controllers/deleteMessage.js +56 -0
  24. package/src/{api/messaging → controllers}/deleteThread.js +10 -10
  25. package/src/controllers/disconnectE2EE.js +47 -0
  26. package/src/controllers/downloadE2EEMedia.js +52 -0
  27. package/src/{api/messaging → controllers}/editMessage.js +42 -29
  28. package/src/controllers/forwardAttachment.js +60 -0
  29. package/src/controllers/getAvatarUser.js +77 -0
  30. package/src/controllers/getCurrentUserID.js +11 -0
  31. package/src/controllers/getE2EEDeviceData.js +53 -0
  32. package/src/controllers/getEmojiUrl.js +37 -0
  33. package/src/{api/messaging → controllers}/getFriendsList.js +13 -11
  34. package/src/{api/messaging → controllers}/getMessage.js +158 -154
  35. package/src/controllers/getRegion.js +11 -0
  36. package/src/{api/threads → controllers}/getThreadHistory.js +148 -110
  37. package/src/controllers/getThreadHistoryDeprecated.js +93 -0
  38. package/src/controllers/getThreadInfo.js +265 -0
  39. package/src/controllers/getThreadInfoDeprecated.js +80 -0
  40. package/src/controllers/getThreadList.js +274 -0
  41. package/src/controllers/getThreadListDeprecated.js +91 -0
  42. package/src/{api/threads → controllers}/getThreadPictures.js +12 -11
  43. package/src/{api/users → controllers}/getUserID.js +12 -11
  44. package/src/controllers/getUserInfo.js +92 -0
  45. package/src/{api/action → controllers}/handleFriendRequest.js +17 -13
  46. package/src/{api/messaging → controllers}/handleMessageRequest.js +14 -14
  47. package/src/controllers/httpGet.js +70 -0
  48. package/src/controllers/httpPost.js +70 -0
  49. package/src/controllers/index.js +75 -0
  50. package/src/controllers/listenMqtt.js +870 -0
  51. package/src/controllers/logout.js +144 -0
  52. package/src/{api/messaging → controllers}/markAsDelivered.js +15 -14
  53. package/src/controllers/markAsRead.js +92 -0
  54. package/src/{api/messaging → controllers}/markAsReadAll.js +12 -11
  55. package/src/{api/messaging → controllers}/markAsSeen.js +16 -18
  56. package/src/{api/messaging → controllers}/muteThread.js +11 -9
  57. package/src/controllers/pinMessage.js +86 -0
  58. package/src/controllers/refreshFb_dtsg.js +89 -0
  59. package/src/controllers/removeUserFromGroup.js +79 -0
  60. package/src/{api/messaging → controllers}/resolvePhotoUrl.js +10 -8
  61. package/src/{api/messaging → controllers}/searchForThread.js +9 -9
  62. package/src/controllers/searchStickers.js +53 -0
  63. package/src/controllers/sendMediaE2EE.js +105 -0
  64. package/src/controllers/sendMessage.js +566 -0
  65. package/src/controllers/sendMessageE2EE.js +77 -0
  66. package/src/controllers/sendMessageMqtt.js +235 -0
  67. package/src/controllers/sendReactionE2EE.js +65 -0
  68. package/src/controllers/sendTypingE2EE.js +71 -0
  69. package/src/controllers/sendTypingIndicator.js +59 -0
  70. package/src/controllers/setMessageReaction.js +161 -0
  71. package/src/controllers/setMessageReactionMqtt.js +72 -0
  72. package/src/controllers/setPostReaction.js +76 -0
  73. package/src/controllers/setTitle.js +86 -0
  74. package/src/controllers/stopListenMqtt.js +79 -0
  75. package/src/controllers/threadColors.js +57 -0
  76. package/src/{api/action → controllers}/unfriend.js +12 -14
  77. package/src/controllers/unsendMessage.js +65 -0
  78. package/src/controllers/unsendMessageE2EE.js +60 -0
  79. package/src/e2ee/bridge.js +488 -0
  80. package/src/e2ee/thread.js +12 -0
  81. package/src/index.js +768 -0
  82. package/src/service/uploadAttachment.js +318 -0
  83. package/src/utils/base-parts/auth.js +286 -0
  84. package/src/utils/base-parts/formatters.js +751 -0
  85. package/src/utils/base-parts/identity.js +169 -0
  86. package/src/utils/base-parts/network.js +159 -0
  87. package/src/utils/base-parts/parsing.js +53 -0
  88. package/src/utils/base-parts/type.js +9 -0
  89. package/src/utils/base.js +18 -0
  90. package/src/utils/defaults.js +10 -0
  91. package/src/utils/format-attachments.js +7 -0
  92. package/src/utils/format-core.js +8 -0
  93. package/src/utils/format-events.js +11 -0
  94. package/src/utils/format-messages.js +10 -0
  95. package/src/utils/format-presence.js +9 -0
  96. package/src/utils/format-threads.js +8 -0
  97. package/src/utils/formatters.js +18 -0
  98. package/src/utils/identity.js +12 -0
  99. package/src/utils/index.js +15 -0
  100. package/src/utils/network.js +12 -0
  101. package/src/utils/parsing.js +11 -0
  102. package/src/utils.js +3 -0
  103. package/test/config.env.example +30 -0
  104. package/test/data/shareAttach.js +146 -0
  105. package/test/data/something.mov +0 -0
  106. package/test/data/test.png +0 -0
  107. package/test/data/test.txt +7 -0
  108. package/test/example-appstate.txt +11 -0
  109. package/test/integration/api.integration.test.js +387 -0
  110. package/test/integration/controllers.appstate.integration.test.js +233 -0
  111. package/test/integration/e2ee.appstate.integration.test.js +290 -0
  112. package/test/integration/env-test-config.js +46 -0
  113. package/test/integration/login.appstate.integration.test.js +47 -0
  114. package/test/integration/page.integration.test.js +139 -0
  115. package/test/jest.setup.js +54 -0
  116. package/test/unit/controllers/controllers.basic.test.js +116 -0
  117. package/test/unit/controllers/controllers.registry.test.js +36 -0
  118. package/test/unit/controllers/e2ee.controllers.test.js +299 -0
  119. package/test/unit/controllers/sendMessage.e2ee-auto.test.js +111 -0
  120. package/test/unit/controllers/sendMessage.transport-fallback.test.js +177 -0
  121. package/test/unit/index/index.test.js +110 -0
  122. package/test/unit/utils/base-parts/auth.test.js +93 -0
  123. package/test/unit/utils/base-parts/formatters.test.js +53 -0
  124. package/test/unit/utils/base-parts/identity.test.js +43 -0
  125. package/test/unit/utils/base-parts/parsing.test.js +38 -0
  126. package/test/unit/utils/base-parts/type.test.js +23 -0
  127. package/test/unit/utils/base.test.js +35 -0
  128. package/func/checkUpdate.js +0 -222
  129. package/func/logAdapter.js +0 -33
  130. package/func/logger.js +0 -48
  131. package/index.d.ts +0 -751
  132. package/index.js +0 -8
  133. package/module/config.js +0 -40
  134. package/module/login.js +0 -133
  135. package/module/loginHelper.js +0 -1296
  136. package/module/options.js +0 -44
  137. package/src/api/action/addExternalModule.js +0 -25
  138. package/src/api/action/changeAvatar.js +0 -137
  139. package/src/api/action/enableAutoSaveAppState.js +0 -73
  140. package/src/api/action/getCurrentUserID.js +0 -7
  141. package/src/api/action/logout.js +0 -76
  142. package/src/api/action/refreshFb_dtsg.js +0 -48
  143. package/src/api/action/setPostReaction.js +0 -106
  144. package/src/api/http/httpGet.js +0 -46
  145. package/src/api/http/httpPost.js +0 -52
  146. package/src/api/http/postFormData.js +0 -47
  147. package/src/api/messaging/addUserToGroup.js +0 -68
  148. package/src/api/messaging/changeAdminStatus.js +0 -126
  149. package/src/api/messaging/changeBlockedStatus.js +0 -48
  150. package/src/api/messaging/changeGroupImage.js +0 -91
  151. package/src/api/messaging/changeNickname.js +0 -70
  152. package/src/api/messaging/changeThreadColor.js +0 -79
  153. package/src/api/messaging/changeThreadEmoji.js +0 -111
  154. package/src/api/messaging/createPoll.js +0 -46
  155. package/src/api/messaging/createThemeAI.js +0 -98
  156. package/src/api/messaging/deleteMessage.js +0 -136
  157. package/src/api/messaging/forwardAttachment.js +0 -57
  158. package/src/api/messaging/getEmojiUrl.js +0 -29
  159. package/src/api/messaging/getThemePictures.js +0 -62
  160. package/src/api/messaging/markAsRead.js +0 -88
  161. package/src/api/messaging/removeUserFromGroup.js +0 -62
  162. package/src/api/messaging/scheduler.js +0 -264
  163. package/src/api/messaging/sendMessage.js +0 -270
  164. package/src/api/messaging/sendTypingIndicator.js +0 -74
  165. package/src/api/messaging/setMessageReaction.js +0 -90
  166. package/src/api/messaging/setTitle.js +0 -124
  167. package/src/api/messaging/shareContact.js +0 -49
  168. package/src/api/messaging/threadColors.js +0 -128
  169. package/src/api/messaging/unsendMessage.js +0 -81
  170. package/src/api/messaging/uploadAttachment.js +0 -492
  171. package/src/api/socket/core/connectMqtt.js +0 -258
  172. package/src/api/socket/core/emitAuth.js +0 -103
  173. package/src/api/socket/core/getSeqID.js +0 -320
  174. package/src/api/socket/core/getTaskResponseData.js +0 -25
  175. package/src/api/socket/core/parseDelta.js +0 -377
  176. package/src/api/socket/detail/buildStream.js +0 -215
  177. package/src/api/socket/detail/constants.js +0 -28
  178. package/src/api/socket/listenMqtt.js +0 -377
  179. package/src/api/socket/middleware/index.js +0 -216
  180. package/src/api/threads/getThreadInfo.js +0 -296
  181. package/src/api/threads/getThreadList.js +0 -293
  182. package/src/api/users/getUserInfo.js +0 -402
  183. package/src/api/users/getUserInfoV2.js +0 -134
  184. package/src/core/sendReqMqtt.js +0 -96
  185. package/src/database/helpers.js +0 -53
  186. package/src/database/models/index.js +0 -88
  187. package/src/database/models/thread.js +0 -50
  188. package/src/database/models/user.js +0 -46
  189. package/src/database/threadData.js +0 -94
  190. package/src/database/userData.js +0 -98
  191. package/src/remote/remoteClient.js +0 -123
  192. package/src/utils/broadcast.js +0 -51
  193. package/src/utils/client.js +0 -10
  194. package/src/utils/constants.js +0 -23
  195. package/src/utils/cookies.js +0 -68
  196. package/src/utils/format/attachment.js +0 -357
  197. package/src/utils/format/cookie.js +0 -9
  198. package/src/utils/format/date.js +0 -50
  199. package/src/utils/format/decode.js +0 -44
  200. package/src/utils/format/delta.js +0 -194
  201. package/src/utils/format/ids.js +0 -64
  202. package/src/utils/format/index.js +0 -64
  203. package/src/utils/format/message.js +0 -88
  204. package/src/utils/format/presence.js +0 -132
  205. package/src/utils/format/readTyp.js +0 -44
  206. package/src/utils/format/thread.js +0 -42
  207. package/src/utils/format/utils.js +0 -141
  208. package/src/utils/headers.js +0 -115
  209. package/src/utils/loginParser/autoLogin.js +0 -125
  210. package/src/utils/loginParser/helpers.js +0 -43
  211. package/src/utils/loginParser/index.js +0 -10
  212. package/src/utils/loginParser/parseAndCheckLogin.js +0 -220
  213. package/src/utils/loginParser/textUtils.js +0 -28
  214. package/src/utils/request/client.js +0 -26
  215. package/src/utils/request/config.js +0 -23
  216. package/src/utils/request/defaults.js +0 -46
  217. package/src/utils/request/helpers.js +0 -46
  218. package/src/utils/request/index.js +0 -17
  219. package/src/utils/request/methods.js +0 -163
  220. package/src/utils/request/proxy.js +0 -21
  221. package/src/utils/request/retry.js +0 -77
  222. package/src/utils/request/sanitize.js +0 -49
@@ -0,0 +1,22 @@
1
+ name: "publish npm by SaGor"
2
+
3
+ on: push
4
+
5
+ jobs:
6
+ publish:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - name: Checkout
10
+ uses: actions/checkout@v2
11
+
12
+ - name: Setup Node.js
13
+ uses: actions/setup-node@v2
14
+ with:
15
+ node-version: 16
16
+ registry-url: https://registry.npmjs.org
17
+
18
+ - name: Publish to NPM
19
+ run: npm publish --access public
20
+ env:
21
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
22
+
package/README.md ADDED
@@ -0,0 +1,282 @@
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)
6
+
7
+ Facebook now has an official API for chat bots [here](https://developers.facebook.com/docs/messenger-platform).
8
+
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.
10
+
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.
12
+
13
+ See [below](#projects-using-this-api) for projects using this API.
14
+
15
+ See the [full changelog](/CHANGELOG.md) for release details.
16
+
17
+ ## Install
18
+ If you just want to use sagor-fca, you should use this command:
19
+ ```bash
20
+ npm install sagor-fca
21
+ ```
22
+ It will download `sagor-fca` from NPM repositories
23
+
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
+ ```bash
27
+ npm install sagor-fca
28
+ ```
29
+
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/).
32
+
33
+ ## Example Usage
34
+ ```javascript
35
+ const login = require("sagor-fca");
36
+
37
+ // Create simple echo bot
38
+ login({email: "FB_EMAIL", password: "FB_PASSWORD"}, (err, api) => {
39
+ if(err) return console.error(err);
40
+
41
+ api.listen((err, message) => {
42
+ api.sendMessage(message.body, message.threadID);
43
+ });
44
+ });
45
+ ```
46
+
47
+ Result:
48
+
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">
50
+
51
+
52
+ ## Documentation
53
+
54
+ You can see it [here](DOCS.md).
55
+
56
+ ## Main Functionality
57
+
58
+ ### Sending a message
59
+ #### api.sendMessage(message, threadID[, callback][, messageID])
60
+
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`)
67
+
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.
69
+
70
+ __Tip__: to find your own ID, you can look inside the cookies. The `userID` is under the name `c_user`.
71
+
72
+ __Example (Basic Message)__
73
+ ```js
74
+ const login = require("sagor-fca");
75
+
76
+ login({email: "FB_EMAIL", password: "FB_PASSWORD"}, (err, api) => {
77
+ if(err) return console.error(err);
78
+
79
+ var yourID = "000000000000000";
80
+ var msg = "Hey!";
81
+ api.sendMessage(msg, yourID);
82
+ });
83
+ ```
84
+
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);
91
+
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
+ ```
101
+
102
+ ------------------------------------
103
+ ### Saving session.
104
+
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.
106
+
107
+ __Example__
108
+
109
+ ```js
110
+ const fs = require("fs");
111
+ const login = require("sagor-fca");
112
+
113
+ var credentials = {email: "FB_EMAIL", password: "FB_PASSWORD"};
114
+
115
+ login(credentials, (err, api) => {
116
+ if(err) return console.error(err);
117
+
118
+ fs.writeFileSync('appstate.json', JSON.stringify(api.getAppState()));
119
+ });
120
+ ```
121
+
122
+ Alternative: Use [c3c-fbstate](https://github.com/lequanglam/c3c-fbstate) to get fbstate.json (appstate.json)
123
+
124
+ ------------------------------------
125
+
126
+ ### Listening to a chat
127
+ #### api.listen(callback)
128
+
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})`.
130
+
131
+ __Example__
132
+
133
+ ```js
134
+ const fs = require("fs");
135
+ const login = require("sagor-fca");
136
+
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);
141
+
142
+ api.setOptions({listenEvents: true});
143
+
144
+ var stopListening = api.listenMqtt((err, event) => {
145
+ if(err) return console.error(err);
146
+
147
+ api.markAsRead(event.threadID, (err) => {
148
+ if(err) console.error(err);
149
+ });
150
+
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
+ });
164
+ });
165
+ ```
166
+
167
+ ------------------------------------
168
+
169
+ ### E2EE Support (meta-messenger bridge)
170
+
171
+ `sagor-fca` supports receiving and sending E2EE messages by bridging to `meta-messenger.js`.
172
+
173
+ Enable E2EE at login:
174
+
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
+
183
+ api.listenMqtt((listenErr, event) => {
184
+ if (listenErr) return console.error(listenErr);
185
+
186
+ if (event.type === "e2ee_message") {
187
+ console.log("[E2EE]", event.body, event.e2ee.chatJid);
188
+ }
189
+ });
190
+ });
191
+ ```
192
+
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.
package/jest.config.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ testEnvironment: "node",
5
+ testMatch: ["<rootDir>/test/**/*.test.js"],
6
+ setupFiles: ["<rootDir>/test/jest.setup.js"],
7
+ clearMocks: true,
8
+ restoreMocks: true,
9
+ verbose: true
10
+ };
package/package.json CHANGED
@@ -1,89 +1,92 @@
1
1
  {
2
2
  "name": "sagor-fca",
3
- "version": "0.0.13",
4
- "description": "Unofficial Facebook Chat API for Node.js with Auto-Update System - modify by SaGor ☄️",
5
- "main": "index.js",
6
- "types": "index.d.ts",
7
- "exports": {
8
- ".": {
9
- "require": "./index.js",
10
- "default": "./index.js",
11
- "types": "./index.d.ts"
12
- }
13
- },
14
- "files": [
15
- "index.js",
16
- "index.d.ts",
17
- "module/",
18
- "func/",
19
- "src/",
20
- "DOCS.md",
21
- "README.md",
22
- "LICENSE",
23
- "CHANGELOG.md"
24
- ],
3
+ "version": "0.0.14",
4
+ "main": "src/index.js",
5
+ "description": "A Facebook chat API that doesn't rely on XMPP. Will NOT be deprecated after April 30th 2015.",
25
6
  "scripts": {
26
- "test": "mocha",
27
- "lint": "eslint ."
7
+ "test": "jest --runInBand --testPathIgnorePatterns=\"/test/integration/\"",
8
+ "test:unit": "jest --runInBand",
9
+ "test:integration": "jest --runInBand --testPathPattern=\"test/integration\"",
10
+ "discover:e2ee-jid": "node scripts/discover-e2ee-jid.js",
11
+ "listen:echo-all": "node scripts/listen-echo-all.js",
12
+ "smoke:e2ee-send": "node scripts/e2ee-send-smoke.js",
13
+ "debug:e2ee-send": "node scripts/e2ee-send-debug.js",
14
+ "build:e2ee": "node -e \"const cp=require('child_process');const fs=require('fs');const path=require('path');let metaPkg;try{metaPkg=require.resolve('meta-messenger.js/package.json');}catch(e){console.error('meta-messenger.js not found. Run: pnpm install');process.exit(1);}const pkgDir=path.dirname(metaPkg);cp.execSync('pnpm install --force --ignore-scripts=false',{cwd:pkgDir,stdio:'inherit',shell:true});cp.execSync('node scripts/postinstall.mjs',{cwd:pkgDir,stdio:'inherit',shell:true});let ext='so';if(process.platform==='win32') ext='dll';if(process.platform==='darwin') ext='dylib';const out=path.join(pkgDir,'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);\"",
15
+ "lint": "eslint \"src/**/*.js\" && eslint --env jest \"test/**/*.js\"",
16
+ "prettier": "prettier \"src/**/*.js\" \"test/**/*.js\" --write"
28
17
  },
29
18
  "repository": {
30
19
  "type": "git",
31
- "url": "git+https://github.com/SAGOR-KINGx/sagor-fca.git"
20
+ "url": "https://github.com/SAGOR-KINGAx/sagor-fca"
32
21
  },
33
22
  "keywords": [
34
23
  "facebook",
35
24
  "chat",
36
25
  "api",
37
- "messenger",
38
- "bot",
39
- "unofficial",
40
- "automation",
41
- "facebook-api",
42
- "facebook-chat",
43
- "facebook-messenger",
44
- "chatbot",
45
- "nodejs",
46
- "sagor-fca"
47
- ],
48
- "author": {
49
- "name": "SaGor",
50
- "url": "https://www.facebook.com/SAGOR.69x"
51
- },
52
- "contributors": [
53
- {
54
- "name": "SaGor",
55
- "url": "https://github.com/SAGOR-KINGx"
56
- }
26
+ "fca",
27
+ "sagor"
57
28
  ],
58
- "license": "MIT",
59
29
  "bugs": {
60
- "url": "https://github.com/SAGOR-KINGx/sagor-fca/issues"
61
- },
62
- "homepage": "https://github.com/SAGOR-KINGx/sagor-fca#readme",
63
- "engines": {
64
- "node": ">=12.0.0"
30
+ "url": "https://github.com/SAGOR-KINGAx/sagor-fca/issues"
65
31
  },
32
+ "author": "Sagor, David, Maude, Benjamin, UIRI, HerokeyVN",
33
+ "license": "MIT",
66
34
  "dependencies": {
67
- "axios": "^1.13.5",
68
- "axios-cookiejar-support": "^5.0.5",
69
- "bluebird": "^3.7.2",
70
- "chalk": "^4.1.2",
71
- "cheerio": "^1.0.0-rc.10",
72
- "duplexify": "^4.1.3",
73
- "gradient-string": "^2.0.2",
35
+ "bluebird": "^2.11.0",
36
+ "cheerio": "^0.22.0",
74
37
  "https-proxy-agent": "^4.0.0",
75
- "mqtt": "^4.3.8",
76
- "sequelize": "^6.37.6",
77
- "sqlite3": "^5.1.7",
78
- "totp-generator": "^1.0.0",
79
- "ws": "^8.18.1"
38
+ "meta-messenger.js": "^1.1.3",
39
+ "mqtt": "^3.0.0",
40
+ "npmlog": "^1.2.1",
41
+ "request": "^2.88.2",
42
+ "websocket-stream": "^5.5.2"
43
+ },
44
+ "pnpm": {
45
+ "overrides": {
46
+ "request@2.88.2>form-data": "2.5.5"
47
+ }
48
+ },
49
+ "engines": {
50
+ "node": ">=22.0.0"
80
51
  },
81
52
  "devDependencies": {
82
- "eslint": "^8.50.0",
83
- "mocha": "^10.2.0"
53
+ "dotenv": "^16.6.1",
54
+ "eslint": "^7.32.0",
55
+ "jest": "^27.5.1",
56
+ "prettier": "^1.19.1"
84
57
  },
85
- "publishConfig": {
86
- "access": "public",
87
- "registry": "https://registry.npmjs.org/"
58
+ "eslintConfig": {
59
+ "env": {
60
+ "es6": true,
61
+ "es2017": true,
62
+ "node": true
63
+ },
64
+ "extends": "eslint:recommended",
65
+ "parserOptions": {
66
+ "sourceType": "module"
67
+ },
68
+ "rules": {
69
+ "linebreak-style": [
70
+ "error",
71
+ "unix"
72
+ ],
73
+ "semi": [
74
+ "error",
75
+ "always"
76
+ ],
77
+ "no-unused-vars": [
78
+ 1,
79
+ {
80
+ "argsIgnorePattern": "^_",
81
+ "varsIgnorePattern": "^_"
82
+ }
83
+ ],
84
+ "no-empty": [
85
+ "error",
86
+ {
87
+ "allowEmptyCatch": true
88
+ }
89
+ ]
90
+ }
88
91
  }
89
92
  }
@@ -0,0 +1,3 @@
1
+ onlyBuiltDependencies:
2
+ - koffi
3
+ - meta-messenger.js