@cexy/hoonfca 1.0.0 → 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 (188) hide show
  1. package/LICENSE +3 -0
  2. package/README.md +451 -43
  3. package/examples/login-with-cookies.js +102 -0
  4. package/examples/verify.js +70 -0
  5. package/index.js +1 -466
  6. package/package.json +98 -6
  7. package/src/apis/addExternalModule.js +24 -0
  8. package/src/apis/addUserToGroup.js +108 -0
  9. package/src/apis/changeAdminStatus.js +148 -0
  10. package/src/apis/changeArchivedStatus.js +61 -0
  11. package/src/apis/changeAvatar.js +103 -0
  12. package/src/apis/changeBio.js +69 -0
  13. package/src/apis/changeBlockedStatus.js +54 -0
  14. package/src/apis/changeGroupImage.js +136 -0
  15. package/src/apis/changeThreadColor.js +116 -0
  16. package/src/{changeThreadEmoji.js → apis/changeThreadEmoji.js} +7 -8
  17. package/src/apis/comment.js +207 -0
  18. package/src/apis/createAITheme.js +129 -0
  19. package/src/apis/createNewGroup.js +79 -0
  20. package/src/apis/createPoll.js +73 -0
  21. package/src/apis/deleteMessage.js +44 -0
  22. package/src/apis/deleteThread.js +52 -0
  23. package/src/apis/e2ee.js +17 -0
  24. package/src/apis/editMessage.js +70 -0
  25. package/src/apis/emoji.js +124 -0
  26. package/src/apis/fetchThemeData.js +82 -0
  27. package/src/apis/follow.js +81 -0
  28. package/src/apis/forwardMessage.js +52 -0
  29. package/src/apis/friend.js +243 -0
  30. package/src/apis/gcmember.js +122 -0
  31. package/src/apis/gcname.js +123 -0
  32. package/src/apis/gcrule.js +119 -0
  33. package/src/apis/getAccess.js +111 -0
  34. package/src/apis/getBotInfo.js +88 -0
  35. package/src/apis/getBotInitialData.js +43 -0
  36. package/src/apis/getFriendsList.js +79 -0
  37. package/src/apis/getMessage.js +423 -0
  38. package/src/apis/getTheme.js +95 -0
  39. package/src/apis/getThemeInfo.js +116 -0
  40. package/src/apis/getThreadHistory.js +239 -0
  41. package/src/apis/getThreadInfo.js +267 -0
  42. package/src/apis/getThreadList.js +232 -0
  43. package/src/apis/getThreadPictures.js +58 -0
  44. package/src/apis/getUserID.js +117 -0
  45. package/src/apis/getUserInfo.js +513 -0
  46. package/src/apis/getUserInfoV2.js +146 -0
  47. package/src/apis/handleMessageRequest.js +50 -0
  48. package/src/apis/httpGet.js +63 -0
  49. package/src/apis/httpPost.js +89 -0
  50. package/src/apis/httpPostFormData.js +69 -0
  51. package/src/apis/listenMqtt.js +1236 -0
  52. package/src/apis/listenSpeed.js +179 -0
  53. package/src/apis/logout.js +87 -0
  54. package/src/apis/markAsDelivered.js +47 -0
  55. package/src/apis/markAsRead.js +99 -0
  56. package/src/apis/markAsReadAll.js +40 -0
  57. package/src/apis/markAsSeen.js +70 -0
  58. package/src/apis/mqttDeltaValue.js +278 -0
  59. package/src/apis/muteThread.js +45 -0
  60. package/src/apis/nickname.js +132 -0
  61. package/src/apis/notes.js +163 -0
  62. package/src/apis/pinMessage.js +150 -0
  63. package/src/apis/produceMetaTheme.js +180 -0
  64. package/src/apis/realtime.js +182 -0
  65. package/src/apis/removeUserFromGroup.js +117 -0
  66. package/src/apis/resolvePhotoUrl.js +58 -0
  67. package/src/apis/searchForThread.js +154 -0
  68. package/src/apis/sendMessage.js +354 -0
  69. package/src/apis/sendMessageMqtt.js +249 -0
  70. package/src/apis/sendTypingIndicator.js +91 -0
  71. package/src/apis/setMessageReaction.js +27 -0
  72. package/src/apis/setMessageReactionMqtt.js +61 -0
  73. package/src/apis/setThreadTheme.js +260 -0
  74. package/src/apis/setThreadThemeMqtt.js +94 -0
  75. package/src/apis/share.js +107 -0
  76. package/src/apis/shareContact.js +66 -0
  77. package/src/apis/stickers.js +257 -0
  78. package/src/apis/story.js +181 -0
  79. package/src/apis/theme.js +233 -0
  80. package/src/apis/unfriend.js +47 -0
  81. package/src/apis/unsendMessage.js +17 -0
  82. package/src/engine/client.js +92 -0
  83. package/src/engine/models/buildAPI.js +152 -0
  84. package/src/engine/models/loginHelper.js +519 -0
  85. package/src/engine/models/setOptions.js +88 -0
  86. package/src/security/e2ee.js +109 -0
  87. package/src/types/index.d.ts +498 -0
  88. package/src/utils/antiSuspension.js +506 -0
  89. package/src/utils/auth-helpers.js +149 -0
  90. package/src/utils/autoReLogin.js +336 -0
  91. package/src/utils/axios.js +436 -0
  92. package/src/utils/cache.js +54 -0
  93. package/src/utils/clients.js +282 -0
  94. package/src/utils/constants.js +410 -0
  95. package/src/utils/formatters/data/formatAttachment.js +370 -0
  96. package/src/utils/formatters/data/formatDelta.js +109 -0
  97. package/src/utils/formatters/index.js +159 -0
  98. package/src/utils/formatters/value/formatCookie.js +91 -0
  99. package/src/utils/formatters/value/formatDate.js +36 -0
  100. package/src/utils/formatters/value/formatID.js +16 -0
  101. package/src/utils/formatters.js +1373 -0
  102. package/src/utils/headers.js +230 -0
  103. package/src/utils/index.js +153 -0
  104. package/src/utils/monitoring.js +333 -0
  105. package/src/utils/rateLimiter.js +319 -0
  106. package/src/utils/tokenRefresh.js +657 -0
  107. package/src/utils/user-agents.js +238 -0
  108. package/src/utils/validation.js +157 -0
  109. package/replit.nix +0 -3
  110. package/src/addExternalModule.js +0 -25
  111. package/src/addUserToGroup.js +0 -98
  112. package/src/changeAdminStatus.js +0 -98
  113. package/src/changeArchivedStatus.js +0 -51
  114. package/src/changeAvatar.js +0 -89
  115. package/src/changeBio.js +0 -74
  116. package/src/changeBlockedStatus.js +0 -45
  117. package/src/changeBlockedStatusMqtt.js +0 -65
  118. package/src/changeCover.js +0 -92
  119. package/src/changeGroupImage.js +0 -110
  120. package/src/changeName.js +0 -106
  121. package/src/changeNickname.js +0 -58
  122. package/src/changeThreadColor.js +0 -62
  123. package/src/changeUsername.js +0 -80
  124. package/src/createCommentPost.js +0 -196
  125. package/src/createNewGroup.js +0 -81
  126. package/src/createPoll.js +0 -64
  127. package/src/createPost.js +0 -285
  128. package/src/data/getThreadInfo.json +0 -1
  129. package/src/deleteMessage.js +0 -55
  130. package/src/deleteThread.js +0 -55
  131. package/src/editMessage.js +0 -66
  132. package/src/follow.js +0 -71
  133. package/src/forwardAttachment.js +0 -57
  134. package/src/getAccess.js +0 -130
  135. package/src/getAvatarUser.js +0 -88
  136. package/src/getBotInitialData.js +0 -59
  137. package/src/getCtx.js +0 -5
  138. package/src/getCurrentUserID.js +0 -5
  139. package/src/getEmojiUrl.js +0 -18
  140. package/src/getFriendsList.js +0 -81
  141. package/src/getMessage.js +0 -827
  142. package/src/getOptions.js +0 -5
  143. package/src/getRegion.js +0 -7
  144. package/src/getThreadHistory.js +0 -496
  145. package/src/getThreadHistoryDeprecated.js +0 -95
  146. package/src/getThreadInfo.js +0 -194
  147. package/src/getThreadInfoDeprecated.js +0 -77
  148. package/src/getThreadList.js +0 -219
  149. package/src/getThreadListDeprecated.js +0 -86
  150. package/src/getThreadPictures.js +0 -85
  151. package/src/getUserID.js +0 -67
  152. package/src/getUserInfo.js +0 -89
  153. package/src/handleFriendRequest.js +0 -56
  154. package/src/handleMessageRequest.js +0 -65
  155. package/src/httpGet.js +0 -53
  156. package/src/httpPost.js +0 -53
  157. package/src/httpPostFormData.js +0 -58
  158. package/src/listenMqtt.js +0 -683
  159. package/src/listenNotification.js +0 -96
  160. package/src/logout.js +0 -77
  161. package/src/markAsDelivered.js +0 -53
  162. package/src/markAsRead.js +0 -74
  163. package/src/markAsReadAll.js +0 -46
  164. package/src/markAsSeen.js +0 -57
  165. package/src/muteThread.js +0 -49
  166. package/src/pinMessage.js +0 -60
  167. package/src/refreshFb_dtsg.js +0 -75
  168. package/src/removeUserFromGroup.js +0 -59
  169. package/src/resolvePhotoUrl.js +0 -47
  170. package/src/searchForThread.js +0 -55
  171. package/src/searchStickers.js +0 -59
  172. package/src/sendMessage.js +0 -444
  173. package/src/sendMessageMqtt.js +0 -326
  174. package/src/sendTypingIndicator.js +0 -54
  175. package/src/setMessageReaction.js +0 -126
  176. package/src/setMessageReactionMqtt.js +0 -74
  177. package/src/setPostReaction.js +0 -103
  178. package/src/setProfileGuard.js +0 -66
  179. package/src/setStoryReaction.js +0 -97
  180. package/src/setTitle.js +0 -100
  181. package/src/shareContact.js +0 -101
  182. package/src/shareLink.js +0 -105
  183. package/src/stopListenMqtt.js +0 -47
  184. package/src/threadColors.js +0 -119
  185. package/src/unfriend.js +0 -58
  186. package/src/unsendMessage.js +0 -51
  187. package/src/uploadAttachment.js +0 -98
  188. package/utils.js +0 -919
@@ -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
+ };
@@ -1,23 +1,23 @@
1
1
  "use strict";
2
2
 
3
3
  const utils = require("../utils");
4
-
5
4
  module.exports = function (defaultFuncs, api, ctx) {
6
5
  return function changeThreadEmoji(emoji, threadID, callback) {
7
- let resolveFunc = () => {};
8
- let rejectFunc = () => {};
9
- const returnPromise = new Promise((resolve, reject) => {
6
+ let resolveFunc = function () {};
7
+ let rejectFunc = function () {};
8
+ const returnPromise = new Promise(function (resolve, reject) {
10
9
  resolveFunc = resolve;
11
10
  rejectFunc = reject;
12
11
  });
13
12
 
14
13
  if (!callback) {
15
14
  callback = function (err) {
16
- if (err) return rejectFunc(err);
15
+ if (err) {
16
+ return rejectFunc(err);
17
+ }
17
18
  resolveFunc();
18
19
  };
19
20
  }
20
-
21
21
  const form = {
22
22
  emoji_choice: emoji,
23
23
  thread_or_other_fbid: threadID,
@@ -27,11 +27,10 @@ module.exports = function (defaultFuncs, api, ctx) {
27
27
  .post(
28
28
  "https://www.facebook.com/messaging/save_thread_emoji/?source=thread_settings&__pc=EXP1%3Amessengerdotcom_pkg",
29
29
  ctx.jar,
30
- form
30
+ form,
31
31
  )
32
32
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
33
33
  .then(function (resData) {
34
- // স্ট্রিক্ট কম্প্যারিসন (===) ব্যবহার করা হয়েছে
35
34
  if (resData.error === 1357031) {
36
35
  throw {
37
36
  error:
@@ -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
+ };
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+
3
+ const utils = require('../utils');
4
+
5
+ module.exports = (defaultFuncs, api, ctx) => {
6
+ return async function createNewGroup(participantIDs, groupTitle, 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(groupTitle) === "Function") {
23
+ callback = groupTitle;
24
+ groupTitle = null;
25
+ }
26
+
27
+ if (utils.getType(participantIDs) !== "Array") {
28
+ throw new Error("createNewGroup: participantIDs should be an array.");
29
+ }
30
+
31
+ if (participantIDs.length < 2) {
32
+ throw new Error("createNewGroup: participantIDs should have at least 2 IDs.");
33
+ }
34
+
35
+ const pids = [];
36
+ for (const n in participantIDs) {
37
+ pids.push({
38
+ fbid: participantIDs[n]
39
+ });
40
+ }
41
+ pids.push({ fbid: ctx.i_userID || ctx.userID });
42
+
43
+ const form = {
44
+ fb_api_caller_class: "RelayModern",
45
+ fb_api_req_friendly_name: "MessengerGroupCreateMutation",
46
+ av: ctx.i_userID || ctx.userID,
47
+ doc_id: "577041672419534",
48
+ variables: JSON.stringify({
49
+ input: {
50
+ entry_point: "jewel_new_group",
51
+ actor_id: ctx.i_userID || ctx.userID,
52
+ participants: pids,
53
+ client_mutation_id: Math.round(Math.random() * 1024).toString(),
54
+ thread_settings: {
55
+ name: groupTitle,
56
+ joinable_mode: "PRIVATE",
57
+ thread_image_fbid: null
58
+ }
59
+ }
60
+ })
61
+ };
62
+
63
+ const res = await defaultFuncs.post("https://www.facebook.com/api/graphql/", ctx.jar, form)
64
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs));
65
+
66
+ if (res.errors) {
67
+ throw res;
68
+ }
69
+
70
+ const threadID = res.data.messenger_group_thread_create.thread.thread_key.thread_fbid;
71
+ callback(null, threadID);
72
+ } catch (err) {
73
+ utils.error("createNewGroup", err);
74
+ callback(err);
75
+ }
76
+
77
+ return returnPromise;
78
+ };
79
+ };
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+
3
+ const utils = require('../utils');
4
+
5
+ module.exports = (defaultFuncs, api, ctx) => {
6
+ return async function createPoll(threadID, questionText, options, 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 (!ctx.mqttClient) {
23
+ throw new Error("Not connected to MQTT. Please use listenMqtt first.");
24
+ }
25
+
26
+ if (!threadID || typeof threadID !== "string") {
27
+ throw new Error("Invalid threadID");
28
+ }
29
+
30
+ if (!questionText || typeof questionText !== "string") {
31
+ throw new Error("questionText must be a string");
32
+ }
33
+
34
+ if (!Array.isArray(options) || options.length < 2) {
35
+ throw new Error("options must be an array with at least 2 options");
36
+ }
37
+
38
+ const payload = {
39
+ epoch_id: utils.generateOfflineThreadingID(),
40
+ tasks: [
41
+ {
42
+ failure_count: null,
43
+ label: "163",
44
+ payload: JSON.stringify({
45
+ question_text: questionText,
46
+ thread_key: threadID,
47
+ options: options,
48
+ sync_group: 1
49
+ }),
50
+ queue_name: "poll_creation",
51
+ task_id: Math.floor(Math.random() * 1001)
52
+ }
53
+ ],
54
+ version_id: "8768858626531631"
55
+ };
56
+
57
+ const form = JSON.stringify({
58
+ app_id: "772021112871879",
59
+ payload: JSON.stringify(payload),
60
+ request_id: ++ctx.wsReqNumber,
61
+ type: 3
62
+ });
63
+
64
+ ctx.mqttClient.publish("/ls_req", form);
65
+ callback(null, { success: true });
66
+ } catch (err) {
67
+ utils.error("createPoll", err);
68
+ callback(err);
69
+ }
70
+
71
+ return returnPromise;
72
+ };
73
+ };
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ const utils = require('../utils');
4
+
5
+ module.exports = (defaultFuncs, api, ctx) => {
6
+ return async function deleteMessage(messageID, 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
+ const form = {
23
+ message_id: messageID
24
+ };
25
+
26
+ const res = await defaultFuncs.post(
27
+ "https://www.facebook.com/ajax/mercury/delete_messages.php",
28
+ ctx.jar,
29
+ form
30
+ ).then(utils.parseAndCheckLogin(ctx, defaultFuncs));
31
+
32
+ if (res && res.error) {
33
+ throw res;
34
+ }
35
+
36
+ return callback(null, { success: true });
37
+ } catch (err) {
38
+ utils.error("deleteMessage", err);
39
+ callback(err);
40
+ }
41
+
42
+ return returnPromise;
43
+ };
44
+ };