File size: 76,982 Bytes
aa0eab9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 |
# Documentation
### You can use callback or .then() .catch() or async/await
* [`login(credentials, options, [callback])`](#logincredentials-options-callback) โ <code>Promise</code>
* [`api.addExternalModule(moduleObj)`](#apiaddexternalmodulemoduleobj)
* [`api.addUserToGroup(userID, threadID, [callback])`](#apiaddusertogroupuserid-threadid-callback) โ <code>Promise</code>
* [`api.changeAdminStatus(threadID, adminIDs, adminStatus, [callback])`](#apichangeadminstatusthreadid-adminids-adminstatus-callback) โ <code>Promise</code>
* [`api.changeArchivedStatus(threadOrThreads, archive, [callback])`](#apichangearchivedstatusthreadorthreads-archive-callback) โ <code>Promise</code>
* [`api.changeBlockedStatus(userID, block, [callback])`](#apichangeblockedstatususerid-block-callback) โ <code>Promise</code>
* [`api.changeGroupImage(image, threadID, [callback])`](#apichangegroupimageimage-threadid-callback) โ <code>Promise</code>
* [`api.changeNickname(nickname, threadID, participantID, [callback])`](#apichangenicknamenickname-threadid-participantid-callback) โ <code>Promise</code>
* [`api.changeThreadColor(color, threadID, [callback])`](#apichangethreadcolorcolor-threadid-callback) โ <code>Promise</code>
* [`api.changeThreadEmoji(emoji, threadID, [callback])`](#apichangethreademojiemoji-threadid-callback) โ <code>Promise</code>
* [`api.createNewGroup(participantIDs, groupTitle, [callback])`](#apicreatenewgroupparticipantids-grouptitle-callback) โ <code>Promise</code>
* [`api.createPoll(title, threadID, options, [callback]) (*temporary deprecated because Facebook is updating this feature*)`](#apicreatepolltitle-threadid-options-callback-temporary-deprecated-because-facebook-is-updating-this-feature) โ <code>Promise</code>
* [`api.deleteMessage(messageOrMessages, [callback])`](#apideletemessagemessageormessages-callback) โ <code>Promise</code>
* [`api.deleteThread(threadOrThreads, [callback])`](#apideletethreadthreadorthreads-callback) โ <code>Promise</code>
* [`api.forwardAttachment(attachmentID, userOrUsers, [callback])`](#apiforwardattachmentattachmentid-userorusers-callback) โ <code>Promise</code>
* [`api.getAppState()`](#apigetappstate) โ <code>Array</code>
* [`api.getCurrentUserID()`](#apigetcurrentuserid) โ <code>string</code>
* [`api.getEmojiUrl(c, size, pixelRatio)`](#apigetemojiurlc-size-pixelratio) โ <code>string</code>
* [`api.getFriendsList([callback])`](#apigetfriendslistcallback) โ <code>Promise</code>
* [`api.getMessage(threadID, messageID, [callback])`](#apigetmessagethreadid-messageid-callback) โ <code>Promise</code>
* [`api.getThreadHistory(threadID, amount, timestamp, [callback])`](#apigetthreadhistorythreadid-amount-timestamp-callback) โ <code>Promise</code>
* [`api.getThreadInfo(threadIDs, [callback])`](#apigetthreadinfothreadids-callback) โ <code>Promise</code>
* [`api.getThreadList(limit, timestamp, tags, [callback])`](#apigetthreadlistlimit-timestamp-tags-callback) โ <code>Promise</code>
* [`api.getThreadPictures(threadID, offset, limit, [callback])`](#apigetthreadpicturesthreadid-offset-limit-callback) โ <code>Promise</code>
* [`api.getUserID(name, [callback])`](#apigetuseridname-callback) โ <code>Promise</code>
* [`api.getUserInfo(ids, [callback])`](#apigetuserinfoids-callback) โ <code>Promise</code>
* [`api.handleMessageRequest(threadID, accept, [callback])`](#apihandlemessagerequestthreadid-accept-callback) โ <code>Promise</code>
* [`api.httpGet(url, form, [customHeader], [callback], [notAPI])`](#apihttpgeturl-form-customheader-callback-notapi) โ <code>Promise</code>
* [`api.httpPost(url, form, [customHeader], [callback], [notAPI])`](#apihttpposturl-form-customheader-callback-notapi) โ <code>Promise</code>
* [`api.httpPostFormData(url, form, [customHeader], [callback], [notAPI])`](#apihttppostformdataurl-form-customheader-callback-notapi) โ <code>Promise</code>
* [~~`api.listen([callback])`~~](#apilistencallback) โ <code>Promise</code>
* [`api.listenMqtt([callback])`](#apilistenmqttcallback) โ <code>Promise</code>
* [`api.logout([callback])`](#apilogoutcallback) โ <code>Promise</code>
* [`api.markAsDelivered(threadID, messageID, [callback]`](#apimarkasdeliveredthreadid-messageid-callback) โ <code>Promise</code>
* [`api.markAsRead(threadID, [read, [callback]])`](#apimarkasreadthreadid-read-callback) โ <code>Promise</code>
* [`api.markAsReadAll([callback])`](#apimarkasreadallcallback) โ <code>Promise</code>
* [`api.markAsSeen([seenTimestamp], [callback])`](#apimarkasseenseentimestamp-callback) โ <code>Promise</code>
* [`api.muteThread(threadID, muteSeconds, [callback])`](#apimutethreadthreadid-muteseconds-callback) โ <code>Promise</code>
* [`api.removeUserFromGroup(userID, threadID, [callback])`](#apiremoveuserfromgroupuserid-threadid-callback) โ <code>Promise</code>
* [`api.resolvePhotoUrl(photoID, [callback])`](#apiresolvephotourlphotoid-callback) โ <code>Promise</code>
* [`api.searchForThread(name, [callback])`](#apisearchforthreadname-callback)
* [`api.sendMessage(message, threadID, [callback], messageID)`](#apisendmessagemessage-threadid-callback-messageid) โ <code>Promise</code>
* [`api.sendTypingIndicator(threadID, [callback])`](#apisendtypingindicatorthreadid-callback) โ <code>Promise</code>
* [`api.setMessageReaction(reaction, messageID, [callback], [forceCustomReaction])`](#apisetmessagereactionreaction-messageid-callback-forcecustomreaction) โ <code>Promise</code>
* [`api.setOptions(options)`](#apisetoptionsoptions) โ <code>Promise</code>
* [`api.setPostReaction(postID, type, [callback])`](#apisetpostreactionpostid-type-callback) โ <code>Promise</code>
* [`api.setTitle(newTitle, threadID, [callback])`](#apisettitlenewtitle-threadid-callback) โ <code>Promise</code>
* [`api.threadColors`](#apithreadcolors) โ <code>Object</code>
* [`api.unsendMessage(messageID, [callback])`](#apiunsendmessagemessageid-callback) โ <code>Promise</code>
* [`api.uploadAttachment(attachments, [callback])`](#apiuploadattachmentattachments-callback) โ <code>Promise</code>
---------------------------------------
### Password safety
**Read this** before you _copy+paste_ examples from below.
You should not store Facebook password in your scripts.
There are few good reasons:
* People who are standing behind you may look at your "code" and get your password if it is on the screen
* 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_"
* 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.
* 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
Preferred method is to have `login.js` that saves `AppState` to a file and then use that file from all your scripts.
This way you can put password in your code for a minute, login to facebook and then remove it.
If you want to be even more safe: _login.js_ can get password with `require("readline")` or with environment variables like this:
```js
var credentials = {
email: process.env.FB_EMAIL,
password: process.env.FB_PASSWORD
}
```
```bash
FB_EMAIL="john.doe@example.com"
FB_PASSWORD="MySuperHardP@ssw0rd"
nodejs login.js
```
---------------------------------------
<a name="login"></a>
### login(credentials, options, [callback])
This function is returned by `require(...)` and is the main entry point to the API.
It allows the user to log into facebook given the right credentials.
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!)
If `callback` is supplied:
* `callback` will be called with a `null` object (for potential errors) and with an object containing all the available functions if logged in successfully.
* `callback` will be called with an error object if failed to login.
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:
* If `callback` is not supplied (using `Promise`), this function will return a `Promise` that behaves like `Promise` received from `login`.
* If `callback` is supplied, this function will still return a `Promise`, but it will not resolve. Instead, the result is called to `callback`.
__Arguments__
* `credentials`: An object containing the fields `email` and `password` used to login, __*or*__ an object containing the field `appState`.
* `options`: An object representing options to use when logging in (as described in [api.setOptions](#setOptions)).
* `callback(err, api)`: A callback called when login is done (successful or not). `err` is an object containing a field `error`.
---
<h1><b>Now login with account and password is no longer available, <a href="#loginWithAppstate">use appState</a> login instead.</b></h1>
~~__Example (Email & Password)__: (it is no longer usable, please use [this](#loginWithAppstate) alternative method)~~
```js
const login = require("fb-chat-api-temp");
login({email: "FB_EMAIL", password: "FB_PASSWORD"}, (err, api) => {
if(err) return console.error(err);
// Here you can use the api
});
```
~~__Example (Email & Password then save appState to file)__: (it is no longer usable, please use [this](#loginWithAppstate) alternative method)~~
```js
const fs = require("fs-extra");
const login = require("fb-chat-api-temp");
login({email: "FB_EMAIL", password: "FB_PASSWORD"}, (err, api) => {
if(err) return console.error(err);
fs.writeFileSync('appstate.json', JSON.stringify(api.getAppState()));
});
```
~~__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`. (it is no longer usable, please use [this](#loginWithAppstate) alternative method)~~
__Example__:
```js
const login = require("fb-chat-api-temp");
const readline = require("readline");
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
const obj = {email: "FB_EMAIL", password: "FB_PASSWORD"};
login(obj, (err, api) => {
if(err) {
switch (err.error) {
case 'login-approval':
console.log('Enter code > ');
rl.on('line', (line) => {
err.continue(line);
rl.close();
});
break;
default:
console.error(err);
}
return;
}
// Logged in!
});
```
__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`.
<a name="loginWithAppstate"></a>
#### __Example (AppState loaded from file)__: You can get fbstate using [this](https://github.com/ntkhang03/c3c-fbstate) extension
```js
const fs = require("fs-extra");
const login = require("fb-chat-api-temp");
login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
if(err) return console.error(err);
// Here you can use the api
});
```
---------------------------------------
<a name="apiaddexternalmodulemoduleobj"></a>
### api.addExternalModule(moduleObj)
This function is used to add external modules to the api object, each module is a function that takes 3 arguments: `defaultFuncs`, `api`, `ctx` and returns a function that will be added to the api object.
Example:
```js
api.addExternalModule({
"example": function(defaultFuncs, api, ctx) {
return function () {
console.log("globalOptions", ctx.globalOptions);
};
}
});
```
---------------------------------------
<a name="addUserToGroup"></a>
### api.addUserToGroup(userID, threadID, [callback])
Adds a user (or array of users) to a group chat.
__Arguments__
* `userID`: User ID or array of user IDs.
* `threadID`: Group chat ID.
* `callback(err)`: A callback called when the query is done (either with an error or with no arguments).
__Example__
```js
api.addUserToGroup("1234567890", "0987654321", (err) => {
if(err)
return console.error(err);
console.log("Added user to group.");
});
```
---------------------------------------
<a name="changeAdminStatus"></a>
### api.changeAdminStatus(threadID, adminIDs, adminStatus, [callback])
Given a adminID, or an array of adminIDs, will set the admin status of the user(s) to `adminStatus`.
__Arguments__
* `threadID`: ID of a group chat (can't use in one-to-one conversations)
* `adminIDs`: The id(s) of users you wish to admin/unadmin (string or an array).
* `adminStatus`: Boolean indicating whether the user(s) should be promoted to admin (`true`) or demoted to a regular user (`false`).
* `callback(err)`: A callback called when the query is done (either with an error or null).
__Example__
```js
const fs = require("fs-extra");
const login = require("fb-chat-api-temp");
login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
if (err) return console.error(err);
let threadID = "0000000000000000";
let newAdmins = ["111111111111111", "222222222222222"];
api.changeAdminStatus(threadID, newAdmins, true, editAdminsCallback);
let adminToRemove = "333333333333333";
api.changeAdminStatus(threadID, adminToRemove, false, editAdminsCallback);
});
function editAdminsCallback(err) {
if (err) return console.error(err);
}
```
---------------------------------------
<a name="changeArchivedStatus"></a>
### api.changeArchivedStatus(threadOrThreads, archive, [callback])
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.
__Arguments__
* `threadOrThreads`: The id(s) of the threads you wish to archive/unarchive.
* `archive`: Boolean indicating the new archive status to assign to the thread(s).
* `callback(err)`: A callback called when the query is done (either with an error or null).
__Example__
```js
const fs = require("fs-extra");
const login = require("fb-chat-api-temp");
login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
if(err) return console.error(err);
api.changeArchivedStatus("000000000000000", true, (err) => {
if(err) return console.error(err);
});
});
```
---------------------------------------
<a name="changeBlockedStatus"></a>
### api.changeBlockedStatus(userID, block, [callback])
Prevents a user from privately contacting you. (Messages in a group chat will still be seen by both parties).
__Arguments__
* `userID`: User ID.
* `block`: Boolean indicating whether to block or unblock the user (true for block).
* `callback(err)`: A callback called when the query is done (either with an error or with no arguments).
---------------------------------------
<a name="changeGroupImage"></a>
### api.changeGroupImage(image, threadID, [callback])
Will change the group chat's image to the given image.
__Arguments__
* `image`: File stream of image.
* `threadID`: String representing the ID of the thread.
* `callback(err)`: A callback called when the change is done (either with an error or null).
__Example__
```js
const fs = require("fs-extra");
const login = require("fb-chat-api-temp");
login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
if(err) return console.error(err);
api.changeGroupImage(fs.createReadStream("./avatar.png"), "000000000000000", (err) => {
if(err) return console.error(err);
});
});
```
---------------------------------------
<a name="changeNickname"></a>
### api.changeNickname(nickname, threadID, participantID, [callback])
Will change the thread user nickname to the one provided.
__Arguments__
* `nickname`: String containing a nickname. Leave empty to reset nickname.
* `threadID`: String representing the ID of the thread.
* `participantID`: String representing the ID of the user.
* `callback(err)`: An optional callback called when the change is done (either with an error or null).
__Example__
```js
const fs = require("fs-extra");
const login = require("fb-chat-api-temp");
login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
if(err) return console.error(err);
api.changeNickname("Example", "000000000000000", "000000000000000", (err) => {
if(err) return console.error(err);
});
});
```
---------------------------------------
<a name="changeThreadColor"></a>
### api.changeThreadColor(color, threadID, [callback])
Will change the thread color to the given hex string color ("#0000ff"). Set it
to empty string if you want the default.
Note: the color needs to start with a "#".
__Arguments__
* `color`: String representing a theme ID (a list of theme ID can be found at `api.threadColors`).
* `threadID`: String representing the ID of the thread.
* `callback(err)`: A callback called when the change is done (either with an error or null).
__Example__
```js
const fs = require("fs-extra");
const login = require("fb-chat-api-temp");
login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
if(err) return console.error(err);
api.changeThreadColor("#0000ff", "000000000000000", (err) => {
if(err) return console.error(err);
});
});
```
---------------------------------------
<a name="changeThreadEmoji"></a>
### api.changeThreadEmoji(emoji, threadID, [callback])
Will change the thread emoji to the one provided.
Note: The UI doesn't play nice with all emoji.
__Arguments__
* `emoji`: String containing a single emoji character.
* `threadID`: String representing the ID of the thread.
* `callback(err)`: A callback called when the change is done (either with an error or null).
__Example__
```js
const fs = require("fs-extra");
const login = require("fb-chat-api-temp");
login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
if(err) return console.error(err);
api.changeThreadEmoji("๐ฏ", "000000000000000", (err) => {
if(err) return console.error(err);
});
});
```
---------------------------------------
<a name="createNewGroup"></a>
### api.createNewGroup(participantIDs, groupTitle, [callback])
Create a new group chat.
__Arguments__
* `participantIDs`: An array containing participant IDs. (*Length must be >= 2*)
* `groupTitle`: The title of the new group chat.
* `callback(err, threadID)`: A callback called when created.
---------------------------------------
<a name="createPoll"></a>
### api.createPoll(title, threadID, options, [callback]) (*temporary deprecated because Facebook is updating this feature*)
Creates a poll with the specified title and optional poll options, which can also be initially selected by the logged-in user.
__Arguments__
* `title`: String containing a title for the poll.
* `threadID`: String representing the ID of the thread.
* `options`: An optional `string : bool` dictionary to specify initial poll options and their initial states (selected/not selected), respectively.
* `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.
__Example__
```js
const fs = require("fs-extra");
const login = require("fb-chat-api-temp");
login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
if(err) return console.error(err);
api.createPoll("Example Poll", "000000000000000", {
"Option 1": false,
"Option 2": true
}, (err) => {
if(err) return console.error(err);
});
});
```
---------------------------------------
<a name="deleteMessage"></a>
### api.deleteMessage(messageOrMessages, [callback])
Takes a messageID or an array of messageIDs and deletes the corresponding message.
__Arguments__
* `messageOrMessages`: A messageID string or messageID string array
* `callback(err)`: A callback called when the query is done (either with an error or null).
__Example__
```js
const fs = require("fs-extra");
const login = require("fb-chat-api-temp");
login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
if(err) return console.error(err);
api.listen((err, message) => {
if(message.body) {
api.sendMessage(message.body, message.threadID, (err, messageInfo) => {
if(err) return console.error(err);
api.deleteMessage(messageInfo.messageID);
});
}
});
});
```
---------------------------------------
<a name="deleteThread"></a>
### api.deleteThread(threadOrThreads, [callback])
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.
__Arguments__
* `threadOrThreads` - The id(s) of the threads you wish to remove from your account.
* `callback(err)` - A callback called when the operation is done, maybe with an object representing an error.
__Example__
```js
const fs = require("fs-extra");
const login = require("fb-chat-api-temp");
login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
if(err) return console.error(err);
api.deleteThread("000000000000000", (err) => {
if(err) return console.error(err);
});
});
```
---------------------------------------
<a name="forwardAttachment"></a>
### api.forwardAttachment(attachmentID, userOrUsers, [callback])
Forwards corresponding attachment to given userID or to every user from an array of userIDs
__Arguments__
* `attachmentID`: The ID field in the attachment object. Recorded audio cannot be forwarded.
* `userOrUsers`: A userID string or usersID string array
* `callback(err)`: A callback called when the query is done (either with an error or null).
---------------------------------------
<a name="getAppState"></a>
### api.getAppState()
Returns current appState which can be saved to a file or stored in a variable.
---------------------------------------
<a name="getCurrentUserID"></a>
### api.getCurrentUserID()
Returns the currently logged-in user's Facebook user ID.
---------------------------------------
<a name="getEmojiUrl"></a>
### api.getEmojiUrl(c, size, pixelRatio)
Returns the URL to a Facebook Messenger-style emoji image asset.
__note__: This function will return a URL regardless of whether the image at the URL actually exists.
This can happen if, for example, Messenger does not have an image asset for the requested emoji.
__Arguments__
* `c` - The emoji character
* `size` - The width and height of the emoji image; supported sizes are 32, 64, and 128
* `pixelRatio` - The pixel ratio of the emoji image; supported ratios are '1.0' and '1.5' (default is '1.0')
__Example__
```js
const fs = require("fs-extra");
const login = require("fb-chat-api-temp");
login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
if(err) return console.error(err);
// Prints https://static.xx.fbcdn.net/images/emoji.php/v8/z9c/1.0/128/1f40d.png
console.log('Snake emoji, 128px (128x128 with pixel ratio of 1.0');
console.log(api.getEmojiUrl('\ud83d\udc0d', 128));
// Prints https://static.xx.fbcdn.net/images/emoji.php/v8/ze1/1.5/128/1f40d.png
console.log('Snake emoji, 192px (128x128 with pixel ratio of 1.5');
console.log(api.getEmojiUrl('\ud83d\udc0d', 128, '1.5'));
});
```
---------------------------------------
<a name="getFriendsList"></a>
### api.getFriendsList([callback])
Returns an array of objects with some information about your friends.
__Arguments__
* `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`.
__Example__
```js
const fs = require("fs-extra");
const login = require("fb-chat-api-temp");
login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
if(err) return console.error(err);
api.getFriendsList((err, data) => {
if(err) return console.error(err);
console.log(data.length);
});
});
```
---------------------------------------
<a name="getMessage"></a>
### api.getMessage(threadID, messageID, [callback])
Returns message data from messageID
__Arguments__
* `threadID`: The ID of the thread you want to get the message from.
* `messageID`: The ID of the message you want to get.
* `callback(err, data)` - A callback called when the query is done.
---------------------------------------
<a name="getThreadHistory"></a>
### api.getThreadHistory(threadID, amount, timestamp, [callback])
Takes a threadID, number of messages, a timestamp, and a callback.
__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.
__Arguments__
* `threadID`: A threadID corresponding to the target chat
* `amount`: The amount of messages to *request*
* `timestamp`: Used to described the time of the most recent message to load. If timestamp is `undefined`, facebook will load the most recent messages.
* `callback(error, history)`: If error is null, history will contain an array of message objects.
__Example__
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.
```js
var timestamp = undefined;
function loadNextThreadHistory(api){
api.getThreadHistory(threadID, 50, timestamp, (err, history) => {
if(err) return console.error(err);
/*
Since the timestamp is from a previous loaded message,
that message will be included in this history so we can discard it unless it is the first load.
*/
if(timestamp != undefined) history.pop();
/*
Handle message history
*/
timestamp = history[0].timestamp;
});
}
```
---------------------------------------
<a name="getThreadInfo"></a>
### api.getThreadInfo(threadIDs, [callback])
Takes a threadID and a callback. Works for both single-user and group threads.
__Arguments__
* `threadIDs`: Either a string/number for one ID or an array of strings/numbers for a batched query.
* `callback(err, info)`: If `err` is `null`, `info` will return
<!-- * in nghiรชng chแปฏ -->
*if `threadIDs` is an array of IDs, `info` will be an array of objects with the following fields:*
```js
{
"4000000000000000": {
threadID: "4000000000000000",
threadName: "Thread Name",
// ...
// thread info
},
"5000000000000000": {
threadID: "5000000000000000",
threadName: "Thread Name",
// ...
// thread info
},
// ...
}
```
*if `threadIDs` is a single ID, `info` will be an object with the following fields:*
```js
{
threadID: "4000000000000000",
threadName: "Thread Name",
// ...
// thread info
}
```
`info` will contain the following fields:
| Key | Description |
| :---------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
| threadID | ID of the thread |
| participantIDs | Array of user IDs in the thread |
| 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. |
| 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. |
| nicknames | Map of nicknames for members of the thread. If there are no nicknames set, this will be `null`. Can be of the form: <ul><li>`{'123456789': "nickname"}`</ul></li> |
| unreadCount | Number of unread messages |
| messageCount | Number of messages |
| imageSrc | URL to the group chat photo. `null` if unset or a 1-1 thread. |
| timestamp | Timestamp of last activity |
| 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. |
| isGroup | boolean, true if this thread is a group thread (more than 2 participants). |
| isSubscribed | |
| folder | The folder that the thread is in. Can be one of: `INBOX`, `ARCHIVED`, `PENDING` or `OTHER` |
| isArchived | True if the thread is archived, false if not |
| cannotReplyReason | If you cannot reply to this thread, this will be a string stating why. Otherwise it will be null. |
| lastReadTimestamp | Timestamp of the last message that is marked as 'read' by the current user. |
| emoji | Object with key 'emoji' whose value is the emoji unicode character. Null if unset. |
| color | String form of the custom color in hexadecimal form. |
| adminIDs | Array of user IDs of the admins of the thread. Empty array if unset. Can be of the form:<ul><li>`[{ id: '123456789' }]`</li></ul> |
| approvalMode | `true` or `false`, used to check if this group requires admin approval to add users |
| 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> |
| inviteLink | Invite link for the thread. <ul><li>`enable`: `true` if the invite link is enabled, `false` if it is disabled</li> <li>`link`: Invite link</li></ul> |
`accountType` is one of the following:
- `"User"`
- `"Page"`
- `"UnavailableMessagingActor"`
- `"ReducedMessagingActor"`
---------------------------------------
<a name="getThreadList"></a>
### api.getThreadList(limit, timestamp, tags, [callback])
Returns information about the user's threads.
__Arguments__
* `limit`: Limit the number of threads to fetch.
* `timestamp`: Request threads *before* this date. `null` means *now*
* `tags`: An array describing which folder to fetch. It should be one of these:
- `["INBOX"]` *(same as `[]`)*
- `["ARCHIVED"]`
- `["PENDING"]`
- `["OTHER"]`
- `["INBOX", "unread"]`
- `["ARCHIVED", "unread"]`
- `["PENDING", "unread"]`
- `["OTHER", "unread"]`
*if you find something new, let us know*
* `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 same structure as [`getThreadInfo`](#getThreadInfo)
`accountType` is one of the following:
- `"User"`
- `"Page"`
- `"UnavailableMessagingActor"`
- `"ReducedMessagingActor"`
(*there might be more*)
<table>
<tr>
<th>Account type</th>
<th>Key</th>
<th>Description</th>
</tr>
<tr>
<td rowspan="12"><code>"User"</code></td>
<td>userID</td>
<td>ID of user</td>
</tr>
<tr>
<td>name</td>
<td>Full name of user</td>
</tr>
<tr>
<td>shortName</td>
<td>Short name of user (most likely first name)</td>
</tr>
<tr>
<td>gender</td>
<td>Either
<code>"MALE"</code>,
<code>"FEMALE"</code>,
<code>"NEUTER"</code> or
<code>"UNKNOWN"</code>
</td>
</tr>
<tr>
<td>url</td>
<td>URL of the user's Facebook profile</td>
</tr>
<tr>
<td>profilePicture</td>
<td>URL of the profile picture</td>
</tr>
<tr>
<td>username</td>
<td>Username of user or
<code>null</code>
</td>
</tr>
<tr>
<td>isViewerFriend</td>
<td>Is the user a friend of you?</td>
</tr>
<tr>
<td>isMessengerUser</td>
<td>Does the user use Messenger?</td>
</tr>
<tr>
<td>isVerified</td>
<td>Is the user verified? (Little blue tick mark)</td>
</tr>
<tr>
<td>isMessageBlockedByViewer</td>
<td>Is the user blocking messages from you?</td>
</tr>
<tr>
<td>isViewerCoworker</td>
<td>Is the user your coworker?
</td>
</tr>
<tr>
<td rowspan="10"><code>"Page"</code></td>
<td>userID</td>
<td>ID of the page</td>
</tr>
<tr>
<td>name</td>
<td>Name of the fanpage</td>
</tr>
<tr>
<td>url</td>
<td>URL of the fanpage</td>
</tr>
<tr>
<td>profilePicture</td>
<td>URL of the profile picture</td>
</tr>
<tr>
<td>username</td>
<td>Username of user or
<code>null</code>
</td>
</tr>
<tr>
<td>acceptsMessengerUserFeedback</td>
<td></td>
</tr>
<tr>
<td>isMessengerUser</td>
<td>Does the fanpage use Messenger?</td>
</tr>
<tr>
<td>isVerified</td>
<td>Is the fanpage verified? (Little blue tick mark)</td>
</tr>
<tr>
<td>isMessengerPlatformBot</td>
<td>Is the fanpage a bot</td>
</tr>
<tr>
<td>isMessageBlockedByViewer</td>
<td>Is the fanpage blocking messages from you?</td>
</tr>
<tr>
<td rowspan="7"><code>"ReducedMessagingActor"</code><br />(account requres verification,<br />messages are hidden)</td>
<td>userID</td>
<td>ID of the user</td>
</tr>
<tr>
<td>name</td>
<td>Name of the user</td>
</tr>
<tr>
<td>url</td>
<td>
<code>null</code>
</td>
</tr>
<tr>
<td>profilePicture</td>
<td>URL of the default Facebook profile picture</td>
</tr>
<tr>
<td>username</td>
<td>Username of user</td>
</td>
</tr>
<tr>
<td>acceptsMessengerUserFeedback</td>
<td></td>
</tr>
<tr>
<td>isMessageBlockedByViewer</td>
<td>Is the user blocking messages from you?</td>
</tr>
<tr>
<td rowspan="7"><code>"UnavailableMessagingActor"</code><br />(account disabled/removed)</td>
<td>userID</td>
<td>ID of the user</td>
</tr>
<tr>
<td>name</td>
<td><em>Facebook User</em> in user's language</td>
</tr>
<tr>
<td>url</td>
<td><code>null</code></td>
</tr>
<tr>
<td>profilePicture</td>
<td>URL of the default **male** Facebook profile picture</td>
</tr>
<tr>
<td>username</td>
<td><code>null</code></td>
</tr>
<tr>
<td>acceptsMessengerUserFeedback</td>
<td></td>
</tr>
<tr>
<td>isMessageBlockedByViewer</td>
<td>Is the user blocking messages from you?</td>
</tr>
</table>
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:
| Key | Description |
| ----------- | --------------------- |
| accountType | type, can be anything |
| userID | ID of the account |
| name | Name of the account |
---------------------------------------
<a name="getThreadPictures"></a>
### api.getThreadPictures(threadID, offset, limit, [callback])
Returns pictures sent in the thread.
__Arguments__
* `threadID`: A threadID corresponding to the target chat
* `offset`: Start index of picture to retrieve, where 0 is the most recent picture
* `limit`: Number of pictures to get, incrementing from the offset index
* `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`.
---------------------------------------
<a name="getUserID"></a>
### api.getUserID(name, [callback])
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).
__Arguments__
* `name` - A string being the name of the item you're looking for.
* `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).
__Example__
```js
const fs = require("fs-extra");
const login = require("fb-chat-api-temp");
login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
if(err) return console.error(err);
api.getUserID("Marc Zuckerbot", (err, data) => {
if(err) return console.error(err);
// Send the message to the best match (best by Facebook's criteria)
var msg = "Hello!"
var threadID = data[0].userID;
api.sendMessage(msg, threadID);
});
});
```
---------------------------------------
<a name="getUserInfo"></a>
### api.getUserInfo(ids, [callback])
Will get some information about the given users.
__Arguments__
* `ids` - Either a string/number for one ID or an array of strings/numbers for a batched query.
* `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:
| Key | Description |
| ------------- | ------------------------------------------------------------------ |
| name | Name of the user |
| firstName | First name of the user |
| vanity | the username of the user if any |
| thumbSrc | URL of the profile picture |
| profileUrl | URL of the profile |
| gender | the gender of the user, with 1 is Female, 2 is Male, 0 is unknown |
| type | type is generally user, group, page, event or app |
| isFriend | is the user a friend of the current user, either `true` or `false` |
| isBirthday | is the user having a birthday today, either `true` or `false` |
| searchTokens | an array of strings that can be used to search for the user |
| alternateName | |
__Example__
```js
const fs = require("fs-extra");
const login = require("fb-chat-api-temp");
login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
if(err) return console.error(err);
api.getUserInfo([1, 2, 3, 4], (err, ret) => {
if(err) return console.error(err);
for(var prop in ret) {
if(ret.hasOwnProperty(prop) && ret[prop].isBirthday) {
api.sendMessage("Happy birthday :)", prop);
}
}
});
});
```
---------------------------------------
<a name="threadColors"></a>
### api.threadColors
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.
<details>
<summary><b>List of colors:</b></summary>
<br>
- MessengerBlue: `196241301102133`
- Viking: `1928399724138152`
- GoldenPoppy: `174636906462322`
- RadicalRed: `2129984390566328`
- Shocking: `2058653964378557`
- FreeSpeechGreen: `2136751179887052`
- Pumpkin: `175615189761153`
- LightCoral: `980963458735625`
- MediumSlateBlue: `234137870477637`
- DeepSkyBlue: `2442142322678320`
- BrilliantRose: `169463077092846`
- DefaultBlue: `196241301102133`
- HotPink: `169463077092846`
- AquaBlue: `2442142322678320`
- BrightPurple: `234137870477637`
- CoralPink: `980963458735625`
- Orange: `175615189761153`
- Green: `2136751179887052`
- LavenderPurple: `2058653964378557`
- Red: `2129984390566328`
- Yellow: `174636906462322`
- TealBlue: `1928399724138152`
- Aqua: `417639218648241`
- Mango: `930060997172551`
- Berry: `164535220883264`
- Citrus: `370940413392601`
- Candy: `205488546921017`
- Earth: `1833559466821043`
- Support: `365557122117011`
- Music: `339021464972092`
- Pride: `1652456634878319`
- DoctorStrange: `538280997628317`
- LoFi: `1060619084701625`
- Sky: `3190514984517598`
- LunarNewYear: `357833546030778`
- Celebration: `627144732056021`
- Chill: `390127158985345`
- StrangerThings: `1059859811490132`
- Dune: `1455149831518874`
- Care: `275041734441112`
- Astrology: `3082966625307060`
- JBalvin: `184305226956268`
- Birthday: `621630955405500`
- Cottagecore: `539927563794799`
- Ocean: `736591620215564`
- Love: `741311439775765`
- TieDye: `230032715012014`
- Monochrome: `788274591712841`
- Default: `3259963564026002`
- Rocket: `582065306070020`
- Berry2: `724096885023603`
- Candy2: `624266884847972`
- Unicorn: `273728810607574`
- Tropical: `262191918210707`
- Maple: `2533652183614000`
- Sushi: `909695489504566`
- Citrus2: `557344741607350`
- Lollipop: `280333826736184`
- Shadow: `271607034185782`
- Rose: `1257453361255152`
- Lavender: `571193503540759`
- Tulip: `2873642949430623`
- Classic: `3273938616164733`
- Peach: `3022526817824329`
- Honey: `672058580051520`
- Kiwi: `3151463484918004`
- Grape: `193497045377796`
- NonBinary: `737761000603635`
- ~~StarWars: `809305022860427`~~ (Facebook removed it.)
</details>
---------------------------------------
<a name="handleMessageRequest"></a>
### api.handleMessageRequest(threadID, accept, [callback])
Accept or ignore message request(s) with thread id `threadID`.
__Arguments__
* `threadID`: A threadID or array of threadIDs corresponding to the target thread(s). Can be numbers or strings.
* `accept`: Boolean indicating the new status to assign to the message request(s); true for inbox, false to others.
* `callback(err)`: A callback called when the query is done (with an error or with null).
---------------------------------------
<a name="httpGet"></a>
### api.httpGet(url, form, [customHeader], [callback], [notAPI])
Get data from a URL with method GET.
__Arguments__
* `url`: A string being the URL to get data from.
* `form`: An object containing the form data to send.
* `customHeader`: An object containing custom headers to send.
* `callback(err, data)`: A callback called when the query is done (either with an error or with the resulting data).
* `notAPI`: A boolean indicating whether the request is made from the API or not (default: false, meaning it's from the API).
---------------------------------------
<a name="httpPost"></a>
### api.httpPost(url, form, [customHeader], [callback], [notAPI])
Get data from a URL with method POST.
__Arguments__
* Similar to [`api.httpGet`](#httpGet).
---------------------------------------
<a name="httpPostFormData"></a>
### api.httpPostFormData(url, form, [customHeader], [callback], [notAPI])
Post form data to a URL.
__Arguments__
* Similar to [`api.httpGet`](#httpGet).
---------------------------------------
<a name="listen"></a>
### ~~api.listen([callback])~~
<a name="listenMqtt"></a>
### api.listenMqtt([callback])
Will call `callback` when a new message is received on this account.
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.
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.
__Arguments__
- `callback(error, message)`: A callback called every time the logged-in account receives a new message.
<a name="message"></a>
__Message__
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:
<table>
<tr>
<th>Event Type</th>
<th>Field</th>
<th>Description</th>
</tr>
<tr>
<td rowspan="9">
<code>"message"</code><br />
A message was sent to a thread.
</td>
<td><code>attachments</code></td>
<td>An array of attachments to the message. Attachments vary in type, see the attachments table below.</td>
</tr>
<tr>
<td><code>body</code></td>
<td>The string corresponding to the message that was just received.</td>
</tr>
<tr>
<td><code>isGroup</code></td>
<td>boolean, true if this thread is a group thread (more than 2 participants).</td>
</tr>
<tr>
<td><code>mentions</code></td>
<td>An object containing people mentioned/tagged in the message in the format { id: name }</td>
</tr>
<tr>
<td><code>messageID</code></td>
<td>A string representing the message ID.</td>
</tr>
<tr>
<td><code>senderID</code></td>
<td>The id of the person who sent the message in the chat with threadID.</td>
</tr>
<tr>
<td><code>threadID</code></td>
<td>The threadID representing the thread in which the message was sent.</td>
</tr>
<tr>
<td><code>isUnread</code></td>
<td>Boolean representing whether or not the message was read.</td>
</tr>
<tr>
<td><code>type</code></td>
<td>For this event type, this will always be the string <code>"message"</code>.</td>
</tr>
<tr>
<td rowspan="6">
<code>"event"</code><br />
An event occurred within a thread. Note that receiving this event type needs to be enabled with `api.setOptions({ listenEvents: true })`
</td>
<td><code>author</code></td>
<td>The person who performed the event.</td>
</tr>
<tr>
<td><code>logMessageBody</code></td>
<td>String printed in the chat.</td>
</tr>
<tr>
<td><code>logMessageData</code></td>
<td>Data relevant to the event.</td>
</tr>
<tr>
<td><code>logMessageType</code></td>
<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>
</tr>
<tr>
<td><code>threadID</code></td>
<td>The threadID representing the thread in which the message was sent.</td>
</tr>
<tr>
<td><code>type</code></td>
<td>For this event type, this will always be the string <code>"event"</code>.</td>
</tr>
<tr>
<td rowspan="5">
<code>"typ"</code><br />
A user in a thread is typing. Note that receiving this event type needs to be enabled with `api.setOptions({ listenTyping: true })`
</td>
<td><code>from</code></td>
<td>ID of the user who started/stopped typing.</td>
</tr>
<tr>
<td><code>fromMobile</code></td>
<td>Boolean representing whether or not the person's using a mobile device to type.</td>
</tr>
<tr>
<td><code>isTyping</code></td>
<td>Boolean representing whether or not a person started typing.</td>
</tr>
<tr>
<td><code>threadID</code></td>
<td>The threadID representing the thread in which a user is typing.</td>
</tr>
<tr>
<td><code>type</code></td>
<td>For this event type, this will always be the string <code>"typ"</code>.</td>
</tr>
<tr>
<td rowspan="3">
<code>"read"</code><br />
The current API user has read a message.
</td>
<td><code>threadID</code></td>
<td>The threadID representing the thread in which the message was sent.</td>
</tr>
<tr>
<td><code>time</code></td>
<td>The time at which the user read the message.</td>
</tr>
<tr>
<td><code>type</code></td>
<td>For this event type, this will always be the string <code>"read"</code>.</td>
</tr>
<tr>
<td rowspan="4">
<code>"read_receipt"</code><br />
A user within a thread has seen a message sent by the API user.
</td>
<td><code>reader</code></td>
<td>ID of the user who just read the message.</td>
</tr>
<tr>
<td><code>threadID</code></td>
<td>The thread in which the message was read.</td>
</tr>
<tr>
<td><code>time</code></td>
<td>The time at which the reader read the message.</td>
</tr>
<tr>
<td><code>type</code></td>
<td>For this event type, this will always be the string <code>"read_receipt"</code>.</td>
</tr>
<tr>
<td rowspan="8">
<code>"message_reaction"</code><br />
A user has sent a reaction to a message.
</td>
<td><code>messageID</code></td>
<td>The ID of the message</td>
</tr>
<tr>
<td><code>offlineThreadingID</code></td>
<td>The offline message ID</td>
</tr>
<tr>
<td><code>reaction</code></td>
<td>Contains reaction emoji</td>
</tr>
<tr>
<td><code>senderID</code></td>
<td>ID of the author the message, where has been reaction added</td>
</tr>
<tr>
<td><code>threadID</code></td>
<td>ID of the thread where the message has been sent</td>
</tr>
<tr>
<td><code>timestamp</code></td>
<td>Unix Timestamp (in miliseconds) when the reaction was sent</td>
</tr>
<tr>
<td><code>type</code></td>
<td>For this event type, this will always be the string <code>"message_reaction"</code>.</td>
</tr>
<tr>
<td><code>userID</code></td>
<td>ID of the reaction sender</td>
</tr>
<tr>
<td rowspan="4"><a name="presence"></a>
<code>"presence"</code><br />
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>
</td>
<td><code>statuses</code></td>
<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>
</tr>
<tr>
<td><code>timestamp</code></td>
<td>The time when the user was last online.</td>
</tr>
<tr>
<td><code>type</code></td>
<td>For this event type, this will always be the string <code>"presence"</code>.</td>
</tr>
<tr>
<td><code>userID</code></td>
<td>The ID of the user whose status this packet is describing.</td>
</tr>
<tr>
<td rowspan="5">
<code>"message_unsend"</code><br />
A revoke message request for a message from a thread was received.
</td>
<td><code>threadID</code></td>
<td>The threadID representing the thread in which the revoke message request was received.</td>
</tr>
<tr>
<td><code>senderID</code></td>
<td>The id of the person who request to revoke message on threadID.</td>
</tr>
<tr>
<td><code>messageID</code></td>
<td>A string representing the message ID that the person request to revoke message want to.</td>
</tr>
<tr>
<td><code>deletionTimestamp</code></td>
<td>The time when the request was sent.</td>
</tr>
<tr>
<td><code>type</code></td>
<td>For this event type, this will always be the string <code>"message_unsend"</code>.</td>
</tr>
<tr>
<td rowspan="10">
<code>"message_reply"</code><br />
A reply message was sent to a thread.
</td>
<td><code>attachments</code></td>
<td>An array of attachments to the message. Attachments vary in type, see the attachments table below.</td>
</tr>
<tr>
<td><code>body</code></td>
<td>The string corresponding to the message that was just received.</td>
</tr>
<tr>
<td><code>isGroup</code></td>
<td>boolean, true if this thread is a group thread (more than 2 participants).</td>
</tr>
<tr>
<td><code>mentions</code></td>
<td>An object containing people mentioned/tagged in the message in the format { id: name }</td>
</tr>
<tr>
<td><code>messageID</code></td>
<td>A string representing the message ID.</td>
</tr>
<tr>
<td><code>senderID</code></td>
<td>The id of the person who sent the message in the chat with threadID.</td>
</tr>
<tr>
<td><code>threadID</code></td>
<td>The threadID representing the thread in which the message was sent.</td>
</tr>
<tr>
<td><code>isUnread</code></td>
<td>Boolean representing whether or not the message was read.</td>
</tr>
<tr>
<td><code>type</code></td>
<td>For this event type, this will always be the string <code>"message_reply"</code>.</td>
</tr>
<tr>
<td><code>messageReply</code></td>
<td>An object represent a message being replied. Content inside is the same like a normal <code>"message"</code> event.</td>
</tr>
</table>
__Attachments__
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:
| Attachment Type | Fields |
| ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `"sticker"` | `ID`, `url`, `packID`, `spriteUrl`, `spriteUrl2x`, `width`, `height`, `caption`, `description`, `frameCount`, `frameRate`, `framesPerRow`, `framesPerCol` |
| `"file"` | `ID`, `filename`, `url`, `isMalicious`, `contentType` |
| `"photo"` | `ID`, `filename`, `thumbnailUrl`, `previewUrl`, `previewWidth`, `previewHeight`, `largePreviewUrl`, `largePreviewWidth`, `largePreviewHeight` |
| `"animated_image"` | `ID`, `filename`, `previewUrl`, `previewWidth`, `previewHeight`, `url`, `width`, `height` |
| `"video"` | `ID`, `filename`, `previewUrl`, `previewWidth`, `previewHeight`, `url`, `width`, `height`, `duration`, `videoType` |
| `"audio"` | `ID`, `filename`, `audioType`, `duration`, `url`, `isVoiceMail` |
| `"location"` | `ID`, `latitude`, `longitude`, `image`, `width`, `height`, `url`, `address` |
| `"share"` | `ID`, `url`, `title`, `description`, `source`, `image`, `width`, `height`, `playable`, `duration`, `playableUrl`, `subattachments`, `properties` |
__Example__
```js
const fs = require("fs-extra");
const login = require("fb-chat-api-temp");
// Simple echo bot. He'll repeat anything that you say.
// Will stop when you say '/stop'
login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
if(err) return console.error(err);
api.setOptions({listenEvents: true});
var listenEmitter = api.listen((err, event) => {
if(err) return console.error(err);
switch (event.type) {
case "message":
if(event.body === '/stop') {
api.sendMessage("Goodbye...", event.threadID);
return listenEmitter.stopListening();
}
api.markAsRead(event.threadID, (err) => {
if(err) console.log(err);
});
api.sendMessage("TEST BOT: " + event.body, event.threadID);
break;
case "event":
console.log(event);
break;
}
});
});
```
---------------------------------------
<a name="logout"></a>
### api.logout([callback])
Logs out the current user.
__Arguments__
* `callback(err)`: A callback called when the query is done (either with an error or with null).
---------------------------------------
<a name="markAsDelivered"></a>
### api.markAsDelivered(threadID, messageID, [callback]])
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.
You can also mark new messages as delivered automatically. This is enabled by default. See [api.setOptions](#setOptions).
__Arguments__
* `threadID` - The id of the thread in which you want to mark the message as delivered.
* `messageID` - The id of the message want to mark as delivered.
* `callback(err)` - A callback called when the operation is done maybe with an object representing an error.
__Example__
```js
const fs = require("fs-extra");
const login = require("facebook-chat-api");
login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
if(err) return console.error(err);
api.listen((err, message) => {
if(err) return console.error(err);
// Marks messages as delivered immediately after they're received
api.markAsDelivered(message.threadID, message.messageID);
});
});
```
---------------------------------------
<a name="markAsRead"></a>
### api.markAsRead(threadID, [read, [callback]])
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.
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.
__Arguments__
* `threadID` - The id of the thread in which you want to mark the messages as read.
* `read` - An optional boolean where `true` means to mark the message as being "read" and `false` means to mark the message as being "unread".
* `callback(err)` - A callback called when the operation is done maybe with an object representing an error.
__Example__
```js
const fs = require("fs-extra");
const login = require("fb-chat-api-temp");
login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
if(err) return console.error(err);
api.listen((err, message) => {
if(err) return console.error(err);
// Marks messages as read immediately after they're received
api.markAsRead(message.threadID);
});
});
```
---------------------------------------
<a name="markAsReadAll"></a>
### api.markAsReadAll([callback])
This function will mark all of messages in your inbox readed.
---------------------------------------
<a name="markAsSeen"></a>
### api.markAsSeen([seenTimestamp], [callback])
This function will mark your entire inbox as seen (don't be confused with read!).
---------------------------------------
<a name="muteThread"></a>
### api.muteThread(threadID, muteSeconds, [callback])
Mute a chat for a period of time, or unmute a chat.
__Arguments__
* `threadID` - The ID of the chat you want to mute.
* `muteSeconds` - Mute the chat for this amount of seconds. Use `0` to unmute a chat. Use '-1' to mute a chat indefinitely.
* `callback(err)` - A callback called when the operation is done maybe with an object representing an error.
__Example__
```js
const fs = require("fs-extra");
const login = require("fb-chat-api-temp");
login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
if(err) return console.error(err);
api.listen((err, message) => {
if(err) return console.error(err);
// Mute all incoming chats for one minute
api.muteThread(message.threadID, 60);
});
});
```
---------------------------------------
<a name="removeUserFromGroup"></a>
### api.removeUserFromGroup(userID, threadID, [callback])
Removes a user from a group chat.
__Arguments__
* `userID`: User ID.
* `threadID`: Group chat ID.
* `callback(err)`: A callback called when the query is done (either with an error or with no arguments).
---------------------------------------
<a name="resolvePhotoUrl"></a>
### api.resolvePhotoUrl(photoID, [callback])
Resolves the URL to the full-size photo, given its ID. This function is useful for retrieving the full-size photo URL
of image attachments in messages, returned by [`api.getThreadHistory`](#getThreadHistory).
__Arguments__
* `photoID`: Photo ID.
* `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.
---------------------------------------
<a name="searchForThread"></a>
### api.searchForThread(name, [callback])
> This part is outdated.
> see #396
Takes a chat title (thread name) and returns matching results as a formatted threads array (ordered according to Facebook).
__Arguments__
* `name`: A messageID string or messageID string array
* `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`
---------------------------------------
<a name="sendMessage"></a>
### api.sendMessage(message, threadID, [callback], messageID)
Sends the given message to the threadID.
__Arguments__
* `message`: A string (for backward compatibility) or a message object as described below.
* `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.
* `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.
* `messageID`: (Optional) A string representing a message you want to reply.
__Message Object__:
Various types of message can be sent:
* *Regular:* set field `body` to the desired message as a string.
* *Sticker:* set a field `sticker` to the desired sticker ID.
* *File or image:* Set field `attachment` to a readable stream or an array of readable streams.
* *URL:* set a field `url` to the desired URL.
* *Emoji:* set field `emoji` to the desired emoji as a string and set field `emojiSize` with size of the emoji (`small`, `medium`, `large`)
* *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`
can be passed in to specify the start index to start searching for the `tag` text
in `body` (default=0). (See below for an example.)
* *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.
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.
__Tip__: to find your own ID, you can look inside the cookies. The `userID` is under the name `c_user`.
__Example (Basic Message)__
```js
const fs = require("fs-extra");
const login = require("fb-chat-api-temp");
login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
if(err) return console.error(err);
var yourID = "000000000000000";
var msg = {body: "Hey!"};
api.sendMessage(msg, yourID);
});
```
__Example (File upload)__
```js
const fs = require("fs-extra");
const login = require("fb-chat-api-temp");
login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
if(err) return console.error(err);
// This example uploads an image called image.jpg
var yourID = "000000000000000";
var msg = {
body: "Hey!",
attachment: fs.createReadStream(__dirname + '/image.jpg')
}
api.sendMessage(msg, yourID);
});
```
__Example (Mention)__
```js
const login = require("fb-chat-api-temp");
login({email: "EMAIL", password: "PASSWORD"}, (err, api) => {
if(err) return console.error(err);
api.listen((err, message) => {
if (message && message.body) {
// Getting the actual sender name from ID involves calling
// `api.getThreadInfo` and `api.getUserInfo`
api.sendMessage({
body: 'Hello @Sender! @Sender!',
mentions: [{
tag: '@Sender',
id: message.senderID,
fromIndex: 9, // Highlight the second occurrence of @Sender
}],
}, message.threadID);
}
});
});
```
__Example (Location)__
```js
const login = require("fb-chat-api-temp");
login({email: "EMAIL", password: "PASSWORD"}, (err, api) => {
if(err) return console.error(err);
var yourID = "000000000000000";
const msg = {
location: { latitude: 48.858093, longitude: 2.294694, current: true },
};
api.sendMessage(msg, yourID);
});
```
---------------------------------------
<a name="sendTypingIndicator"></a>
### api.sendTypingIndicator(threadID, [callback])
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`.
__Arguments__
* `threadID`: Group chat ID.
* `callback(err)`: A callback called when the query is done (with an error or with null).
---------------------------------------
<a name="setMessageReaction"></a>
### api.setMessageReaction(reaction, messageID, [callback], forceCustomReaction)
Sets reaction on message
__Arguments__
* `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.
* `messageID`: A string representing the message ID.
* `callback(err)`: A callback called when sending the reaction is done.
* `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)**
__Supported Emojis__
| Emoji | Text | Unicode | Shortcuts |
| ----- | ---- | -------------- | --------------------------- |
| ๐ | `๐` | `\uD83D\uDE0D` | `:love:`, `:heart_eyes:` |
| ๐ | `๐` | `\uD83D\uDE06` | `:haha:`, `:laughing:` |
| ๐ฎ | `๐ฎ` | `\uD83D\uDE2E` | `:wow:`, `:open_mouth:` |
| ๐ข | `๐ข` | `\uD83D\uDE22` | `:sad:`, `:cry:` |
| ๐ | `๐ ` | `\uD83D\uDE20` | `:angry:` |
| ๐ | `๐` | `\uD83D\uDC4D` | `:like:`, `:thumbsup:` |
| ๐ | `๐` | `\uD83D\uDC4E` | `:dislike:`, `:thumbsdown:` |
| โค | `โค` | `\u2764` | `:heart:` |
| ๐ | `๐` | `\uD83D\uDC97` | `:glowingheart:` |
---------------------------------------
<a name="setOptions"></a>
### api.setOptions(options)
Sets various configurable options for the api.
__Arguments__
* `options` - An object containing the new values for the options that you want
to set. If the value for an option is unspecified, it is unchanged. The following options are possible.
- `logLevel`: The desired logging level as determined by npmlog. Choose
from either `"silly"`, `"verbose"`, `"info"`, `"http"`, `"warn"`, `"error"`, or `"silent"`.
- `selfListen`: (Default `false`) Set this to `true` if you want your api
to receive messages from its own account. This is to be used with
caution, as it can result in loops (a simple echo bot will send messages
forever).
- `listenEvents`: (Default `false`) Will make [api.listen](#listen) also handle events (look at api.listen for more details).
- `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.
- `updatePresence`: (Default `false`) Will make [api.listen](#listen) also return `presence` ([api.listen](#presence) for more details).
- `forceLogin`: (Default `false`) Will automatically approve of any recent logins and continue with the login process.
- `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.
__Example__
```js
const fs = require("fs-extra");
const login = require("fb-chat-api-temp");
// Simple echo bot. This will send messages forever.
login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
if(err) return console.error(err);
api.setOptions({
selfListen: true,
logLevel: "silent"
});
api.listen((err, message) => {
if(err) return console.error(err);
// Ignore empty messages (photos etc.)
if (typeof message.body === "string") {
api.sendMessage(message.body, message.threadID);
}
});
});
```
---------------------------------------
<a name="setPostReaction"></a>
### api.setPostReaction(postID, type, [callback])
__Arguments__
* `postID`: id of the post to react.
* `type`: A string reaction type or key reaction.
* `callback(err, obj)`: A callback called when the query is done.
| Key | Reaction Type |
| --- | ------------- |
| 0 | unlike |
| 1 | like |
| 2 | heart |
| 16 | love |
| 4 | haha |
| 3 | wow |
| 7 | sad |
| 8 | angry |
---------------------------------------
<a name="setTitle"></a>
### api.setTitle(newTitle, threadID, [callback])
Sets the title of the group chat with thread id `threadID` to `newTitle`.
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.
__Arguments__
* `newTitle`: A string representing the new title.
* `threadID`: A string or number representing a thread. It happens to be someone's userID in the case of a one to one conversation.
* `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.
---------------------------------------
<a name="unsendMessage"></a>
### api.unsendMessage(messageID, [callback])
Revokes a message from anyone that could see that message with `messageID`
Note: This will only work if the message is sent by you and was sent less than 10 minutes ago.
__Arguments__
* `messageID`: Message ID you want to unsend.
* `callback(err)`: A callback called when the query is done (with an error or with null).
---------------------------------------
<a name="uploadAttachments"></a>
### api.uploadAttachment(attachments, [callback])
This function is used to upload attachments to Facebook. It is used internally by [api.sendMessage](#apisendmessagemessage-threadid-callback-messageid).
__Arguments__
<!-- readable stream or an array of readable streams. -->
* `attachments`: A readable stream or an array of readable streams to upload.
* `callback(err, info)`: A callback called when the upload is done (either with an error or with the uploaded file info).
__Example__
```js
const fs = require("fs-extra");
const login = require("fb-chat-api-temp");
login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
if (err)
return console.error(err);
// Send a local file as a stream
const iamgeOne = fs.createReadStream(__dirname + '/image.jpg');
const iamgeTwo = fs.createReadStream(__dirname + '/image2.jpg');
api.uploadAttachment([iamgeOne, iamgeTwo], (err, attachments) => {
if(err)
return console.error(err);
console.log(attachments);
});
});
|