fca-neokex-fix 1.0.1

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 (114) hide show
  1. package/CHANGELOG.md +220 -0
  2. package/LICENSE +26 -0
  3. package/README.md +346 -0
  4. package/THEME_FEATURES.md +137 -0
  5. package/examples/README.md +131 -0
  6. package/examples/apply-ai-theme.js +127 -0
  7. package/examples/check-current-theme.js +74 -0
  8. package/examples/simple-bot.js +114 -0
  9. package/examples/test-bot.js +752 -0
  10. package/examples/test-logging.js +85 -0
  11. package/examples/theme-usage-example.js +53 -0
  12. package/index.js +2 -0
  13. package/package.json +105 -0
  14. package/src/apis/addExternalModule.js +24 -0
  15. package/src/apis/addUserToGroup.js +108 -0
  16. package/src/apis/changeAdminStatus.js +148 -0
  17. package/src/apis/changeArchivedStatus.js +61 -0
  18. package/src/apis/changeAvatar.js +103 -0
  19. package/src/apis/changeBio.js +69 -0
  20. package/src/apis/changeBlockedStatus.js +54 -0
  21. package/src/apis/changeGroupImage.js +136 -0
  22. package/src/apis/changeThreadColor.js +116 -0
  23. package/src/apis/comment.js +207 -0
  24. package/src/apis/createAITheme.js +129 -0
  25. package/src/apis/createNewGroup.js +79 -0
  26. package/src/apis/createPoll.js +73 -0
  27. package/src/apis/deleteMessage.js +44 -0
  28. package/src/apis/deleteThread.js +52 -0
  29. package/src/apis/editMessage.js +70 -0
  30. package/src/apis/emoji.js +124 -0
  31. package/src/apis/fetchThemeData.js +65 -0
  32. package/src/apis/follow.js +81 -0
  33. package/src/apis/forwardMessage.js +52 -0
  34. package/src/apis/friend.js +243 -0
  35. package/src/apis/gcmember.js +122 -0
  36. package/src/apis/gcname.js +123 -0
  37. package/src/apis/gcrule.js +119 -0
  38. package/src/apis/getAccess.js +111 -0
  39. package/src/apis/getBotInfo.js +88 -0
  40. package/src/apis/getBotInitialData.js +43 -0
  41. package/src/apis/getFriendsList.js +79 -0
  42. package/src/apis/getMessage.js +423 -0
  43. package/src/apis/getTheme.js +104 -0
  44. package/src/apis/getThemeInfo.js +96 -0
  45. package/src/apis/getThreadHistory.js +239 -0
  46. package/src/apis/getThreadInfo.js +257 -0
  47. package/src/apis/getThreadList.js +222 -0
  48. package/src/apis/getThreadPictures.js +58 -0
  49. package/src/apis/getUserID.js +83 -0
  50. package/src/apis/getUserInfo.js +495 -0
  51. package/src/apis/getUserInfoV2.js +146 -0
  52. package/src/apis/handleMessageRequest.js +50 -0
  53. package/src/apis/httpGet.js +63 -0
  54. package/src/apis/httpPost.js +89 -0
  55. package/src/apis/httpPostFormData.js +69 -0
  56. package/src/apis/listenMqtt.js +796 -0
  57. package/src/apis/listenSpeed.js +170 -0
  58. package/src/apis/logout.js +63 -0
  59. package/src/apis/markAsDelivered.js +47 -0
  60. package/src/apis/markAsRead.js +95 -0
  61. package/src/apis/markAsReadAll.js +41 -0
  62. package/src/apis/markAsSeen.js +70 -0
  63. package/src/apis/mqttDeltaValue.js +330 -0
  64. package/src/apis/muteThread.js +45 -0
  65. package/src/apis/nickname.js +132 -0
  66. package/src/apis/notes.js +163 -0
  67. package/src/apis/pinMessage.js +141 -0
  68. package/src/apis/produceMetaTheme.js +180 -0
  69. package/src/apis/realtime.js +161 -0
  70. package/src/apis/removeUserFromGroup.js +117 -0
  71. package/src/apis/resolvePhotoUrl.js +58 -0
  72. package/src/apis/searchForThread.js +154 -0
  73. package/src/apis/sendMessage.js +281 -0
  74. package/src/apis/sendMessageMqtt.js +188 -0
  75. package/src/apis/sendTypingIndicator.js +41 -0
  76. package/src/apis/setMessageReaction.js +27 -0
  77. package/src/apis/setMessageReactionMqtt.js +61 -0
  78. package/src/apis/setThreadTheme.js +260 -0
  79. package/src/apis/setThreadThemeMqtt.js +94 -0
  80. package/src/apis/share.js +107 -0
  81. package/src/apis/shareContact.js +66 -0
  82. package/src/apis/stickers.js +257 -0
  83. package/src/apis/story.js +181 -0
  84. package/src/apis/theme.js +233 -0
  85. package/src/apis/unfriend.js +47 -0
  86. package/src/apis/unsendMessage.js +17 -0
  87. package/src/database/appStateBackup.js +189 -0
  88. package/src/database/models/index.js +56 -0
  89. package/src/database/models/thread.js +31 -0
  90. package/src/database/models/user.js +32 -0
  91. package/src/database/threadData.js +101 -0
  92. package/src/database/userData.js +90 -0
  93. package/src/engine/client.js +91 -0
  94. package/src/engine/models/buildAPI.js +109 -0
  95. package/src/engine/models/loginHelper.js +326 -0
  96. package/src/engine/models/setOptions.js +53 -0
  97. package/src/utils/auth-helpers.js +149 -0
  98. package/src/utils/autoReLogin.js +169 -0
  99. package/src/utils/axios.js +290 -0
  100. package/src/utils/clients.js +270 -0
  101. package/src/utils/constants.js +396 -0
  102. package/src/utils/formatters/data/formatAttachment.js +370 -0
  103. package/src/utils/formatters/data/formatDelta.js +153 -0
  104. package/src/utils/formatters/index.js +159 -0
  105. package/src/utils/formatters/value/formatCookie.js +91 -0
  106. package/src/utils/formatters/value/formatDate.js +36 -0
  107. package/src/utils/formatters/value/formatID.js +16 -0
  108. package/src/utils/formatters.js +1067 -0
  109. package/src/utils/headers.js +199 -0
  110. package/src/utils/index.js +151 -0
  111. package/src/utils/monitoring.js +358 -0
  112. package/src/utils/rateLimiter.js +380 -0
  113. package/src/utils/tokenRefresh.js +311 -0
  114. package/src/utils/user-agents.js +238 -0
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+
3
+ const utils = require('../utils');
4
+
5
+ module.exports = (defaultFuncs, api, ctx) => {
6
+ return async function changeBio(bio, publish, callback) {
7
+ let resolveFunc = () => {};
8
+ let rejectFunc = () => {};
9
+ const returnPromise = new Promise((resolve, reject) => {
10
+ resolveFunc = resolve;
11
+ rejectFunc = reject;
12
+ });
13
+
14
+ if (!callback) {
15
+ if (utils.getType(publish) === "Function") {
16
+ callback = publish;
17
+ publish = false;
18
+ } else {
19
+ callback = (err) => {
20
+ if (err) return rejectFunc(err);
21
+ resolveFunc();
22
+ };
23
+ }
24
+ }
25
+
26
+ if (utils.getType(publish) !== "Boolean") {
27
+ publish = false;
28
+ }
29
+
30
+ if (utils.getType(bio) !== "String") {
31
+ bio = "";
32
+ publish = false;
33
+ }
34
+
35
+ try {
36
+ const form = {
37
+ fb_api_caller_class: "RelayModern",
38
+ fb_api_req_friendly_name: "ProfileCometSetBioMutation",
39
+ doc_id: "2725043627607610",
40
+ variables: JSON.stringify({
41
+ input: {
42
+ bio: bio,
43
+ publish_bio_feed_story: publish,
44
+ actor_id: ctx.i_userID || ctx.userID,
45
+ client_mutation_id: Math.round(Math.random() * 1024).toString()
46
+ },
47
+ hasProfileTileViewID: false,
48
+ profileTileViewID: null,
49
+ scale: 1
50
+ }),
51
+ av: ctx.i_userID || ctx.userID
52
+ };
53
+
54
+ const res = await defaultFuncs.post("https://www.facebook.com/api/graphql/", ctx.jar, form)
55
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs));
56
+
57
+ if (res.errors) {
58
+ throw res;
59
+ }
60
+
61
+ callback(null, { success: true });
62
+ } catch (err) {
63
+ utils.error("changeBio", err);
64
+ callback(err);
65
+ }
66
+
67
+ return returnPromise;
68
+ };
69
+ };
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ const utils = require('../utils');
4
+
5
+ module.exports = (defaultFuncs, api, ctx) => {
6
+ return async function changeBlockedStatus(userID, block, callback) {
7
+ let resolveFunc = () => {};
8
+ let rejectFunc = () => {};
9
+ const returnPromise = new Promise((resolve, reject) => {
10
+ resolveFunc = resolve;
11
+ rejectFunc = reject;
12
+ });
13
+
14
+ if (!callback) {
15
+ callback = (err, result) => {
16
+ if (err) return rejectFunc(err);
17
+ resolveFunc(result);
18
+ };
19
+ }
20
+
21
+ try {
22
+ if (utils.getType(block) === "Function") {
23
+ callback = block;
24
+ block = true;
25
+ }
26
+
27
+ if (utils.getType(block) !== "Boolean") {
28
+ throw new Error("block parameter must be a boolean");
29
+ }
30
+
31
+ const form = {
32
+ fbid: userID,
33
+ block: block
34
+ };
35
+
36
+ const res = await defaultFuncs.post(
37
+ "https://www.facebook.com/ajax/profile/manage_blocking.php",
38
+ ctx.jar,
39
+ form
40
+ ).then(utils.parseAndCheckLogin(ctx, defaultFuncs));
41
+
42
+ if (res && res.error) {
43
+ throw res;
44
+ }
45
+
46
+ return callback(null, { success: true, blocked: block });
47
+ } catch (err) {
48
+ utils.error("changeBlockedStatus", err);
49
+ callback(err);
50
+ }
51
+
52
+ return returnPromise;
53
+ };
54
+ };
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+
3
+ const utils = require('../utils');
4
+
5
+ module.exports = (defaultFuncs, api, ctx) => {
6
+ async function handleUpload(image) {
7
+ const form = {
8
+ images_only: "true",
9
+ "attachment[]": image
10
+ };
11
+ return defaultFuncs
12
+ .postFormData("https://upload.facebook.com/ajax/mercury/upload.php", ctx.jar, form, {})
13
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
14
+ .then(resData => {
15
+ if (resData.error) throw resData;
16
+ return resData.payload.metadata[0];
17
+ });
18
+ }
19
+
20
+ return async function changeGroupImage(image, threadID, callback) {
21
+ let resolveFunc = () => {};
22
+ let rejectFunc = () => {};
23
+ const returnPromise = new Promise((resolve, reject) => {
24
+ resolveFunc = resolve;
25
+ rejectFunc = reject;
26
+ });
27
+
28
+ if (!callback) {
29
+ callback = (err, result) => {
30
+ if (err) return rejectFunc(err);
31
+ resolveFunc(result);
32
+ };
33
+ }
34
+
35
+ try {
36
+ if (!ctx.mqttClient) {
37
+ throw new Error("Not connected to MQTT. Please use listenMqtt first.");
38
+ }
39
+
40
+ if (!threadID || typeof threadID !== "string") {
41
+ throw new Error("Invalid threadID");
42
+ }
43
+
44
+ if (!utils.isReadableStream(image)) {
45
+ throw new Error("image must be a readable stream");
46
+ }
47
+
48
+ const reqID = ++ctx.wsReqNumber;
49
+ const taskID = ++ctx.wsTaskNumber;
50
+
51
+ let responseHandled = false;
52
+ const onResponse = (topic, message) => {
53
+ if (topic !== "/ls_resp" || responseHandled) return;
54
+ let jsonMsg;
55
+ try {
56
+ jsonMsg = JSON.parse(message.toString());
57
+ jsonMsg.payload = JSON.parse(jsonMsg.payload);
58
+ } catch (err) {
59
+ return;
60
+ }
61
+ if (jsonMsg.request_id !== reqID) return;
62
+ responseHandled = true;
63
+ clearTimeout(timeout);
64
+ ctx.mqttClient.removeListener("message", onResponse);
65
+ callback(null, { success: true, response: jsonMsg.payload });
66
+ resolveFunc({ success: true, response: jsonMsg.payload });
67
+ };
68
+
69
+ const timeout = setTimeout(() => {
70
+ if (!responseHandled) {
71
+ responseHandled = true;
72
+ ctx.mqttClient.removeListener("message", onResponse);
73
+ const err = new Error("MQTT request timeout");
74
+ callback(err);
75
+ rejectFunc(err);
76
+ }
77
+ }, 30000);
78
+
79
+ ctx.mqttClient.on("message", onResponse);
80
+
81
+ const payload = await handleUpload(image);
82
+ const imageID = payload.image_id;
83
+
84
+ const taskPayload = {
85
+ thread_key: threadID,
86
+ image_id: imageID,
87
+ sync_group: 1
88
+ };
89
+
90
+ const mqttPayload = {
91
+ epoch_id: utils.generateOfflineThreadingID(),
92
+ tasks: [
93
+ {
94
+ failure_count: null,
95
+ label: "37",
96
+ payload: JSON.stringify(taskPayload),
97
+ queue_name: "thread_image",
98
+ task_id: taskID
99
+ }
100
+ ],
101
+ version_id: "8798795233522156"
102
+ };
103
+
104
+ const request = {
105
+ app_id: "2220391788200892",
106
+ payload: JSON.stringify(mqttPayload),
107
+ request_id: reqID,
108
+ type: 3
109
+ };
110
+
111
+ ctx.mqttClient.publish("/ls_req", JSON.stringify(request), {
112
+ qos: 1,
113
+ retain: false
114
+ }, (err) => {
115
+ if (err && !responseHandled) {
116
+ responseHandled = true;
117
+ clearTimeout(timeout);
118
+ ctx.mqttClient.removeListener("message", onResponse);
119
+ callback(err);
120
+ rejectFunc(err);
121
+ }
122
+ });
123
+ } catch (err) {
124
+ if (!responseHandled) {
125
+ responseHandled = true;
126
+ clearTimeout(timeout);
127
+ ctx.mqttClient.removeListener("message", onResponse);
128
+ utils.error("changeGroupImage", err);
129
+ callback(err);
130
+ rejectFunc(err);
131
+ }
132
+ }
133
+
134
+ return returnPromise;
135
+ };
136
+ };
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+
3
+ const utils = require('../utils');
4
+
5
+ module.exports = (defaultFuncs, api, ctx) => {
6
+ return async function changeThreadColor(color, threadID, callback) {
7
+ let reqID = ++ctx.wsReqNumber;
8
+ let resolveFunc = () => {};
9
+ let rejectFunc = () => {};
10
+ const returnPromise = new Promise((resolve, reject) => {
11
+ resolveFunc = resolve;
12
+ rejectFunc = reject;
13
+ });
14
+
15
+ if (!callback) {
16
+ callback = (err, data) => {
17
+ if (err) return rejectFunc(err);
18
+ resolveFunc(data);
19
+ };
20
+ }
21
+
22
+ try {
23
+ if (!ctx.mqttClient) {
24
+ throw new Error("Not connected to MQTT. Please use listenMqtt first.");
25
+ }
26
+
27
+ const content = {
28
+ app_id: "2220391788200892",
29
+ payload: JSON.stringify({
30
+ data_trace_id: null,
31
+ epoch_id: parseInt(utils.generateOfflineThreadingID()),
32
+ tasks: [
33
+ {
34
+ failure_count: null,
35
+ label: "43",
36
+ payload: JSON.stringify({
37
+ thread_key: threadID,
38
+ theme_fbid: color,
39
+ source: null,
40
+ sync_group: 1,
41
+ payload: null
42
+ }),
43
+ queue_name: "thread_theme",
44
+ task_id: ++ctx.wsTaskNumber
45
+ }
46
+ ],
47
+ version_id: "8798795233522156"
48
+ }),
49
+ request_id: reqID,
50
+ type: 3
51
+ };
52
+
53
+ let responseHandled = false;
54
+
55
+ const handleRes = (topic, message) => {
56
+ if (responseHandled) return;
57
+ if (topic !== "/ls_resp") return;
58
+ let jsonMsg;
59
+ try {
60
+ jsonMsg = JSON.parse(message.toString());
61
+ jsonMsg.payload = JSON.parse(jsonMsg.payload);
62
+ } catch (err) {
63
+ return;
64
+ }
65
+ if (jsonMsg.request_id !== reqID) return;
66
+ responseHandled = true;
67
+ clearTimeout(timeout);
68
+ ctx.mqttClient.removeListener("message", handleRes);
69
+ try {
70
+ const msgID = jsonMsg.payload.step[1][2][2][1][2];
71
+ const msgReplace = jsonMsg.payload.step[1][2][2][1][4];
72
+ const bodies = {
73
+ body: msgReplace,
74
+ messageID: msgID
75
+ };
76
+ callback(null, bodies);
77
+ resolveFunc(bodies);
78
+ } catch (err) {
79
+ callback(null, { success: true });
80
+ resolveFunc({ success: true });
81
+ }
82
+ };
83
+
84
+ const timeout = setTimeout(() => {
85
+ if (!responseHandled) {
86
+ responseHandled = true;
87
+ ctx.mqttClient.removeListener("message", handleRes);
88
+ const err = new Error("MQTT request timeout");
89
+ callback(err);
90
+ rejectFunc(err);
91
+ }
92
+ }, 30000);
93
+
94
+ ctx.mqttClient.on("message", handleRes);
95
+
96
+ ctx.mqttClient.publish("/ls_req", JSON.stringify(content), {
97
+ qos: 1,
98
+ retain: false
99
+ }, (err) => {
100
+ if (err && !responseHandled) {
101
+ responseHandled = true;
102
+ clearTimeout(timeout);
103
+ ctx.mqttClient.removeListener("message", handleRes);
104
+ callback(err);
105
+ rejectFunc(err);
106
+ }
107
+ });
108
+ } catch (err) {
109
+ utils.error("changeThreadColor", err);
110
+ callback(err);
111
+ rejectFunc(err);
112
+ }
113
+
114
+ return returnPromise;
115
+ };
116
+ };
@@ -0,0 +1,207 @@
1
+ 'use strict';
2
+
3
+ const utils = require('../utils');
4
+
5
+ /**
6
+ * Handles the upload of attachments (images/videos) for a comment.
7
+ * @param {object} defaultFuncs - The default functions for making API requests.
8
+ * @param {object} ctx - The context object.
9
+ * @param {object} msg - The message object, containing attachments.
10
+ * @param {object} form - The main form object to be populated.
11
+ * @returns {Promise<void>}
12
+ */
13
+ async function handleUpload(defaultFuncs, ctx, msg, form) {
14
+ if (!msg.attachments || msg.attachments.length === 0) {
15
+ return;
16
+ }
17
+
18
+ const uploads = msg.attachments.map(item => {
19
+ if (!utils.isReadableStream(item)) {
20
+ throw new Error('Attachments must be a readable stream.');
21
+ }
22
+ return defaultFuncs
23
+ .postFormData('https://www.facebook.com/ajax/ufi/upload/', ctx.jar, {
24
+ profile_id: ctx.userID,
25
+ source: 19,
26
+ target_id: ctx.userID,
27
+ file: item
28
+ })
29
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
30
+ .then(res => {
31
+ if (res.error || !res.payload?.fbid) {
32
+ throw res;
33
+ }
34
+ return { media: { id: res.payload.fbid } };
35
+ });
36
+ });
37
+
38
+ const results = await Promise.all(uploads);
39
+ form.input.attachments.push(...results);
40
+ }
41
+
42
+ /**
43
+ * Handles a URL attachment for a comment.
44
+ * @param {object} msg - The message object.
45
+ * @param {object} form - The main form object.
46
+ */
47
+ function handleURL(msg, form) {
48
+ if (typeof msg.url === 'string') {
49
+ form.input.attachments.push({
50
+ link: {
51
+ external: {
52
+ url: msg.url
53
+ }
54
+ }
55
+ });
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Handles mentions in the comment body.
61
+ * @param {object} msg - The message object.
62
+ * @param {object} form - The main form object.
63
+ */
64
+ function handleMentions(msg, form) {
65
+ if (!msg.mentions) return;
66
+
67
+ for (const item of msg.mentions) {
68
+ const { tag, id, fromIndex } = item;
69
+ if (typeof tag !== 'string' || !id) {
70
+ utils.warn('createCommentPost', 'Mentions must have a string "tag" and an "id".');
71
+ continue;
72
+ }
73
+ const offset = msg.body.indexOf(tag, fromIndex || 0);
74
+ if (offset < 0) {
75
+ utils.warn('createCommentPost', `Mention for "${tag}" not found in message string.`);
76
+ continue;
77
+ }
78
+ form.input.message.ranges.push({
79
+ entity: { id },
80
+ length: tag.length,
81
+ offset
82
+ });
83
+ }
84
+ }
85
+
86
+ /**
87
+ * Handles a sticker attachment for a comment.
88
+ * @param {object} msg - The message object.
89
+ * @param {object} form - The main form object.
90
+ */
91
+ function handleSticker(msg, form) {
92
+ if (msg.sticker) {
93
+ form.input.attachments.push({
94
+ media: {
95
+ id: String(msg.sticker)
96
+ }
97
+ });
98
+ }
99
+ }
100
+
101
+ /**
102
+ * Submits the final comment form to the GraphQL endpoint.
103
+ * @param {object} defaultFuncs - The default functions.
104
+ * @param {object} ctx - The context object.
105
+ * @param {object} form - The fully constructed form object.
106
+ * @returns {Promise<object>} A promise that resolves with the comment info.
107
+ */
108
+ async function createContent(defaultFuncs, ctx, form) {
109
+ const res = await defaultFuncs
110
+ .post('https://www.facebook.com/api/graphql/', ctx.jar, {
111
+ fb_api_caller_class: 'RelayModern',
112
+ fb_api_req_friendly_name: 'useCometUFICreateCommentMutation',
113
+ variables: JSON.stringify(form),
114
+ server_timestamps: true,
115
+ doc_id: 6993516810709754
116
+ })
117
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs));
118
+
119
+ if (res.errors) {
120
+ throw res;
121
+ }
122
+
123
+ const commentEdge = res.data.comment_create.feedback_comment_edge;
124
+ return {
125
+ id: commentEdge.node.id,
126
+ url: commentEdge.node.feedback.url,
127
+ count: res.data.comment_create.feedback.total_comment_count
128
+ };
129
+ }
130
+
131
+ /**
132
+ * Creates a comment on a Facebook post. Can also reply to an existing comment.
133
+ * @param {string|object} msg - The message to post. Can be a string or an object with `body`, `attachments`, `mentions`, etc.
134
+ * @param {string} postID - The ID of the post to comment on.
135
+ * @param {string} [replyCommentID] - (Optional) The ID of the comment to reply to.
136
+ * @param {function} [callback] - (Optional) A callback function.
137
+ * @returns {Promise<object>} A promise that resolves with the new comment's information.
138
+ */
139
+ module.exports = function(defaultFuncs, api, ctx) {
140
+ return async function createCommentPost(msg, postID, replyCommentID, callback) {
141
+ let cb;
142
+ const returnPromise = new Promise((resolve, reject) => {
143
+ cb = (error, info) => info ? resolve(info) : reject(error);
144
+ });
145
+
146
+ if (typeof replyCommentID === 'function') {
147
+ callback = replyCommentID;
148
+ replyCommentID = null;
149
+ }
150
+ if (typeof callback === 'function') {
151
+ cb = callback;
152
+ }
153
+
154
+ if (typeof msg !== 'string' && typeof msg !== 'object') {
155
+ const error = 'Message must be a string or an object.';
156
+ utils.error('createCommentPost', error);
157
+ return cb(error);
158
+ }
159
+ if (typeof postID !== 'string') {
160
+ const error = 'postID must be a string.';
161
+ utils.error('createCommentPost', error);
162
+ return cb(error);
163
+ }
164
+
165
+ let messageObject = typeof msg === 'string' ? { body: msg } : { ...msg };
166
+ messageObject.mentions = messageObject.mentions || [];
167
+ messageObject.attachments = messageObject.attachments || [];
168
+
169
+ const form = {
170
+ feedLocation: 'NEWSFEED',
171
+ feedbackSource: 1,
172
+ groupID: null,
173
+ input: {
174
+ client_mutation_id: Math.round(Math.random() * 19).toString(),
175
+ actor_id: ctx.userID,
176
+ attachments: [],
177
+ feedback_id: Buffer.from('feedback:' + postID).toString('base64'),
178
+ message: {
179
+ ranges: [],
180
+ text: messageObject.body || ''
181
+ },
182
+ reply_comment_parent_fbid: replyCommentID || null,
183
+ is_tracking_encrypted: true,
184
+ tracking: [],
185
+ feedback_source: 'NEWS_FEED',
186
+ idempotence_token: 'client:' + utils.getGUID(),
187
+ session_id: utils.getGUID()
188
+ },
189
+ scale: 1,
190
+ useDefaultActor: false
191
+ };
192
+
193
+ try {
194
+ await handleUpload(defaultFuncs, ctx, messageObject, form);
195
+ handleURL(messageObject, form);
196
+ handleMentions(messageObject, form);
197
+ handleSticker(messageObject, form);
198
+ const info = await createContent(defaultFuncs, ctx, form);
199
+ cb(null, info);
200
+ } catch (err) {
201
+ utils.error('createCommentPost', err);
202
+ cb(err);
203
+ }
204
+
205
+ return returnPromise;
206
+ };
207
+ };
@@ -0,0 +1,129 @@
1
+ /**
2
+ * @by Allou Mohamed
3
+ * do not remove the author name to get more updates
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const utils = require("../utils");
9
+
10
+ module.exports = function (defaultFuncs, api, ctx) {
11
+ return function createAITheme(prompt, numThemes, callback) {
12
+ if (typeof numThemes === 'function') {
13
+ callback = numThemes;
14
+ numThemes = 3;
15
+ }
16
+ if (typeof numThemes !== 'number' || numThemes < 1) {
17
+ numThemes = 3;
18
+ }
19
+ if (numThemes > 10) {
20
+ numThemes = 10;
21
+ }
22
+
23
+ const form = {
24
+ av: ctx.i_userID || ctx.userID,
25
+ qpl_active_flow_ids: "25308101,25309433,521482085",
26
+ fb_api_caller_class: "RelayModern",
27
+ fb_api_req_friendly_name: "useGenerateAIThemeMutation",
28
+ variables: JSON.stringify({
29
+ input: {
30
+ client_mutation_id: "1",
31
+ actor_id: ctx.i_userID || ctx.userID,
32
+ bypass_cache: true,
33
+ caller: "MESSENGER",
34
+ num_themes: numThemes,
35
+ prompt: prompt
36
+ }
37
+ }),
38
+ server_timestamps: true,
39
+ doc_id: "23873748445608673",
40
+ fb_api_analytics_tags: JSON.stringify([
41
+ "qpl_active_flow_ids=25308101,25309433,521482085"
42
+ ]),
43
+ fb_dtsg: ctx.fb_dtsg
44
+ };
45
+
46
+ const extractUrl = (obj) => {
47
+ if (!obj) return null;
48
+ if (typeof obj === 'string') return obj;
49
+ return obj.uri || obj.url || null;
50
+ };
51
+
52
+ const normalizeTheme = (theme) => {
53
+ const normalized = { ...theme };
54
+
55
+ let lightUrl = null;
56
+ let darkUrl = null;
57
+
58
+ const previewUrls = theme.preview_image_urls || theme.preview_images || theme.preview_urls;
59
+
60
+ if (previewUrls) {
61
+ if (typeof previewUrls === 'string') {
62
+ lightUrl = darkUrl = previewUrls;
63
+ } else if (Array.isArray(previewUrls)) {
64
+ lightUrl = extractUrl(previewUrls[0]) || null;
65
+ darkUrl = extractUrl(previewUrls[1]) || lightUrl;
66
+ } else if (typeof previewUrls === 'object') {
67
+ lightUrl = extractUrl(previewUrls.light_mode) || extractUrl(previewUrls.light) || null;
68
+ darkUrl = extractUrl(previewUrls.dark_mode) || extractUrl(previewUrls.dark) || null;
69
+ }
70
+ }
71
+
72
+ if (!lightUrl && theme.background_asset && theme.background_asset.image) {
73
+ lightUrl = extractUrl(theme.background_asset.image);
74
+ }
75
+ if (!lightUrl && theme.icon_asset && theme.icon_asset.image) {
76
+ lightUrl = extractUrl(theme.icon_asset.image);
77
+ }
78
+
79
+ if (!darkUrl && theme.alternative_themes && theme.alternative_themes.length > 0) {
80
+ const darkTheme = theme.alternative_themes[0];
81
+ if (darkTheme.background_asset && darkTheme.background_asset.image) {
82
+ darkUrl = extractUrl(darkTheme.background_asset.image);
83
+ }
84
+ if (!darkUrl && darkTheme.icon_asset && darkTheme.icon_asset.image) {
85
+ darkUrl = extractUrl(darkTheme.icon_asset.image);
86
+ }
87
+ }
88
+
89
+ if (lightUrl && !darkUrl) {
90
+ darkUrl = lightUrl;
91
+ } else if (darkUrl && !lightUrl) {
92
+ lightUrl = darkUrl;
93
+ }
94
+
95
+ if (lightUrl || darkUrl) {
96
+ normalized.preview_image_urls = {
97
+ light_mode: lightUrl,
98
+ dark_mode: darkUrl
99
+ };
100
+ }
101
+
102
+ return normalized;
103
+ };
104
+
105
+ const promise = defaultFuncs
106
+ .post("https://web.facebook.com/api/graphql/", ctx.jar, form)
107
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
108
+ .then(resData => {
109
+ if (resData.errors) {
110
+ throw resData.errors;
111
+ }
112
+ const themes = resData.data.xfb_generate_ai_themes_from_prompt.themes;
113
+ return themes.map(normalizeTheme);
114
+ });
115
+
116
+ if (callback) {
117
+ promise.then(data => callback(null, data)).catch(err => {
118
+ utils.error("createAITheme", err.message || err);
119
+ callback(err);
120
+ });
121
+ return;
122
+ }
123
+
124
+ return promise.catch(err => {
125
+ utils.error("createAITheme", err.message || err);
126
+ throw err;
127
+ });
128
+ };
129
+ };