@dongdev/fca-unofficial 3.0.30 → 4.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 (104) hide show
  1. package/LICENSE +191 -0
  2. package/README.md +224 -406
  3. package/dist/index.d.mts +1241 -0
  4. package/dist/index.d.ts +1241 -0
  5. package/dist/index.js +27749 -0
  6. package/dist/index.mjs +27713 -0
  7. package/docs/ARCHITECTURE.md +467 -0
  8. package/docs/DOCS.md +686 -0
  9. package/fca-config.example.json +33 -0
  10. package/package.json +33 -22
  11. package/test/fca.test.cjs +533 -0
  12. package/CHANGELOG.md +0 -293
  13. package/DOCS.md +0 -2712
  14. package/func/checkUpdate.js +0 -222
  15. package/func/logAdapter.js +0 -33
  16. package/func/logger.js +0 -48
  17. package/index.d.ts +0 -751
  18. package/index.js +0 -8
  19. package/module/config.js +0 -40
  20. package/module/login.js +0 -133
  21. package/module/loginHelper.js +0 -1296
  22. package/module/options.js +0 -44
  23. package/src/api/action/addExternalModule.js +0 -25
  24. package/src/api/action/changeAvatar.js +0 -137
  25. package/src/api/action/changeBio.js +0 -75
  26. package/src/api/action/enableAutoSaveAppState.js +0 -73
  27. package/src/api/action/getCurrentUserID.js +0 -7
  28. package/src/api/action/handleFriendRequest.js +0 -57
  29. package/src/api/action/logout.js +0 -76
  30. package/src/api/action/refreshFb_dtsg.js +0 -48
  31. package/src/api/action/setPostReaction.js +0 -106
  32. package/src/api/action/unfriend.js +0 -54
  33. package/src/api/http/httpGet.js +0 -46
  34. package/src/api/http/httpPost.js +0 -52
  35. package/src/api/http/postFormData.js +0 -47
  36. package/src/api/messaging/addUserToGroup.js +0 -68
  37. package/src/api/messaging/changeAdminStatus.js +0 -126
  38. package/src/api/messaging/changeArchivedStatus.js +0 -55
  39. package/src/api/messaging/changeBlockedStatus.js +0 -48
  40. package/src/api/messaging/changeGroupImage.js +0 -91
  41. package/src/api/messaging/changeNickname.js +0 -70
  42. package/src/api/messaging/changeThreadColor.js +0 -79
  43. package/src/api/messaging/changeThreadEmoji.js +0 -111
  44. package/src/api/messaging/createNewGroup.js +0 -88
  45. package/src/api/messaging/createPoll.js +0 -46
  46. package/src/api/messaging/createThemeAI.js +0 -98
  47. package/src/api/messaging/deleteMessage.js +0 -136
  48. package/src/api/messaging/deleteThread.js +0 -56
  49. package/src/api/messaging/editMessage.js +0 -68
  50. package/src/api/messaging/forwardAttachment.js +0 -57
  51. package/src/api/messaging/getEmojiUrl.js +0 -29
  52. package/src/api/messaging/getFriendsList.js +0 -82
  53. package/src/api/messaging/getMessage.js +0 -829
  54. package/src/api/messaging/getThemePictures.js +0 -62
  55. package/src/api/messaging/handleMessageRequest.js +0 -65
  56. package/src/api/messaging/markAsDelivered.js +0 -57
  57. package/src/api/messaging/markAsRead.js +0 -88
  58. package/src/api/messaging/markAsReadAll.js +0 -49
  59. package/src/api/messaging/markAsSeen.js +0 -61
  60. package/src/api/messaging/muteThread.js +0 -50
  61. package/src/api/messaging/removeUserFromGroup.js +0 -62
  62. package/src/api/messaging/resolvePhotoUrl.js +0 -43
  63. package/src/api/messaging/scheduler.js +0 -264
  64. package/src/api/messaging/searchForThread.js +0 -52
  65. package/src/api/messaging/sendMessage.js +0 -270
  66. package/src/api/messaging/sendTypingIndicator.js +0 -74
  67. package/src/api/messaging/setMessageReaction.js +0 -91
  68. package/src/api/messaging/setTitle.js +0 -124
  69. package/src/api/messaging/shareContact.js +0 -49
  70. package/src/api/messaging/threadColors.js +0 -128
  71. package/src/api/messaging/unsendMessage.js +0 -81
  72. package/src/api/messaging/uploadAttachment.js +0 -492
  73. package/src/api/socket/core/connectMqtt.js +0 -258
  74. package/src/api/socket/core/emitAuth.js +0 -103
  75. package/src/api/socket/core/getSeqID.js +0 -320
  76. package/src/api/socket/core/getTaskResponseData.js +0 -25
  77. package/src/api/socket/core/parseDelta.js +0 -377
  78. package/src/api/socket/detail/buildStream.js +0 -215
  79. package/src/api/socket/detail/constants.js +0 -28
  80. package/src/api/socket/listenMqtt.js +0 -377
  81. package/src/api/socket/middleware/index.js +0 -216
  82. package/src/api/threads/getThreadHistory.js +0 -664
  83. package/src/api/threads/getThreadInfo.js +0 -295
  84. package/src/api/threads/getThreadList.js +0 -293
  85. package/src/api/threads/getThreadPictures.js +0 -78
  86. package/src/api/users/getUserID.js +0 -65
  87. package/src/api/users/getUserInfo.js +0 -399
  88. package/src/api/users/getUserInfoV2.js +0 -134
  89. package/src/core/sendReqMqtt.js +0 -96
  90. package/src/database/models/index.js +0 -87
  91. package/src/database/models/thread.js +0 -50
  92. package/src/database/models/user.js +0 -46
  93. package/src/database/threadData.js +0 -98
  94. package/src/database/userData.js +0 -89
  95. package/src/remote/remoteClient.js +0 -123
  96. package/src/utils/broadcast.js +0 -51
  97. package/src/utils/client.js +0 -10
  98. package/src/utils/constants.js +0 -23
  99. package/src/utils/cookies.js +0 -68
  100. package/src/utils/format.js +0 -1174
  101. package/src/utils/headers.js +0 -115
  102. package/src/utils/loginParser.js +0 -365
  103. package/src/utils/messageFormat.js +0 -1173
  104. package/src/utils/request.js +0 -332
package/module/options.js DELETED
@@ -1,44 +0,0 @@
1
- const { getType } = require("../src/utils/format");
2
- const { setProxy } = require("../src/utils/request");
3
- const logger = require("../func/logger");
4
- const Boolean_Option = [
5
- "online",
6
- "selfListen",
7
- "listenEvents",
8
- "updatePresence",
9
- "forceLogin",
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
- logger("setOptions Unrecognized option given to setOptions: " + key, "warn");
39
- break;
40
- }
41
- }
42
- }
43
- }
44
- module.exports = { setOptions, Boolean_Option };
@@ -1,25 +0,0 @@
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
- };
@@ -1,137 +0,0 @@
1
- "use strict";
2
-
3
- const log = require("../../../func/logAdapter");
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
- };
@@ -1,75 +0,0 @@
1
- "use strict";
2
-
3
- const log = require("../../../func/logAdapter");
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
- };
@@ -1,73 +0,0 @@
1
- "use strict";
2
- const fs = require("fs");
3
- const path = require("path");
4
- const logger = require("../../../func/logger");
5
-
6
- /**
7
- * Enable automatic AppState saving
8
- * @param {Object} options - Options for auto-save
9
- * @param {string} [options.filePath] - Path to save AppState (default: "appstate.json")
10
- * @param {number} [options.interval] - Save interval in milliseconds (default: 10 minutes)
11
- * @param {boolean} [options.saveOnLogin] - Save immediately on login (default: true)
12
- * @returns {Function} Function to disable auto-save
13
- */
14
- module.exports = function (defaultFuncs, api, ctx) {
15
- return function enableAutoSaveAppState(options = {}) {
16
- const filePath = options.filePath || path.join(process.cwd(), "appstate.json");
17
- const interval = options.interval || 10 * 60 * 1000; // 10 minutes default
18
- const saveOnLogin = options.saveOnLogin !== false; // default true
19
-
20
- // Save function
21
- function saveAppState() {
22
- try {
23
- const appState = api.getAppState();
24
- if (!appState || !appState.appState || appState.appState.length === 0) {
25
- logger("AppState is empty, skipping save", "warn");
26
- return;
27
- }
28
-
29
- const data = JSON.stringify(appState, null, 2);
30
- fs.writeFileSync(filePath, data, "utf8");
31
- logger(`AppState saved to ${filePath}`, "info");
32
- } catch (error) {
33
- logger(`Error saving AppState: ${error && error.message ? error.message : String(error)}`, "error");
34
- }
35
- }
36
-
37
- // Save immediately if requested
38
- let immediateSaveTimer = null;
39
- if (saveOnLogin) {
40
- // Delay a bit to ensure login is complete
41
- immediateSaveTimer = setTimeout(() => {
42
- saveAppState();
43
- immediateSaveTimer = null;
44
- }, 2000);
45
- }
46
-
47
- // Set up interval
48
- const intervalId = setInterval(saveAppState, interval);
49
- logger(`Auto-save AppState enabled: ${filePath} (every ${Math.round(interval / 1000 / 60)} minutes)`, "info");
50
-
51
- // Store interval ID for cleanup
52
- if (!ctx._autoSaveInterval) {
53
- ctx._autoSaveInterval = [];
54
- }
55
- ctx._autoSaveInterval.push(intervalId);
56
-
57
- // Return disable function
58
- return function disableAutoSaveAppState() {
59
- // Clear immediate save timer if still pending
60
- if (immediateSaveTimer) {
61
- clearTimeout(immediateSaveTimer);
62
- immediateSaveTimer = null;
63
- }
64
- // Clear interval
65
- clearInterval(intervalId);
66
- const index = ctx._autoSaveInterval ? ctx._autoSaveInterval.indexOf(intervalId) : -1;
67
- if (index !== -1) {
68
- ctx._autoSaveInterval.splice(index, 1);
69
- }
70
- logger("Auto-save AppState disabled", "info");
71
- };
72
- };
73
- };
@@ -1,7 +0,0 @@
1
- "use strict";
2
-
3
- module.exports = function(defaultFuncs, api, ctx) {
4
- return function getCurrentUserID() {
5
- return ctx.userID;
6
- };
7
- };
@@ -1,57 +0,0 @@
1
- "use strict";
2
-
3
- const log = require("../../../func/logAdapter");
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
- };
@@ -1,76 +0,0 @@
1
- "use strict";
2
-
3
- const log = require("../../../func/logAdapter");
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
- };
@@ -1,48 +0,0 @@
1
- "use strict";
2
-
3
- const log = require("../../../func/logAdapter");
4
- const { getFrom } = require("../../utils/constants");
5
- const { get } = require("../../utils/request")
6
- const { getType } = require("../../utils/format");
7
- module.exports = function (defaultFuncs, api, ctx) {
8
- return function refreshFb_dtsg(obj, callback) {
9
- if (typeof obj === "function") {
10
- callback = obj;
11
- obj = {};
12
- }
13
- if (!obj) obj = {};
14
- if (getType(obj) !== "Object") {
15
- throw new CustomError("The first parameter must be an object or a callback function");
16
- }
17
- let resolveFunc, rejectFunc;
18
- const returnPromise = new Promise((resolve, reject) => {
19
- resolveFunc = resolve;
20
- rejectFunc = reject;
21
- });
22
- if (!callback) {
23
- callback = (err, data) => err ? rejectFunc(err) : resolveFunc(data);
24
- }
25
- if (Object.keys(obj).length === 0) {
26
- get("https://www.facebook.com/", ctx.jar, null, ctx.globalOptions, { noRef: true }).then(({ data }) => {
27
- const fb_dtsg = getFrom(data, '["DTSGInitData",[],{"token":"', '","');
28
- const jazoest = getFrom(data, "jazoest=", '",');
29
- if (!fb_dtsg) throw new Error("Could not find fb_dtsg in HTML after requesting Facebook.");
30
- Object.assign(ctx, { fb_dtsg, jazoest });
31
- callback(null, {
32
- data: { fb_dtsg, jazoest },
33
- message: "Refreshed fb_dtsg and jazoest",
34
- });
35
- }).catch(err => {
36
- console.error("refreshFb_dtsg", err);
37
- callback(err);
38
- });
39
- } else {
40
- Object.assign(ctx, obj);
41
- callback(null, {
42
- data: obj,
43
- message: `Refreshed ${Object.keys(obj).join(", ")}`,
44
- });
45
- }
46
- return returnPromise;
47
- };
48
- };
@@ -1,106 +0,0 @@
1
- "use strict";
2
-
3
- const log = require("../../../func/logAdapter");
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
- };