chards-script 1.0.3

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.

Potentially problematic release.


This version of chards-script might be problematic. Click here for more details.

Files changed (116) hide show
  1. package/.cache/replit/__replit_disk_meta.json +1 -0
  2. package/.cache/replit/modules.stamp +1 -0
  3. package/.cache/replit/nix/env.json +1 -0
  4. package/.config/configstore/update-notifier-npm.json +4 -0
  5. package/.replit +89 -0
  6. package/.upm/store.json +1 -0
  7. package/CountTime.json +1 -0
  8. package/Extra/Database/index.js +469 -0
  9. package/Extra/ExtraAddons.js +82 -0
  10. package/Extra/ExtraFindUID.js +62 -0
  11. package/Extra/ExtraGetThread.js +340 -0
  12. package/Extra/ExtraScreenShot.js +430 -0
  13. package/Extra/ExtraUptimeRobot.js +38 -0
  14. package/Extra/Html/Classic/script.js +119 -0
  15. package/Extra/Html/Classic/style.css +60 -0
  16. package/Extra/Security/Index.js +173 -0
  17. package/Extra/Security/Step_1.js +6 -0
  18. package/Extra/Security/Step_2.js +22 -0
  19. package/Extra/Security/Step_3.js +22 -0
  20. package/Extra/Src/Change_Environment.js +24 -0
  21. package/Extra/Src/Check_Update.js +67 -0
  22. package/Extra/Src/History.js +115 -0
  23. package/Extra/Src/Instant_Update.js +65 -0
  24. package/Extra/Src/Last-Run.js +65 -0
  25. package/Extra/Src/Release_Memory.js +41 -0
  26. package/Extra/Src/Websocket.js +213 -0
  27. package/Extra/Src/image/checkmate.jpg +0 -0
  28. package/Extra/Src/uuid.js +137 -0
  29. package/Func/AcceptAgreement.js +31 -0
  30. package/Func/ClearCache.js +64 -0
  31. package/Func/ReportV1.js +54 -0
  32. package/Index.js +383 -0
  33. package/Language/index.json +217 -0
  34. package/Main.js +1228 -0
  35. package/README.md +2172 -0
  36. package/SECURITY.md +18 -0
  37. package/broadcast.js +40 -0
  38. package/logger.js +66 -0
  39. package/package.json +133 -0
  40. package/replit.nix +9 -0
  41. package/src/Dev_Horizon_Data.js +125 -0
  42. package/src/Premium.js +25 -0
  43. package/src/Screenshot.js +83 -0
  44. package/src/addExternalModule.js +16 -0
  45. package/src/addUserToGroup.js +79 -0
  46. package/src/changeAdminStatus.js +79 -0
  47. package/src/changeArchivedStatus.js +41 -0
  48. package/src/changeAvt.js +85 -0
  49. package/src/changeBio.js +65 -0
  50. package/src/changeBlockedStatus.js +36 -0
  51. package/src/changeGroupImage.js +106 -0
  52. package/src/changeNickname.js +45 -0
  53. package/src/changeThreadColor.js +62 -0
  54. package/src/changeThreadEmoji.js +42 -0
  55. package/src/createNewGroup.js +70 -0
  56. package/src/createPoll.js +60 -0
  57. package/src/deleteMessage.js +45 -0
  58. package/src/deleteThread.js +43 -0
  59. package/src/forwardAttachment.js +48 -0
  60. package/src/getAccessToken.js +28 -0
  61. package/src/getCurrentUserID.js +7 -0
  62. package/src/getEmojiUrl.js +27 -0
  63. package/src/getFriendsList.js +73 -0
  64. package/src/getMessage.js +80 -0
  65. package/src/getThreadHistory.js +537 -0
  66. package/src/getThreadInfo.js +425 -0
  67. package/src/getThreadList.js +213 -0
  68. package/src/getThreadMain.js +220 -0
  69. package/src/getThreadPictures.js +59 -0
  70. package/src/getUID.js +59 -0
  71. package/src/getUserID.js +62 -0
  72. package/src/getUserInfo.js +113 -0
  73. package/src/getUserInfoMain.js +65 -0
  74. package/src/getUserInfoV2.js +34 -0
  75. package/src/getUserInfoV3.js +63 -0
  76. package/src/getUserInfoV4.js +55 -0
  77. package/src/getUserInfoV5.js +61 -0
  78. package/src/handleFriendRequest.js +46 -0
  79. package/src/handleMessageRequest.js +49 -0
  80. package/src/httpGet.js +49 -0
  81. package/src/httpPost.js +48 -0
  82. package/src/httpPostFormData.js +41 -0
  83. package/src/listenMqtt.js +797 -0
  84. package/src/logout.js +68 -0
  85. package/src/markAsDelivered.js +48 -0
  86. package/src/markAsRead.js +70 -0
  87. package/src/markAsReadAll.js +43 -0
  88. package/src/markAsSeen.js +51 -0
  89. package/src/muteThread.js +47 -0
  90. package/src/removeUserFromGroup.js +49 -0
  91. package/src/resolvePhotoUrl.js +37 -0
  92. package/src/searchForThread.js +43 -0
  93. package/src/sendMessage.js +379 -0
  94. package/src/sendTypingIndicator.js +80 -0
  95. package/src/setMessageReaction.js +109 -0
  96. package/src/setPostReaction.js +102 -0
  97. package/src/setTitle.js +74 -0
  98. package/src/threadColors.js +39 -0
  99. package/src/unfriend.js +43 -0
  100. package/src/unsendMessage.js +40 -0
  101. package/test/Database_Test.js +4 -0
  102. package/test/Db2.js +530 -0
  103. package/test/Horizon_Database/A_README.md +1 -0
  104. package/test/Horizon_Database/Database.db +0 -0
  105. package/test/data/shareAttach.js +146 -0
  106. package/test/data/something.mov +0 -0
  107. package/test/data/test.png +0 -0
  108. package/test/data/test.txt +7 -0
  109. package/test/env/.env +0 -0
  110. package/test/example-config.json +18 -0
  111. package/test/example-db.db +0 -0
  112. package/test/memoryleak.js +18 -0
  113. package/test/test-page.js +140 -0
  114. package/test/test.js +385 -0
  115. package/test/testv2.js +18 -0
  116. package/utils.js +1684 -0
package/README.md ADDED
@@ -0,0 +1,2172 @@
1
+ <!-- # ◉ UNOFFICIAL FACEBOOK CHAT API ◉ -->
2
+
3
+ <h1 align="center">
4
+ <code>◉ UNOFFICIAL FACEBOOK CHAT API ◉</code>
5
+ </h1>
6
+ <h3 align="center"></h3>
7
+
8
+ <p align="center">
9
+ <a aria-label="NPM Version" href="https://www.npmjs.com/package/chards-script">
10
+ <img alt="" src="https://img.shields.io/npm/v/chards-script.svg?label=NPM&logo=npm&style=for-the-badge&color=F2984A&logoColor=white">
11
+ </a>
12
+ <a aria-label="NPM Download Count" href="https://www.npmjs.com/package/chards-script">
13
+ <img alt="" src="https://img.shields.io/npm/dt/chards-script?label=Downloads&style=for-the-badge&color=D2667B">
14
+ </a>
15
+ <a aria-label="chards-script Size" href="https://www.npmjs.com/package/chards-script">
16
+ <img alt="" src="https://img.shields.io/bundlephobia/minzip/chards-script?style=for-the-badge&color=8B77CD">
17
+ </a>
18
+ <a aria-label="Join the community on Slack" href="https://join.slack.com/t/chards-scriptworkspace/shared_invite/zt-1y1g3570m-Hx_N3IShMYBMkR6jpRyRjw">
19
+ <img alt="" src="https://img.shields.io/badge/Slack-339AE0?style=for-the-badge&logo=slack&logoColor=white&label=Community">
20
+ </a>
21
+ </p>
22
+
23
+ ## 🤝🏻 Connect With ChardsScript
24
+
25
+ [![MIT License][license-image]][license-url]
26
+ [![npm dependents](https://badgen.net/npm/dependents/chards-script)](https://www.npmjs.com/package/chards-script?activeTab=dependents)
27
+ [![Downloads](https://badgen.net/npm/dt/chards-script)](https://www.npmjs.com/package/chards-script)
28
+ [![run on repl.it](https://img.shields.io/badge/Run_on_Replit-f26207?logo=replit&logoColor=white)](https://repl.it/github/chalk/chalk)
29
+
30
+ [license-image]: https://img.shields.io/badge/license-MIT-blue.svg?style=flat
31
+ [license-url]: LICENSE
32
+
33
+ ## Important !
34
+
35
+ + This package requires NodeJS 14.17.0 to work properly.
36
+ + All credits goes to the rightful owner and amazing individuals who have make and also contribute to build this package, me/myself is not allowed to gain credits on this and I can do only maintain and update the package as much as I can.
37
+
38
+ ## Support For :
39
+
40
+ + Support English, Vietnamese !,
41
+ + All bots if using listenMqtt first.
42
+
43
+ # Security Policy
44
+
45
+ + if have any Vulnerability finded contact: Author(KanzuWakazaki.Main@proton.me) or (Facebook.com/Lazic.Kanzu). Thanks!
46
+
47
+ + else you can contact the unofficial maintainer of this Fca.
48
+
49
+ ## Supported Versions
50
+
51
+ Use this section to tell people about which versions of your project are
52
+ currently being supported with security updates.
53
+
54
+ | Version | Supported |
55
+ | ------- | ------------------ |
56
+ | StableVersion | :white_check_mark: |
57
+ | AutoUpdate | :white_check_mark:|
58
+ | Modified | :white_check_mark:
59
+
60
+ ## Reporting a Vulnerability
61
+
62
+ Contact Author / Maintainer or create pull!
63
+
64
+ # API for Messenger Chatbots
65
+
66
+ Facebook now has API for creating chatbots [Here](https://developers.facebook.com/docs/messenger-platform).
67
+
68
+ ### This API might cause your account to be flagged like you've never experienced before, be careful.
69
+
70
+ Note! If you want to use this API, check the document at [Here](https://github.com/Schmavery/facebook-chat-api).
71
+
72
+ ## Download
73
+
74
+ #### If you have a chards-script.zip file
75
+
76
+ ##### Sample Replit SETUP
77
+
78
+ + 1st step:
79
+ ```shell
80
+ unzip chards-script.zip
81
+ ```
82
+
83
+ + 2nd step:
84
+ ```shell
85
+ cd chards-script
86
+ ```
87
+
88
+ + 3rd step:
89
+ ```shell
90
+ npm i
91
+ ```
92
+
93
+ + then back to local
94
+ ```shell
95
+ cd ..
96
+ ```
97
+
98
+ ## NPM
99
+
100
+ + If want to installed from npm
101
+
102
+ ```shell
103
+ npm i chards-script@latest
104
+ ```
105
+
106
+ ## If You Want to Test the API
107
+
108
+ + The benefits for doing this are that you won't waste time on flagged accounts and you'll have an account Use it with a testing account : [Facebook Whitehat Accounts](https://www.facebook.com/whitehat/accounts/).
109
+
110
+ ## How to Use
111
+
112
+ ```javascript
113
+ const login = require("chards-script"); // get it from the library
114
+
115
+ // logging in
116
+ login({email: "email", password: "password"}, (err, api) => {
117
+
118
+ if(err) return console.error(err); // error case
119
+
120
+ // create a bot that mimics you automatically:
121
+ api.listenMqtt((err, message) => {
122
+ api.sendMessage(message.body, message.threadID);
123
+ });
124
+
125
+ });
126
+ ```
127
+
128
+ + The result is that it will mimic you as shown below:
129
+ <img width="517" alt="screen shot 2016-11-04 at 14 36 00.jpg" src="https://raw.githubusercontent.com/richardcabaelretada/Unofficial-script/main/prefix_bot.png">
130
+
131
+ + If you want advanced usage, use the listed types of bots above!
132
+
133
+ ## List
134
+
135
+ You can read the full API documentation at => [here](DOCS.md).
136
+
137
+ ## Installation for Mirai:
138
+
139
+ You need to go to the Mirai.js file, then find this line
140
+ ```js
141
+ var login = require('a bot');
142
+ /* It can be :
143
+ var login = require('chards-script');
144
+ ...
145
+ */
146
+ ```
147
+
148
+ And replace it with:
149
+
150
+ ```js
151
+ var login = require('chards-script')
152
+ ```
153
+
154
+ After that, just run it as usual!
155
+
156
+ ## Self Study
157
+
158
+ + If you want to study or create a bot for yourself, go to this link to read its features and how to use it => [Link](https://github.com/Schmavery/facebook-chat-api#Unofficial%20Facebook%20Chat%20API)
159
+
160
+ ------------------------------------
161
+
162
+ ### Saving Login Information.
163
+
164
+ + To save it, you need a state like (Cookie, etc,..) to save it or use the login code above to log in!
165
+
166
+ + And this mode is already available in some Vietnamese bots, so you can rest assured!
167
+
168
+ __Guide to Using AppState__
169
+
170
+ ```js
171
+ const fs = require("fs");
172
+ const login = require("chards-script");
173
+
174
+ var credentials = {email: "FB_EMAIL", password: "FB_PASSWORD"}; // account information
175
+
176
+ login(credentials, (err, api) => {
177
+ if(err) return console.error(err);
178
+ // logging in
179
+ fs.writeFileSync('appstate.json', JSON.stringify(api.getAppState(), null,'\t')); // create appstate
180
+ });
181
+ ```
182
+
183
+ + Or, easier (more professional), you can use => [c3c-fbstate](https://github.com/c3cbot/c3c-fbstate) to get Fbstate and then rename it to Apstate! (appstate.json)
184
+
185
+ ------------------------------------
186
+
187
+ ## FAQs
188
+
189
+ FAQs => [Link](https://github.com/Schmavery/facebook-chat-api#FAQS)
190
+
191
+ # Documentation
192
+
193
+ - [`login`](#login)
194
+ - [`api.addUserToGroup`](#addUserToGroup)
195
+ - [`api.changeAdminStatus`](#changeAdminStatus)
196
+ - [`api.changeApprovalMode`](#changeApprovalMode)
197
+ - [`api.changeArchivedStatus`](#changeArchivedStatus)
198
+ - [`api.changeBlockedStatus`](#changeBlockedStatus)
199
+ - [`api.changeGroupImage`](#changeGroupImage)
200
+ - [`api.changeNickname`](#changeNickname)
201
+ - [`api.changeThreadColor`](#changeThreadColor)
202
+ - [`api.changeThreadEmoji`](#changeThreadEmoji)
203
+ - [`api.createNewGroup`](#createNewGroup)
204
+ - [`api.createPoll`](#createPoll)
205
+ - [`api.deleteMessage`](#deleteMessage)
206
+ - [`api.deleteThread`](#deleteThread)
207
+ - [`api.forwardAttachment`](#forwardAttachment)
208
+ - [`api.getAppState`](#getAppState)
209
+ - [`api.getCurrentUserID`](#getCurrentUserID)
210
+ - [`api.getEmojiUrl`](#getEmojiUrl)
211
+ - [`api.getFriendsList`](#getFriendsList)
212
+ - [`api.getThreadHistory`](#getThreadHistory)
213
+ - [`api.getThreadInfo`](#getThreadInfo)
214
+ - [`api.getThreadList`](#getThreadList)
215
+ - [`api.getThreadPictures`](#getThreadPictures)
216
+ - [`api.getUserID`](#getUserID)
217
+ - [`api.getUserInfo`](#getUserInfo)
218
+ - [`api.handleMessageRequest`](#handleMessageRequest)
219
+ - [`api.listen`](#listen)
220
+ - [`api.listenMqtt`](#listenMqtt)
221
+ - [`api.logout`](#logout)
222
+ - [`api.markAsDelivered`](#markAsDelivered)
223
+ - [`api.markAsRead`](#markAsRead)
224
+ - [`api.markAsReadAll`](#markAsReadAll)
225
+ - [`api.markAsSeen`](#markAsSeen)
226
+ - [`api.muteThread`](#muteThread)
227
+ - [`api.removeUserFromGroup`](#removeUserFromGroup)
228
+ - [`api.resolvePhotoUrl`](#resolvePhotoUrl)
229
+ - [`api.searchForThread`](#searchForThread)
230
+ - [`api.sendMessage`](#sendMessage)
231
+ - [`api.sendTypingIndicator`](#sendTypingIndicator)
232
+ - [`api.setMessageReaction`](#setMessageReaction)
233
+ - [`api.setOptions`](#setOptions)
234
+ - [`api.setTitle`](#setTitle)
235
+ - [`api.threadColors`](#threadColors)
236
+ - [`api.unsendMessage`](#unsendMessage)
237
+
238
+ ---
239
+
240
+ ### Password safety
241
+
242
+ **Read this** before you _copy+paste_ examples from below.
243
+
244
+ You should not store Facebook password in your scripts.
245
+ There are few good reasons:
246
+
247
+ - People who are standing behind you may look at your "code" and get your password if it is on the screen
248
+ - 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_"
249
+ - 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.
250
+ - 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
251
+
252
+ Preferred method is to have `login.js` that saves `AppState` to a file and then use that file from all your scripts.
253
+ This way you can put password in your code for a minute, login to facebook and then remove it.
254
+
255
+ If you want to be even more safe: _login.js_ can get password with `require("readline")` or with environment variables like this:
256
+
257
+ ```js
258
+ var credentials = {
259
+ email: process.env.FB_EMAIL,
260
+ password: process.env.FB_PASSWORD,
261
+ };
262
+ ```
263
+
264
+ ```bash
265
+ FB_EMAIL="john.doe@example.com"
266
+ FB_PASSWORD="MySuperHardP@ssw0rd"
267
+ nodejs login.js
268
+ ```
269
+
270
+ ---
271
+
272
+ <a name="login"></a>
273
+
274
+ ### login(credentials[, options][, callback])
275
+
276
+ This function is returned by `require(...)` and is the main entry point to the API.
277
+
278
+ It allows the user to log into facebook given the right credentials.
279
+
280
+ 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!)
281
+
282
+ If `callback` is supplied:
283
+
284
+ - `callback` will be called with a `null` object (for potential errors) and with an object containing all the available functions if logged in successfully.
285
+
286
+ - `callback` will be called with an error object if failed to login.
287
+
288
+ 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:
289
+
290
+ - If `callback` is not supplied (using `Promise`), this function will return a `Promise` that behaves like `Promise` received from `login`.
291
+
292
+ - If `callback` is supplied, this function will still return a `Promise`, but it will not resolve. Instead, the result is called to `callback`.
293
+
294
+ **Arguments**
295
+
296
+ - `credentials`: An object containing the fields `email` and `password` used to login, **_or_** an object containing the field `appState`.
297
+ - `options`: An object representing options to use when logging in (as described in [api.setOptions](#setOptions)).
298
+ - `callback(err, api)`: A callback called when login is done (successful or not). `err` is an object containing a field `error`.
299
+
300
+ **Example (Email & Password)**
301
+
302
+ ```js
303
+ const login = require("chards-script");
304
+
305
+ login({ email: "FB_EMAIL", password: "FB_PASSWORD" }, (err, api) => {
306
+ if (err) return console.error(err);
307
+ // Here you can use the api
308
+ });
309
+ ```
310
+
311
+ **Example (Email & Password then save appState to file)**
312
+
313
+ ```js
314
+ const fs = require("fs");
315
+ const login = require("chards-script");
316
+
317
+ login({ email: "FB_EMAIL", password: "FB_PASSWORD" }, (err, api) => {
318
+ if (err) return console.error(err);
319
+
320
+ fs.writeFileSync("appstate.json", JSON.stringify(api.getAppState()));
321
+ });
322
+ ```
323
+
324
+ **Example (AppState loaded from file)**
325
+
326
+ ```js
327
+ const fs = require("fs");
328
+ const login = require("chards-script");
329
+
330
+ login(
331
+ { appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) },
332
+ (err, api) => {
333
+ if (err) return console.error(err);
334
+ // Here you can use the api
335
+ }
336
+ );
337
+ ```
338
+
339
+ **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`.
340
+
341
+ **Example**:
342
+
343
+ ```js
344
+ const fs = require("fs");
345
+ const login = require("chards-script");
346
+ const readline = require("readline");
347
+
348
+ var rl = readline.createInterface({
349
+ input: process.stdin,
350
+ output: process.stdout,
351
+ });
352
+
353
+ const obj = { email: "FB_EMAIL", password: "FB_PASSWORD" };
354
+ login(obj, (err, api) => {
355
+ if (err) {
356
+ switch (err.error) {
357
+ case "login-approval":
358
+ console.log("Enter code > ");
359
+ rl.on("line", (line) => {
360
+ err.continue(line);
361
+ rl.close();
362
+ });
363
+ break;
364
+ default:
365
+ console.error(err);
366
+ }
367
+ return;
368
+ }
369
+
370
+ // Logged in!
371
+ });
372
+ ```
373
+
374
+ **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`.
375
+
376
+ ---
377
+
378
+ <a name="addUserToGroup"></a>
379
+
380
+ ### api.addUserToGroup(userID, threadID[, callback])
381
+
382
+ Adds a user (or array of users) to a group chat.
383
+
384
+ **Arguments**
385
+
386
+ - `userID`: User ID or array of user IDs.
387
+ - `threadID`: Group chat ID.
388
+ - `callback(err)`: A callback called when the query is done (either with an error or with no arguments).
389
+
390
+ ---
391
+
392
+ <a name="changeAdminStatus"></a>
393
+
394
+ ### api.changeAdminStatus(threadID, adminIDs, adminStatus[, callback])
395
+
396
+ Given a adminID, or an array of adminIDs, will set the admin status of the user(s) to `adminStatus`.
397
+
398
+ **Arguments**
399
+
400
+ - `threadID`: ID of a group chat (can't use in one-to-one conversations)
401
+ - `adminIDs`: The id(s) of users you wish to admin/unadmin (string or an array).
402
+ - `adminStatus`: Boolean indicating whether the user(s) should be promoted to admin (`true`) or demoted to a regular user (`false`).
403
+ - `callback(err)`: A callback called when the query is done (either with an error or null).
404
+
405
+ **Example**
406
+
407
+ ```js
408
+ const fs = require("fs");
409
+ const login = require("chards-script");
410
+
411
+ login(
412
+ { appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) },
413
+ (err, api) => {
414
+ if (err) return console.error(err);
415
+
416
+ let threadID = "0000000000000000";
417
+ let newAdmins = ["111111111111111", "222222222222222"];
418
+ api.changeAdminStatus(threadID, newAdmins, true, editAdminsCallback);
419
+
420
+ let adminToRemove = "333333333333333";
421
+ api.changeAdminStatus(
422
+ threadID,
423
+ adminToRemove,
424
+ false,
425
+ editAdminsCallback
426
+ );
427
+ }
428
+ );
429
+
430
+ function editAdminsCallback(err) {
431
+ if (err) return console.error(err);
432
+ }
433
+ ```
434
+
435
+ ---
436
+
437
+ <a name="changeApprovalMode"></a>
438
+
439
+ ### api.changeApprovalMode(approvalMode, threadID[, callback])
440
+
441
+ Turns on or off the approval mode for a group chat. When approval mode is on, users must be approved by an admin before they can join the group chat.
442
+
443
+ **Arguments**
444
+
445
+ - `approvalMode`: Number indicating whether the approval mode should be turned on (`1`) or off (`0`).
446
+ - `threadID`: String representing the ID of the thread.
447
+ - `callback(err)`: A callback called when the query is done (either with an error or null).
448
+
449
+ **Example**
450
+
451
+ ```js
452
+ const fs = require("fs");
453
+ const login = require("chards-script");
454
+
455
+ login(
456
+ { appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) },
457
+ (err, api) => {
458
+ if (err) return console.error(err);
459
+
460
+ api.changeApprovalMode(1, "000000000000000", (err) => {
461
+ if (err) return console.error(err);
462
+ });
463
+ }
464
+ );
465
+ ```
466
+
467
+ ---
468
+
469
+ <a name="changeArchivedStatus"></a>
470
+
471
+ ### api.changeArchivedStatus(threadOrThreads, archive[, callback])
472
+
473
+ 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.
474
+
475
+ **Arguments**
476
+
477
+ - `threadOrThreads`: The id(s) of the threads you wish to archive/unarchive.
478
+ - `archive`: Boolean indicating the new archive status to assign to the thread(s).
479
+ - `callback(err)`: A callback called when the query is done (either with an error or null).
480
+
481
+ **Example**
482
+
483
+ ```js
484
+ const fs = require("fs");
485
+ const login = require("chards-script");
486
+
487
+ login(
488
+ { appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) },
489
+ (err, api) => {
490
+ if (err) return console.error(err);
491
+
492
+ api.changeArchivedStatus("000000000000000", true, (err) => {
493
+ if (err) return console.error(err);
494
+ });
495
+ }
496
+ );
497
+ ```
498
+
499
+ ---
500
+
501
+ <a name="changeBlockedStatus"></a>
502
+
503
+ ### api.changeBlockedStatus(userID, block[, callback])
504
+
505
+ Prevents a user from privately contacting you. (Messages in a group chat will still be seen by both parties).
506
+
507
+ **Arguments**
508
+
509
+ - `userID`: User ID.
510
+ - `block`: Boolean indicating whether to block or unblock the user (true for block).
511
+ - `callback(err)`: A callback called when the query is done (either with an error or with no arguments).
512
+
513
+ ---
514
+
515
+ <a name="changeGroupImage"></a>
516
+
517
+ ### api.changeGroupImage(image, threadID[, callback])
518
+
519
+ Will change the group chat's image to the given image.
520
+
521
+ **Arguments**
522
+
523
+ - `image`: File stream of image.
524
+ - `threadID`: String representing the ID of the thread.
525
+ - `callback(err)`: A callback called when the change is done (either with an error or null).
526
+
527
+ **Example**
528
+
529
+ ```js
530
+ const fs = require("fs");
531
+ const login = require("chards-script");
532
+
533
+ login(
534
+ { appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) },
535
+ (err, api) => {
536
+ if (err) return console.error(err);
537
+
538
+ api.changeGroupImage(
539
+ fs.createReadStream("./avatar.png"),
540
+ "000000000000000",
541
+ (err) => {
542
+ if (err) return console.error(err);
543
+ }
544
+ );
545
+ }
546
+ );
547
+ ```
548
+
549
+ ---
550
+
551
+ <a name="changeNickname"></a>
552
+
553
+ ### api.changeNickname(nickname, threadID, participantID[, callback])
554
+
555
+ Will change the thread user nickname to the one provided.
556
+
557
+ **Arguments**
558
+
559
+ - `nickname`: String containing a nickname. Leave empty to reset nickname.
560
+ - `threadID`: String representing the ID of the thread.
561
+ - `participantID`: String representing the ID of the user.
562
+ - `callback(err)`: An optional callback called when the change is done (either with an error or null).
563
+
564
+ **Example**
565
+
566
+ ```js
567
+ const fs = require("fs");
568
+ const login = require("chards-script");
569
+
570
+ login(
571
+ { appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) },
572
+ (err, api) => {
573
+ if (err) return console.error(err);
574
+
575
+ api.changeNickname(
576
+ "Example",
577
+ "000000000000000",
578
+ "000000000000000",
579
+ (err) => {
580
+ if (err) return console.error(err);
581
+ }
582
+ );
583
+ }
584
+ );
585
+ ```
586
+
587
+ ---
588
+
589
+ <a name="changeThreadColor"></a>
590
+
591
+ ### api.changeThreadColor(color, threadID[, callback])
592
+
593
+ Will change the thread color to the given hex string color ("#0000ff"). Set it
594
+ to empty string if you want the default.
595
+
596
+ Note: the color needs to start with a "#".
597
+
598
+ **Arguments**
599
+
600
+ - `color`: String representing a theme ID (a list of theme ID can be found at `api.threadColors`).
601
+ - `threadID`: String representing the ID of the thread.
602
+ - `callback(err)`: A callback called when the change is done (either with an error or null).
603
+
604
+ **Example**
605
+
606
+ ```js
607
+ const fs = require("fs");
608
+ const login = require("chards-script");
609
+
610
+ login(
611
+ { appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) },
612
+ (err, api) => {
613
+ if (err) return console.error(err);
614
+
615
+ api.changeThreadColor("#0000ff", "000000000000000", (err) => {
616
+ if (err) return console.error(err);
617
+ });
618
+ }
619
+ );
620
+ ```
621
+
622
+ ---
623
+
624
+ <a name="changeThreadEmoji"></a>
625
+
626
+ ### api.changeThreadEmoji(emoji, threadID[, callback])
627
+
628
+ Will change the thread emoji to the one provided.
629
+
630
+ Note: The UI doesn't play nice with all emoji.
631
+
632
+ **Arguments**
633
+
634
+ - `emoji`: String containing a single emoji character.
635
+ - `threadID`: String representing the ID of the thread.
636
+ - `callback(err)`: A callback called when the change is done (either with an error or null).
637
+
638
+ **Example**
639
+
640
+ ```js
641
+ const fs = require("fs");
642
+ const login = require("chards-script");
643
+
644
+ login(
645
+ { appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) },
646
+ (err, api) => {
647
+ if (err) return console.error(err);
648
+
649
+ api.changeThreadEmoji("💯", "000000000000000", (err) => {
650
+ if (err) return console.error(err);
651
+ });
652
+ }
653
+ );
654
+ ```
655
+
656
+ ---
657
+
658
+ <a name="createNewGroup"></a>
659
+
660
+ ### api.createNewGroup(participantIDs[, groupTitle][, callback])
661
+
662
+ Create a new group chat.
663
+
664
+ **Arguments**
665
+
666
+ - `participantIDs`: An array containing participant IDs. (_Length must be >= 2_)
667
+ - `groupTitle`: The title of the new group chat.
668
+ - `callback(err, threadID)`: A callback called when created.
669
+
670
+ ---
671
+
672
+ <a name="createPoll"></a>
673
+
674
+ ### api.createPoll(title, threadID[, options][, callback]) (_temporary deprecated because Facebook is updating this feature_)
675
+
676
+ Creates a poll with the specified title and optional poll options, which can also be initially selected by the logged-in user.
677
+
678
+ **Arguments**
679
+
680
+ - `title`: String containing a title for the poll.
681
+ - `threadID`: String representing the ID of the thread.
682
+ - `options`: An optional `string : bool` dictionary to specify initial poll options and their initial states (selected/not selected), respectively.
683
+ - `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.
684
+
685
+ **Example**
686
+
687
+ ```js
688
+ const fs = require("fs");
689
+ const login = require("chards-script");
690
+
691
+ login(
692
+ { appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) },
693
+ (err, api) => {
694
+ if (err) return console.error(err);
695
+
696
+ api.createPoll(
697
+ "Example Poll",
698
+ "000000000000000",
699
+ {
700
+ "Option 1": false,
701
+ "Option 2": true,
702
+ },
703
+ (err) => {
704
+ if (err) return console.error(err);
705
+ }
706
+ );
707
+ }
708
+ );
709
+ ```
710
+
711
+ ---
712
+
713
+ <a name="deleteMessage"></a>
714
+
715
+ ### api.deleteMessage(messageOrMessages[, callback])
716
+
717
+ Takes a messageID or an array of messageIDs and deletes the corresponding message.
718
+
719
+ **Arguments**
720
+
721
+ - `messageOrMessages`: A messageID string or messageID string array
722
+ - `callback(err)`: A callback called when the query is done (either with an error or null).
723
+
724
+ **Example**
725
+
726
+ ```js
727
+ const fs = require("fs");
728
+ const login = require("chards-script");
729
+
730
+ login(
731
+ { appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) },
732
+ (err, api) => {
733
+ if (err) return console.error(err);
734
+
735
+ api.listen((err, message) => {
736
+ if (message.body) {
737
+ api.sendMessage(
738
+ message.body,
739
+ message.threadID,
740
+ (err, messageInfo) => {
741
+ if (err) return console.error(err);
742
+
743
+ api.deleteMessage(messageInfo.messageID);
744
+ }
745
+ );
746
+ }
747
+ });
748
+ }
749
+ );
750
+ ```
751
+
752
+ ---
753
+
754
+ <a name="deleteThread"></a>
755
+
756
+ ### api.deleteThread(threadOrThreads[, callback])
757
+
758
+ 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.
759
+
760
+ **Arguments**
761
+
762
+ - `threadOrThreads` - The id(s) of the threads you wish to remove from your account.
763
+ - `callback(err)` - A callback called when the operation is done, maybe with an object representing an error.
764
+
765
+ **Example**
766
+
767
+ ```js
768
+ const fs = require("fs");
769
+ const login = require("chards-script");
770
+
771
+ login(
772
+ { appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) },
773
+ (err, api) => {
774
+ if (err) return console.error(err);
775
+
776
+ api.deleteThread("000000000000000", (err) => {
777
+ if (err) return console.error(err);
778
+ });
779
+ }
780
+ );
781
+ ```
782
+
783
+ ---
784
+
785
+ <a name="forwardAttachment"></a>
786
+
787
+ ### api.forwardAttachment(attachmentID, userOrUsers[, callback])
788
+
789
+ Forwards corresponding attachment to given userID or to every user from an array of userIDs
790
+
791
+ **Arguments**
792
+
793
+ - `attachmentID`: The ID field in the attachment object. Recorded audio cannot be forwarded.
794
+ - `userOrUsers`: A userID string or usersID string array
795
+ - `callback(err)`: A callback called when the query is done (either with an error or null).
796
+
797
+ ---
798
+
799
+ <a name="getAppState"></a>
800
+
801
+ ### api.getAppState()
802
+
803
+ Returns current appState which can be saved to a file or stored in a variable.
804
+
805
+ ---
806
+
807
+ <a name="getCurrentUserID"></a>
808
+
809
+ ### api.getCurrentUserID()
810
+
811
+ Returns the currently logged-in user's Facebook user ID.
812
+
813
+ ---
814
+
815
+ <a name="getEmojiUrl"></a>
816
+
817
+ ### api.getEmojiUrl(c, size[, pixelRatio])
818
+
819
+ Returns the URL to a Facebook Messenger-style emoji image asset.
820
+
821
+ **note**: This function will return a URL regardless of whether the image at the URL actually exists.
822
+ This can happen if, for example, Messenger does not have an image asset for the requested emoji.
823
+
824
+ **Arguments**
825
+
826
+ - `c` - The emoji character
827
+ - `size` - The width and height of the emoji image; supported sizes are 32, 64, and 128
828
+ - `pixelRatio` - The pixel ratio of the emoji image; supported ratios are '1.0' and '1.5' (default is '1.0')
829
+
830
+ **Example**
831
+
832
+ ```js
833
+ const fs = require("fs");
834
+ const login = require("chards-script");
835
+
836
+ login(
837
+ { appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) },
838
+ (err, api) => {
839
+ if (err) return console.error(err);
840
+
841
+ // Prints https://static.xx.fbcdn.net/images/emoji.php/v8/z9c/1.0/128/1f40d.png
842
+ console.log("Snake emoji, 128px (128x128 with pixel ratio of 1.0");
843
+ console.log(api.getEmojiUrl("\ud83d\udc0d", 128));
844
+
845
+ // Prints https://static.xx.fbcdn.net/images/emoji.php/v8/ze1/1.5/128/1f40d.png
846
+ console.log("Snake emoji, 192px (128x128 with pixel ratio of 1.5");
847
+ console.log(api.getEmojiUrl("\ud83d\udc0d", 128, "1.5"));
848
+ }
849
+ );
850
+ ```
851
+
852
+ ---
853
+
854
+ <a name="getFriendsList"></a>
855
+
856
+ ### api.getFriendsList(callback)
857
+
858
+ Returns an array of objects with some information about your friends.
859
+
860
+ **Arguments**
861
+
862
+ - `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`.
863
+
864
+ **Example**
865
+
866
+ ```js
867
+ const fs = require("fs");
868
+ const login = require("chards-script");
869
+
870
+ login(
871
+ { appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) },
872
+ (err, api) => {
873
+ if (err) return console.error(err);
874
+
875
+ api.getFriendsList((err, data) => {
876
+ if (err) return console.error(err);
877
+
878
+ console.log(data.length);
879
+ });
880
+ }
881
+ );
882
+ ```
883
+
884
+ ---
885
+
886
+ <a name="getThreadHistory"></a>
887
+
888
+ ### api.getThreadHistory(threadID, amount, timestamp, callback)
889
+
890
+ Takes a threadID, number of messages, a timestamp, and a callback.
891
+
892
+ **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.
893
+
894
+ **Arguments**
895
+
896
+ - `threadID`: A threadID corresponding to the target chat
897
+ - `amount`: The amount of messages to _request_
898
+ - `timestamp`: Used to described the time of the most recent message to load. If timestamp is `undefined`, facebook will load the most recent messages.
899
+ - `callback(error, history)`: If error is null, history will contain an array of message objects.
900
+
901
+ **Example**
902
+
903
+ 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.
904
+
905
+ ```js
906
+ var timestamp = undefined;
907
+
908
+ function loadNextThreadHistory(api) {
909
+ api.getThreadHistory(threadID, 50, timestamp, (err, history) => {
910
+ if (err) return console.error(err);
911
+
912
+ /*
913
+ Since the timestamp is from a previous loaded message,
914
+ that message will be included in this history so we can discard it unless it is the first load.
915
+ */
916
+ if (timestamp != undefined) history.pop();
917
+
918
+ /*
919
+ Handle message history
920
+ */
921
+
922
+ timestamp = history[0].timestamp;
923
+ });
924
+ }
925
+ ```
926
+
927
+ ---
928
+
929
+ <a name="getThreadInfo"></a>
930
+
931
+ ### api.getThreadInfo(threadID[, callback])
932
+
933
+ Takes a threadID and a callback. Works for both single-user and group threads.
934
+
935
+ **Arguments**
936
+
937
+ - `threadID`: A threadID corresponding to the target thread.
938
+ - `callback(err, info)`: If `err` is `null`, `info` will contain the following properties:
939
+
940
+ | Key | Description |
941
+ | ----------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
942
+ | threadID | ID of the thread |
943
+ | participantIDs | Array of user IDs in the thread |
944
+ | 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. |
945
+ | 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. |
946
+ | nicknames | Map of nicknames for members of the thread. If there are no nicknames set, this will be null. |
947
+ | unreadCount | Number of unread messages |
948
+ | messageCount | Number of messages |
949
+ | imageSrc | URL to the group chat photo. Null if unset or a 1-1 thread. |
950
+ | timestamp | Timestamp of last activity |
951
+ | 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. |
952
+ | isGroup | boolean, true if this thread is a group thread (more than 2 participants). |
953
+ | isSubscribed | |
954
+ | folder | The folder that the thread is in. Can be one of: <ul><li>'inbox'</li><li>'archive'</li></ul> |
955
+ | isArchived | True if the thread is archived, false if not |
956
+ | cannotReplyReason | If you cannot reply to this thread, this will be a string stating why. Otherwise it will be null. |
957
+ | lastReadTimestamp | Timestamp of the last message that is marked as 'read' by the current user. |
958
+ | emoji | Object with key 'emoji' whose value is the emoji unicode character. Null if unset. |
959
+ | color | String form of the custom color in hexadecimal form. |
960
+ | adminIDs | Array of user IDs of the admins of the thread. Empty array if unset. |
961
+ | approvalMode | `true` or `false`, used to check if this group requires admin approval to add users |
962
+ | 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> |
963
+
964
+ ---
965
+
966
+ <a name="getThreadList"></a>
967
+
968
+ ### api.getThreadList(limit, timestamp, tags, callback)
969
+
970
+ Returns information about the user's threads.
971
+
972
+ **Arguments**
973
+
974
+ - `limit`: Limit the number of threads to fetch.
975
+ - `timestamp`: Request threads _before_ this date. `null` means _now_
976
+ - `tags`: An array describing which folder to fetch. It should be one of these:
977
+ - `["INBOX"]` _(same as `[]`)_
978
+ - `["ARCHIVED"]`
979
+ - `["PENDING"]`
980
+ - `["OTHER"]`
981
+ - `["INBOX", "unread"]`
982
+ - `["ARCHIVED", "unread"]`
983
+ - `["PENDING", "unread"]`
984
+ - `["OTHER", "unread"]`
985
+
986
+ _if you find something new, let us know_
987
+
988
+ - `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:
989
+
990
+ **Thread list**
991
+
992
+ | Key | Description |
993
+ | -------------------- | ----------------------------------------------------------------------------------- |
994
+ | threadID | ID of the thread |
995
+ | name | The name of the thread |
996
+ | unreadCount | Amount of unread messages in thread |
997
+ | messageCount | Amount of messages in thread |
998
+ | imageSrc | Link to the thread's image or `null` |
999
+ | emoji | The default emoji in thread (classic like is `null`) |
1000
+ | color | Thread's message color in `RRGGBB` (default blue is `null`) |
1001
+ | nicknames | An array of `{"userid": "1234", "nickname": "John Doe"}` |
1002
+ | muteUntil | Timestamp until the mute expires or `null` |
1003
+ | participants | An array of participants. See below |
1004
+ | adminIDs | An array of thread admin IDs |
1005
+ | folder | `INBOX`, `ARCHIVED`, `PENDING` or `OTHER` |
1006
+ | isGroup | `true` or `false` |
1007
+ | customizationEnabled | `false` in one-to-one conversations with `Page` or `ReducedMessagingActor` |
1008
+ | participantAddMode | currently `"ADD"` for groups and `null` otherwise |
1009
+ | reactionsMuteMode | `REACTIONS_NOT_MUTED` or `REACTIONS_MUTED` |
1010
+ | mentionsMuteMode | `MENTIONS_NOT_MUTED` or `MENTIONS_MUTED` |
1011
+ | isArchived | `true` or `false` |
1012
+ | isSubscribed | `true` or `false` |
1013
+ | timestamp | timestamp in miliseconds |
1014
+ | snippet | Snippet's text message |
1015
+ | snippetAttachments | Attachments in snippet |
1016
+ | snippetSender | ID of snippet sender |
1017
+ | lastMessageTimestamp | timestamp in milliseconds |
1018
+ | lastReadTimestamp | timestamp in milliseconds or `null` |
1019
+ | cannotReplyReason | `null`, `"RECIPIENTS_NOT_LOADABLE"` or `"BLOCKED"` |
1020
+ | approvalMode | `true` or `false`, used to check if this group requires admin approval to add users |
1021
+
1022
+ **`participants` format**
1023
+
1024
+ `accountType` is one of the following:
1025
+
1026
+ - `"User"`
1027
+ - `"Page"`
1028
+ - `"UnavailableMessagingActor"`
1029
+ - `"ReducedMessagingActor"`
1030
+
1031
+ (_there might be more_)
1032
+
1033
+ <table>
1034
+ <tr>
1035
+ <th>Account type</th>
1036
+ <th>Key</th>
1037
+ <th>Description</th>
1038
+ </tr>
1039
+ <tr>
1040
+ <td rowspan="12"><code>"User"</code></td>
1041
+ <td>userID</td>
1042
+ <td>ID of user</td>
1043
+ </tr>
1044
+ <tr>
1045
+ <td>name</td>
1046
+ <td>Full name of user</td>
1047
+ </tr>
1048
+ <tr>
1049
+ <td>shortName</td>
1050
+ <td>Short name of user (most likely first name)</td>
1051
+ </tr>
1052
+ <tr>
1053
+ <td>gender</td>
1054
+ <td>Either
1055
+ <code>"MALE"</code>,
1056
+ <code>"FEMALE"</code>,
1057
+ <code>"NEUTER"</code> or
1058
+ <code>"UNKNOWN"</code>
1059
+ </td>
1060
+ </tr>
1061
+ <tr>
1062
+ <td>url</td>
1063
+ <td>URL of the user's Facebook profile</td>
1064
+ </tr>
1065
+ <tr>
1066
+ <td>profilePicture</td>
1067
+ <td>URL of the profile picture</td>
1068
+ </tr>
1069
+ <tr>
1070
+ <td>username</td>
1071
+ <td>Username of user or
1072
+ <code>null</code>
1073
+ </td>
1074
+ </tr>
1075
+ <tr>
1076
+ <td>isViewerFriend</td>
1077
+ <td>Is the user a friend of you?</td>
1078
+ </tr>
1079
+ <tr>
1080
+ <td>isMessengerUser</td>
1081
+ <td>Does the user use Messenger?</td>
1082
+ </tr>
1083
+ <tr>
1084
+ <td>isVerified</td>
1085
+ <td>Is the user verified? (Little blue tick mark)</td>
1086
+ </tr>
1087
+ <tr>
1088
+ <td>isMessageBlockedByViewer</td>
1089
+ <td>Is the user blocking messages from you?</td>
1090
+ </tr>
1091
+ <tr>
1092
+ <td>isViewerCoworker</td>
1093
+ <td>Is the user your coworker?
1094
+ </td>
1095
+ </tr>
1096
+
1097
+ <tr>
1098
+ <td rowspan="10"><code>"Page"</code></td>
1099
+ <td>userID</td>
1100
+ <td>ID of the page</td>
1101
+ </tr>
1102
+ <tr>
1103
+ <td>name</td>
1104
+ <td>Name of the fanpage</td>
1105
+ </tr>
1106
+ <tr>
1107
+ <td>url</td>
1108
+ <td>URL of the fanpage</td>
1109
+ </tr>
1110
+ <tr>
1111
+ <td>profilePicture</td>
1112
+ <td>URL of the profile picture</td>
1113
+ </tr>
1114
+ <tr>
1115
+ <td>username</td>
1116
+ <td>Username of user or
1117
+ <code>null</code>
1118
+ </td>
1119
+ </tr>
1120
+ <tr>
1121
+ <td>acceptsMessengerUserFeedback</td>
1122
+ <td></td>
1123
+ </tr>
1124
+ <tr>
1125
+ <td>isMessengerUser</td>
1126
+ <td>Does the fanpage use Messenger?</td>
1127
+ </tr>
1128
+ <tr>
1129
+ <td>isVerified</td>
1130
+ <td>Is the fanpage verified? (Little blue tick mark)</td>
1131
+ </tr>
1132
+ <tr>
1133
+ <td>isMessengerPlatformBot</td>
1134
+ <td>Is the fanpage a bot</td>
1135
+ </tr>
1136
+ <tr>
1137
+ <td>isMessageBlockedByViewer</td>
1138
+ <td>Is the fanpage blocking messages from you?</td>
1139
+ </tr>
1140
+
1141
+ <tr>
1142
+ <td rowspan="7"><code>"ReducedMessagingActor"</code><br />(account requres verification,<br />messages are hidden)</td>
1143
+ <td>userID</td>
1144
+ <td>ID of the user</td>
1145
+ </tr>
1146
+ <tr>
1147
+ <td>name</td>
1148
+ <td>Name of the user</td>
1149
+ </tr>
1150
+ <tr>
1151
+ <td>url</td>
1152
+ <td>
1153
+ <code>null</code>
1154
+ </td>
1155
+ </tr>
1156
+ <tr>
1157
+ <td>profilePicture</td>
1158
+ <td>URL of the default Facebook profile picture</td>
1159
+ </tr>
1160
+ <tr>
1161
+ <td>username</td>
1162
+ <td>Username of user</td>
1163
+ </td>
1164
+ </tr>
1165
+ <tr>
1166
+ <td>acceptsMessengerUserFeedback</td>
1167
+ <td></td>
1168
+ </tr>
1169
+ <tr>
1170
+ <td>isMessageBlockedByViewer</td>
1171
+ <td>Is the user blocking messages from you?</td>
1172
+ </tr>
1173
+ <tr>
1174
+ <td rowspan="7"><code>"UnavailableMessagingActor"</code><br />(account disabled/removed)</td>
1175
+ <td>userID</td>
1176
+ <td>ID of the user</td>
1177
+ </tr>
1178
+ <tr>
1179
+ <td>name</td>
1180
+ <td><em>Facebook User</em> in user's language</td>
1181
+ </tr>
1182
+ <tr>
1183
+ <td>url</td>
1184
+ <td><code>null</code></td>
1185
+ </tr>
1186
+ <tr>
1187
+ <td>profilePicture</td>
1188
+ <td>URL of the default **male** Facebook profile picture</td>
1189
+ </tr>
1190
+ <tr>
1191
+ <td>username</td>
1192
+ <td><code>null</code></td>
1193
+ </tr>
1194
+ <tr>
1195
+ <td>acceptsMessengerUserFeedback</td>
1196
+ <td></td>
1197
+ </tr>
1198
+ <tr>
1199
+ <td>isMessageBlockedByViewer</td>
1200
+ <td>Is the user blocking messages from you?</td>
1201
+ </tr>
1202
+ </table>
1203
+
1204
+ 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:
1205
+
1206
+ | Key | Description |
1207
+ | ----------- | --------------------- |
1208
+ | accountType | type, can be anything |
1209
+ | userID | ID of the account |
1210
+ | name | Name of the account |
1211
+
1212
+ ---
1213
+
1214
+ <a name="getThreadPictures"></a>
1215
+
1216
+ ### api.getThreadPictures(threadID, offset, limit, callback)
1217
+
1218
+ Returns pictures sent in the thread.
1219
+
1220
+ **Arguments**
1221
+
1222
+ - `threadID`: A threadID corresponding to the target chat
1223
+ - `offset`: Start index of picture to retrieve, where 0 is the most recent picture
1224
+ - `limit`: Number of pictures to get, incrementing from the offset index
1225
+ - `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`.
1226
+
1227
+ ---
1228
+
1229
+ <a name="getUserID"></a>
1230
+
1231
+ ### api.getUserID(name, callback)
1232
+
1233
+ 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).
1234
+
1235
+ **Arguments**
1236
+
1237
+ - `name` - A string being the name of the item you're looking for.
1238
+ - `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).
1239
+
1240
+ **Example**
1241
+
1242
+ ```js
1243
+ const fs = require("fs");
1244
+ const login = require("chards-script");
1245
+
1246
+ login(
1247
+ { appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) },
1248
+ (err, api) => {
1249
+ if (err) return console.error(err);
1250
+
1251
+ api.getUserID("Marc Zuckerbot", (err, data) => {
1252
+ if (err) return console.error(err);
1253
+
1254
+ // Send the message to the best match (best by Facebook's criteria)
1255
+ var msg = "Hello!";
1256
+ var threadID = data[0].userID;
1257
+ api.sendMessage(msg, threadID);
1258
+ });
1259
+ }
1260
+ );
1261
+ ```
1262
+
1263
+ ---
1264
+
1265
+ <a name="getUserInfo"></a>
1266
+
1267
+ ### api.getUserInfo(ids, callback)
1268
+
1269
+ Will get some information about the given users.
1270
+
1271
+ **Arguments**
1272
+
1273
+ - `ids` - Either a string/number for one ID or an array of strings/numbers for a batched query.
1274
+ - `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`.
1275
+
1276
+ **Example**
1277
+
1278
+ ```js
1279
+ const fs = require("fs");
1280
+ const login = require("chards-script");
1281
+
1282
+ login(
1283
+ { appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) },
1284
+ (err, api) => {
1285
+ if (err) return console.error(err);
1286
+
1287
+ api.getUserInfo([1, 2, 3, 4], (err, ret) => {
1288
+ if (err) return console.error(err);
1289
+
1290
+ for (var prop in ret) {
1291
+ if (ret.hasOwnProperty(prop) && ret[prop].isBirthday) {
1292
+ api.sendMessage("Happy birthday :)", prop);
1293
+ }
1294
+ }
1295
+ });
1296
+ }
1297
+ );
1298
+ ```
1299
+
1300
+ ---
1301
+
1302
+ <a name="threadColors"></a>
1303
+
1304
+ ### api.threadColors
1305
+
1306
+ 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.
1307
+
1308
+ - DefaultBlue: `196241301102133`
1309
+ - HotPink: `169463077092846`
1310
+ - AquaBlue: `2442142322678320`
1311
+ - BrightPurple: `234137870477637`
1312
+ - CoralPink: `980963458735625`
1313
+ - Orange: `175615189761153`
1314
+ - Green: `2136751179887052`
1315
+ - LavenderPurple: `2058653964378557`
1316
+ - Red: `2129984390566328`
1317
+ - Yellow: `174636906462322`
1318
+ - TealBlue: `1928399724138152`
1319
+ - Aqua: `417639218648241`
1320
+ - Mango: `930060997172551`
1321
+ - Berry: `164535220883264`
1322
+ - Citrus: `370940413392601`
1323
+ - Candy: `205488546921017`
1324
+ - ~~StarWars: `809305022860427`~~ (Facebook removed it.)
1325
+
1326
+ ---
1327
+
1328
+ <a name="handleMessageRequest"></a>
1329
+
1330
+ ### api.handleMessageRequest(threadID, accept[, callback])
1331
+
1332
+ Accept or ignore message request(s) with thread id `threadID`.
1333
+
1334
+ **Arguments**
1335
+
1336
+ - `threadID`: A threadID or array of threadIDs corresponding to the target thread(s). Can be numbers or strings.
1337
+ - `accept`: Boolean indicating the new status to assign to the message request(s); true for inbox, false to others.
1338
+ - `callback(err)`: A callback called when the query is done (with an error or with null).
1339
+
1340
+ ---
1341
+
1342
+ <a name="listen"></a>
1343
+
1344
+ ### api.listen([callback])
1345
+
1346
+ <a name="listenMqtt"></a>
1347
+
1348
+ ### api.listenMqtt([callback])
1349
+
1350
+ Will call `callback` when a new message is received on this account.
1351
+ 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.
1352
+
1353
+ 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.
1354
+
1355
+ **Arguments**
1356
+
1357
+ - `callback(error, message)`: A callback called every time the logged-in account receives a new message.
1358
+
1359
+ <a name="message"></a>
1360
+ **Message**
1361
+
1362
+ 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:
1363
+
1364
+ <table>
1365
+ <tr>
1366
+ <th>Event Type</th>
1367
+ <th>Field</th>
1368
+ <th>Description</th>
1369
+ </tr>
1370
+ <tr>
1371
+ <td rowspan="9">
1372
+ <code>"message"</code><br />
1373
+ A message was sent to a thread.
1374
+ </td>
1375
+ <td><code>attachments</code></td>
1376
+ <td>An array of attachments to the message. Attachments vary in type, see the attachments table below.</td>
1377
+ </tr>
1378
+ <tr>
1379
+ <td><code>body</code></td>
1380
+ <td>The string corresponding to the message that was just received.</td>
1381
+ </tr>
1382
+ <tr>
1383
+ <td><code>isGroup</code></td>
1384
+ <td>boolean, true if this thread is a group thread (more than 2 participants).</td>
1385
+ </tr>
1386
+ <tr>
1387
+ <td><code>mentions</code></td>
1388
+ <td>An object containing people mentioned/tagged in the message in the format { id: name }</td>
1389
+ </tr>
1390
+ <tr>
1391
+ <td><code>messageID</code></td>
1392
+ <td>A string representing the message ID.</td>
1393
+ </tr>
1394
+ <tr>
1395
+ <td><code>senderID</code></td>
1396
+ <td>The id of the person who sent the message in the chat with threadID.</td>
1397
+ </tr>
1398
+ <tr>
1399
+ <td><code>threadID</code></td>
1400
+ <td>The threadID representing the thread in which the message was sent.</td>
1401
+ </tr>
1402
+ <tr>
1403
+ <td><code>isUnread</code></td>
1404
+ <td>Boolean representing whether or not the message was read.</td>
1405
+ </tr>
1406
+ <tr>
1407
+ <td><code>type</code></td>
1408
+ <td>For this event type, this will always be the string <code>"message"</code>.</td>
1409
+ </tr>
1410
+ <tr>
1411
+ <td rowspan="6">
1412
+ <code>"event"</code><br />
1413
+ An event occurred within a thread. Note that receiving this event type needs to be enabled with `api.setOptions({ listenEvents: true })`
1414
+ </td>
1415
+ <td><code>author</code></td>
1416
+ <td>The person who performed the event.</td>
1417
+ </tr>
1418
+ <tr>
1419
+ <td><code>logMessageBody</code></td>
1420
+ <td>String printed in the chat.</td>
1421
+ </tr>
1422
+ <tr>
1423
+ <td><code>logMessageData</code></td>
1424
+ <td>Data relevant to the event.</td>
1425
+ </tr>
1426
+ <tr>
1427
+ <td><code>logMessageType</code></td>
1428
+ <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>)</td>
1429
+ </tr>
1430
+ <tr>
1431
+ <td><code>threadID</code></td>
1432
+ <td>The threadID representing the thread in which the message was sent.</td>
1433
+ </tr>
1434
+ <tr>
1435
+ <td><code>type</code></td>
1436
+ <td>For this event type, this will always be the string <code>"event"</code>.</td>
1437
+ </tr>
1438
+ <tr>
1439
+ <td rowspan="5">
1440
+ <code>"typ"</code><br />
1441
+ A user in a thread is typing. Note that receiving this event type needs to be enabled with `api.setOptions({ listenTyping: true })`
1442
+ </td>
1443
+ <td><code>from</code></td>
1444
+ <td>ID of the user who started/stopped typing.</td>
1445
+ </tr>
1446
+ <tr>
1447
+ <td><code>fromMobile</code></td>
1448
+ <td>Boolean representing whether or not the person's using a mobile device to type.</td>
1449
+ </tr>
1450
+ <tr>
1451
+ <td><code>isTyping</code></td>
1452
+ <td>Boolean representing whether or not a person started typing.</td>
1453
+ </tr>
1454
+ <tr>
1455
+ <td><code>threadID</code></td>
1456
+ <td>The threadID representing the thread in which a user is typing.</td>
1457
+ </tr>
1458
+ <tr>
1459
+ <td><code>type</code></td>
1460
+ <td>For this event type, this will always be the string <code>"typ"</code>.</td>
1461
+ </tr>
1462
+ <tr>
1463
+ <td rowspan="3">
1464
+ <code>"read"</code><br />
1465
+ The current API user has read a message.
1466
+ </td>
1467
+ <td><code>threadID</code></td>
1468
+ <td>The threadID representing the thread in which the message was sent.</td>
1469
+ </tr>
1470
+ <tr>
1471
+ <td><code>time</code></td>
1472
+ <td>The time at which the user read the message.</td>
1473
+ </tr>
1474
+ <tr>
1475
+ <td><code>type</code></td>
1476
+ <td>For this event type, this will always be the string <code>"read"</code>.</td>
1477
+ </tr>
1478
+ <tr>
1479
+ <td rowspan="4">
1480
+ <code>"read_receipt"</code><br />
1481
+ A user within a thread has seen a message sent by the API user.
1482
+ </td>
1483
+ <td><code>reader</code></td>
1484
+ <td>ID of the user who just read the message.</td>
1485
+ </tr>
1486
+ <tr>
1487
+ <td><code>threadID</code></td>
1488
+ <td>The thread in which the message was read.</td>
1489
+ </tr>
1490
+ <tr>
1491
+ <td><code>time</code></td>
1492
+ <td>The time at which the reader read the message.</td>
1493
+ </tr>
1494
+ <tr>
1495
+ <td><code>type</code></td>
1496
+ <td>For this event type, this will always be the string <code>"read_receipt"</code>.</td>
1497
+ </tr>
1498
+ <tr>
1499
+ <td rowspan="8">
1500
+ <code>"message_reaction"</code><br />
1501
+ A user has sent a reaction to a message.
1502
+ </td>
1503
+ <td><code>messageID</code></td>
1504
+ <td>The ID of the message</td>
1505
+ </tr>
1506
+ <tr>
1507
+ <td><code>offlineThreadingID</code></td>
1508
+ <td>The offline message ID</td>
1509
+ </tr>
1510
+ <tr>
1511
+ <td><code>reaction</code></td>
1512
+ <td>Contains reaction emoji</td>
1513
+ </tr>
1514
+ <tr>
1515
+ <td><code>senderID</code></td>
1516
+ <td>ID of the author the message, where has been reaction added</td>
1517
+ </tr>
1518
+ <tr>
1519
+ <td><code>threadID</code></td>
1520
+ <td>ID of the thread where the message has been sent</td>
1521
+ </tr>
1522
+ <tr>
1523
+ <td><code>timestamp</code></td>
1524
+ <td>Unix Timestamp (in miliseconds) when the reaction was sent</td>
1525
+ </tr>
1526
+ <tr>
1527
+ <td><code>type</code></td>
1528
+ <td>For this event type, this will always be the string <code>"message_reaction"</code>.</td>
1529
+ </tr>
1530
+ <tr>
1531
+ <td><code>userID</code></td>
1532
+ <td>ID of the reaction sender</td>
1533
+ </tr>
1534
+ <tr>
1535
+ <td rowspan="4"><a name="presence"></a>
1536
+ <code>"presence"</code><br />
1537
+ 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>
1538
+ </td>
1539
+ <td><code>statuses</code></td>
1540
+ <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>
1541
+ </tr>
1542
+ <tr>
1543
+ <td><code>timestamp</code></td>
1544
+ <td>The time when the user was last online.</td>
1545
+ </tr>
1546
+ <tr>
1547
+ <td><code>type</code></td>
1548
+ <td>For this event type, this will always be the string <code>"presence"</code>.</td>
1549
+ </tr>
1550
+ <tr>
1551
+ <td><code>userID</code></td>
1552
+ <td>The ID of the user whose status this packet is describing.</td>
1553
+ </tr>
1554
+ <tr>
1555
+ <td rowspan="5">
1556
+ <code>"message_unsend"</code><br />
1557
+ A revoke message request for a message from a thread was received.
1558
+ </td>
1559
+ <td><code>threadID</code></td>
1560
+ <td>The threadID representing the thread in which the revoke message request was received.</td>
1561
+ </tr>
1562
+ <tr>
1563
+ <td><code>senderID</code></td>
1564
+ <td>The id of the person who request to revoke message on threadID.</td>
1565
+ </tr>
1566
+ <tr>
1567
+ <td><code>messageID</code></td>
1568
+ <td>A string representing the message ID that the person request to revoke message want to.</td>
1569
+ </tr>
1570
+ <tr>
1571
+ <td><code>deletionTimestamp</code></td>
1572
+ <td>The time when the request was sent.</td>
1573
+ </tr>
1574
+ <tr>
1575
+ <td><code>type</code></td>
1576
+ <td>For this event type, this will always be the string <code>"message_unsend"</code>.</td>
1577
+ </tr>
1578
+ <tr>
1579
+ <td rowspan="10">
1580
+ <code>"message_reply"</code><br />
1581
+ A reply message was sent to a thread.
1582
+ </td>
1583
+ <td><code>attachments</code></td>
1584
+ <td>An array of attachments to the message. Attachments vary in type, see the attachments table below.</td>
1585
+ </tr>
1586
+ <tr>
1587
+ <td><code>body</code></td>
1588
+ <td>The string corresponding to the message that was just received.</td>
1589
+ </tr>
1590
+ <tr>
1591
+ <td><code>isGroup</code></td>
1592
+ <td>boolean, true if this thread is a group thread (more than 2 participants).</td>
1593
+ </tr>
1594
+ <tr>
1595
+ <td><code>mentions</code></td>
1596
+ <td>An object containing people mentioned/tagged in the message in the format { id: name }</td>
1597
+ </tr>
1598
+ <tr>
1599
+ <td><code>messageID</code></td>
1600
+ <td>A string representing the message ID.</td>
1601
+ </tr>
1602
+ <tr>
1603
+ <td><code>senderID</code></td>
1604
+ <td>The id of the person who sent the message in the chat with threadID.</td>
1605
+ </tr>
1606
+ <tr>
1607
+ <td><code>threadID</code></td>
1608
+ <td>The threadID representing the thread in which the message was sent.</td>
1609
+ </tr>
1610
+ <tr>
1611
+ <td><code>isUnread</code></td>
1612
+ <td>Boolean representing whether or not the message was read.</td>
1613
+ </tr>
1614
+ <tr>
1615
+ <td><code>type</code></td>
1616
+ <td>For this event type, this will always be the string <code>"message_reply"</code>.</td>
1617
+ </tr>
1618
+ <tr>
1619
+ <td><code>messageReply</code></td>
1620
+ <td>An object represent a message being replied. Content inside is the same like a normal <code>"message"</code> event.</td>
1621
+ </tr>
1622
+ </table>
1623
+
1624
+ **Attachments**
1625
+
1626
+ 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:
1627
+
1628
+ | Attachment Type | Fields |
1629
+ | ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
1630
+ | `"sticker"` | `ID`, `url`, `packID`, `spriteUrl`, `spriteUrl2x`, `width`, `height`, `caption`, `description`, `frameCount`, `frameRate`, `framesPerRow`, `framesPerCol` |
1631
+ | `"file"` | `ID`, `filename`, `url`, `isMalicious`, `contentType` |
1632
+ | `"photo"` | `ID`, `filename`, `thumbnailUrl`, `previewUrl`, `previewWidth`, `previewHeight`, `largePreviewUrl`, `largePreviewWidth`, `largePreviewHeight` |
1633
+ | `"animated_image"` | `ID`, `filename`, `previewUrl`, `previewWidth`, `previewHeight`, `url`, `width`, `height` |
1634
+ | `"video"` | `ID`, `filename`, `previewUrl`, `previewWidth`, `previewHeight`, `url`, `width`, `height`, `duration`, `videoType` |
1635
+ | `"audio"` | `ID`, `filename`, `audioType`, `duration`, `url`, `isVoiceMail` |
1636
+ | `"location"` | `ID`, `latitude`, `longitude`, `image`, `width`, `height`, `url`, `address` |
1637
+ | `"share"` | `ID`, `url`, `title`, `description`, `source`, `image`, `width`, `height`, `playable`, `duration`, `playableUrl`, `subattachments`, `properties` |
1638
+
1639
+ **Example**
1640
+
1641
+ ```js
1642
+ const fs = require("fs");
1643
+ const login = require("chards-script");
1644
+
1645
+ // Simple echo bot. He'll repeat anything that you say.
1646
+ // Will stop when you say '/stop'
1647
+
1648
+ login(
1649
+ { appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) },
1650
+ (err, api) => {
1651
+ if (err) return console.error(err);
1652
+
1653
+ api.setOptions({ listenEvents: true });
1654
+
1655
+ var listenEmitter = api.listen((err, event) => {
1656
+ if (err) return console.error(err);
1657
+
1658
+ switch (event.type) {
1659
+ case "message":
1660
+ if (event.body === "/stop") {
1661
+ api.sendMessage("Goodbye...", event.threadID);
1662
+ return listenEmitter.stopListening();
1663
+ }
1664
+ api.markAsRead(event.threadID, (err) => {
1665
+ if (err) console.log(err);
1666
+ });
1667
+ api.sendMessage("TEST BOT: " + event.body, event.threadID);
1668
+ break;
1669
+ case "event":
1670
+ console.log(event);
1671
+ break;
1672
+ }
1673
+ });
1674
+ }
1675
+ );
1676
+ ```
1677
+
1678
+ ---
1679
+
1680
+ <a name="logout"></a>
1681
+
1682
+ ### api.logout([callback])
1683
+
1684
+ Logs out the current user.
1685
+
1686
+ **Arguments**
1687
+
1688
+ - `callback(err)`: A callback called when the query is done (either with an error or with null).
1689
+
1690
+ ---
1691
+
1692
+ <a name="markAsDelivered"></a>
1693
+
1694
+ ### api.markAsDelivered(threadID, messageID[, callback]])
1695
+
1696
+ 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.
1697
+
1698
+ You can also mark new messages as delivered automatically. This is enabled by default. See [api.setOptions](#setOptions).
1699
+
1700
+ **Arguments**
1701
+
1702
+ - `threadID` - The id of the thread in which you want to mark the message as delivered.
1703
+ - `messageID` - The id of the message want to mark as delivered.
1704
+ - `callback(err)` - A callback called when the operation is done maybe with an object representing an error.
1705
+
1706
+ **Example**
1707
+
1708
+ ```js
1709
+ const fs = require("fs");
1710
+ const login = require("facebook-chat-api");
1711
+
1712
+ login(
1713
+ { appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) },
1714
+ (err, api) => {
1715
+ if (err) return console.error(err);
1716
+
1717
+ api.listen((err, message) => {
1718
+ if (err) return console.error(err);
1719
+
1720
+ // Marks messages as delivered immediately after they're received
1721
+ api.markAsDelivered(message.threadID, message.messageID);
1722
+ });
1723
+ }
1724
+ );
1725
+ ```
1726
+
1727
+ ---
1728
+
1729
+ <a name="markAsRead"></a>
1730
+
1731
+ ### api.markAsRead(threadID, [read[, callback]])
1732
+
1733
+ 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.
1734
+
1735
+ 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.
1736
+
1737
+ **Arguments**
1738
+
1739
+ - `threadID` - The id of the thread in which you want to mark the messages as read.
1740
+ - `read` - An optional boolean where `true` means to mark the message as being "read" and `false` means to mark the message as being "unread".
1741
+ - `callback(err)` - A callback called when the operation is done maybe with an object representing an error.
1742
+
1743
+ **Example**
1744
+
1745
+ ```js
1746
+ const fs = require("fs");
1747
+ const login = require("chards-script");
1748
+
1749
+ login(
1750
+ { appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) },
1751
+ (err, api) => {
1752
+ if (err) return console.error(err);
1753
+
1754
+ api.listen((err, message) => {
1755
+ if (err) return console.error(err);
1756
+
1757
+ // Marks messages as read immediately after they're received
1758
+ api.markAsRead(message.threadID);
1759
+ });
1760
+ }
1761
+ );
1762
+ ```
1763
+
1764
+ ---
1765
+
1766
+ <a name="markAsReadAll"></a>
1767
+
1768
+ ### api.markAsReadAll([callback])
1769
+
1770
+ This function will mark all of messages in your inbox readed.
1771
+
1772
+ ---
1773
+
1774
+ <a name="markAsSeen"></a>
1775
+
1776
+ ### api.markAsSeen([seenTimestamp][, callback])
1777
+
1778
+ This function will mark your entire inbox as seen (don't be confused with read!).
1779
+
1780
+ ---
1781
+
1782
+ <a name="muteThread"></a>
1783
+
1784
+ ### api.muteThread(threadID, muteSeconds[, callback])
1785
+
1786
+ Mute a chat for a period of time, or unmute a chat.
1787
+
1788
+ **Arguments**
1789
+
1790
+ - `threadID` - The ID of the chat you want to mute.
1791
+ - `muteSeconds` - Mute the chat for this amount of seconds. Use `0` to unmute a chat. Use '-1' to mute a chat indefinitely.
1792
+ - `callback(err)` - A callback called when the operation is done maybe with an object representing an error.
1793
+
1794
+ **Example**
1795
+
1796
+ ```js
1797
+ const fs = require("fs");
1798
+ const login = require("chards-script");
1799
+
1800
+ login(
1801
+ { appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) },
1802
+ (err, api) => {
1803
+ if (err) return console.error(err);
1804
+
1805
+ api.listen((err, message) => {
1806
+ if (err) return console.error(err);
1807
+
1808
+ // Mute all incoming chats for one minute
1809
+ api.muteThread(message.threadID, 60);
1810
+ });
1811
+ }
1812
+ );
1813
+ ```
1814
+
1815
+ ---
1816
+
1817
+ <a name="removeUserFromGroup"></a>
1818
+
1819
+ ### api.removeUserFromGroup(userID, threadID[, callback])
1820
+
1821
+ Removes a user from a group chat.
1822
+
1823
+ **Arguments**
1824
+
1825
+ - `userID`: User ID.
1826
+ - `threadID`: Group chat ID.
1827
+ - `callback(err)`: A callback called when the query is done (either with an error or with no arguments).
1828
+
1829
+ ---
1830
+
1831
+ <a name="resolvePhotoUrl"></a>
1832
+
1833
+ ### api.resolvePhotoUrl(photoID, callback)
1834
+
1835
+ Resolves the URL to the full-size photo, given its ID. This function is useful for retrieving the full-size photo URL
1836
+ of image attachments in messages, returned by [`api.getThreadHistory`](#getThreadHistory).
1837
+
1838
+ **Arguments**
1839
+
1840
+ - `photoID`: Photo ID.
1841
+ - `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.
1842
+
1843
+ ---
1844
+
1845
+ <a name="searchForThread"></a>
1846
+
1847
+ ### api.searchForThread(name, callback)
1848
+
1849
+ > This part is outdated.
1850
+ > see #396
1851
+
1852
+ Takes a chat title (thread name) and returns matching results as a formatted threads array (ordered according to Facebook).
1853
+
1854
+ **Arguments**
1855
+
1856
+ - `name`: A messageID string or messageID string array
1857
+ - `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`
1858
+
1859
+ ---
1860
+
1861
+ <a name="sendMessage"></a>
1862
+
1863
+ ### api.sendMessage(message, threadID[, callback][, messageid])
1864
+
1865
+ Sends the given message to the threadID.
1866
+
1867
+ **Arguments**
1868
+
1869
+ - `message`: A string (for backward compatibility) or a message object as described below.
1870
+ - `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.
1871
+ - `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.
1872
+ - `messageID`: (Optional) A string representing a message you want to reply.
1873
+
1874
+ **Message Object**:
1875
+
1876
+ Various types of message can be sent:
1877
+
1878
+ - _Regular:_ set field `body` to the desired message as a string.
1879
+ - _Sticker:_ set a field `sticker` to the desired sticker ID.
1880
+ - _File or image:_ Set field `attachment` to a readable stream or an array of readable streams.
1881
+ - _URL:_ set a field `url` to the desired URL.
1882
+ - _Emoji:_ set field `emoji` to the desired emoji as a string and set field `emojiSize` with size of the emoji (`small`, `medium`, `large`)
1883
+ - _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`
1884
+ can be passed in to specify the start index to start searching for the `tag` text
1885
+ in `body` (default=0). (See below for an example.)
1886
+ - _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.
1887
+
1888
+ 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.
1889
+
1890
+ **Tip**: to find your own ID, you can look inside the cookies. The `userID` is under the name `c_user`.
1891
+
1892
+ **Example (Basic Message)**
1893
+
1894
+ ```js
1895
+ const fs = require("fs");
1896
+ const login = require("chards-script");
1897
+
1898
+ login(
1899
+ { appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) },
1900
+ (err, api) => {
1901
+ if (err) return console.error(err);
1902
+
1903
+ var yourID = "000000000000000";
1904
+ var msg = { body: "Hey!" };
1905
+ api.sendMessage(msg, yourID);
1906
+ }
1907
+ );
1908
+ ```
1909
+
1910
+ **Example (File upload)**
1911
+
1912
+ ```js
1913
+ const fs = require("fs");
1914
+ const login = require("chards-script");
1915
+
1916
+ login(
1917
+ { appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) },
1918
+ (err, api) => {
1919
+ if (err) return console.error(err);
1920
+
1921
+ // This example uploads an image called image.jpg
1922
+ var yourID = "000000000000000";
1923
+ var msg = {
1924
+ body: "Hey!",
1925
+ attachment: fs.createReadStream(__dirname + "/image.jpg"),
1926
+ };
1927
+ api.sendMessage(msg, yourID);
1928
+ }
1929
+ );
1930
+ ```
1931
+
1932
+ **Example (Mention)**
1933
+
1934
+ ```js
1935
+ const login = require("chards-script");
1936
+
1937
+ login({ email: "EMAIL", password: "PASSWORD" }, (err, api) => {
1938
+ if (err) return console.error(err);
1939
+
1940
+ api.listen((err, message) => {
1941
+ if (message && message.body) {
1942
+ // Getting the actual sender name from ID involves calling
1943
+ // `api.getThreadInfo` and `api.getUserInfo`
1944
+ api.sendMessage(
1945
+ {
1946
+ body: "Hello @Sender! @Sender!",
1947
+ mentions: [
1948
+ {
1949
+ tag: "@Sender",
1950
+ id: message.senderID,
1951
+ fromIndex: 9, // Highlight the second occurrence of @Sender
1952
+ },
1953
+ ],
1954
+ },
1955
+ message.threadID
1956
+ );
1957
+ }
1958
+ });
1959
+ });
1960
+ ```
1961
+
1962
+ **Example (Location)**
1963
+
1964
+ ```js
1965
+ const login = require("chards-script");
1966
+ login({ email: "EMAIL", password: "PASSWORD" }, (err, api) => {
1967
+ if (err) return console.error(err);
1968
+ var yourID = "000000000000000";
1969
+ const msg = {
1970
+ location: { latitude: 48.858093, longitude: 2.294694, current: true },
1971
+ };
1972
+ api.sendMessage(msg, yourID);
1973
+ });
1974
+ ```
1975
+
1976
+ ---
1977
+
1978
+ <a name="sendTypingIndicator"></a>
1979
+
1980
+ ### api.sendTypingIndicator(threadID[, callback])
1981
+
1982
+ 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`.
1983
+
1984
+ **Arguments**
1985
+
1986
+ - `threadID`: Group chat ID.
1987
+ - `callback(err)`: A callback called when the query is done (with an error or with null).
1988
+
1989
+ ---
1990
+
1991
+ <a name="setMessageReaction"></a>
1992
+
1993
+ ### api.setMessageReaction(reaction, messageID[, callback[, forceCustomReaction]])
1994
+
1995
+ Sets reaction on message
1996
+
1997
+ **Arguments**
1998
+
1999
+ - `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.
2000
+ - `messageID`: A string representing the message ID.
2001
+ - `callback(err)`: A callback called when sending the reaction is done.
2002
+ - `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)**
2003
+
2004
+ **Supported Emojis**
2005
+
2006
+ | Emoji | Text | Unicode | Shortcuts |
2007
+ | ----- | ---- | -------------- | --------------------------- |
2008
+ | 😍 | `😍` | `\uD83D\uDE0D` | `:love:`, `:heart_eyes:` |
2009
+ | 😆 | `😆` | `\uD83D\uDE06` | `:haha:`, `:laughing:` |
2010
+ | 😮 | `😮` | `\uD83D\uDE2E` | `:wow:`, `:open_mouth:` |
2011
+ | 😢 | `😢` | `\uD83D\uDE22` | `:sad:`, `:cry:` |
2012
+ | 😠 | `😠` | `\uD83D\uDE20` | `:angry:` |
2013
+ | 👍 | `👍` | `\uD83D\uDC4D` | `:like:`, `:thumbsup:` |
2014
+ | 👎 | `👎` | `\uD83D\uDC4E` | `:dislike:`, `:thumbsdown:` |
2015
+ | ❤ | `❤` | `\u2764` | `:heart:` |
2016
+ | 💗 | `💗` | `\uD83D\uDC97` | `:glowingheart:` |
2017
+
2018
+ ---
2019
+
2020
+ <a name="setOptions"></a>
2021
+
2022
+ ### api.setOptions(options)
2023
+
2024
+ Sets various configurable options for the api.
2025
+
2026
+ **Arguments**
2027
+
2028
+ - `options` - An object containing the new values for the options that you want
2029
+ to set. If the value for an option is unspecified, it is unchanged. The following options are possible.
2030
+ - `logLevel`: The desired logging level as determined by npmlog. Choose
2031
+ from either `"silly"`, `"verbose"`, `"info"`, `"http"`, `"warn"`, `"error"`, or `"silent"`.
2032
+ - `selfListen`: (Default `false`) Set this to `true` if you want your api
2033
+ to receive messages from its own account. This is to be used with
2034
+ caution, as it can result in loops (a simple echo bot will send messages
2035
+ forever).
2036
+ - `listenEvents`: (Default `false`) Will make [api.listen](#listen) also handle events (look at api.listen for more details).
2037
+ - `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.
2038
+ - `updatePresence`: (Default `false`) Will make [api.listen](#listen) also return `presence` ([api.listen](#presence) for more details).
2039
+ - `forceLogin`: (Default `false`) Will automatically approve of any recent logins and continue with the login process.
2040
+ - `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. - `autoMarkDelivery`: (Default `true`) Will automatically mark new messages as delivered. See [api.markAsDelivered](#markAsDelivered). - `autoMarkRead`: (Default `false`) Will automatically mark new messages as read/seen. See [api.markAsRead](#markAsRead). - `proxy`: (Default empty) Set this to proxy server address to use proxy. Note: Only HTTP Proxies which support CONNECT method is supported. - `online`: (Default `true`) Set account's online state.
2041
+
2042
+ **Example**
2043
+
2044
+ ```js
2045
+ const fs = require("fs");
2046
+ const login = require("chards-script");
2047
+
2048
+ // Simple echo bot. This will send messages forever.
2049
+
2050
+ login(
2051
+ { appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) },
2052
+ (err, api) => {
2053
+ if (err) return console.error(err);
2054
+
2055
+ api.setOptions({
2056
+ selfListen: true,
2057
+ logLevel: "silent",
2058
+ });
2059
+
2060
+ api.listen((err, message) => {
2061
+ if (err) return console.error(err);
2062
+
2063
+ // Ignore empty messages (photos etc.)
2064
+ if (typeof message.body === "string") {
2065
+ api.sendMessage(message.body, message.threadID);
2066
+ }
2067
+ });
2068
+ }
2069
+ );
2070
+ ```
2071
+
2072
+ ---
2073
+
2074
+ <a name="setTitle"></a>
2075
+
2076
+ ### api.setTitle(newTitle, threadID[, callback])
2077
+
2078
+ Sets the title of the group chat with thread id `threadID` to `newTitle`.
2079
+
2080
+ 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.
2081
+
2082
+ **Arguments**
2083
+
2084
+ - `newTitle`: A string representing the new title.
2085
+ - `threadID`: A string or number representing a thread. It happens to be someone's userID in the case of a one to one conversation.
2086
+ - `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.
2087
+
2088
+ ---
2089
+
2090
+ <a name="unsendMessage"></a>
2091
+
2092
+ ### api.unsendMessage(messageID[, callback])
2093
+
2094
+ Revokes a message from anyone that could see that message with `messageID`
2095
+
2096
+ Note: This will only work if the message is sent by you and was sent less than 10 minutes ago.
2097
+
2098
+ **Arguments**
2099
+
2100
+ - `messageID`: Message ID you want to unsend.
2101
+ - `callback(err)`: A callback called when the query is done (with an error or with null).
2102
+
2103
+ ---
2104
+
2105
+ ## FAQS
2106
+
2107
+ 1. How do I run tests?
2108
+
2109
+ > 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`.
2110
+
2111
+ 2. Why doesn't `sendMessage` always work when I'm logged in as a page?
2112
+
2113
+ > Pages can't start conversations with users directly; this is to prevent pages from spamming users.
2114
+
2115
+ 3. What do I do when `login` doesn't work?
2116
+
2117
+ > 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).
2118
+
2119
+ 4. How can I avoid logging in every time? Can I log into a previous session?
2120
+
2121
+ > 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.
2122
+
2123
+ 5. Do you support sending messages as a page?
2124
+
2125
+ > Yes, set the pageID option on login (this doesn't work if you set it using api.setOptions, it affects the login process).
2126
+ >
2127
+ > ```js
2128
+ > login(credentials, {pageID: "000000000000000"}, (err, api) => { … }
2129
+ > ```
2130
+
2131
+ 6. I'm getting some crazy weird syntax error like `SyntaxError: Unexpected token [`!!!
2132
+
2133
+ > Please try to update your version of node.js before submitting an issue of this nature. We like to use new language features.
2134
+
2135
+ 7. I don't want all of these logging messages!
2136
+ > You can use `api.setOptions` to silence the logging. You get the `api` object from `login` (see example above). Do
2137
+ >
2138
+ > ```js
2139
+ > api.setOptions({
2140
+ > logLevel: "silent",
2141
+ > });
2142
+ > ```
2143
+
2144
+ <a name="projects-using-this-api"></a>
2145
+
2146
+ ## Projects using this API:
2147
+
2148
+ - [c3c](https://github.com/lequanglam/c3c) - A bot that can be customizable using plugins. Support Facebook & Discord.
2149
+
2150
+ ## Projects using this API (original repository, facebook-chat-api):
2151
+
2152
+ - [Messer](https://github.com/mjkaufer/Messer) - Command-line messaging for Facebook Messenger
2153
+ - [messen](https://github.com/tomquirk/messen) - Rapidly build Facebook Messenger apps in Node.js
2154
+ - [Concierge](https://github.com/concierge/Concierge) - Concierge is a highly modular, easily extensible general purpose chat bot with a built in package manager
2155
+ - [Marc Zuckerbot](https://github.com/bsansouci/marc-zuckerbot) - Facebook chat bot
2156
+ - [Marc Thuckerbot](https://github.com/bsansouci/lisp-bot) - Programmable lisp bot
2157
+ - [MarkovsInequality](https://github.com/logicx24/MarkovsInequality) - Extensible chat bot adding useful functions to Facebook Messenger
2158
+ - [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.
2159
+ - [Larry Pudding Dog Bot](https://github.com/Larry850806/facebook-chat-bot) - A facebook bot you can easily customize the response
2160
+ - [fbash](https://github.com/avikj/fbash) - Run commands on your computer's terminal over Facebook Messenger
2161
+ - [Klink](https://github.com/KeNt178/klink) - This Chrome extension will 1-click share the link of your active tab over Facebook Messenger
2162
+ - [Botyo](https://github.com/ivkos/botyo) - Modular bot designed for group chat rooms on Facebook
2163
+ - [matrix-puppet-facebook](https://github.com/matrix-hacks/matrix-puppet-facebook) - A facebook bridge for [matrix](https://matrix.org)
2164
+ - [facebot](https://github.com/Weetbix/facebot) - A facebook bridge for Slack.
2165
+ - [Botium](https://github.com/codeforequity-at/botium-core) - The Selenium for Chatbots
2166
+ - [Messenger-CLI](https://github.com/AstroCB/Messenger-CLI) - A command-line interface for sending and receiving messages through Facebook Messenger.
2167
+ - [AssumeZero-Bot](https://github.com/AstroCB/AssumeZero-Bot) – A highly customizable Facebook Messenger bot for group chats.
2168
+ - [Miscord](https://github.com/Bjornskjald/miscord) - An easy-to-use Facebook bridge for Discord.
2169
+ - [chat-bridge](https://github.com/rexx0520/chat-bridge) - A Messenger, Telegram and IRC chat bridge.
2170
+ - [messenger-auto-reply](https://gitlab.com/theSander/messenger-auto-reply) - An auto-reply service for Messenger.
2171
+ - [BotCore](https://github.com/AstroCB/BotCore) – A collection of tools for writing and managing Facebook Messenger bots.
2172
+ - [mnotify](https://github.com/AstroCB/mnotify) – A command-line utility for sending alerts and notifications through Facebook Messenger.