@cexy/hoonfca 1.0.1 → 1.0.3

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 (170) hide show
  1. package/.travis.yml +6 -0
  2. package/LICENSE-MIT +21 -0
  3. package/index.d.ts +620 -0
  4. package/index.js +778 -1
  5. package/package.json +31 -84
  6. package/src/{apis/addExternalModule.js → addExternalModule.js} +4 -5
  7. package/src/addUserToGroup.js +113 -0
  8. package/src/changeAdminStatus.js +95 -0
  9. package/src/changeApprovalMode.js +79 -0
  10. package/src/changeArchivedStatus.js +55 -0
  11. package/src/changeBio.js +76 -0
  12. package/src/changeBlockedStatus.js +47 -0
  13. package/src/changeBlockedStatusMqtt.js +86 -0
  14. package/src/changeGroupImage.js +133 -0
  15. package/src/changeNickname.js +59 -0
  16. package/src/changeThreadColor.js +71 -0
  17. package/src/{apis/changeThreadEmoji.js → changeThreadEmoji.js} +8 -6
  18. package/src/createNewGroup.js +88 -0
  19. package/src/createPoll.js +130 -0
  20. package/src/deleteMessage.js +56 -0
  21. package/src/deleteThread.js +56 -0
  22. package/src/editMessage.js +63 -0
  23. package/src/forwardAttachment.js +60 -0
  24. package/src/forwardMessage.js +63 -0
  25. package/src/getCurrentUserID.js +7 -0
  26. package/src/getEmojiUrl.js +29 -0
  27. package/src/getFriendsList.js +84 -0
  28. package/src/getGroupsList.js +83 -0
  29. package/src/getMarketplace.js +84 -0
  30. package/src/getNotifications.js +86 -0
  31. package/src/getPagesList.js +83 -0
  32. package/src/getStories.js +88 -0
  33. package/src/getThreadHistory.js +647 -0
  34. package/src/getThreadInfo.js +222 -0
  35. package/src/getThreadList.js +292 -0
  36. package/src/getThreadPictures.js +79 -0
  37. package/src/getUserID.js +66 -0
  38. package/src/getUserInfo.js +128 -0
  39. package/src/handleFriendRequest.js +57 -0
  40. package/src/handleMessageRequest.js +65 -0
  41. package/src/{apis/httpGet.js → httpGet.js} +15 -20
  42. package/src/httpPost.js +58 -0
  43. package/src/listenMqtt.js +1018 -0
  44. package/src/logout.js +75 -0
  45. package/src/markAsDelivered.js +58 -0
  46. package/src/{apis/markAsRead.js → markAsRead.js} +19 -30
  47. package/src/markAsReadAll.js +50 -0
  48. package/src/markAsSeen.js +61 -0
  49. package/src/muteThread.js +52 -0
  50. package/src/pinMessage.js +61 -0
  51. package/src/removeUserFromGroup.js +79 -0
  52. package/src/resolvePhotoUrl.js +45 -0
  53. package/src/searchForThread.js +53 -0
  54. package/src/searchUsers.js +89 -0
  55. package/src/sendComment.js +161 -0
  56. package/src/sendMessage.js +457 -0
  57. package/src/sendTypingIndicator.js +179 -0
  58. package/src/setBio.js +86 -0
  59. package/src/setMessageReaction.js +186 -0
  60. package/src/setPostReaction.js +71 -0
  61. package/src/setTheme.js +313 -0
  62. package/src/setTitle.js +90 -0
  63. package/src/shareContact.js +53 -0
  64. package/src/shareLink.js +62 -0
  65. package/src/threadColors.js +57 -0
  66. package/src/unfriend.js +53 -0
  67. package/src/unsendMessage.js +104 -0
  68. package/utils.js +1447 -0
  69. package/LICENSE +0 -3
  70. package/README.md +0 -491
  71. package/examples/login-with-cookies.js +0 -102
  72. package/examples/verify.js +0 -70
  73. package/src/apis/addUserToGroup.js +0 -108
  74. package/src/apis/changeAdminStatus.js +0 -148
  75. package/src/apis/changeArchivedStatus.js +0 -61
  76. package/src/apis/changeAvatar.js +0 -103
  77. package/src/apis/changeBio.js +0 -69
  78. package/src/apis/changeBlockedStatus.js +0 -54
  79. package/src/apis/changeGroupImage.js +0 -136
  80. package/src/apis/changeThreadColor.js +0 -116
  81. package/src/apis/comment.js +0 -207
  82. package/src/apis/createAITheme.js +0 -129
  83. package/src/apis/createNewGroup.js +0 -79
  84. package/src/apis/createPoll.js +0 -73
  85. package/src/apis/deleteMessage.js +0 -44
  86. package/src/apis/deleteThread.js +0 -52
  87. package/src/apis/e2ee.js +0 -17
  88. package/src/apis/editMessage.js +0 -70
  89. package/src/apis/emoji.js +0 -124
  90. package/src/apis/fetchThemeData.js +0 -82
  91. package/src/apis/follow.js +0 -81
  92. package/src/apis/forwardMessage.js +0 -52
  93. package/src/apis/friend.js +0 -243
  94. package/src/apis/gcmember.js +0 -122
  95. package/src/apis/gcname.js +0 -123
  96. package/src/apis/gcrule.js +0 -119
  97. package/src/apis/getAccess.js +0 -111
  98. package/src/apis/getBotInfo.js +0 -88
  99. package/src/apis/getBotInitialData.js +0 -43
  100. package/src/apis/getFriendsList.js +0 -79
  101. package/src/apis/getMessage.js +0 -423
  102. package/src/apis/getTheme.js +0 -95
  103. package/src/apis/getThemeInfo.js +0 -116
  104. package/src/apis/getThreadHistory.js +0 -239
  105. package/src/apis/getThreadInfo.js +0 -267
  106. package/src/apis/getThreadList.js +0 -232
  107. package/src/apis/getThreadPictures.js +0 -58
  108. package/src/apis/getUserID.js +0 -117
  109. package/src/apis/getUserInfo.js +0 -513
  110. package/src/apis/getUserInfoV2.js +0 -146
  111. package/src/apis/handleMessageRequest.js +0 -50
  112. package/src/apis/httpPost.js +0 -89
  113. package/src/apis/httpPostFormData.js +0 -69
  114. package/src/apis/listenMqtt.js +0 -1236
  115. package/src/apis/listenSpeed.js +0 -179
  116. package/src/apis/logout.js +0 -87
  117. package/src/apis/markAsDelivered.js +0 -47
  118. package/src/apis/markAsReadAll.js +0 -40
  119. package/src/apis/markAsSeen.js +0 -70
  120. package/src/apis/mqttDeltaValue.js +0 -278
  121. package/src/apis/muteThread.js +0 -45
  122. package/src/apis/nickname.js +0 -132
  123. package/src/apis/notes.js +0 -163
  124. package/src/apis/pinMessage.js +0 -150
  125. package/src/apis/produceMetaTheme.js +0 -180
  126. package/src/apis/realtime.js +0 -182
  127. package/src/apis/removeUserFromGroup.js +0 -117
  128. package/src/apis/resolvePhotoUrl.js +0 -58
  129. package/src/apis/searchForThread.js +0 -154
  130. package/src/apis/sendMessage.js +0 -354
  131. package/src/apis/sendMessageMqtt.js +0 -249
  132. package/src/apis/sendTypingIndicator.js +0 -91
  133. package/src/apis/setMessageReaction.js +0 -27
  134. package/src/apis/setMessageReactionMqtt.js +0 -61
  135. package/src/apis/setThreadTheme.js +0 -260
  136. package/src/apis/setThreadThemeMqtt.js +0 -94
  137. package/src/apis/share.js +0 -107
  138. package/src/apis/shareContact.js +0 -66
  139. package/src/apis/stickers.js +0 -257
  140. package/src/apis/story.js +0 -181
  141. package/src/apis/theme.js +0 -233
  142. package/src/apis/unfriend.js +0 -47
  143. package/src/apis/unsendMessage.js +0 -17
  144. package/src/engine/client.js +0 -92
  145. package/src/engine/models/buildAPI.js +0 -152
  146. package/src/engine/models/loginHelper.js +0 -519
  147. package/src/engine/models/setOptions.js +0 -88
  148. package/src/security/e2ee.js +0 -109
  149. package/src/types/index.d.ts +0 -498
  150. package/src/utils/antiSuspension.js +0 -506
  151. package/src/utils/auth-helpers.js +0 -149
  152. package/src/utils/autoReLogin.js +0 -336
  153. package/src/utils/axios.js +0 -436
  154. package/src/utils/cache.js +0 -54
  155. package/src/utils/clients.js +0 -282
  156. package/src/utils/constants.js +0 -410
  157. package/src/utils/formatters/data/formatAttachment.js +0 -370
  158. package/src/utils/formatters/data/formatDelta.js +0 -109
  159. package/src/utils/formatters/index.js +0 -159
  160. package/src/utils/formatters/value/formatCookie.js +0 -91
  161. package/src/utils/formatters/value/formatDate.js +0 -36
  162. package/src/utils/formatters/value/formatID.js +0 -16
  163. package/src/utils/formatters.js +0 -1373
  164. package/src/utils/headers.js +0 -230
  165. package/src/utils/index.js +0 -153
  166. package/src/utils/monitoring.js +0 -333
  167. package/src/utils/rateLimiter.js +0 -319
  168. package/src/utils/tokenRefresh.js +0 -657
  169. package/src/utils/user-agents.js +0 -238
  170. package/src/utils/validation.js +0 -157
@@ -1,116 +0,0 @@
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,207 +0,0 @@
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
- };
@@ -1,129 +0,0 @@
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
- };
@@ -1,79 +0,0 @@
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
- };
@@ -1,73 +0,0 @@
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
- };
@@ -1,44 +0,0 @@
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
- };
@@ -1,52 +0,0 @@
1
- "use strict";
2
-
3
- const utils = require('../utils');
4
-
5
- module.exports = (defaultFuncs, api, ctx) => {
6
- return async function deleteThread(threadOrThreads, 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
- client: "mercury"
24
- };
25
-
26
- if (utils.getType(threadOrThreads) !== "Array") {
27
- threadOrThreads = [threadOrThreads];
28
- }
29
-
30
- for (let i = 0; i < threadOrThreads.length; i++) {
31
- form["ids[" + i + "]"] = threadOrThreads[i];
32
- }
33
-
34
- const res = await defaultFuncs.post(
35
- "https://www.facebook.com/ajax/mercury/delete_thread.php",
36
- ctx.jar,
37
- form
38
- ).then(utils.parseAndCheckLogin(ctx, defaultFuncs));
39
-
40
- if (res && res.error) {
41
- throw res;
42
- }
43
-
44
- callback(null, { success: true });
45
- } catch (err) {
46
- utils.error("deleteThread", err);
47
- callback(err);
48
- }
49
-
50
- return returnPromise;
51
- };
52
- };