@lazyneoaz/nkxchat 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/LICENSE +3 -0
  2. package/README.md +199 -0
  3. package/examples/login-with-cookies.js +102 -0
  4. package/examples/verify.js +70 -0
  5. package/index.js +2 -0
  6. package/package.json +84 -0
  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/apis/changeThreadEmoji.js +53 -0
  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/editMessage.js +70 -0
  24. package/src/apis/emoji.js +124 -0
  25. package/src/apis/enableAutoSaveAppState.js +69 -0
  26. package/src/apis/fetchThemeData.js +113 -0
  27. package/src/apis/follow.js +81 -0
  28. package/src/apis/forwardAttachment.js +178 -0
  29. package/src/apis/forwardMessage.js +52 -0
  30. package/src/apis/friend.js +243 -0
  31. package/src/apis/gcmember.js +122 -0
  32. package/src/apis/gcname.js +123 -0
  33. package/src/apis/gcrule.js +119 -0
  34. package/src/apis/getAccess.js +111 -0
  35. package/src/apis/getBotInfo.js +88 -0
  36. package/src/apis/getBotInitialData.js +43 -0
  37. package/src/apis/getEmojiUrl.js +40 -0
  38. package/src/apis/getFriendsList.js +79 -0
  39. package/src/apis/getMessage.js +423 -0
  40. package/src/apis/getTheme.js +123 -0
  41. package/src/apis/getThemeInfo.js +116 -0
  42. package/src/apis/getThemePictures.js +87 -0
  43. package/src/apis/getThreadColors.js +119 -0
  44. package/src/apis/getThreadHistory.js +239 -0
  45. package/src/apis/getThreadInfo.js +267 -0
  46. package/src/apis/getThreadList.js +232 -0
  47. package/src/apis/getThreadPictures.js +58 -0
  48. package/src/apis/getUserID.js +117 -0
  49. package/src/apis/getUserInfo.js +513 -0
  50. package/src/apis/getUserInfoV2.js +146 -0
  51. package/src/apis/handleFriendRequest.js +66 -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 +924 -0
  57. package/src/apis/listenSpeed.js +178 -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 +40 -0
  62. package/src/apis/markAsSeen.js +70 -0
  63. package/src/apis/mqttDeltaValue.js +252 -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 +150 -0
  68. package/src/apis/produceMetaTheme.js +160 -0
  69. package/src/apis/realtime.js +182 -0
  70. package/src/apis/refreshFb_dtsg.js +94 -0
  71. package/src/apis/removeUserFromGroup.js +117 -0
  72. package/src/apis/resolvePhotoUrl.js +58 -0
  73. package/src/apis/searchForThread.js +154 -0
  74. package/src/apis/sendEffect.js +306 -0
  75. package/src/apis/sendMessage.js +353 -0
  76. package/src/apis/sendMessageMqtt.js +255 -0
  77. package/src/apis/sendTypingIndicator.js +40 -0
  78. package/src/apis/setMessageReaction.js +27 -0
  79. package/src/apis/setMessageReactionMqtt.js +61 -0
  80. package/src/apis/setPostReaction.js +118 -0
  81. package/src/apis/setThreadTheme.js +210 -0
  82. package/src/apis/setThreadThemeMqtt.js +94 -0
  83. package/src/apis/setTitle.js +26 -0
  84. package/src/apis/share.js +106 -0
  85. package/src/apis/shareContact.js +66 -0
  86. package/src/apis/stickers.js +257 -0
  87. package/src/apis/story.js +181 -0
  88. package/src/apis/theme.js +233 -0
  89. package/src/apis/unfriend.js +47 -0
  90. package/src/apis/unsendMessage.js +17 -0
  91. package/src/apis/uploadAttachment.js +87 -0
  92. package/src/database/appStateBackup.js +189 -0
  93. package/src/database/models/index.js +56 -0
  94. package/src/database/models/thread.js +31 -0
  95. package/src/database/models/user.js +32 -0
  96. package/src/database/threadData.js +101 -0
  97. package/src/database/userData.js +90 -0
  98. package/src/engine/client.js +92 -0
  99. package/src/engine/models/buildAPI.js +118 -0
  100. package/src/engine/models/loginHelper.js +492 -0
  101. package/src/engine/models/setOptions.js +88 -0
  102. package/src/types/index.d.ts +498 -0
  103. package/src/utils/antiSuspension.js +516 -0
  104. package/src/utils/auth-helpers.js +149 -0
  105. package/src/utils/autoReLogin.js +237 -0
  106. package/src/utils/axios.js +368 -0
  107. package/src/utils/cache.js +54 -0
  108. package/src/utils/clients.js +279 -0
  109. package/src/utils/constants.js +525 -0
  110. package/src/utils/formatters/data/formatAttachment.js +370 -0
  111. package/src/utils/formatters/data/formatDelta.js +109 -0
  112. package/src/utils/formatters/index.js +159 -0
  113. package/src/utils/formatters/value/formatCookie.js +91 -0
  114. package/src/utils/formatters/value/formatDate.js +36 -0
  115. package/src/utils/formatters/value/formatID.js +16 -0
  116. package/src/utils/formatters.js +1369 -0
  117. package/src/utils/headers.js +235 -0
  118. package/src/utils/index.js +152 -0
  119. package/src/utils/monitoring.js +333 -0
  120. package/src/utils/rateLimiter.js +251 -0
  121. package/src/utils/tokenRefresh.js +285 -0
  122. package/src/utils/user-agents.js +238 -0
  123. package/src/utils/validation.js +157 -0
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ const utils = require("../utils");
4
+ module.exports = function (defaultFuncs, api, ctx) {
5
+ return function changeThreadEmoji(emoji, threadID, callback) {
6
+ let resolveFunc = function () {};
7
+ let rejectFunc = function () {};
8
+ const returnPromise = new Promise(function (resolve, reject) {
9
+ resolveFunc = resolve;
10
+ rejectFunc = reject;
11
+ });
12
+
13
+ if (!callback) {
14
+ callback = function (err) {
15
+ if (err) {
16
+ return rejectFunc(err);
17
+ }
18
+ resolveFunc();
19
+ };
20
+ }
21
+ const form = {
22
+ emoji_choice: emoji,
23
+ thread_or_other_fbid: threadID,
24
+ };
25
+
26
+ defaultFuncs
27
+ .post(
28
+ "https://www.facebook.com/messaging/save_thread_emoji/?source=thread_settings&__pc=EXP1%3Amessengerdotcom_pkg",
29
+ ctx.jar,
30
+ form,
31
+ )
32
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
33
+ .then(function (resData) {
34
+ if (resData.error === 1357031) {
35
+ throw {
36
+ error:
37
+ "Trying to change emoji of a chat that doesn't exist. Have at least one message in the thread before trying to change the emoji.",
38
+ };
39
+ }
40
+ if (resData.error) {
41
+ throw resData;
42
+ }
43
+
44
+ return callback();
45
+ })
46
+ .catch(function (err) {
47
+ utils.error("changeThreadEmoji", err);
48
+ return callback(err);
49
+ });
50
+
51
+ return returnPromise;
52
+ };
53
+ };
@@ -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
+ };
@@ -0,0 +1,52 @@
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
+ };
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ /**
3
+ * @author RFS-ADRENO
4
+ * @rewrittenBy Isai Ivanov
5
+ */
6
+
7
+ const utils = require('../utils');
8
+
9
+ function canBeCalled(func) {
10
+ try {
11
+ Reflect.apply(func, null, []);
12
+ return true;
13
+ } catch (error) {
14
+ return false;
15
+ }
16
+ }
17
+
18
+ /**
19
+ * A function for editing bot's messages.
20
+ * @param {string} text - The text with which the bot will edit its messages.
21
+ * @param {string} messageID - The message ID of the message the bot will edit.
22
+ * @param {Object} callback - Callback for the function.
23
+ */
24
+
25
+ module.exports = function (defaultFuncs, api, ctx) {
26
+ return function editMessage(text, messageID, callback) {
27
+ if (!ctx.mqttClient) {
28
+ throw new Error('Not connected to MQTT');
29
+ }
30
+
31
+ ctx.wsReqNumber += 1;
32
+ ctx.wsTaskNumber += 1;
33
+
34
+ const queryPayload = {
35
+ message_id: messageID,
36
+ text
37
+ };
38
+
39
+ const query = {
40
+ failure_count: null,
41
+ label: '742',
42
+ payload: JSON.stringify(queryPayload),
43
+ queue_name: 'edit_message',
44
+ task_id: ctx.wsTaskNumber
45
+ };
46
+
47
+ const context = {
48
+ app_id: '2220391788200892',
49
+ payload: {
50
+ data_trace_id: null,
51
+ epoch_id: parseInt(utils.generateOfflineThreadingID()),
52
+ tasks: [query],
53
+ version_id: '6903494529735864'
54
+ },
55
+ request_id: ctx.wsReqNumber,
56
+ type: 3
57
+ };
58
+
59
+ context.payload = JSON.stringify(context.payload);
60
+
61
+
62
+
63
+
64
+
65
+ ctx.mqttClient.publish('/ls_req', JSON.stringify(context), {
66
+ qos: 1, retain: false
67
+ });
68
+ };
69
+ };
70
+