nexus-fca 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/DOCS.md +2047 -0
  3. package/Fca_Database/database.sqlite +0 -0
  4. package/LICENSE-MIT +21 -0
  5. package/README.md +240 -0
  6. package/docs/README.md +9 -0
  7. package/docs/addExternalModule.md +15 -0
  8. package/docs/addUserToGroup.md +20 -0
  9. package/docs/changeAdminStatus.md +21 -0
  10. package/docs/changeArchivedStatus.md +19 -0
  11. package/docs/changeAvatar.md +21 -0
  12. package/docs/changeAvatarV2.md +18 -0
  13. package/docs/changeBio.md +15 -0
  14. package/docs/changeBlockedStatus.md +16 -0
  15. package/docs/changeBlockedStatusMqtt.md +16 -0
  16. package/docs/changeCover.md +15 -0
  17. package/docs/changeGroupImage.md +16 -0
  18. package/docs/changeName.md +18 -0
  19. package/docs/changeNickname.md +17 -0
  20. package/docs/changeThreadColor.md +16 -0
  21. package/docs/changeThreadEmoji.md +16 -0
  22. package/docs/changeUsername.md +15 -0
  23. package/docs/createCommentPost.md +16 -0
  24. package/docs/createNewGroup.md +16 -0
  25. package/docs/createPoll.md +17 -0
  26. package/docs/createPost.md +15 -0
  27. package/docs/deleteMessage.md +15 -0
  28. package/docs/deleteThread.md +15 -0
  29. package/docs/editMessage.md +16 -0
  30. package/docs/follow.md +15 -0
  31. package/docs/forwardAttachment.md +16 -0
  32. package/docs/getAccess.md +17 -0
  33. package/docs/getAvatarUser.md +15 -0
  34. package/docs/getBotInitialData.md +14 -0
  35. package/docs/getCtx.md +14 -0
  36. package/docs/getCurrentUserID.md +12 -0
  37. package/docs/getEmojiUrl.md +17 -0
  38. package/docs/getFriendsList.md +14 -0
  39. package/docs/getMessage.md +15 -0
  40. package/docs/getOptions.md +14 -0
  41. package/docs/getRegion.md +14 -0
  42. package/docs/getThreadHistory.md +17 -0
  43. package/docs/getThreadHistoryDeprecated.md +17 -0
  44. package/docs/getThreadInfo.md +15 -0
  45. package/docs/getThreadInfoDeprecated.md +17 -0
  46. package/docs/getThreadList.md +17 -0
  47. package/docs/getThreadListDeprecated.md +17 -0
  48. package/docs/getThreadPictures.md +17 -0
  49. package/docs/getUID.md +15 -0
  50. package/docs/getUserID.md +15 -0
  51. package/docs/getUserInfo.md +15 -0
  52. package/docs/handleFriendRequest.md +16 -0
  53. package/docs/handleMessageRequest.md +16 -0
  54. package/docs/httpGet.md +15 -0
  55. package/docs/httpPost.md +16 -0
  56. package/docs/httpPostFormData.md +16 -0
  57. package/docs/listenMqtt.md +17 -0
  58. package/docs/listenNotification.md +14 -0
  59. package/docs/logout.md +14 -0
  60. package/docs/markAsDelivered.md +16 -0
  61. package/docs/markAsRead.md +16 -0
  62. package/docs/markAsReadAll.md +14 -0
  63. package/docs/markAsSeen.md +15 -0
  64. package/docs/muteThread.md +16 -0
  65. package/docs/pinMessage.md +17 -0
  66. package/docs/postFormData.md +16 -0
  67. package/docs/refreshFb_dtsg.md +14 -0
  68. package/docs/removeUserFromGroup.md +16 -0
  69. package/docs/resolvePhotoUrl.md +15 -0
  70. package/docs/searchForThread.md +15 -0
  71. package/docs/searchStickers.md +15 -0
  72. package/docs/sendComment.md +16 -0
  73. package/docs/sendMessage.md +16 -0
  74. package/docs/sendMessageMqtt.md +16 -0
  75. package/docs/sendTypingIndicator.md +15 -0
  76. package/docs/setMessageReaction.md +17 -0
  77. package/docs/setMessageReactionMqtt.md +16 -0
  78. package/docs/setPostReaction.md +16 -0
  79. package/docs/setProfileGuard.md +15 -0
  80. package/docs/setStoryReaction.md +16 -0
  81. package/docs/setTitle.md +16 -0
  82. package/docs/shareContact.md +16 -0
  83. package/docs/shareLink.md +16 -0
  84. package/docs/stopListenMqtt.md +8 -0
  85. package/docs/threadColors.md +11 -0
  86. package/docs/unfriend.md +15 -0
  87. package/docs/unsendMessage.md +15 -0
  88. package/docs/uploadAttachment.md +15 -0
  89. package/fca-config.json +7 -0
  90. package/index.d.ts +618 -0
  91. package/index.js +361 -0
  92. package/lib/database/models/index.js +47 -0
  93. package/lib/database/models/thread.js +31 -0
  94. package/lib/database/threadData.js +93 -0
  95. package/lib/logger.js +24 -0
  96. package/lib/login.js +0 -0
  97. package/package.json +90 -0
  98. package/src/addExternalModule.js +19 -0
  99. package/src/addUserToGroup.js +113 -0
  100. package/src/changeAdminStatus.js +79 -0
  101. package/src/changeArchivedStatus.js +55 -0
  102. package/src/changeAvatar.js +126 -0
  103. package/src/changeAvatarV2.js +77 -0
  104. package/src/changeBio.js +77 -0
  105. package/src/changeBlockedStatus.js +47 -0
  106. package/src/changeBlockedStatusMqtt.js +71 -0
  107. package/src/changeCover.js +72 -0
  108. package/src/changeGroupImage.js +132 -0
  109. package/src/changeName.js +79 -0
  110. package/src/changeNickname.js +59 -0
  111. package/src/changeThreadColor.js +65 -0
  112. package/src/changeThreadEmoji.js +55 -0
  113. package/src/changeUsername.js +58 -0
  114. package/src/createCommentPost.js +225 -0
  115. package/src/createNewGroup.js +86 -0
  116. package/src/createPoll.js +71 -0
  117. package/src/createPost.js +276 -0
  118. package/src/deleteMessage.js +56 -0
  119. package/src/deleteThread.js +56 -0
  120. package/src/editMessage.js +57 -0
  121. package/src/follow.js +54 -0
  122. package/src/forwardAttachment.js +60 -0
  123. package/src/getAccess.js +67 -0
  124. package/src/getAvatarUser.js +56 -0
  125. package/src/getBotInitialData.js +37 -0
  126. package/src/getCtx.js +6 -0
  127. package/src/getCurrentUserID.js +7 -0
  128. package/src/getEmojiUrl.js +29 -0
  129. package/src/getFriendsList.js +83 -0
  130. package/src/getMessage.js +796 -0
  131. package/src/getOptions.js +6 -0
  132. package/src/getRegion.js +8 -0
  133. package/src/getThreadHistory.js +666 -0
  134. package/src/getThreadHistoryDeprecated.js +55 -0
  135. package/src/getThreadInfo.js +535 -0
  136. package/src/getThreadInfoDeprecated.js +49 -0
  137. package/src/getThreadList.js +192 -0
  138. package/src/getThreadListDeprecated.js +54 -0
  139. package/src/getThreadPictures.js +79 -0
  140. package/src/getUID.js +67 -0
  141. package/src/getUserID.js +66 -0
  142. package/src/getUserInfo.js +80 -0
  143. package/src/handleFriendRequest.js +61 -0
  144. package/src/handleMessageRequest.js +65 -0
  145. package/src/httpGet.js +57 -0
  146. package/src/httpPost.js +57 -0
  147. package/src/httpPostFormData.js +63 -0
  148. package/src/listenMqtt.js +1039 -0
  149. package/src/listenNotification.js +65 -0
  150. package/src/logout.js +75 -0
  151. package/src/markAsDelivered.js +58 -0
  152. package/src/markAsRead.js +80 -0
  153. package/src/markAsReadAll.js +50 -0
  154. package/src/markAsSeen.js +59 -0
  155. package/src/muteThread.js +52 -0
  156. package/src/pinMessage.js +59 -0
  157. package/src/postFormData.js +46 -0
  158. package/src/refreshFb_dtsg.js +66 -0
  159. package/src/removeUserFromGroup.js +79 -0
  160. package/src/resolvePhotoUrl.js +45 -0
  161. package/src/searchForThread.js +53 -0
  162. package/src/searchStickers.js +51 -0
  163. package/src/sendComment.js +63 -0
  164. package/src/sendMessage.js +328 -0
  165. package/src/sendMessageMqtt.js +316 -0
  166. package/src/sendTypingIndicator.js +103 -0
  167. package/src/setMessageReaction.js +119 -0
  168. package/src/setMessageReactionMqtt.js +61 -0
  169. package/src/setPostReaction.js +109 -0
  170. package/src/setProfileGuard.js +45 -0
  171. package/src/setStoryReaction.js +62 -0
  172. package/src/setTitle.js +86 -0
  173. package/src/shareContact.js +49 -0
  174. package/src/shareLink.js +59 -0
  175. package/src/stopListenMqtt.js +21 -0
  176. package/src/threadColors.js +131 -0
  177. package/src/unfriend.js +52 -0
  178. package/src/unsendMessage.js +49 -0
  179. package/src/uploadAttachment.js +95 -0
  180. package/utils.js +1432 -0
package/DOCS.md ADDED
@@ -0,0 +1,2047 @@
1
+ # Nexus-FCA Documentation
2
+
3
+ > Nexus-FCA is an advanced, safe, and custom Facebook Chat API. Use responsibly. Not affiliated with Facebook.
4
+
5
+ * [`login`](#login)
6
+ * [`api.addUserToGroup`](#addUserToGroup)
7
+ * [`api.changeAdminStatus`](#changeAdminStatus)
8
+ * [`api.changeArchivedStatus`](#changeArchivedStatus)
9
+ * [`api.changeBlockedStatus`](#changeBlockedStatus)
10
+ * [`api.changeGroupImage`](#changeGroupImage)
11
+ * [`api.changeNickname`](#changeNickname)
12
+ * [`api.changeThreadColor`](#changeThreadColor)
13
+ * [`api.changeThreadEmoji`](#changeThreadEmoji)
14
+ * [`api.createNewGroup`](#createNewGroup)
15
+ * [`api.createPoll`](#createPoll)
16
+ * [`api.deleteMessage`](#deleteMessage)
17
+ * [`api.deleteThread`](#deleteThread)
18
+ * [`api.forwardAttachment`](#forwardAttachment)
19
+ * [`api.getAppState`](#getAppState)
20
+ * [`api.getCurrentUserID`](#getCurrentUserID)
21
+ * [`api.getEmojiUrl`](#getEmojiUrl)
22
+ * [`api.getFriendsList`](#getFriendsList)
23
+ * [`api.getThreadHistory`](#getThreadHistory)
24
+ * [`api.getThreadInfo`](#getThreadInfo)
25
+ * [`api.getThreadList`](#getThreadList)
26
+ * [`api.getThreadPictures`](#getThreadPictures)
27
+ * [`api.getUserID`](#getUserID)
28
+ * [`api.getUserInfo`](#getUserInfo)
29
+ * [`api.handleMessageRequest`](#handleMessageRequest)
30
+ * [`api.listenMqtt`](#listenMqtt)
31
+ * [`api.logout`](#logout)
32
+ * [`api.markAsDelivered`](#markAsDelivered)
33
+ * [`api.markAsRead`](#markAsRead)
34
+ * [`api.markAsReadAll`](#markAsReadAll)
35
+ * [`api.markAsSeen`](#markAsSeen)
36
+ * [`api.muteThread`](#muteThread)
37
+ * [`api.removeUserFromGroup`](#removeUserFromGroup)
38
+ * [`api.resolvePhotoUrl`](#resolvePhotoUrl)
39
+ * [`api.searchForThread`](#searchForThread)
40
+ * [`api.sendMessage`](#sendMessage)
41
+ * [`api.sendTypingIndicator`](#sendTypingIndicator)
42
+ * [`api.setMessageReaction`](#setMessageReaction)
43
+ * [`api.setOptions`](#setOptions)
44
+ * [`api.setTitle`](#setTitle)
45
+ * [`api.threadColors`](#threadColors)
46
+ * [`api.unsendMessage`](#unsendMessage)
47
+ * [`Advanced & Ported Features`](#advancedPortedFeatures)
48
+
49
+ ---------------------------------------
50
+
51
+ ### Password safety
52
+
53
+ **Read this** before you _copy+paste_ examples from below.
54
+
55
+ You should not store Facebook password in your scripts.
56
+ There are few good reasons:
57
+ * People who are standing behind you may look at your "code" and get your password if it is on the screen
58
+ * Backups of source files may be readable by someone else. "_There is nothing secret in my code, why should I ever password protect my backups_"
59
+ * You can't push your code to Github (or any onther service) without removing your password from the file. Remember: Even if you undo your accidential commit with password, Git doesn't delete it, that commit is just not used but is still readable by everybody.
60
+ * If you change your password in the future (maybe it leaked because _someone_ stored password in source file… oh… well…) you will have to change every occurrence in your scripts
61
+
62
+ Preferred method is to have `login.js` that saves `AppState` to a file and then use that file from all your scripts.
63
+ This way you can put password in your code for a minute, login to facebook and then remove it.
64
+
65
+ If you want to be even more safe: _login.js_ can get password with `require("readline")` or with environment variables like this:
66
+ ```js
67
+ var credentials = {
68
+ email: process.env.FB_EMAIL,
69
+ password: process.env.FB_PASSWORD
70
+ }
71
+ ```
72
+ ```bash
73
+ FB_EMAIL="john.doe@example.com"
74
+ FB_PASSWORD="MySuperHardP@ssw0rd"
75
+ nodejs login.js
76
+ ```
77
+
78
+ ---------------------------------------
79
+
80
+ <a name="login"></a>
81
+ ### login(credentials[, options][, callback])
82
+
83
+ This function is returned by `require('nexus-fca')` and is the main entry point to the API.
84
+
85
+ It allows the user to log into facebook given the right credentials.
86
+
87
+ Return a Promise that will resolve if logged in successfully, or reject if failed to login. (will not resolve or reject if callback is supplied!)
88
+
89
+ If `callback` is supplied:
90
+
91
+ * `callback` will be called with a `null` object (for potential errors) and with an object containing all the available functions if logged in successfully.
92
+
93
+ * `callback` will be called with an error object if failed to login.
94
+
95
+ If `login-approval` error was thrown: Inside error object is `continue` function, you can call that function with 2FA code. The behaviour of this function depends on how you call `login` with:
96
+
97
+ * If `callback` is not supplied (using `Promise`), this function will return a `Promise` that behaves like `Promise` received from `login`.
98
+
99
+ * If `callback` is supplied, this function will still return a `Promise`, but it will not resolve. Instead, the result is called to `callback`.
100
+
101
+ __Arguments__
102
+
103
+ * `credentials`: An object containing the fields `email` and `password` used to login, __*or*__ an object containing the field `appState`.
104
+ * `options`: An object representing options to use when logging in (as described in [api.setOptions](#setOptions)).
105
+ * `callback(err, api)`: A callback called when login is done (successful or not). `err` is an object containing a field `error`.
106
+
107
+ __Example (Email & Password)__
108
+
109
+ ```js
110
+ const login = require("nexus-fca");
111
+
112
+ login({email: "FB_EMAIL", password: "FB_PASSWORD"}, (err, api) => {
113
+ if(err) return console.error(err);
114
+ // Here you can use the api
115
+ });
116
+ ```
117
+
118
+ __Example (Email & Password then save appState to file)__
119
+
120
+ ```js
121
+ const fs = require("fs");
122
+ const login = require("nexus-fca");
123
+
124
+ login({email: "FB_EMAIL", password: "FB_PASSWORD"}, (err, api) => {
125
+ if(err) return console.error(err);
126
+
127
+ fs.writeFileSync('appstate.json', JSON.stringify(api.getAppState()));
128
+ });
129
+ ```
130
+
131
+ __Example (AppState loaded from file)__
132
+
133
+ ```js
134
+ const fs = require("fs");
135
+ const login = require("nexus-fca");
136
+
137
+ login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
138
+ if(err) return console.error(err);
139
+ // Here you can use the api
140
+ });
141
+ ```
142
+
143
+ __Login Approvals (2-Factor Auth)__: When you try to login with Login Approvals enabled, your callback will be called with an error `'login-approval'` that has a `continue` function that accepts the approval code as a `string` or a `number`.
144
+
145
+ __Example__:
146
+
147
+ ```js
148
+ const fs = require("fs");
149
+ const login = require("nexus-fca");
150
+ const readline = require("readline");
151
+
152
+ var rl = readline.createInterface({
153
+ input: process.stdin,
154
+ output: process.stdout
155
+ });
156
+
157
+ const obj = {email: "FB_EMAIL", password: "FB_PASSWORD"};
158
+ login(obj, (err, api) => {
159
+ if(err) {
160
+ switch (err.error) {
161
+ case 'login-approval':
162
+ console.log('Enter code > ');
163
+ rl.on('line', (line) => {
164
+ err.continue(line);
165
+ rl.close();
166
+ });
167
+ break;
168
+ default:
169
+ console.error(err);
170
+ }
171
+ return;
172
+ }
173
+
174
+ // Logged in!
175
+ });
176
+ ```
177
+
178
+ __Review Recent Login__: Sometimes Facebook will ask you to review your recent logins. This means you've recently logged in from a unrecognized location. This will will result in the callback being called with an error `'review-recent-login'` by default. If you wish to automatically approve all recent logins, you can set the option `forceLogin` to `true` in the `loginOptions`.
179
+
180
+ ---------------------------------------
181
+
182
+ <a name="addUserToGroup"></a>
183
+ ### api.addUserToGroup(userID, threadID[, callback])
184
+
185
+ Adds a user (or array of users) to a group chat.
186
+
187
+ __Arguments__
188
+
189
+ * `userID`: User ID or array of user IDs.
190
+ * `threadID`: Group chat ID.
191
+ * `callback(err)`: A callback called when the query is done (either with an error or with no arguments).
192
+
193
+ ---------------------------------------
194
+
195
+ <a name="changeAdminStatus"></a>
196
+ ### api.changeAdminStatus(threadID, adminIDs, adminStatus)
197
+
198
+ Given a adminID, or an array of adminIDs, will set the admin status of the user(s) to `adminStatus`.
199
+
200
+ __Arguments__
201
+ * `threadID`: ID of a group chat (can't use in one-to-one conversations)
202
+ * `adminIDs`: The id(s) of users you wish to admin/unadmin (string or an array).
203
+ * `adminStatus`: Boolean indicating whether the user(s) should be promoted to admin (`true`) or demoted to a regular user (`false`).
204
+
205
+ __Example__
206
+
207
+ ```js
208
+ const fs = require("fs");
209
+ const login = require("nexus-fca");
210
+
211
+ login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, async function(err, api) {
212
+ if (err) return console.error(err);
213
+
214
+ let threadID = "0000000000000000";
215
+ let newAdmins = ["111111111111111", "222222222222222"];
216
+ await api.changeAdminStatus(threadID, newAdmins, true);
217
+
218
+ let adminToRemove = "333333333333333";
219
+ await api.changeAdminStatus(threadID, adminToRemove, false);
220
+
221
+ });
222
+
223
+ ```
224
+
225
+ ---------------------------------------
226
+
227
+ <a name="changeArchivedStatus"></a>
228
+ ### api.changeArchivedStatus(threadOrThreads, archive[, callback])
229
+
230
+ Given a threadID, or an array of threadIDs, will set the archive status of the threads to `archive`. Archiving a thread will hide it from the logged-in user's inbox until the next time a message is sent or received.
231
+
232
+ __Arguments__
233
+ * `threadOrThreads`: The id(s) of the threads you wish to archive/unarchive.
234
+ * `archive`: Boolean indicating the new archive status to assign to the thread(s).
235
+ * `callback(err)`: A callback called when the query is done (either with an error or null).
236
+
237
+ __Example__
238
+
239
+ ```js
240
+ const fs = require("fs");
241
+ const login = require("nexus-fca");
242
+
243
+ login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
244
+ if(err) return console.error(err);
245
+
246
+ api.changeArchivedStatus("000000000000000", true, (err) => {
247
+ if(err) return console.error(err);
248
+ });
249
+ });
250
+ ```
251
+
252
+ ---------------------------------------
253
+
254
+ <a name="changeBlockedStatus"></a>
255
+ ### api.changeBlockedStatus(userID, block[, callback])
256
+
257
+ Prevents a user from privately contacting you. (Messages in a group chat will still be seen by both parties).
258
+
259
+ __Arguments__
260
+
261
+ * `userID`: User ID.
262
+ * `block`: Boolean indicating whether to block or unblock the user (true for block).
263
+ * `callback(err)`: A callback called when the query is done (either with an error or with no arguments).
264
+
265
+ ---------------------------------------
266
+
267
+ <a name="changeGroupImage"></a>
268
+ ### api.changeGroupImage(image, threadID[, callback])
269
+
270
+ Will change the group chat's image to the given image.
271
+
272
+ __Arguments__
273
+ * `image`: File stream of image.
274
+ * `threadID`: String representing the ID of the thread.
275
+ * `callback(err)`: A callback called when the change is done (either with an error or null).
276
+
277
+ __Example__
278
+
279
+ ```js
280
+ const fs = require("fs");
281
+ const login = require("nexus-fca");
282
+
283
+ login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
284
+ if(err) return console.error(err);
285
+
286
+ api.changeGroupImage(fs.createReadStream("./avatar.png"), "000000000000000", (err) => {
287
+ if(err) return console.error(err);
288
+ });
289
+ });
290
+ ```
291
+
292
+ ---------------------------------------
293
+
294
+ <a name="changeNickname"></a>
295
+ ### api.changeNickname(nickname, threadID, participantID[, callback])
296
+
297
+ Will change the thread user nickname to the one provided.
298
+
299
+ __Arguments__
300
+ * `nickname`: String containing a nickname. Leave empty to reset nickname.
301
+ * `threadID`: String representing the ID of the thread.
302
+ * `participantID`: String representing the ID of the user.
303
+ * `callback(err)`: An optional callback called when the change is done (either with an error or null).
304
+
305
+ __Example__
306
+
307
+ ```js
308
+ const fs = require("fs");
309
+ const login = require("nexus-fca");
310
+
311
+ login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
312
+ if(err) return console.error(err);
313
+
314
+ api.changeNickname("Example", "000000000000000", "000000000000000", (err) => {
315
+ if(err) return console.error(err);
316
+ });
317
+ });
318
+ ```
319
+
320
+ ---------------------------------------
321
+
322
+ <a name="changeThreadColor"></a>
323
+ ### api.changeThreadColor(color, threadID[, callback])
324
+
325
+ Will change the thread color to the given hex string color ("#0000ff"). Set it
326
+ to empty string if you want the default.
327
+
328
+ Note: the color needs to start with a "#".
329
+
330
+ __Arguments__
331
+ * `color`: String representing a theme ID (a list of theme ID can be found at `api.threadColors`).
332
+ * `threadID`: String representing the ID of the thread.
333
+ * `callback(err)`: A callback called when the change is done (either with an error or null).
334
+
335
+ __Example__
336
+
337
+ ```js
338
+ const fs = require("fs");
339
+ const login = require("nexus-fca");
340
+
341
+ login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
342
+ if(err) return console.error(err);
343
+
344
+ api.changeThreadColor("#0000ff", "000000000000000", (err) => {
345
+ if(err) return console.error(err);
346
+ });
347
+ });
348
+ ```
349
+
350
+ ---------------------------------------
351
+
352
+ <a name="changeThreadEmoji"></a>
353
+ ### api.changeThreadEmoji(emoji, threadID[, callback])
354
+
355
+ Will change the thread emoji to the one provided.
356
+
357
+ Note: The UI doesn't play nice with all emoji.
358
+
359
+ __Arguments__
360
+ * `emoji`: String containing a single emoji character.
361
+ * `threadID`: String representing the ID of the thread.
362
+ * `callback(err)`: A callback called when the change is done (either with an error or null).
363
+
364
+ __Example__
365
+
366
+ ```js
367
+ const fs = require("fs");
368
+ const login = require("nexus-fca");
369
+
370
+ login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
371
+ if(err) return console.error(err);
372
+
373
+ api.changeThreadEmoji("💯", "000000000000000", (err) => {
374
+ if(err) return console.error(err);
375
+ });
376
+ });
377
+ ```
378
+
379
+ ---------------------------------------
380
+
381
+ <a name="createNewGroup"></a>
382
+ ### api.createNewGroup(participantIDs[, groupTitle][, callback])
383
+
384
+ Create a new group chat.
385
+
386
+ __Arguments__
387
+ * `participantIDs`: An array containing participant IDs. (*Length must be >= 2*)
388
+ * `groupTitle`: The title of the new group chat.
389
+ * `callback(err, threadID)`: A callback called when created.
390
+
391
+ ---------------------------------------
392
+
393
+ <a name="createPoll"></a>
394
+ ### api.createPoll(title, threadID[, options][, callback]) (*temporary deprecated because Facebook is updating this feature*)
395
+
396
+ Creates a poll with the specified title and optional poll options, which can also be initially selected by the logged-in user.
397
+
398
+ __Arguments__
399
+ * `title`: String containing a title for the poll.
400
+ * `threadID`: String representing the ID of the thread.
401
+ * `options`: An optional `string : bool` dictionary to specify initial poll options and their initial states (selected/not selected), respectively.
402
+ * `callback(err)`: An optional callback called when the poll is posted (either with an error or null) - can omit the `options` parameter and use this as the third parameter if desired.
403
+
404
+ __Example__
405
+
406
+ ```js
407
+ const fs = require("fs");
408
+ const login = require("nexus-fca");
409
+
410
+ login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
411
+ if(err) return console.error(err);
412
+
413
+ api.createPoll("Example Poll", "000000000000000", {
414
+ "Option 1": false,
415
+ "Option 2": true
416
+ }, (err) => {
417
+ if(err) return console.error(err);
418
+ });
419
+ });
420
+ ```
421
+
422
+ ---------------------------------------
423
+
424
+ <a name="deleteMessage"></a>
425
+ ### api.deleteMessage(messageOrMessages[, callback])
426
+
427
+ Takes a messageID or an array of messageIDs and deletes the corresponding message.
428
+
429
+ __Arguments__
430
+ * `messageOrMessages`: A messageID string or messageID string array
431
+ * `callback(err)`: A callback called when the query is done (either with an error or null).
432
+
433
+ __Example__
434
+ ```js
435
+ const fs = require("fs");
436
+ const login = require("nexus-fca");
437
+
438
+ login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
439
+ if(err) return console.error(err);
440
+
441
+ api.listen((err, message) => {
442
+ if(message.body) {
443
+ api.sendMessage(message.body, message.threadID, (err, messageInfo) => {
444
+ if(err) return console.error(err);
445
+
446
+ api.deleteMessage(messageInfo.messageID);
447
+ });
448
+ }
449
+ });
450
+ });
451
+ ```
452
+
453
+ ---------------------------------------
454
+
455
+ <a name="deleteThread"></a>
456
+ ### api.deleteThread(threadOrThreads[, callback])
457
+
458
+ Given a threadID, or an array of threadIDs, will delete the threads from your account. Note that this does *not* remove the messages from Facebook's servers - anyone who hasn't deleted the thread can still view all of the messages.
459
+
460
+ __Arguments__
461
+
462
+ * `threadOrThreads` - The id(s) of the threads you wish to remove from your account.
463
+ * `callback(err)` - A callback called when the operation is done, maybe with an object representing an error.
464
+
465
+ __Example__
466
+
467
+ ```js
468
+ const fs = require("fs");
469
+ const login = require("nexus-fca");
470
+
471
+ login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
472
+ if(err) return console.error(err);
473
+
474
+ api.deleteThread("000000000000000", (err) => {
475
+ if(err) return console.error(err);
476
+ });
477
+ });
478
+ ```
479
+
480
+ ---------------------------------------
481
+
482
+ <a name="forwardAttachment"></a>
483
+ ### api.forwardAttachment(attachmentID, userOrUsers[, callback])
484
+
485
+ Forwards corresponding attachment to given userID or to every user from an array of userIDs
486
+
487
+ __Arguments__
488
+ * `attachmentID`: The ID field in the attachment object. Recorded audio cannot be forwarded.
489
+ * `userOrUsers`: A userID string or usersID string array
490
+ * `callback(err)`: A callback called when the query is done (either with an error or null).
491
+
492
+ ---------------------------------------
493
+
494
+ <a name="getAppState"></a>
495
+ ### api.getAppState()
496
+
497
+ Returns current appState which can be saved to a file or stored in a variable.
498
+
499
+ ---------------------------------------
500
+
501
+ <a name="getCurrentUserID"></a>
502
+ ### api.getCurrentUserID()
503
+
504
+ Returns the currently logged-in user's Facebook user ID.
505
+
506
+ ---------------------------------------
507
+
508
+ <a name="getEmojiUrl"></a>
509
+ ### api.getEmojiUrl(c, size[, pixelRatio])
510
+
511
+ Returns the URL to a Facebook Messenger-style emoji image asset.
512
+
513
+ __note__: This function will return a URL regardless of whether the image at the URL actually exists.
514
+ This can happen if, for example, Messenger does not have an image asset for the requested emoji.
515
+
516
+ __Arguments__
517
+
518
+ * `c` - The emoji character
519
+ * `size` - The width and height of the emoji image; supported sizes are 32, 64, and 128
520
+ * `pixelRatio` - The pixel ratio of the emoji image; supported ratios are '1.0' and '1.5' (default is '1.0')
521
+
522
+ __Example__
523
+
524
+ ```js
525
+ const fs = require("fs");
526
+ const login = require("nexus-fca");
527
+
528
+ login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
529
+ if(err) return console.error(err);
530
+
531
+ // Prints https://static.xx.fbcdn.net/images/emoji.php/v8/z9c/1.0/128/1f40d.png
532
+ console.log('Snake emoji, 128px (128x128 with pixel ratio of 1.0');
533
+ console.log(api.getEmojiUrl('\ud83d\udc0d', 128));
534
+
535
+ // Prints https://static.xx.fbcdn.net/images/emoji.php/v8/ze1/1.5/128/1f40d.png
536
+ console.log('Snake emoji, 192px (128x128 with pixel ratio of 1.5');
537
+ console.log(api.getEmojiUrl('\ud83d\udc0d', 128, '1.5'));
538
+ });
539
+ ```
540
+
541
+ ---------------------------------------
542
+
543
+ <a name="getFriendsList"></a>
544
+ ### api.getFriendsList(callback)
545
+
546
+ Returns an array of objects with some information about your friends.
547
+
548
+ __Arguments__
549
+
550
+ * `callback(err, arr)` - A callback called when the query is done (either with an error or with an confirmation object). `arr` is an array of objects with the following fields: `alternateName`, `firstName`, `gender`, `userID`, `isFriend`, `fullName`, `profilePicture`, `type`, `profileUrl`, `vanity`, `isBirthday`.
551
+
552
+ __Example__
553
+
554
+ ```js
555
+ const fs = require("fs");
556
+ const login = require("nexus-fca");
557
+
558
+ login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
559
+ if(err) return console.error(err);
560
+
561
+ api.getFriendsList((err, data) => {
562
+ if(err) return console.error(err);
563
+
564
+ console.log(data.length);
565
+ });
566
+ });
567
+ ```
568
+
569
+ ---------------------------------------
570
+
571
+ <a name="getThreadHistory"></a>
572
+ ### api.getThreadHistory(threadID, amount, timestamp, callback)
573
+
574
+ Takes a threadID, number of messages, a timestamp, and a callback.
575
+
576
+ __note__: if you're getting a 500 error, it's possible that you're requesting too many messages. Try reducing that number and see if that works.
577
+
578
+ __Arguments__
579
+ * `threadID`: A threadID corresponding to the target chat
580
+ * `amount`: The amount of messages to *request*
581
+ * `timestamp`: Used to described the time of the most recent message to load. If timestamp is `undefined`, facebook will load the most recent messages.
582
+ * `callback(error, history)`: If error is null, history will contain an array of message objects.
583
+
584
+ __Example__
585
+
586
+ To load 50 messages at a time, we can use `undefined` as the timestamp to retrieve the most recent messages and use the timestamp of the earliest message to load the next 50.
587
+
588
+ ```js
589
+ var timestamp = undefined;
590
+
591
+ function loadNextThreadHistory(api){
592
+ api.getThreadHistory(threadID, 50, timestamp, (err, history) => {
593
+ if(err) return console.error(err);
594
+
595
+ /*
596
+ Since the timestamp is from a previous loaded message,
597
+ that message will be included in this history so we can discard it unless it is the first load.
598
+ */
599
+ if(timestamp != undefined) history.pop();
600
+
601
+ /*
602
+ Handle message history
603
+ */
604
+
605
+ timestamp = history[0].timestamp;
606
+ });
607
+ }
608
+ ```
609
+
610
+ ---------------------------------------
611
+
612
+ <a name="getThreadInfo"></a>
613
+ ### api.getThreadInfo(threadID[, callback])
614
+
615
+ Takes a threadID and a callback. Works for both single-user and group threads.
616
+
617
+ __Arguments__
618
+ * `threadID`: A threadID corresponding to the target thread.
619
+ * `callback(err, info)`: If `err` is `null`, `info` will contain the following properties:
620
+
621
+ | Key | Description |
622
+ |----------|:-------------:|
623
+ | threadID | ID of the thread |
624
+ | participantIDs | Array of user IDs in the thread |
625
+ | threadName | Name of the thread. Usually the name of the user. In group chats, this will be empty if the name of the group chat is unset. |
626
+ | userInfo | An array contains info of members, which has the same structure as [`getUserInfo`](#getUserInfo), but add a key `id`, contain ID of member currently at. |
627
+ | nicknames | Map of nicknames for members of the thread. If there are no nicknames set, this will be null. |
628
+ | unreadCount | Number of unread messages |
629
+ | messageCount | Number of messages |
630
+ | imageSrc | URL to the group chat photo. Null if unset or a 1-1 thread. |
631
+ | timestamp | Timestamp of last activity |
632
+ | muteUntil | Timestamp at which the thread will no longer be muted. The timestamp will be -1 if the thread is muted indefinitely or null if the thread is not muted. |
633
+ | isGroup | boolean, true if this thread is a group thread (more than 2 participants). |
634
+ | isSubscribed | |
635
+ | folder | The folder that the thread is in. Can be one of: <ul><li>'inbox'</li><li>'archive'</li></ul> |
636
+ | isArchived | True if the thread is archived, false if not |
637
+ | cannotReplyReason | If you cannot reply to this thread, this will be a string stating why. Otherwise it will be null. |
638
+ | lastReadTimestamp | Timestamp of the last message that is marked as 'read' by the current user. |
639
+ | emoji | Object with key 'emoji' whose value is the emoji unicode character. Null if unset. |
640
+ | color | String form of the custom color in hexadecimal form. |
641
+ | adminIDs | Array of user IDs of the admins of the thread. Empty array if unset. |
642
+ | approvalMode | `true` or `false`, used to check if this group requires admin approval to add users |
643
+ | approvalQueue | Array of object that has the following keys: <ul><li>`inviterID`: ID of the user invited the person to the group</li><li>`requesterID`: ID of the person waiting to be approved</li><li>`timestamp`: Request timestamp</li></ul> |
644
+
645
+ ---------------------------------------
646
+
647
+ <a name="getThreadList"></a>
648
+ ### api.getThreadList(limit, timestamp, tags, callback)
649
+
650
+ Returns information about the user's threads.
651
+
652
+ __Arguments__
653
+
654
+ * `limit`: Limit the number of threads to fetch.
655
+ * `timestamp`: Request threads *before* this date. `null` means *now*
656
+ * `tags`: An array describing which folder to fetch. It should be one of these:
657
+ - `["INBOX"]` *(same as `[]`)*
658
+ - `["ARCHIVED"]`
659
+ - `["PENDING"]`
660
+ - `["OTHER"]`
661
+ - `["INBOX", "unread"]`
662
+ - `["ARCHIVED", "unread"]`
663
+ - `["PENDING", "unread"]`
664
+ - `["OTHER", "unread"]`
665
+
666
+ *if you find something new, let us know*
667
+
668
+ * `callback(err, list)`: Callback called when the query is done (either with an error or with a proper result). `list` is an *array* with objects with the following properties:
669
+
670
+ __Thread list__
671
+
672
+ | Key | Description |
673
+ |----------------------|-------------------------------------------------------------|
674
+ | threadID | ID of the thread |
675
+ | name | The name of the thread |
676
+ | unreadCount | Amount of unread messages in thread |
677
+ | messageCount | Amount of messages in thread |
678
+ | imageSrc | Link to the thread's image or `null` |
679
+ | emoji | The default emoji in thread (classic like is `null`) |
680
+ | color | Thread's message color in `RRGGBB` (default blue is `null`) |
681
+ | nicknames | An array of `{"userid": "1234", "nickname": "John Doe"}` |
682
+ | muteUntil | Timestamp until the mute expires or `null` |
683
+ | participants | An array of participants. See below |
684
+ | adminIDs | An array of thread admin IDs |
685
+ | folder | `INBOX`, `ARCHIVED`, `PENDING` or `OTHER` |
686
+ | isGroup | `true` or `false` |
687
+ | customizationEnabled | `false` in one-to-one conversations with `Page` or `ReducedMessagingActor` |
688
+ | participantAddMode | currently `"ADD"` for groups and `null` otherwise |
689
+ | reactionsMuteMode | `REACTIONS_NOT_MUTED` or `REACTIONS_MUTED` |
690
+ | mentionsMuteMode | `MENTIONS_NOT_MUTED` or `MENTIONS_MUTED` |
691
+ | isArchived | `true` or `false` |
692
+ | isSubscribed | `true` or `false` |
693
+ | timestamp | timestamp in miliseconds |
694
+ | snippet | Snippet's text message |
695
+ | snippetAttachments | Attachments in snippet |
696
+ | snippetSender | ID of snippet sender |
697
+ | lastMessageTimestamp | timestamp in milliseconds |
698
+ | lastReadTimestamp | timestamp in milliseconds or `null` |
699
+ | cannotReplyReason | `null`, `"RECIPIENTS_NOT_LOADABLE"` or `"BLOCKED"` |
700
+ | approvalMode | `true` or `false`, used to check if this group requires admin approval to add users |
701
+
702
+ __`participants` format__
703
+
704
+ `accountType` is one of the following:
705
+ - `"User"`
706
+ - `"Page"`
707
+ - `"UnavailableMessagingActor"`
708
+ - `"ReducedMessagingActor"`
709
+
710
+ (*there might be more*)
711
+
712
+ <table>
713
+ <tr>
714
+ <th>Account type</th>
715
+ <th>Key</th>
716
+ <th>Description</th>
717
+ </tr>
718
+ <tr>
719
+ <td rowspan="12"><code>"User"</code></td>
720
+ <td>userID</td>
721
+ <td>ID of user</td>
722
+ </tr>
723
+ <tr>
724
+ <td>name</td>
725
+ <td>Full name of user</td>
726
+ </tr>
727
+ <tr>
728
+ <td>shortName</td>
729
+ <td>Short name of user (most likely first name)</td>
730
+ </tr>
731
+ <tr>
732
+ <td>gender</td>
733
+ <td>Either
734
+ <code>"MALE"</code>,
735
+ <code>"FEMALE"</code>,
736
+ <code>"NEUTER"</code> or
737
+ <code>"UNKNOWN"</code>
738
+ </td>
739
+ </tr>
740
+ <tr>
741
+ <td>url</td>
742
+ <td>URL of the user's Facebook profile</td>
743
+ </tr>
744
+ <tr>
745
+ <td>profilePicture</td>
746
+ <td>URL of the profile picture</td>
747
+ </tr>
748
+ <tr>
749
+ <td>username</td>
750
+ <td>Username of user or
751
+ <code>null</code>
752
+ </td>
753
+ </tr>
754
+ <tr>
755
+ <td>isViewerFriend</td>
756
+ <td>Is the user a friend of you?</td>
757
+ </tr>
758
+ <tr>
759
+ <td>isMessengerUser</td>
760
+ <td>Does the user use Messenger?</td>
761
+ </tr>
762
+ <tr>
763
+ <td>isVerified</td>
764
+ <td>Is the user verified? (Little blue tick mark)</td>
765
+ </tr>
766
+ <tr>
767
+ <td>isMessageBlockedByViewer</td>
768
+ <td>Is the user blocking messages from you?</td>
769
+ </tr>
770
+ <tr>
771
+ <td>isViewerCoworker</td>
772
+ <td>Is the user your coworker?
773
+ </td>
774
+ </tr>
775
+
776
+ <tr>
777
+ <td rowspan="10"><code>"Page"</code></td>
778
+ <td>userID</td>
779
+ <td>ID of the page</td>
780
+ </tr>
781
+ <tr>
782
+ <td>name</td>
783
+ <td>Name of the fanpage</td>
784
+ </tr>
785
+ <tr>
786
+ <td>url</td>
787
+ <td>URL of the fanpage</td>
788
+ </tr>
789
+ <tr>
790
+ <td>profilePicture</td>
791
+ <td>URL of the profile picture</td>
792
+ </tr>
793
+ <tr>
794
+ <td>username</td>
795
+ <td>Username of user or
796
+ <code>null</code>
797
+ </td>
798
+ </tr>
799
+ <tr>
800
+ <td>acceptsMessengerUserFeedback</td>
801
+ <td></td>
802
+ </tr>
803
+ <tr>
804
+ <td>isMessengerUser</td>
805
+ <td>Does the fanpage use Messenger?</td>
806
+ </tr>
807
+ <tr>
808
+ <td>isVerified</td>
809
+ <td>Is the fanpage verified? (Little blue tick mark)</td>
810
+ </tr>
811
+ <tr>
812
+ <td>isMessengerPlatformBot</td>
813
+ <td>Is the fanpage a bot</td>
814
+ </tr>
815
+ <tr>
816
+ <td>isMessageBlockedByViewer</td>
817
+ <td>Is the fanpage blocking messages from you?</td>
818
+ </tr>
819
+
820
+ <tr>
821
+ <td rowspan="7"><code>"ReducedMessagingActor"</code><br />(account requres verification,<br />messages are hidden)</td>
822
+ <td>userID</td>
823
+ <td>ID of the user</td>
824
+ </tr>
825
+ <tr>
826
+ <td>name</td>
827
+ <td>Name of the user</td>
828
+ </tr>
829
+ <tr>
830
+ <td>url</td>
831
+ <td>
832
+ <code>null</code>
833
+ </td>
834
+ </tr>
835
+ <tr>
836
+ <td>profilePicture</td>
837
+ <td>URL of the default Facebook profile picture</td>
838
+ </tr>
839
+ <tr>
840
+ <td>username</td>
841
+ <td>Username of user</td>
842
+ </td>
843
+ </tr>
844
+ <tr>
845
+ <td>acceptsMessengerUserFeedback</td>
846
+ <td></td>
847
+ </tr>
848
+ <tr>
849
+ <td>isMessageBlockedByViewer</td>
850
+ <td>Is the user blocking messages from you?</td>
851
+ </tr>
852
+ <tr>
853
+ <td rowspan="7"><code>"UnavailableMessagingActor"</code><br />(account disabled/removed)</td>
854
+ <td>userID</td>
855
+ <td>ID of the user</td>
856
+ </tr>
857
+ <tr>
858
+ <td>name</td>
859
+ <td><em>Facebook User</em> in user's language</td>
860
+ </tr>
861
+ <tr>
862
+ <td>url</td>
863
+ <td><code>null</code></td>
864
+ </tr>
865
+ <tr>
866
+ <td>profilePicture</td>
867
+ <td>URL of the default **male** Facebook profile picture</td>
868
+ </tr>
869
+ <tr>
870
+ <td>username</td>
871
+ <td><code>null</code></td>
872
+ </tr>
873
+ <tr>
874
+ <td>acceptsMessengerUserFeedback</td>
875
+ <td></td>
876
+ </tr>
877
+ <tr>
878
+ <td>isMessageBlockedByViewer</td>
879
+ <td>Is the user blocking messages from you?</td>
880
+ </tr>
881
+ </table>
882
+
883
+
884
+ In a case that some account type is not supported, we return just this *(but you can't rely on it)* and log a warning to the console:
885
+
886
+ | Key | Description |
887
+ |--------------|-------------------------|
888
+ | accountType | type, can be anything |
889
+ | userID | ID of the account |
890
+ | name | Name of the account |
891
+
892
+
893
+ ---------------------------------------
894
+
895
+ <a name="getThreadPictures"></a>
896
+ ### api.getThreadPictures(threadID, offset, limit, callback)
897
+
898
+ Returns pictures sent in the thread.
899
+
900
+ __Arguments__
901
+
902
+ * `threadID`: A threadID corresponding to the target chat
903
+ * `offset`: Start index of picture to retrieve, where 0 is the most recent picture
904
+ * `limit`: Number of pictures to get, incrementing from the offset index
905
+ * `callback(err, arr)`: A callback called when the query is done (either with an error or with an confirmation object). `arr` is an array of objects with `uri`, `width`, and `height`.
906
+
907
+ ---------------------------------------
908
+
909
+ <a name="getUserID"></a>
910
+ ### api.getUserID(name, callback)
911
+
912
+ Given the full name or vanity name of a Facebook user, event, page, group or app, the call will perform a Facebook Graph search and return all corresponding IDs (order determined by Facebook).
913
+
914
+ __Arguments__
915
+
916
+ * `name` - A string being the name of the item you're looking for.
917
+ * `callback(err, obj)` - A callback called when the search is done (either with an error or with the resulting object). `obj` is an array which contains all of the items that facebook graph search found, ordered by "importance". Each item in the array has the following properties: `userID`,`photoUrl`,`indexRank`, `name`, `isVerified`, `profileUrl`, `category`, `score`, `type` (type is generally user, group, page, event or app).
918
+
919
+ __Example__
920
+
921
+ ```js
922
+ const fs = require("fs");
923
+ const login = require("nexus-fca");
924
+
925
+ login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
926
+ if(err) return console.error(err);
927
+
928
+ api.getUserID("Marc Zuckerbot", (err, data) => {
929
+ if(err) return console.error(err);
930
+
931
+ // Send the message to the best match (best by Facebook's criteria)
932
+ var msg = "Hello!"
933
+ var threadID = data[0].userID;
934
+ api.sendMessage(msg, threadID);
935
+ });
936
+ });
937
+ ```
938
+
939
+ ---------------------------------------
940
+
941
+ <a name="getUserInfo"></a>
942
+ ### api.getUserInfo(ids, callback)
943
+
944
+ Will get some information about the given users.
945
+
946
+ __Arguments__
947
+
948
+ * `ids` - Either a string/number for one ID or an array of strings/numbers for a batched query.
949
+ * `callback(err, obj)` - A callback called when the query is done (either with an error or with an confirmation object). `obj` is a mapping from userId to another object containing the following properties: `name`, `firstName`, `vanity` (user's chosen facebook handle, if any), `thumbSrc`, `profileUrl`, `gender`, `type` (type is generally user, group, page, event or app), `isFriend`, `isBirthday`, `searchTokens`, `alternateName`.
950
+
951
+ __Example__
952
+
953
+ ```js
954
+ const fs = require("fs");
955
+ const login = require("nexus-fca");
956
+
957
+ login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
958
+ if(err) return console.error(err);
959
+
960
+ api.getUserInfo([1, 2, 3, 4], (err, ret) => {
961
+ if(err) return console.error(err);
962
+
963
+ for(var prop in ret) {
964
+ if(ret.hasOwnProperty(prop) && ret[prop].isBirthday) {
965
+ api.sendMessage("Happy birthday :)", prop);
966
+ }
967
+ }
968
+ });
969
+ });
970
+ ```
971
+
972
+ ---------------------------------------
973
+
974
+ <a name="threadColors"></a>
975
+ ### api.threadColors
976
+
977
+ A dictionary mapping names of all currently valid thread themes to their theme ID that are accepted by [`api.changeThreadColor`](#changeThreadColor). These themes, listed below, are the ones present in the palette UI used for selecting thread themes on the Messenger client.
978
+
979
+ - DefaultBlue: `196241301102133`
980
+ - HotPink: `169463077092846`
981
+ - AquaBlue: `2442142322678320`
982
+ - BrightPurple: `234137870477637`
983
+ - CoralPink: `980963458735625`
984
+ - Orange: `175615189761153`
985
+ - Green: `2136751179887052`
986
+ - LavenderPurple: `2058653964378557`
987
+ - Red: `2129984390566328`
988
+ - Yellow: `174636906462322`
989
+ - TealBlue: `1928399724138152`
990
+ - Aqua: `417639218648241`
991
+ - Mango: `930060997172551`
992
+ - Berry: `164535220883264`
993
+ - Citrus: `370940413392601`
994
+ - Candy: `205488546921017`
995
+ - ~~StarWars: `809305022860427`~~ (Facebook removed it.)
996
+
997
+ ---------------------------------------
998
+
999
+ <a name="handleMessageRequest"></a>
1000
+ ### api.handleMessageRequest(threadID, accept[, callback])
1001
+
1002
+ Accept or ignore message request(s) with thread id `threadID`.
1003
+
1004
+ __Arguments__
1005
+
1006
+ * `threadID`: A threadID or array of threadIDs corresponding to the target thread(s). Can be numbers or strings.
1007
+ * `accept`: Boolean indicating the new status to assign to the message request(s); true for inbox, false to others.
1008
+ * `callback(err)`: A callback called when the query is done (with an error or with null).
1009
+
1010
+ ---------------------------------------
1011
+
1012
+ <a name="listen"></a>
1013
+ ### api.listen([callback])
1014
+ <a name="listenMqtt"></a>
1015
+ ### api.listenMqtt([callback])
1016
+
1017
+ Will call `callback` when a new message is received on this account.
1018
+ 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})`. This returns an `EventEmitter` that contains function `stopListening` that will stop the `listen` loop and is guaranteed to prevent any future calls to the callback given to `listen`. An immediate call to `stopListening` when an error occurs will prevent the listen function to continue.
1019
+
1020
+ If `callback` is not defined, or isn't a `Function`, you can listen to messages with event `message` and `error` from `EventEmitter` returned by this function.
1021
+
1022
+ __Arguments__
1023
+
1024
+ - `callback(error, message)`: A callback called every time the logged-in account receives a new message.
1025
+
1026
+ <a name="message"></a>
1027
+ __Message__
1028
+
1029
+ The message object will contain different fields based on its type (as determined by its `type` field). By default, the only type that will be listened for is `message`. If enabled through [setOptions](#setOptions), the message object may alternatively represent an event e.g. a read receipt. The available event types are as follows:
1030
+
1031
+ <table>
1032
+ <tr>
1033
+ <th>Event Type</th>
1034
+ <th>Field</th>
1035
+ <th>Description</th>
1036
+ </tr>
1037
+ <tr>
1038
+ <td rowspan="10">
1039
+ <code>"message"</code><br />
1040
+ A message was sent to a thread.
1041
+ </td>
1042
+ <td><code>attachments</code></td>
1043
+ <td>An array of attachments to the message. Attachments vary in type, see the attachments table below.</td>
1044
+ </tr>
1045
+ <tr>
1046
+ <td><code>body</code></td>
1047
+ <td>The string corresponding to the message that was just received.</td>
1048
+ </tr>
1049
+ <tr>
1050
+ <td><code>isGroup</code></td>
1051
+ <td>boolean, true if this thread is a group thread (more than 2 participants).</td>
1052
+ </tr>
1053
+ <tr>
1054
+ <td><code>mentions</code></td>
1055
+ <td>An object containing people mentioned/tagged in the message in the format { id: name }</td>
1056
+ </tr>
1057
+ <tr>
1058
+ <td><code>messageID</code></td>
1059
+ <td>A string representing the message ID.</td>
1060
+ </tr>
1061
+ <tr>
1062
+ <td><code>senderID</code></td>
1063
+ <td>The id of the person who sent the message in the chat with threadID.</td>
1064
+ </tr>
1065
+ <tr>
1066
+ <td><code>threadID</code></td>
1067
+ <td>The threadID representing the thread in which the message was sent.</td>
1068
+ </tr>
1069
+ <tr>
1070
+ <td><code>isUnread</code></td>
1071
+ <td>Boolean representing whether or not the message was read.</td>
1072
+ </tr>
1073
+ <tr>
1074
+ <td><code>participantIDs</code></td>
1075
+ <td>An array containing participant IDs.</td>
1076
+ </tr>
1077
+ <tr>
1078
+ <td><code>type</code></td>
1079
+ <td>For this event type, this will always be the string <code>"message"</code>.</td>
1080
+ </tr>
1081
+ <tr>
1082
+ <td rowspan="7">
1083
+ <code>"event"</code><br />
1084
+ An event occurred within a thread. Note that receiving this event type needs to be enabled with `api.setOptions({ listenEvents: true })`
1085
+ </td>
1086
+ <td><code>author</code></td>
1087
+ <td>The person who performed the event.</td>
1088
+ </tr>
1089
+ <tr>
1090
+ <td><code>logMessageBody</code></td>
1091
+ <td>String printed in the chat.</td>
1092
+ </tr>
1093
+ <tr>
1094
+ <td><code>logMessageData</code></td>
1095
+ <td>Data relevant to the event.</td>
1096
+ </tr>
1097
+ <tr>
1098
+ <td><code>logMessageType</code></td>
1099
+ <td>String representing the type of event (<code>log:subscribe</code>, <code>log:unsubscribe</code>, <code>log:thread-name</code>, <code>log:thread-color</code>, <code>log:thread-icon</code>, <code>log:user-nickname</code>, <code>log:thread-call</code>, <code>log:thread-admins</code>)</td>
1100
+ </tr>
1101
+ <tr>
1102
+ <td><code>threadID</code></td>
1103
+ <td>The threadID representing the thread in which the message was sent.</td>
1104
+ </tr>
1105
+ <tr>
1106
+ <td><code>participantIDs</code></td>
1107
+ <td>An array containing participant IDs.</td>
1108
+ </tr>
1109
+ <tr>
1110
+ <td><code>type</code></td>
1111
+ <td>For this event type, this will always be the string <code>"event"</code>.</td>
1112
+ </tr>
1113
+ <tr>
1114
+ <td rowspan="5">
1115
+ <code>"typ"</code><br />
1116
+ A user in a thread is typing. Note that receiving this event type needs to be enabled with `api.setOptions({ listenTyping: true })`
1117
+ </td>
1118
+ <td><code>from</code></td>
1119
+ <td>ID of the user who started/stopped typing.</td>
1120
+ </tr>
1121
+ <tr>
1122
+ <td><code>fromMobile</code></td>
1123
+ <td>Boolean representing whether or not the person's using a mobile device to type.</td>
1124
+ </tr>
1125
+ <tr>
1126
+ <td><code>isTyping</code></td>
1127
+ <td>Boolean representing whether or not a person started typing.</td>
1128
+ </tr>
1129
+ <tr>
1130
+ <td><code>threadID</code></td>
1131
+ <td>The threadID representing the thread in which a user is typing.</td>
1132
+ </tr>
1133
+ <tr>
1134
+ <td><code>type</code></td>
1135
+ <td>For this event type, this will always be the string <code>"typ"</code>.</td>
1136
+ </tr>
1137
+ <tr>
1138
+ <td rowspan="3">
1139
+ <code>"read"</code><br />
1140
+ The current API user has read a message.
1141
+ </td>
1142
+ <td><code>threadID</code></td>
1143
+ <td>The threadID representing the thread in which the message was sent.</td>
1144
+ </tr>
1145
+ <tr>
1146
+ <td><code>time</code></td>
1147
+ <td>The time at which the user read the message.</td>
1148
+ </tr>
1149
+ <tr>
1150
+ <td><code>type</code></td>
1151
+ <td>For this event type, this will always be the string <code>"read"</code>.</td>
1152
+ </tr>
1153
+ <tr>
1154
+ <td rowspan="4">
1155
+ <code>"read_receipt"</code><br />
1156
+ A user within a thread has seen a message sent by the API user.
1157
+ </td>
1158
+ <td><code>reader</code></td>
1159
+ <td>ID of the user who just read the message.</td>
1160
+ </tr>
1161
+ <tr>
1162
+ <td><code>threadID</code></td>
1163
+ <td>The thread in which the message was read.</td>
1164
+ </tr>
1165
+ <tr>
1166
+ <td><code>time</code></td>
1167
+ <td>The time at which the reader read the message.</td>
1168
+ </tr>
1169
+ <tr>
1170
+ <td><code>type</code></td>
1171
+ <td>For this event type, this will always be the string <code>"read_receipt"</code>.</td>
1172
+ </tr>
1173
+ <tr>
1174
+ <td rowspan="8">
1175
+ <code>"message_reaction"</code><br />
1176
+ A user has sent a reaction to a message.
1177
+ </td>
1178
+ <td><code>messageID</code></td>
1179
+ <td>The ID of the message</td>
1180
+ </tr>
1181
+ <tr>
1182
+ <td><code>offlineThreadingID</code></td>
1183
+ <td>The offline message ID</td>
1184
+ </tr>
1185
+ <tr>
1186
+ <td><code>reaction</code></td>
1187
+ <td>Contains reaction emoji</td>
1188
+ </tr>
1189
+ <tr>
1190
+ <td><code>senderID</code></td>
1191
+ <td>ID of the author the message, where has been reaction added</td>
1192
+ </tr>
1193
+ <tr>
1194
+ <td><code>threadID</code></td>
1195
+ <td>ID of the thread where the message has been sent</td>
1196
+ </tr>
1197
+ <tr>
1198
+ <td><code>timestamp</code></td>
1199
+ <td>Unix Timestamp (in miliseconds) when the reaction was sent</td>
1200
+ </tr>
1201
+ <tr>
1202
+ <td><code>type</code></td>
1203
+ <td>For this event type, this will always be the string <code>"message_reaction"</code>.</td>
1204
+ </tr>
1205
+ <tr>
1206
+ <td><code>userID</code></td>
1207
+ <td>ID of the reaction sender</td>
1208
+ </tr>
1209
+ <tr>
1210
+ <td rowspan="4"><a name="presence"></a>
1211
+ <code>"presence"</code><br />
1212
+ The online status of the user's friends. Note that receiving this event type needs to be enabled with <code>api.setOptions({ updatePresence: true })</code>
1213
+ </td>
1214
+ <td><code>statuses</code></td>
1215
+ <td>The online status of the user. <code>0</code> means the user is idle (away for 2 minutes) and <code>2</code> means the user is online (we don't know what 1 or above 2 means...).</td>
1216
+ </tr>
1217
+ <tr>
1218
+ <td><code>timestamp</code></td>
1219
+ <td>The time when the user was last online.</td>
1220
+ </tr>
1221
+ <tr>
1222
+ <td><code>type</code></td>
1223
+ <td>For this event type, this will always be the string <code>"presence"</code>.</td>
1224
+ </tr>
1225
+ <tr>
1226
+ <td><code>userID</code></td>
1227
+ <td>The ID of the user whose status this packet is describing.</td>
1228
+ </tr>
1229
+ <tr>
1230
+ <td rowspan="5">
1231
+ <code>"message_unsend"</code><br />
1232
+ A revoke message request for a message from a thread was received.
1233
+ </td>
1234
+ <td><code>threadID</code></td>
1235
+ <td>The threadID representing the thread in which the revoke message request was received.</td>
1236
+ </tr>
1237
+ <tr>
1238
+ <td><code>senderID</code></td>
1239
+ <td>The id of the person who request to revoke message on threadID.</td>
1240
+ </tr>
1241
+ <tr>
1242
+ <td><code>messageID</code></td>
1243
+ <td>A string representing the message ID that the person request to revoke message want to.</td>
1244
+ </tr>
1245
+ <tr>
1246
+ <td><code>deletionTimestamp</code></td>
1247
+ <td>The time when the request was sent.</td>
1248
+ </tr>
1249
+ <tr>
1250
+ <td><code>type</code></td>
1251
+ <td>For this event type, this will always be the string <code>"message_unsend"</code>.</td>
1252
+ </tr>
1253
+ <tr>
1254
+ <td rowspan="11">
1255
+ <code>"message_reply"</code><br />
1256
+ A reply message was sent to a thread.
1257
+ </td>
1258
+ <td><code>attachments</code></td>
1259
+ <td>An array of attachments to the message. Attachments vary in type, see the attachments table below.</td>
1260
+ </tr>
1261
+ <tr>
1262
+ <td><code>body</code></td>
1263
+ <td>The string corresponding to the message that was just received.</td>
1264
+ </tr>
1265
+ <tr>
1266
+ <td><code>isGroup</code></td>
1267
+ <td>boolean, true if this thread is a group thread (more than 2 participants).</td>
1268
+ </tr>
1269
+ <tr>
1270
+ <td><code>mentions</code></td>
1271
+ <td>An object containing people mentioned/tagged in the message in the format { id: name }</td>
1272
+ </tr>
1273
+ <tr>
1274
+ <td><code>messageID</code></td>
1275
+ <td>A string representing the message ID.</td>
1276
+ </tr>
1277
+ <tr>
1278
+ <td><code>senderID</code></td>
1279
+ <td>The id of the person who sent the message in the chat with threadID.</td>
1280
+ </tr>
1281
+ <tr>
1282
+ <td><code>threadID</code></td>
1283
+ <td>The threadID representing the thread in which the message was sent.</td>
1284
+ </tr>
1285
+ <tr>
1286
+ <td><code>isUnread</code></td>
1287
+ <td>Boolean representing whether or not the message was read.</td>
1288
+ </tr>
1289
+ <tr>
1290
+ <td><code>type</code></td>
1291
+ <td>For this event type, this will always be the string <code>"message_reply"</code>.</td>
1292
+ </tr>
1293
+ <tr>
1294
+ <td><code>participantIDs</code></td>
1295
+ <td>An array containing participant IDs.</td>
1296
+ </tr>
1297
+ <tr>
1298
+ <td><code>messageReply</code></td>
1299
+ <td>An object represent a message being replied. Content inside is the same like a normal <code>"message"</code> event.</td>
1300
+ </tr>
1301
+ </table>
1302
+
1303
+ __Attachments__
1304
+
1305
+ Similar to how messages can vary based on their `type`, so too can the `attachments` within `"message"` events. Each attachment will consist of an object of one of the following types:
1306
+
1307
+ | Attachment Type | Fields |
1308
+ | --------------- | ------ |
1309
+ | `"sticker"` | `ID`, `url`, `packID`, `spriteUrl`, `spriteUrl2x`, `width`, `height`, `caption`, `description`, `frameCount`, `frameRate`, `framesPerRow`, `framesPerCol` |
1310
+ | `"file"` | `ID`, `filename`, `url`, `isMalicious`, `contentType` |
1311
+ | `"photo"` | `ID`, `filename`, `thumbnailUrl`, `previewUrl`, `previewWidth`, `previewHeight`, `largePreviewUrl`, `largePreviewWidth`, `largePreviewHeight` |
1312
+ | `"animated_image"` | `ID`, `filename`, `previewUrl`, `previewWidth`, `previewHeight`, `url`, `width`, `height` |
1313
+ | `"video"` | `ID`, `filename`, `previewUrl`, `previewWidth`, `previewHeight`, `url`, `width`, `height`, `duration`, `videoType` |
1314
+ | `"audio"` | `ID`, `filename`, `audioType`, `duration`, `url`, `isVoiceMail` |
1315
+ | `"location"` | `ID`, `latitude`, `longitude`, `image`, `width`, `height`, `url`, `address` |
1316
+ | `"share"` | `ID`, `url`, `title`, `description`, `source`, `image`, `width`, `height`, `playable`, `duration`, `playableUrl`, `subattachments`, `properties` |
1317
+
1318
+ __Example__
1319
+
1320
+ ```js
1321
+ const fs = require("fs");
1322
+ const login = require("nexus-fca");
1323
+
1324
+ // Simple echo bot. He'll repeat anything that you say.
1325
+ // Will stop when you say '/stop'
1326
+
1327
+ login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
1328
+ if(err) return console.error(err);
1329
+
1330
+ api.setOptions({listenEvents: true});
1331
+
1332
+ var listenEmitter = api.listen((err, event) => {
1333
+ if(err) return console.error(err);
1334
+
1335
+ switch (event.type) {
1336
+ case "message":
1337
+ if(event.body === '/stop') {
1338
+ api.sendMessage("Goodbye...", event.threadID);
1339
+ return listenEmitter.stopListening();
1340
+ }
1341
+ api.markAsRead(event.threadID, (err) => {
1342
+ if(err) console.log(err);
1343
+ });
1344
+ api.sendMessage("TEST BOT: " + event.body, event.threadID);
1345
+ break;
1346
+ case "event":
1347
+ console.log(event);
1348
+ break;
1349
+ }
1350
+ });
1351
+ });
1352
+ ```
1353
+
1354
+ ---------------------------------------
1355
+
1356
+ <a name="logout"></a>
1357
+ ### api.logout([callback])
1358
+
1359
+ Logs out the current user.
1360
+
1361
+ __Arguments__
1362
+
1363
+ * `callback(err)`: A callback called when the query is done (either with an error or with null).
1364
+
1365
+ ---------------------------------------
1366
+
1367
+ <a name="markAsDelivered"></a>
1368
+ ### api.markAsDelivered(threadID, messageID[, callback]])
1369
+
1370
+ Given a threadID and a messageID will mark that message as delivered. If a message is marked as delivered that tells facebook servers that it was recieved.
1371
+
1372
+ You can also mark new messages as delivered automatically. This is enabled by default. See [api.setOptions](#setOptions).
1373
+
1374
+ __Arguments__
1375
+
1376
+ * `threadID` - The id of the thread in which you want to mark the message as delivered.
1377
+ * `messageID` - The id of the message want to mark as delivered.
1378
+ * `callback(err)` - A callback called when the operation is done maybe with an object representing an error.
1379
+
1380
+ __Example__
1381
+
1382
+ ```js
1383
+ const fs = require("fs");
1384
+ const login = require("nexus-fca");
1385
+
1386
+ login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
1387
+ if(err) return console.error(err);
1388
+
1389
+ api.listen((err, message) => {
1390
+ if(err) return console.error(err);
1391
+
1392
+ // Marks messages as delivered immediately after they're received
1393
+ api.markAsDelivered(message.threadID, message.messageID);
1394
+ });
1395
+ });
1396
+ ```
1397
+
1398
+ ---------------------------------------
1399
+
1400
+ <a name="markAsRead"></a>
1401
+ ### api.markAsRead(threadID, [read[, callback]])
1402
+
1403
+ Given a threadID will mark all the unread messages in a thread as read. Facebook will take a couple of seconds to show that you've read the messages.
1404
+
1405
+ You can also mark new messages as read automatically. See [api.setOptions](#setOptions). But be careful, this will make your account getting banned, especially when receiving *HUGE* amount of messages.
1406
+
1407
+ __Arguments__
1408
+
1409
+ * `threadID` - The id of the thread in which you want to mark the messages as read.
1410
+ * `read` - An optional boolean where `true` means to mark the message as being "read" and `false` means to mark the message as being "unread".
1411
+ * `callback(err)` - A callback called when the operation is done maybe with an object representing an error.
1412
+
1413
+ __Example__
1414
+
1415
+ ```js
1416
+ const fs = require("fs");
1417
+ const login = require("nexus-fca");
1418
+
1419
+ login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
1420
+ if(err) return console.error(err);
1421
+
1422
+ api.listen((err, message) => {
1423
+ if(err) return console.error(err);
1424
+
1425
+ // Marks messages as read immediately after they're received
1426
+ api.markAsRead(message.threadID);
1427
+ });
1428
+ });
1429
+ ```
1430
+
1431
+ ---------------------------------------
1432
+
1433
+ <a name="markAsReadAll"></a>
1434
+ ### api.markAsReadAll([callback])
1435
+
1436
+ This function will mark all of messages in your inbox readed.
1437
+
1438
+ ---------------------------------------
1439
+
1440
+ <a name="markAsSeen"></a>
1441
+ ### api.markAsSeen([seenTimestamp][, callback])
1442
+
1443
+ This function will mark your entire inbox as seen (don't be confused with read!).
1444
+
1445
+ ---------------------------------------
1446
+
1447
+ <a name="muteThread"></a>
1448
+ ### api.muteThread(threadID, muteSeconds[, callback])
1449
+
1450
+ Mute a chat for a period of time, or unmute a chat.
1451
+
1452
+ __Arguments__
1453
+
1454
+ * `threadID` - The ID of the chat you want to mute.
1455
+ * `muteSeconds` - Mute the chat for this amount of seconds. Use `0` to unmute a chat. Use '-1' to mute a chat indefinitely.
1456
+ * `callback(err)` - A callback called when the operation is done maybe with an object representing an error.
1457
+
1458
+ __Example__
1459
+
1460
+ ```js
1461
+ const fs = require("fs");
1462
+ const login = require("nexus-fca");
1463
+
1464
+ login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
1465
+ if(err) return console.error(err);
1466
+
1467
+ api.listen((err, message) => {
1468
+ if(err) return console.error(err);
1469
+
1470
+ // Mute all incoming chats for one minute
1471
+ api.muteThread(message.threadID, 60);
1472
+ });
1473
+ });
1474
+ ```
1475
+
1476
+ ---------------------------------------
1477
+
1478
+ <a name="removeUserFromGroup"></a>
1479
+ ### api.removeUserFromGroup(userID, threadID[, callback])
1480
+
1481
+ Removes a user from a group chat.
1482
+
1483
+ __Arguments__
1484
+
1485
+ * `userID`: User ID.
1486
+ * `threadID`: Group chat ID.
1487
+ * `callback(err)`: A callback called when the query is done (either with an error or with no arguments).
1488
+
1489
+ ---------------------------------------
1490
+
1491
+ <a name="resolvePhotoUrl"></a>
1492
+ ### api.resolvePhotoUrl(photoID, callback)
1493
+
1494
+ Resolves the URL to the full-size photo, given its ID. This function is useful for retrieving the full-size photo URL
1495
+ of image attachments in messages, returned by [`api.getThreadHistory`](#getThreadHistory).
1496
+
1497
+ __Arguments__
1498
+
1499
+ * `photoID`: Photo ID.
1500
+ * `callback(err, url)`: A callback called when the query is done (either with an error or with the photo's URL). `url` is a string with the photo's URL.
1501
+
1502
+ ---------------------------------------
1503
+
1504
+ <a name="searchForThread"></a>
1505
+ ### api.searchForThread(name, callback)
1506
+
1507
+ > This part is outdated.
1508
+ > see #396
1509
+
1510
+ Takes a chat title (thread name) and returns matching results as a formatted threads array (ordered according to Facebook).
1511
+
1512
+ __Arguments__
1513
+ * `name`: A messageID string or messageID string array
1514
+ * `callback(err, obj)`: A callback called when the query is done (either with an error or a thread object). The object passed in the callback has the following shape: `threadID`, <del>`participants`</del>, `participantIDs`, `formerParticipants`, `name`, `nicknames`, `snippet`, `snippetHasAttachment`, `snippetAttachments`, `snippetSender`, `unreadCount`, `messageCount`, `imageSrc`, `timestamp`, `serverTimestamp`, `muteSettings`, `isCanonicalUser`, `isCanonical`, `canonicalFbid`, `isSubscribed`, `rootMessageThreadingID`, `folder`, `isArchived`, `recipientsLoadable`, `hasEmailParticipant`, `readOnly`, `canReply`, `composerEnabled`, `blockedParticipants`, `lastMessageID`
1515
+
1516
+ ---------------------------------------
1517
+
1518
+ <a name="sendMessage"></a>
1519
+ ### api.sendMessage(message, threadID[, callback][, messageID])
1520
+
1521
+ Sends the given message to the threadID.
1522
+
1523
+ __Arguments__
1524
+
1525
+ * `message`: A string (for backward compatibility) or a message object as described below.
1526
+ * `threadID`: A string, number, or array representing a thread. It happens to be someone's userID in the case of a one to one conversation or an array of userIDs when starting a new group chat.
1527
+ * `callback(err, messageInfo)`: (Optional) A callback called when sending the message is done (either with an error or with an confirmation object). `messageInfo` contains the `threadID` where the message was sent and a `messageID`, as well as the `timestamp` of the message.
1528
+ * `messageID`: (Optional) A string representing a message you want to reply.
1529
+
1530
+ __Message Object__:
1531
+
1532
+ Various types of message can be sent:
1533
+ * *Regular:* set field `body` to the desired message as a string.
1534
+ * *Sticker:* set a field `sticker` to the desired sticker ID.
1535
+ * *File or image:* Set field `attachment` to a readable stream or an array of readable streams.
1536
+ * *URL:* set a field `url` to the desired URL.
1537
+ * *Emoji:* set field `emoji` to the desired emoji as a string and set field `emojiSize` with size of the emoji (`small`, `medium`, `large`)
1538
+ * *Mentions:* set field `mentions` to an array of objects. Objects should have the `tag` field set to the text that should be highlighted in the mention. The object should have an `id` field, where the `id` is the user id of the person being mentioned. The instance of `tag` that is highlighted is determined through indexOf, an optional `fromIndex`
1539
+ can be passed in to specify the start index to start searching for the `tag` text
1540
+ in `body` (default=0). (See below for an example.)
1541
+ * *Location:* set field `location` to an object with `latitude` and `longitude` fields. Optionally set field `current` of the `location` object to true to indicate the location is the user’s current location. Otherwise the location will be sent as a pinned location.
1542
+
1543
+ 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.
1544
+
1545
+ __Tip__: to find your own ID, you can look inside the cookies. The `userID` is under the name `c_user`.
1546
+
1547
+ __Example (Basic Message)__
1548
+ ```js
1549
+ const fs = require("fs");
1550
+ const login = require("nexus-fca");
1551
+
1552
+ login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
1553
+ if(err) return console.error(err);
1554
+
1555
+ var yourID = "000000000000000";
1556
+ var msg = {body: "Hey!"};
1557
+ api.sendMessage(msg, yourID);
1558
+ });
1559
+ ```
1560
+
1561
+ __Example (File upload)__
1562
+ ```js
1563
+ const fs = require("fs");
1564
+ const login = require("nexus-fca");
1565
+
1566
+ login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
1567
+ if(err) return console.error(err);
1568
+
1569
+ // This example uploads an image called image.jpg
1570
+ var yourID = "000000000000000";
1571
+ var msg = {
1572
+ body: "Hey!",
1573
+ attachment: fs.createReadStream(__dirname + '/image.jpg')
1574
+ }
1575
+ api.sendMessage(msg, yourID);
1576
+ });
1577
+ ```
1578
+
1579
+ __Example (Mention)__
1580
+ ```js
1581
+ const login = require("nexus-fca");
1582
+
1583
+ login({email: "EMAIL", password: "PASSWORD"}, (err, api) => {
1584
+ if(err) return console.error(err);
1585
+
1586
+ api.listen((err, message) => {
1587
+ if (message && message.body) {
1588
+ // Getting the actual sender name from ID involves calling
1589
+ // `api.getThreadInfo` and `api.getUserInfo`
1590
+ api.sendMessage({
1591
+ body: 'Hello @Sender! @Sender!',
1592
+ mentions: [{
1593
+ tag: '@Sender',
1594
+ id: message.senderID,
1595
+ fromIndex: 9, // Highlight the second occurrence of @Sender
1596
+ }],
1597
+ }, message.threadID);
1598
+ }
1599
+ });
1600
+ });
1601
+ ```
1602
+
1603
+ __Example (Location)__
1604
+ ```js
1605
+ const login = require("nexus-fca");
1606
+ login({email: "EMAIL", password: "PASSWORD"}, (err, api) => {
1607
+ if(err) return console.error(err);
1608
+ var yourID = "000000000000000";
1609
+ const msg = {
1610
+ location: { latitude: 48.858093, longitude: 2.294694, current: true },
1611
+ };
1612
+ api.sendMessage(msg, yourID);
1613
+ });
1614
+ ```
1615
+
1616
+ ---------------------------------------
1617
+
1618
+ <a name="sendTypingIndicator"></a>
1619
+ ### api.sendTypingIndicator(threadID[, callback])
1620
+
1621
+ Sends a "USERNAME is typing" indicator to other members of the thread indicated by `threadID`. This indication will disappear after 30 second or when the `end` function is called. The `end` function is returned by `api.sendTypingIndicator`.
1622
+
1623
+ __Arguments__
1624
+
1625
+ * `threadID`: Group chat ID.
1626
+ * `callback(err)`: A callback called when the query is done (with an error or with null).
1627
+
1628
+ ---------------------------------------
1629
+
1630
+ <a name="setMessageReaction"></a>
1631
+ ### api.setMessageReaction(reaction, messageID[, callback[, forceCustomReaction]])
1632
+
1633
+ Sets reaction on message
1634
+
1635
+ __Arguments__
1636
+
1637
+ * `reaction`: A string containing either an emoji, an emoji in unicode, or an emoji shortcut (see list of supported emojis below). The string can be left empty ("") in order to remove a reaction.
1638
+ * `messageID`: A string representing the message ID.
1639
+ * `callback(err)`: A callback called when sending the reaction is done.
1640
+ * `forceCustomReaction`: Forcing the use of an emoji for setting reaction **(WARNING: NOT TESTED, YOU SHOULD NOT USE THIS AT ALL, UNLESS YOU'RE TESTING A NEW EMOJI)**
1641
+
1642
+ __Supported Emojis__
1643
+
1644
+ |Emoji|Text|Unicode|Shortcuts|
1645
+ |---|---|---|---|
1646
+ |😍|`😍`|`\uD83D\uDE0D`|`:love:`, `:heart_eyes:`|
1647
+ |😆|`😆`|`\uD83D\uDE06`|`:haha:`, `:laughing:`|
1648
+ |😮|`😮`|`\uD83D\uDE2E`|`:wow:`, `:open_mouth:`|
1649
+ |😢|`😢`|`\uD83D\uDE22`|`:sad:`, `:cry:`|
1650
+ |😠|`😠`|`\uD83D\uDE20`|`:angry:`|
1651
+ |👍|`👍`|`\uD83D\uDC4D`|`:like:`, `:thumbsup:`|
1652
+ |👎|`👎`|`\uD83D\uDC4E`|`:dislike:`, `:thumbsdown:`|
1653
+ |❤|`❤`|`\u2764`|`:heart:`|
1654
+ |💗|`💗`|`\uD83D\uDC97`|`:glowingheart:`|
1655
+
1656
+ ---------------------------------------
1657
+
1658
+ <a name="setOptions"></a>
1659
+ ### api.setOptions(options)
1660
+
1661
+ Sets various configurable options for the api.
1662
+
1663
+ __Arguments__
1664
+
1665
+ * `options` - An object containing the new values for the options that you want
1666
+ to set. If the value for an option is unspecified, it is unchanged. The following options are possible.
1667
+ - `pauseLog`: (Default `false`) Set this to `true` if you want to pause the npmlog output.
1668
+ - `logLevel`: The desired logging level as determined by npmlog. Choose
1669
+ from either `"silly"`, `"verbose"`, `"info"`, `"http"`, `"warn"`, `"error"`, or `"silent"`.
1670
+ - `selfListen`: (Default `false`) Set this to `true` if you want your api
1671
+ to receive messages from its own account. This is to be used with
1672
+ caution, as it can result in loops (a simple echo bot will send messages
1673
+ forever).
1674
+ - `listenEvents`: (Default `false`) Will make [api.listen](#listen) also handle events (look at api.listen for more details).
1675
+ - `pageID`: (Default empty) Makes [api.listen](#listen) only receive messages through the page specified by that ID. Also makes [api.sendMessage](#sendMessage) send from the page.
1676
+ - `updatePresence`: (Default `false`) Will make [api.listen](#listen) also return `presence` ([api.listen](#presence) for more details).
1677
+ - `forceLogin`: (Default `false`) Will automatically approve of any recent logins and continue with the login process.
1678
+ - `userAgent`: (Default `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/600.3.18 (KHTML, like Gecko) Version/8.0.3 Safari/600.3.18`) The desired simulated User Agent.
1679
+ - `autoMarkDelivery`: (Default `true`) Will automatically mark new messages as delivered. See [api.markAsDelivered](#markAsDelivered).
1680
+ - `autoMarkRead`: (Default `false`) Will automatically mark new messages as read/seen. See [api.markAsRead](#markAsRead).
1681
+ - `proxy`: (Default empty) Set this to proxy server address to use proxy. Note: Only HTTP Proxies which support CONNECT method is supported.
1682
+ - `online`: (Default `true`) Set account's online state.
1683
+
1684
+ __Example__
1685
+
1686
+ ```js
1687
+ const fs = require("fs");
1688
+ const login = require("nexus-fca");
1689
+
1690
+ // Simple echo bot. This will send messages forever.
1691
+
1692
+ login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
1693
+ if(err) return console.error(err);
1694
+
1695
+ api.setOptions({
1696
+ selfListen: true,
1697
+ logLevel: "silent"
1698
+ });
1699
+
1700
+ api.listen((err, message) => {
1701
+ if(err) return console.error(err);
1702
+
1703
+ // Ignore empty messages (photos etc.)
1704
+ if (typeof message.body === "string") {
1705
+ api.sendMessage(message.body, message.threadID);
1706
+ }
1707
+ });
1708
+ });
1709
+ ```
1710
+
1711
+ ---------------------------------------
1712
+
1713
+ <a name="setTitle"></a>
1714
+ ### api.setTitle(newTitle, threadID[, callback])
1715
+
1716
+ Sets the title of the group chat with thread id `threadID` to `newTitle`.
1717
+
1718
+ Note: This will not work if the thread id corresponds to a single-user chat or if the bot is not in the group chat.
1719
+
1720
+ __Arguments__
1721
+
1722
+ * `newTitle`: A string representing the new title.
1723
+ * `threadID`: A string or number representing a thread. It happens to be someone's userID in the case of a one to one conversation.
1724
+ * `callback(err, obj)` - A callback called when sending the message is done (either with an error or with an confirmation object). `obj` contains only the threadID where the message was sent.
1725
+
1726
+ ---------------------------------------
1727
+
1728
+ <a name="unsendMessage"></a>
1729
+ ### api.unsendMessage(messageID[, callback])
1730
+
1731
+ Revokes a message from anyone that could see that message with `messageID`
1732
+
1733
+ Note: This will only work if the message is sent by you and was sent less than 10 minutes ago.
1734
+
1735
+ __Arguments__
1736
+
1737
+ * `messageID`: Message ID you want to unsend.
1738
+ * `callback(err)`: A callback called when the query is done (with an error or with null).
1739
+
1740
+ ---------------------------------------
1741
+
1742
+ # Advanced & Ported Features (Nexus-FCA)
1743
+
1744
+ Below are advanced features and modules ported from ws3-fca-main and custom-developed for Nexus-FCA. These provide extended capabilities beyond the standard Facebook Chat API. Use responsibly and review safety notes for each feature.
1745
+
1746
+ ## api.changeAvatarV2(imagePath, callback)
1747
+ Change your Facebook profile avatar using a local image file.
1748
+
1749
+ - **Arguments:**
1750
+ - `imagePath`: Path to the image file (string).
1751
+ - `callback(err, res)`: Callback with error or result.
1752
+ - **Example:**
1753
+ ```js
1754
+ api.changeAvatarV2('./avatar.jpg', (err, res) => {
1755
+ if (err) return console.error(err);
1756
+ console.log('Avatar changed!', res);
1757
+ });
1758
+ ```
1759
+ - **Safety Note:** Use images that comply with Facebook's community standards.
1760
+
1761
+ ## api.shareLink(url, threadID, callback)
1762
+ Share a link to a thread (group or user).
1763
+
1764
+ - **Arguments:**
1765
+ - `url`: The URL to share (string).
1766
+ - `threadID`: Target thread ID (string).
1767
+ - `callback(err, res)`: Callback with error or result.
1768
+ - **Example:**
1769
+ ```js
1770
+ api.shareLink('https://example.com', '1234567890', (err, res) => {
1771
+ if (err) return console.error(err);
1772
+ console.log('Link shared!', res);
1773
+ });
1774
+ ```
1775
+
1776
+ ## api.setProfileGuard(enable, callback)
1777
+ Enable or disable Facebook profile picture guard.
1778
+
1779
+ - **Arguments:**
1780
+ - `enable`: Boolean to enable (true) or disable (false) guard.
1781
+ - `callback(err, res)`: Callback with error or result.
1782
+ - **Example:**
1783
+ ```js
1784
+ api.setProfileGuard(true, (err, res) => {
1785
+ if (err) return console.error(err);
1786
+ console.log('Profile guard enabled!', res);
1787
+ });
1788
+ ```
1789
+
1790
+ ## api.setStoryReaction(storyID, reaction, callback)
1791
+ React to a Facebook story.
1792
+
1793
+ - **Arguments:**
1794
+ - `storyID`: The ID of the story (string).
1795
+ - `reaction`: Emoji or reaction string.
1796
+ - `callback(err, res)`: Callback with error or result.
1797
+ - **Example:**
1798
+ ```js
1799
+ api.setStoryReaction('story_id', '😍', (err, res) => {
1800
+ if (err) return console.error(err);
1801
+ console.log('Reacted to story!', res);
1802
+ });
1803
+ ```
1804
+
1805
+ ## api.setMessageReactionMqtt(messageID, reaction, callback)
1806
+ Set a message reaction using the MQTT protocol (advanced, faster, more reliable for some accounts).
1807
+
1808
+ - **Arguments:**
1809
+ - `messageID`: The message ID (string).
1810
+ - `reaction`: Emoji or reaction string.
1811
+ - `callback(err, res)`: Callback with error or result.
1812
+ - **Example:**
1813
+ ```js
1814
+ api.setMessageReactionMqtt('mid.$cAA...', '👍', (err, res) => {
1815
+ if (err) return console.error(err);
1816
+ console.log('Reaction sent!', res);
1817
+ });
1818
+ ```
1819
+
1820
+ ## api.changeBlockedStatusMqtt(userID, block, callback)
1821
+ Block or unblock a user using the MQTT protocol.
1822
+
1823
+ - **Arguments:**
1824
+ - `userID`: The user ID (string).
1825
+ - `block`: Boolean to block (true) or unblock (false).
1826
+ - `callback(err, res)`: Callback with error or result.
1827
+ - **Example:**
1828
+ ```js
1829
+ api.changeBlockedStatusMqtt('1000123456789', true, (err, res) => {
1830
+ if (err) return console.error(err);
1831
+ console.log('User blocked!', res);
1832
+ });
1833
+ ```
1834
+
1835
+ ## api.changeCover(imagePath, callback)
1836
+ Change your Facebook cover photo.
1837
+
1838
+ - **Arguments:**
1839
+ - `imagePath`: Path to the image file (string).
1840
+ - `callback(err, res)`: Callback with error or result.
1841
+ - **Example:**
1842
+ ```js
1843
+ api.changeCover('./cover.jpg', (err, res) => {
1844
+ if (err) return console.error(err);
1845
+ console.log('Cover photo changed!', res);
1846
+ });
1847
+ ```
1848
+
1849
+ ## api.changeName(newName, callback)
1850
+ Change your Facebook profile name.
1851
+
1852
+ - **Arguments:**
1853
+ - `newName`: New name (string).
1854
+ - `callback(err, res)`: Callback with error or result.
1855
+ - **Example:**
1856
+ ```js
1857
+ api.changeName('New Name', (err, res) => {
1858
+ if (err) return console.error(err);
1859
+ console.log('Name changed!', res);
1860
+ });
1861
+ ```
1862
+ - **Safety Note:** Changing your name too frequently may result in Facebook restrictions.
1863
+
1864
+ ## api.createCommentPost(postID, comment, callback)
1865
+ Comment on a Facebook post.
1866
+
1867
+ - **Arguments:**
1868
+ - `postID`: The post ID (string).
1869
+ - `comment`: Comment text (string).
1870
+ - `callback(err, res)`: Callback with error or result.
1871
+ - **Example:**
1872
+ ```js
1873
+ api.createCommentPost('1234567890', 'Nice post!', (err, res) => {
1874
+ if (err) return console.error(err);
1875
+ console.log('Comment posted!', res);
1876
+ });
1877
+ ```
1878
+
1879
+ ## api.createPost(content, callback)
1880
+ Create a new Facebook post.
1881
+
1882
+ - **Arguments:**
1883
+ - `content`: Post content (string).
1884
+ - `callback(err, res)`: Callback with error or result.
1885
+ - **Example:**
1886
+ ```js
1887
+ api.createPost('Hello, world!', (err, res) => {
1888
+ if (err) return console.error(err);
1889
+ console.log('Post created!', res);
1890
+ });
1891
+ ```
1892
+
1893
+ ## api.follow(userID, callback)
1894
+ Follow a Facebook user.
1895
+
1896
+ - **Arguments:**
1897
+ - `userID`: The user ID to follow (string).
1898
+ - `callback(err, res)`: Callback with error or result.
1899
+ - **Example:**
1900
+ ```js
1901
+ api.follow('1000123456789', (err, res) => {
1902
+ if (err) return console.error(err);
1903
+ console.log('Now following user!', res);
1904
+ });
1905
+ ```
1906
+
1907
+ ## api.getAccess(callback)
1908
+ Get your current Facebook access token (advanced usage).
1909
+
1910
+ - **Arguments:**
1911
+ - `callback(err, token)`: Callback with error or access token string.
1912
+ - **Example:**
1913
+ ```js
1914
+ api.getAccess((err, token) => {
1915
+ if (err) return console.error(err);
1916
+ console.log('Access token:', token);
1917
+ });
1918
+ ```
1919
+ - **Safety Note:** Keep your access token private.
1920
+
1921
+ ## api.getAvatarUser(userID, callback)
1922
+ Get the avatar (profile picture) of a user.
1923
+
1924
+ - **Arguments:**
1925
+ - `userID`: The user ID (string).
1926
+ - `callback(err, url)`: Callback with error or avatar URL.
1927
+ - **Example:**
1928
+ ```js
1929
+ api.getAvatarUser('1000123456789', (err, url) => {
1930
+ if (err) return console.error(err);
1931
+ console.log('Avatar URL:', url);
1932
+ });
1933
+ ```
1934
+
1935
+ ## api.getCtx(callback)
1936
+ Get the current Facebook context/session info.
1937
+
1938
+ - **Arguments:**
1939
+ - `callback(err, ctx)`: Callback with error or context object.
1940
+ - **Example:**
1941
+ ```js
1942
+ api.getCtx((err, ctx) => {
1943
+ if (err) return console.error(err);
1944
+ console.log('Context:', ctx);
1945
+ });
1946
+ ```
1947
+
1948
+ ## api.getOptions(callback)
1949
+ Get the current Nexus-FCA options.
1950
+
1951
+ - **Arguments:**
1952
+ - `callback(err, options)`: Callback with error or options object.
1953
+ - **Example:**
1954
+ ```js
1955
+ api.getOptions((err, options) => {
1956
+ if (err) return console.error(err);
1957
+ console.log('Options:', options);
1958
+ });
1959
+ ```
1960
+
1961
+ ## api.getRegion(callback)
1962
+ Get your current Facebook region info.
1963
+
1964
+ - **Arguments:**
1965
+ - `callback(err, region)`: Callback with error or region string/object.
1966
+ - **Example:**
1967
+ ```js
1968
+ api.getRegion((err, region) => {
1969
+ if (err) return console.error(err);
1970
+ console.log('Region:', region);
1971
+ });
1972
+ ```
1973
+
1974
+ ## api.getThreadHistoryDeprecated(...)
1975
+ ## api.getThreadInfoDeprecated(...)
1976
+ ## api.getThreadListDeprecated(...)
1977
+ Legacy versions of thread history/info/list. Use only if the main methods do not work for your account. Arguments are similar to their non-deprecated counterparts.
1978
+
1979
+ - **Safety Note:** Deprecated methods may be removed in future versions.
1980
+
1981
+ ## api.getUID(username, callback)
1982
+ Get the Facebook user ID from a username.
1983
+
1984
+ - **Arguments:**
1985
+ - `username`: The Facebook username (string).
1986
+ - `callback(err, userID)`: Callback with error or user ID.
1987
+ - **Example:**
1988
+ ```js
1989
+ api.getUID('zuck', (err, userID) => {
1990
+ if (err) return console.error(err);
1991
+ console.log('User ID:', userID);
1992
+ });
1993
+ ```
1994
+
1995
+ ## api.listenNotification(callback)
1996
+ Listen for Facebook notifications (advanced, experimental).
1997
+
1998
+ - **Arguments:**
1999
+ - `callback(err, notification)`: Callback with error or notification object.
2000
+ - **Example:**
2001
+ ```js
2002
+ api.listenNotification((err, notification) => {
2003
+ if (err) return console.error(err);
2004
+ console.log('Notification:', notification);
2005
+ });
2006
+ ```
2007
+
2008
+ ## api.searchStickers(query, callback)
2009
+ Search for Facebook stickers by keyword.
2010
+
2011
+ - **Arguments:**
2012
+ - `query`: Search keyword (string).
2013
+ - `callback(err, stickers)`: Callback with error or sticker array.
2014
+ - **Example:**
2015
+ ```js
2016
+ api.searchStickers('cat', (err, stickers) => {
2017
+ if (err) return console.error(err);
2018
+ console.log('Stickers:', stickers);
2019
+ });
2020
+ ```
2021
+
2022
+ ## api.sendComment(postID, comment, callback)
2023
+ Send a comment to a Facebook post.
2024
+
2025
+ - **Arguments:**
2026
+ - `postID`: The post ID (string).
2027
+ - `comment`: Comment text (string).
2028
+ - `callback(err, res)`: Callback with error or result.
2029
+ - **Example:**
2030
+ ```js
2031
+ api.sendComment('1234567890', 'Great post!', (err, res) => {
2032
+ if (err) return console.error(err);
2033
+ console.log('Comment sent!', res);
2034
+ });
2035
+ ```
2036
+
2037
+ ## api.stopListenMqtt()
2038
+ Stop the MQTT listener (advanced, for bots/services that need to cleanly disconnect).
2039
+
2040
+ - **Example:**
2041
+ ```js
2042
+ api.stopListenMqtt();
2043
+ ```
2044
+
2045
+ ---------------------------------------
2046
+
2047
+ For more details and per-feature guides, see the `doc/` folder (if available) or the source code in `src/`.