stfca 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/LICENSE-MIT +4 -0
  2. package/README.md +325 -0
  3. package/index.d.ts +615 -0
  4. package/index.js +1 -0
  5. package/module/config.js +33 -0
  6. package/module/login.js +48 -0
  7. package/module/loginHelper.js +722 -0
  8. package/module/options.js +44 -0
  9. package/package.json +69 -0
  10. package/src/api/action/addExternalModule.js +25 -0
  11. package/src/api/action/changeAvatar.js +137 -0
  12. package/src/api/action/changeBio.js +75 -0
  13. package/src/api/action/getCurrentUserID.js +7 -0
  14. package/src/api/action/handleFriendRequest.js +57 -0
  15. package/src/api/action/logout.js +76 -0
  16. package/src/api/action/refreshFb_dtsg.js +71 -0
  17. package/src/api/action/setPostReaction.js +106 -0
  18. package/src/api/action/unfriend.js +54 -0
  19. package/src/api/http/httpGet.js +46 -0
  20. package/src/api/http/httpPost.js +52 -0
  21. package/src/api/http/postFormData.js +47 -0
  22. package/src/api/messaging/addUserToGroup.js +68 -0
  23. package/src/api/messaging/changeAdminStatus.js +122 -0
  24. package/src/api/messaging/changeArchivedStatus.js +55 -0
  25. package/src/api/messaging/changeBlockedStatus.js +48 -0
  26. package/src/api/messaging/changeGroupImage.js +90 -0
  27. package/src/api/messaging/changeNickname.js +70 -0
  28. package/src/api/messaging/changeThreadColor.js +79 -0
  29. package/src/api/messaging/changeThreadEmoji.js +106 -0
  30. package/src/api/messaging/createNewGroup.js +88 -0
  31. package/src/api/messaging/createPoll.js +43 -0
  32. package/src/api/messaging/deleteMessage.js +56 -0
  33. package/src/api/messaging/deleteThread.js +56 -0
  34. package/src/api/messaging/editMessage.js +68 -0
  35. package/src/api/messaging/forwardAttachment.js +51 -0
  36. package/src/api/messaging/getEmojiUrl.js +29 -0
  37. package/src/api/messaging/getFriendsList.js +82 -0
  38. package/src/api/messaging/getMessage.js +829 -0
  39. package/src/api/messaging/handleMessageRequest.js +65 -0
  40. package/src/api/messaging/markAsDelivered.js +57 -0
  41. package/src/api/messaging/markAsRead.js +88 -0
  42. package/src/api/messaging/markAsReadAll.js +49 -0
  43. package/src/api/messaging/markAsSeen.js +61 -0
  44. package/src/api/messaging/muteThread.js +50 -0
  45. package/src/api/messaging/removeUserFromGroup.js +105 -0
  46. package/src/api/messaging/resolvePhotoUrl.js +43 -0
  47. package/src/api/messaging/searchForThread.js +52 -0
  48. package/src/api/messaging/sendMessage.js +379 -0
  49. package/src/api/messaging/sendMessageMqtt.js +323 -0
  50. package/src/api/messaging/sendTypingIndicator.js +67 -0
  51. package/src/api/messaging/setMessageReaction.js +75 -0
  52. package/src/api/messaging/setTitle.js +119 -0
  53. package/src/api/messaging/shareContact.js +49 -0
  54. package/src/api/messaging/threadColors.js +128 -0
  55. package/src/api/messaging/unsendMessage.js +81 -0
  56. package/src/api/messaging/uploadAttachment.js +95 -0
  57. package/src/api/socket/core/connectMqtt.js +179 -0
  58. package/src/api/socket/core/getSeqID.js +25 -0
  59. package/src/api/socket/core/getTaskResponseData.js +22 -0
  60. package/src/api/socket/core/markDelivery.js +12 -0
  61. package/src/api/socket/core/parseDelta.js +351 -0
  62. package/src/api/socket/detail/buildStream.js +208 -0
  63. package/src/api/socket/detail/constants.js +24 -0
  64. package/src/api/socket/listenMqtt.js +133 -0
  65. package/src/api/threads/getThreadHistory.js +664 -0
  66. package/src/api/threads/getThreadInfo.js +358 -0
  67. package/src/api/threads/getThreadList.js +248 -0
  68. package/src/api/threads/getThreadPictures.js +78 -0
  69. package/src/api/users/getUserID.js +65 -0
  70. package/src/api/users/getUserInfo.js +319 -0
  71. package/src/api/users/getUserInfoV2.js +133 -0
  72. package/src/core/sendReqMqtt.js +63 -0
  73. package/src/database/models/index.js +49 -0
  74. package/src/database/models/thread.js +31 -0
  75. package/src/database/models/user.js +32 -0
  76. package/src/database/threadData.js +98 -0
  77. package/src/database/userData.js +89 -0
  78. package/src/utils/client.js +214 -0
  79. package/src/utils/constants.js +23 -0
  80. package/src/utils/format.js +1111 -0
  81. package/src/utils/headers.js +41 -0
  82. package/src/utils/request.js +215 -0
@@ -0,0 +1,44 @@
1
+ const { getType } = require("../src/utils/format");
2
+ const { setProxy } = require("../src/utils/request");
3
+ const Boolean_Option = [
4
+ "online",
5
+ "selfListen",
6
+ "listenEvents",
7
+ "updatePresence",
8
+ "forceLogin",
9
+ "autoMarkDelivery",
10
+ "autoMarkRead",
11
+ "listenTyping",
12
+ "autoReconnect",
13
+ "emitReady",
14
+ "selfListenEvent"
15
+ ];
16
+ function setOptions(globalOptions, options) {
17
+ for (const key of Object.keys(options || {})) {
18
+ if (Boolean_Option.includes(key)) {
19
+ globalOptions[key] = Boolean(options[key]);
20
+ continue;
21
+ }
22
+ switch (key) {
23
+ case "userAgent": {
24
+ globalOptions.userAgent = options.userAgent || "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36";
25
+ break;
26
+ }
27
+ case "proxy": {
28
+ if (typeof options.proxy !== "string") {
29
+ delete globalOptions.proxy;
30
+ setProxy();
31
+ } else {
32
+ globalOptions.proxy = options.proxy;
33
+ setProxy(globalOptions.proxy);
34
+ }
35
+ break;
36
+ }
37
+ default: {
38
+ console.warn("setOptions Unrecognized option given to setOptions: " + key);
39
+ break;
40
+ }
41
+ }
42
+ }
43
+ }
44
+ module.exports = { setOptions, Boolean_Option };
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "stfca",
3
+ "version": "1.0.0",
4
+ "description": "Unofficial Facebook Chat API for Node.js",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"No tests specified\" && exit 0",
8
+ "lint": "eslint .",
9
+ "prepublishOnly": "echo \"Preparing to publish...\""
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/sheikhtamimlover/fca-unofficial.git"
14
+ },
15
+ "keywords": [
16
+ "facebook",
17
+ "chat",
18
+ "api",
19
+ "messenger",
20
+ "bot",
21
+ "unofficial",
22
+ "automation",
23
+ "facebook-api",
24
+ "facebook-chat",
25
+ "facebook-messenger",
26
+ "chatbot",
27
+ "nodejs",
28
+ "fca"
29
+ ],
30
+ "author": {
31
+ "name": "ST | Sheikh Tamim",
32
+ "url": "https://www.facebook.com/hamza.chudena"
33
+ },
34
+ "license": "MIT",
35
+ "bugs": {
36
+ "url": "https://github.com/sheikhtamimlover/fca-unofficial/issues"
37
+ },
38
+ "homepage": "https://github.com/sheikhtamimlover/fca-unofficial#readme",
39
+ "engines": {
40
+ "node": ">=12.0.0"
41
+ },
42
+ "dependencies": {
43
+ "axios": "latest",
44
+ "axios-cookiejar-support": "^5.0.5",
45
+ "bluebird": "^3.7.2",
46
+ "chalk": "^4.1.2",
47
+ "cheerio": "^1.0.0-rc.10",
48
+ "duplexify": "^4.1.3",
49
+ "gradient-string": "^2.0.2",
50
+ "https-proxy-agent": "^4.0.0",
51
+ "mqtt": "^4.3.8",
52
+ "npmlog": "^1.2.0",
53
+ "request": "^2.53.0",
54
+ "sequelize": "^6.37.6",
55
+ "sqlite3": "^5.1.7",
56
+ "totp-generator": "^1.0.0",
57
+ "ws": "^8.18.1"
58
+ },
59
+ "devDependencies": {
60
+ "eslint": "^8.50.0",
61
+ "mocha": "^10.2.0"
62
+ },
63
+ "optionalDependencies": {},
64
+ "peerDependencies": {},
65
+ "publishConfig": {
66
+ "access": "public",
67
+ "registry": "https://registry.npmjs.org/"
68
+ }
69
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ const { getType } = require("../../utils/format");
4
+
5
+ module.exports = function(defaultFuncs, api, ctx) {
6
+ return function addExternalModule(moduleObj) {
7
+ if (getType(moduleObj) == "Object") {
8
+ for (const apiName in moduleObj) {
9
+ if (getType(moduleObj[apiName]) == "Function") {
10
+ api[apiName] = moduleObj[apiName](defaultFuncs, api, ctx);
11
+ } else {
12
+ throw new Error(
13
+ `Item "${apiName}" in moduleObj must be a function, not ${getType(
14
+ moduleObj[apiName]
15
+ )}!`
16
+ );
17
+ }
18
+ }
19
+ } else {
20
+ throw new Error(
21
+ `moduleObj must be an object, not ${getType(moduleObj)}!`
22
+ );
23
+ }
24
+ };
25
+ };
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+
3
+ const log = require("npmlog");
4
+ const { isReadableStream } = require("../../utils/constants");
5
+ const { parseAndCheckLogin } = require("../../utils/client");
6
+ const { formatID, getType } = require("../../utils/format");
7
+ module.exports = function(defaultFuncs, api, ctx) {
8
+ function handleUpload(image, callback) {
9
+ const uploads = [];
10
+
11
+ const form = {
12
+ profile_id: ctx.userID,
13
+ photo_source: 57,
14
+ av: ctx.userID,
15
+ file: image
16
+ };
17
+
18
+ uploads.push(
19
+ defaultFuncs
20
+ .postFormData(
21
+ "https://www.facebook.com/profile/picture/upload/",
22
+ ctx.jar,
23
+ form,
24
+ {}
25
+ )
26
+ .then(parseAndCheckLogin(ctx, defaultFuncs))
27
+ .then(function(resData) {
28
+ if (resData.error) {
29
+ throw resData;
30
+ }
31
+ return resData;
32
+ })
33
+ );
34
+
35
+ // resolve all promises
36
+ Promise.all(uploads)
37
+ .then(function(resData) {
38
+ callback(null, resData);
39
+ })
40
+ .catch(function(err) {
41
+ log.error("handleUpload", err);
42
+ return callback(err);
43
+ });
44
+ }
45
+
46
+ return function changeAvatar(
47
+ image,
48
+ caption = "",
49
+ timestamp = null,
50
+ callback
51
+ ) {
52
+ let resolveFunc = function() {};
53
+ let rejectFunc = function() {};
54
+ const returnPromise = new Promise(function(resolve, reject) {
55
+ resolveFunc = resolve;
56
+ rejectFunc = reject;
57
+ });
58
+
59
+ if (!timestamp && getType(caption) === "Number") {
60
+ timestamp = caption;
61
+ caption = "";
62
+ }
63
+
64
+ if (
65
+ !timestamp &&
66
+ !callback &&
67
+ (getType(caption) == "Function" ||
68
+ getType(caption) == "AsyncFunction")
69
+ ) {
70
+ callback = caption;
71
+ caption = "";
72
+ timestamp = null;
73
+ }
74
+
75
+ if (!callback)
76
+ callback = function(err, data) {
77
+ if (err) {
78
+ return rejectFunc(err);
79
+ }
80
+ resolveFunc(data);
81
+ };
82
+
83
+ if (!isReadableStream(image))
84
+ return callback("Image is not a readable stream");
85
+
86
+ handleUpload(image, function(err, payload) {
87
+ if (err) {
88
+ return callback(err);
89
+ }
90
+
91
+ const form = {
92
+ av: ctx.i_userID || ctx.userID,
93
+ fb_api_req_friendly_name: "ProfileCometProfilePictureSetMutation",
94
+ fb_api_caller_class: "RelayModern",
95
+ doc_id: "5066134240065849",
96
+ variables: JSON.stringify({
97
+ input: {
98
+ caption,
99
+ existing_photo_id: payload[0].payload.fbid,
100
+ expiration_time: timestamp,
101
+ profile_id: ctx.i_userID || ctx.userID,
102
+ profile_pic_method: "EXISTING",
103
+ profile_pic_source: "TIMELINE",
104
+ scaled_crop_rect: {
105
+ height: 1,
106
+ width: 1,
107
+ x: 0,
108
+ y: 0
109
+ },
110
+ skip_cropping: true,
111
+ actor_id: ctx.i_userID || ctx.userID,
112
+ client_mutation_id: Math.round(Math.random() * 19).toString()
113
+ },
114
+ isPage: false,
115
+ isProfile: true,
116
+ scale: 3
117
+ })
118
+ };
119
+
120
+ defaultFuncs
121
+ .post("https://www.facebook.com/api/graphql/", ctx.jar, form)
122
+ .then(parseAndCheckLogin(ctx, defaultFuncs))
123
+ .then(function(resData) {
124
+ if (resData.errors) {
125
+ throw resData;
126
+ }
127
+ return callback(null, resData[0].data.profile_picture_set);
128
+ })
129
+ .catch(function(err) {
130
+ log.error("changeAvatar", err);
131
+ return callback(err);
132
+ });
133
+ });
134
+
135
+ return returnPromise;
136
+ };
137
+ };
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+
3
+ const log = require("npmlog");
4
+ const { parseAndCheckLogin } = require("../../utils/client");
5
+ const { getType } = require("../../utils/format");
6
+ module.exports = function(defaultFuncs, api, ctx) {
7
+ return function changeBio(bio, publish, callback) {
8
+ let resolveFunc = function() {};
9
+ let rejectFunc = function() {};
10
+ const returnPromise = new Promise(function(resolve, reject) {
11
+ resolveFunc = resolve;
12
+ rejectFunc = reject;
13
+ });
14
+
15
+ if (!callback) {
16
+ if (
17
+ getType(publish) == "Function" ||
18
+ getType(publish) == "AsyncFunction"
19
+ ) {
20
+ callback = publish;
21
+ } else {
22
+ callback = function(err) {
23
+ if (err) {
24
+ return rejectFunc(err);
25
+ }
26
+ resolveFunc();
27
+ };
28
+ }
29
+ }
30
+
31
+ if (getType(publish) != "Boolean") {
32
+ publish = false;
33
+ }
34
+
35
+ if (getType(bio) != "String") {
36
+ bio = "";
37
+ publish = false;
38
+ }
39
+
40
+ const form = {
41
+ fb_api_caller_class: "RelayModern",
42
+ fb_api_req_friendly_name: "ProfileCometSetBioMutation",
43
+ doc_id: "2725043627607610",
44
+ variables: JSON.stringify({
45
+ input: {
46
+ bio: bio,
47
+ publish_bio_feed_story: publish,
48
+ actor_id: ctx.i_userID || ctx.userID,
49
+ client_mutation_id: Math.round(Math.random() * 1024).toString()
50
+ },
51
+ hasProfileTileViewID: false,
52
+ profileTileViewID: null,
53
+ scale: 1
54
+ }),
55
+ av: ctx.i_userID || ctx.userID
56
+ };
57
+
58
+ defaultFuncs
59
+ .post("https://www.facebook.com/api/graphql/", ctx.jar, form)
60
+ .then(parseAndCheckLogin(ctx, defaultFuncs))
61
+ .then(function(resData) {
62
+ if (resData.errors) {
63
+ throw resData;
64
+ }
65
+
66
+ return callback();
67
+ })
68
+ .catch(function(err) {
69
+ log.error("changeBio", err);
70
+ return callback(err);
71
+ });
72
+
73
+ return returnPromise;
74
+ };
75
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ module.exports = function(defaultFuncs, api, ctx) {
4
+ return function getCurrentUserID() {
5
+ return ctx.userID;
6
+ };
7
+ };
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ const log = require("npmlog");
4
+ const { parseAndCheckLogin } = require("../../utils/client");
5
+ const { getType } = require("../../utils/format");
6
+ module.exports = function(defaultFuncs, api, ctx) {
7
+ return function handleFriendRequest(userID, accept, callback) {
8
+ if (getType(accept) !== "Boolean") {
9
+ throw {
10
+ error: "Please pass a boolean as a second argument."
11
+ };
12
+ }
13
+
14
+ let resolveFunc = function() {};
15
+ let rejectFunc = function() {};
16
+ const returnPromise = new Promise(function(resolve, reject) {
17
+ resolveFunc = resolve;
18
+ rejectFunc = reject;
19
+ });
20
+
21
+ if (!callback) {
22
+ callback = function(err, friendList) {
23
+ if (err) {
24
+ return rejectFunc(err);
25
+ }
26
+ resolveFunc(friendList);
27
+ };
28
+ }
29
+
30
+ const form = {
31
+ viewer_id: ctx.userID,
32
+ "frefs[0]": "jwl",
33
+ floc: "friend_center_requests",
34
+ ref: "/reqs.php",
35
+ action: accept ? "confirm" : "reject"
36
+ };
37
+
38
+ defaultFuncs
39
+ .post("https://www.facebook.com/requests/friends/ajax/", ctx.jar, form)
40
+ .then(parseAndCheckLogin(ctx, defaultFuncs))
41
+ .then(function(resData) {
42
+ if (resData.payload.err) {
43
+ throw {
44
+ err: resData.payload.err
45
+ };
46
+ }
47
+
48
+ return callback();
49
+ })
50
+ .catch(function(err) {
51
+ log.error("handleFriendRequest", err);
52
+ return callback(err);
53
+ });
54
+
55
+ return returnPromise;
56
+ };
57
+ };
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+
3
+ const log = require("npmlog");
4
+ const { parseAndCheckLogin } = require("../../utils/client");
5
+ const { getFrom } = require("../../utils/constants");
6
+ const { saveCookies } = require("../../utils/client");
7
+ module.exports = function(defaultFuncs, api, ctx) {
8
+ return function logout(callback) {
9
+ let resolveFunc = function() {};
10
+ let rejectFunc = function() {};
11
+ const returnPromise = new Promise(function(resolve, reject) {
12
+ resolveFunc = resolve;
13
+ rejectFunc = reject;
14
+ });
15
+
16
+ if (!callback) {
17
+ callback = function(err, friendList) {
18
+ if (err) {
19
+ return rejectFunc(err);
20
+ }
21
+ resolveFunc(friendList);
22
+ };
23
+ }
24
+
25
+ const form = {
26
+ pmid: "0"
27
+ };
28
+
29
+ defaultFuncs
30
+ .post(
31
+ "https://www.facebook.com/bluebar/modern_settings_menu/?help_type=364455653583099&show_contextual_help=1",
32
+ ctx.jar,
33
+ form
34
+ )
35
+ .then(parseAndCheckLogin(ctx, defaultFuncs))
36
+ .then(function(resData) {
37
+ const elem = resData.jsmods.instances[0][2][0].filter(function(v) {
38
+ return v.value === "logout";
39
+ })[0];
40
+
41
+ const html = resData.jsmods.markup.filter(function(v) {
42
+ return v[0] === elem.markup.__m;
43
+ })[0][1].__html;
44
+
45
+ const form = {
46
+ fb_dtsg: getFrom(html, '"fb_dtsg" value="', '"'),
47
+ ref: getFrom(html, '"ref" value="', '"'),
48
+ h: getFrom(html, '"h" value="', '"')
49
+ };
50
+
51
+ return defaultFuncs
52
+ .post("https://www.facebook.com/logout.php", ctx.jar, form)
53
+ .then(saveCookies(ctx.jar));
54
+ })
55
+ .then(function(res) {
56
+ if (!res.headers) {
57
+ throw { error: "An error occurred when logging out." };
58
+ }
59
+
60
+ return defaultFuncs
61
+ .get(res.headers.location, ctx.jar)
62
+ .then(saveCookies(ctx.jar));
63
+ })
64
+ .then(function() {
65
+ ctx.loggedIn = false;
66
+ log.info("logout", "Logged out successfully.");
67
+ callback();
68
+ })
69
+ .catch(function(err) {
70
+ log.error("logout", err);
71
+ return callback(err);
72
+ });
73
+
74
+ return returnPromise;
75
+ };
76
+ };
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+
3
+ const log = require("npmlog");
4
+ const { getFrom } = require("../../utils/constants");
5
+ const { get } = require("../../utils/request")
6
+ module.exports = function(defaultFuncs, api, ctx) {
7
+ return function refreshFb_dtsg(obj, callback) {
8
+ let resolveFunc, rejectFunc;
9
+ const returnPromise = new Promise((resolve, reject) => {
10
+ resolveFunc = resolve;
11
+ rejectFunc = reject;
12
+ });
13
+ if (
14
+ getType(obj) === "Function" ||
15
+ getType(obj) === "AsyncFunction"
16
+ ) {
17
+ callback = obj;
18
+ obj = {};
19
+ }
20
+ if (!obj) obj = {};
21
+ if (getType(obj) !== "Object") {
22
+ throw Error(
23
+ "The first parameter must be an object or a callback function"
24
+ );
25
+ }
26
+ if (!callback) {
27
+ callback = (err, data) => (err ? rejectFunc(err) : resolveFunc(data));
28
+ }
29
+ if (Object.keys(obj).length === 0) {
30
+ get(
31
+ "https://www.facebook.com/",
32
+ ctx.jar,
33
+ null,
34
+ ctx.globalOptions,
35
+ {
36
+ noRef: true
37
+ }
38
+ )
39
+ .then(resData => {
40
+ const fb_dtsg = getFrom(
41
+ resData.body,
42
+ '["DTSGInitData",[],{"token":"',
43
+ '","'
44
+ );
45
+ const jazoest = getFrom(resData.body, "jazoest=", '",');
46
+ if (!fb_dtsg) {
47
+ throw Error(
48
+ "Could not find fb_dtsg in HTML after requesting Facebook."
49
+ );
50
+ }
51
+ ctx.fb_dtsg = fb_dtsg;
52
+ ctx.jazoest = jazoest;
53
+ callback(null, {
54
+ data: { fb_dtsg, jazoest },
55
+ message: "Refreshed fb_dtsg and jazoest"
56
+ });
57
+ })
58
+ .catch(err => {
59
+ log.error("refreshFb_dtsg", err);
60
+ callback(err);
61
+ });
62
+ } else {
63
+ Object.assign(ctx, obj);
64
+ callback(null, {
65
+ data: obj,
66
+ message: "Refreshed " + Object.keys(obj).join(", ")
67
+ });
68
+ }
69
+ return returnPromise;
70
+ };
71
+ };
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+
3
+ const log = require("npmlog");
4
+ const { parseAndCheckLogin } = require("../../utils/client");
5
+ const { getType } = require("../../utils/format");
6
+ function formatData(resData) {
7
+ return {
8
+ viewer_feedback_reaction_info:
9
+ resData.feedback_react.feedback.viewer_feedback_reaction_info,
10
+ supported_reactions: resData.feedback_react.feedback.supported_reactions,
11
+ top_reactions: resData.feedback_react.feedback.top_reactions.edges,
12
+ reaction_count: resData.feedback_react.feedback.reaction_count
13
+ };
14
+ }
15
+
16
+ module.exports = function(defaultFuncs, api, ctx) {
17
+ return function setPostReaction(postID, type, callback) {
18
+ let resolveFunc = function() {};
19
+ let rejectFunc = function() {};
20
+ const returnPromise = new Promise(function(resolve, reject) {
21
+ resolveFunc = resolve;
22
+ rejectFunc = reject;
23
+ });
24
+
25
+ if (!callback) {
26
+ if (
27
+ getType(type) === "Function" ||
28
+ getType(type) === "AsyncFunction"
29
+ ) {
30
+ callback = type;
31
+ type = 0;
32
+ } else {
33
+ callback = function(err, data) {
34
+ if (err) {
35
+ return rejectFunc(err);
36
+ }
37
+ resolveFunc(data);
38
+ };
39
+ }
40
+ }
41
+
42
+ const map = {
43
+ unlike: 0,
44
+ like: 1,
45
+ heart: 2,
46
+ love: 16,
47
+ haha: 4,
48
+ wow: 3,
49
+ sad: 7,
50
+ angry: 8
51
+ };
52
+
53
+ if (getType(type) !== "Number" && getType(type) === "String") {
54
+ type = map[type.toLowerCase()];
55
+ }
56
+
57
+ if (getType(type) !== "Number" && getType(type) !== "String") {
58
+ throw {
59
+ error: "setPostReaction: Invalid reaction type"
60
+ };
61
+ }
62
+
63
+ if (type != 0 && !type) {
64
+ throw {
65
+ error: "setPostReaction: Invalid reaction type"
66
+ };
67
+ }
68
+
69
+ const form = {
70
+ av: ctx.userID,
71
+ fb_api_caller_class: "RelayModern",
72
+ fb_api_req_friendly_name: "CometUFIFeedbackReactMutation",
73
+ doc_id: "4769042373179384",
74
+ variables: JSON.stringify({
75
+ input: {
76
+ actor_id: ctx.userID,
77
+ feedback_id: Buffer.from("feedback:" + postID).toString("base64"),
78
+ feedback_reaction: type,
79
+ feedback_source: "OBJECT",
80
+ is_tracking_encrypted: true,
81
+ tracking: [],
82
+ session_id: "f7dd50dd-db6e-4598-8cd9-561d5002b423",
83
+ client_mutation_id: Math.round(Math.random() * 19).toString()
84
+ },
85
+ useDefaultActor: false,
86
+ scale: 3
87
+ })
88
+ };
89
+
90
+ defaultFuncs
91
+ .post("https://www.facebook.com/api/graphql/", ctx.jar, form)
92
+ .then(parseAndCheckLogin(ctx, defaultFuncs))
93
+ .then(function(resData) {
94
+ if (resData.errors) {
95
+ throw resData;
96
+ }
97
+ return callback(null, formatData(resData.data));
98
+ })
99
+ .catch(function(err) {
100
+ log.error("setPostReaction", err);
101
+ return callback(err);
102
+ });
103
+
104
+ return returnPromise;
105
+ };
106
+ };