ws-rapido 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 (84) hide show
  1. package/index.js +477 -0
  2. package/package.json +46 -0
  3. package/src/addExternalModule.js +25 -0
  4. package/src/addUserToGroup.js +115 -0
  5. package/src/changeAdminStatus.js +103 -0
  6. package/src/changeArchivedStatus.js +55 -0
  7. package/src/changeAvatar.js +136 -0
  8. package/src/changeAvatarV2.js +86 -0
  9. package/src/changeBio.js +76 -0
  10. package/src/changeBlockedStatus.js +49 -0
  11. package/src/changeBlockedStatusMqtt.js +80 -0
  12. package/src/changeCover.js +72 -0
  13. package/src/changeGroupImage.js +135 -0
  14. package/src/changeName.js +78 -0
  15. package/src/changeNickname.js +59 -0
  16. package/src/changeThreadColor.js +65 -0
  17. package/src/changeThreadEmoji.js +55 -0
  18. package/src/changeUsername.js +58 -0
  19. package/src/createCommentPost.js +229 -0
  20. package/src/createNewGroup.js +88 -0
  21. package/src/createPoll.js +71 -0
  22. package/src/createPost.js +275 -0
  23. package/src/data/getThreadInfo.json +1 -0
  24. package/src/deleteMessage.js +56 -0
  25. package/src/deleteThread.js +56 -0
  26. package/src/editMessage.js +76 -0
  27. package/src/follow.js +74 -0
  28. package/src/forwardAttachment.js +60 -0
  29. package/src/getAccess.js +111 -0
  30. package/src/getAvatarUser.js +78 -0
  31. package/src/getBotInitialData.js +43 -0
  32. package/src/getCtx.js +5 -0
  33. package/src/getCurrentUserID.js +7 -0
  34. package/src/getEmojiUrl.js +29 -0
  35. package/src/getFriendsList.js +83 -0
  36. package/src/getMessage.js +835 -0
  37. package/src/getOptions.js +5 -0
  38. package/src/getRegion.js +7 -0
  39. package/src/getThreadHistory.js +680 -0
  40. package/src/getThreadHistoryDeprecated.js +93 -0
  41. package/src/getThreadInfo.js +227 -0
  42. package/src/getThreadInfoDeprecated.js +80 -0
  43. package/src/getThreadList.js +269 -0
  44. package/src/getThreadListDeprecated.js +75 -0
  45. package/src/getThreadPictures.js +79 -0
  46. package/src/getUID.js +122 -0
  47. package/src/getUserID.js +66 -0
  48. package/src/getUserInfo.js +82 -0
  49. package/src/handleFriendRequest.js +57 -0
  50. package/src/handleMessageRequest.js +65 -0
  51. package/src/httpGet.js +64 -0
  52. package/src/httpPost.js +64 -0
  53. package/src/httpPostFormData.js +70 -0
  54. package/src/listenMqtt.js +674 -0
  55. package/src/listenNotification.js +85 -0
  56. package/src/logout.js +75 -0
  57. package/src/markAsDelivered.js +55 -0
  58. package/src/markAsRead.js +85 -0
  59. package/src/markAsReadAll.js +50 -0
  60. package/src/markAsSeen.js +61 -0
  61. package/src/muteThread.js +52 -0
  62. package/src/pinMessage.js +59 -0
  63. package/src/refreshFb_dtsg.js +89 -0
  64. package/src/removeUserFromGroup.js +79 -0
  65. package/src/resolvePhotoUrl.js +45 -0
  66. package/src/searchForThread.js +53 -0
  67. package/src/searchStickers.js +53 -0
  68. package/src/sendMessage.js +442 -0
  69. package/src/sendMessageMqtt.js +316 -0
  70. package/src/sendTypingIndicator.js +28 -0
  71. package/src/setMessageReaction.js +122 -0
  72. package/src/setMessageReactionMqtt.js +62 -0
  73. package/src/setPostReaction.js +108 -0
  74. package/src/setProfileGuard.js +44 -0
  75. package/src/setStoryReaction.js +64 -0
  76. package/src/setTitle.js +90 -0
  77. package/src/shareContact.js +110 -0
  78. package/src/shareLink.js +59 -0
  79. package/src/stopListenMqtt.js +23 -0
  80. package/src/threadColors.js +131 -0
  81. package/src/unfriend.js +52 -0
  82. package/src/unsendMessage.js +45 -0
  83. package/src/uploadAttachment.js +94 -0
  84. package/utils.js +1441 -0
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+
3
+ const utils = require("../utils");
4
+ // @NethWs3Dev
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ return function createNewGroup(participantIDs, groupTitle, callback) {
8
+ if (utils.getType(groupTitle) == "Function") {
9
+ callback = groupTitle;
10
+ groupTitle = null;
11
+ }
12
+
13
+ if (utils.getType(participantIDs) !== "Array") {
14
+ throw { error: "createNewGroup: participantIDs should be an array." };//
15
+ }
16
+
17
+ if (participantIDs.length < 2) {
18
+ throw {
19
+ error: "createNewGroup: participantIDs should have at least 2 IDs.",
20
+ };
21
+ }
22
+
23
+ let resolveFunc = function () {};
24
+ let rejectFunc = function () {};
25
+ const returnPromise = new Promise(function (resolve, reject) {
26
+ resolveFunc = resolve;
27
+ rejectFunc = reject;
28
+ });
29
+
30
+ if (!callback) {
31
+ callback = function (err, threadID) {
32
+ if (err) {
33
+ return rejectFunc(err);
34
+ }
35
+ resolveFunc(threadID);
36
+ };
37
+ }
38
+
39
+ const pids = [];
40
+ for (const n in participantIDs) {
41
+ pids.push({
42
+ fbid: participantIDs[n],
43
+ });
44
+ }
45
+ pids.push({ fbid: ctx.userID });
46
+
47
+ const form = {
48
+ fb_api_caller_class: "RelayModern",
49
+ fb_api_req_friendly_name: "MessengerGroupCreateMutation",
50
+ av: ctx.userID,
51
+ //This doc_id is valid as of January 11th, 2020
52
+ doc_id: "577041672419534",
53
+ variables: JSON.stringify({
54
+ input: {
55
+ entry_point: "jewel_new_group",
56
+ actor_id: ctx.userID,
57
+ participants: pids,
58
+ client_mutation_id: Math.round(Math.random() * 1024).toString(),
59
+ thread_settings: {
60
+ name: groupTitle,
61
+ joinable_mode: "PRIVATE",
62
+ thread_image_fbid: null,
63
+ },
64
+ },
65
+ }),
66
+ };
67
+
68
+ defaultFuncs
69
+ .post("https://www.facebook.com/api/graphql/", ctx.jar, form)
70
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
71
+ .then(function (resData) {
72
+ if (resData.errors) {
73
+ throw resData;
74
+ }
75
+ return callback(
76
+ null,
77
+ resData.data.messenger_group_thread_create.thread.thread_key
78
+ .thread_fbid,
79
+ );
80
+ })
81
+ .catch(function (err) {
82
+ utils.error("createNewGroup", err);
83
+ return callback(err);
84
+ });
85
+
86
+ return returnPromise;
87
+ };
88
+ };
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+
3
+ const utils = require("../utils");
4
+ // @NethWs3Dev
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ return function createPoll(title, threadID, options, callback) {
8
+ let resolveFunc = function () {};
9
+ let rejectFunc = function () {};
10
+ const returnPromise = new Promise(function (resolve, reject) {
11
+ resolveFunc = resolve;
12
+ rejectFunc = reject;
13
+ });
14
+
15
+ if (!callback) {
16
+ if (utils.getType(options) == "Function") {
17
+ callback = options;
18
+ options = null;
19
+ } else {
20
+ callback = function (err) {
21
+ if (err) {
22
+ return rejectFunc(err);
23
+ }
24
+ resolveFunc();
25
+ };
26
+ }
27
+ }
28
+ if (!options) {
29
+ options = {}; // Initial poll options are optional
30
+ }
31
+
32
+ const form = {
33
+ target_id: threadID,
34
+ question_text: title,
35
+ };
36
+
37
+ // Set fields for options (and whether they are selected initially by the posting user)
38
+ let ind = 0;
39
+ for (const opt in options) {
40
+ // eslint-disable-next-line no-prototype-builtins
41
+ if (options.hasOwnProperty(opt)) {
42
+ form["option_text_array[" + ind + "]"] = opt;
43
+ form["option_is_selected_array[" + ind + "]"] = options[opt]
44
+ ? "1"
45
+ : "0";
46
+ ind++;
47
+ }
48
+ }
49
+
50
+ defaultFuncs
51
+ .post(
52
+ "https://www.facebook.com/messaging/group_polling/create_poll/?dpr=1",
53
+ ctx.jar,
54
+ form,
55
+ )
56
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
57
+ .then(function (resData) {
58
+ if (resData.payload.status != "success") {
59
+ throw resData;
60
+ }
61
+
62
+ return callback();
63
+ })
64
+ .catch(function (err) {
65
+ utils.error("createPoll", err);
66
+ return callback(err);
67
+ });
68
+
69
+ return returnPromise;
70
+ };
71
+ };
@@ -0,0 +1,275 @@
1
+ 'use strict';
2
+
3
+ var utils = require('../utils');
4
+
5
+ module.exports = function (defaultFuncs, api, ctx) {
6
+ function handleUpload(msg, form) {
7
+ var cb;
8
+ var rt = new Promise(function (resolve, reject) {
9
+ cb = error => error ? reject(error) : resolve();
10
+ });
11
+
12
+ if (!msg.attachment) cb();
13
+ else {
14
+ msg.attachment = Array.isArray(msg.attachment) ? msg.attachment : [msg.attachment];
15
+ let uploads = [];
16
+ for (let attachment of msg.attachment) {
17
+ if (!utils.isReadableStream(attachment))
18
+ cb('Attachment should be a readable stream, not ' + utils.getType(attachment));
19
+
20
+ var vari = {
21
+ source: 8,
22
+ profile_id: ctx.userID,
23
+ waterfallxapp: 'comet',
24
+ farr: attachment,
25
+ upload_id: 'jsc_c_6'
26
+ }
27
+ var main = defaultFuncs
28
+ .postFormData('https://upload.facebook.com/ajax/react_composer/attachments/photo/upload', ctx.jar, vari)
29
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
30
+ .then(function (res) {
31
+ if (res.error || res.errors)
32
+ throw res;
33
+
34
+ return res.payload;
35
+ });
36
+
37
+ uploads.push(main);
38
+ }
39
+
40
+ Promise
41
+ .all(uploads)
42
+ .then(function (res) {
43
+ for (let payload of res) {
44
+ if (!payload) break;
45
+ form.input.attachments.push({
46
+ photo: {
47
+ id: payload.photoID
48
+ }
49
+ });
50
+ }
51
+
52
+ return cb();
53
+ })
54
+ .catch(cb);
55
+ }
56
+
57
+ return rt;
58
+ }
59
+
60
+ function handleUrl(msg, form) {
61
+ var cb;
62
+ var rt = new Promise(function (resolve, reject) {
63
+ cb = error => error ? reject(error) : resolve();
64
+ });
65
+
66
+ if (!msg.url) cb();
67
+ else {
68
+ var vari = {
69
+ feedLocation: "FEED_COMPOSER",
70
+ focusCommentID: null,
71
+ goodwillCampaignId: "",
72
+ goodwillCampaignMediaIds: [],
73
+ goodwillContentType: null,
74
+ params: {
75
+ url: msg.url
76
+ },
77
+ privacySelectorRenderLocation: "COMET_COMPOSER",
78
+ renderLocation: "composer_preview",
79
+ parentStoryID: null,
80
+ scale: 1,
81
+ useDefaultActor: false,
82
+ shouldIncludeStoryAttachment: false,
83
+ __relay_internal__pv__IsWorkUserrelayprovider: false,
84
+ __relay_internal__pv__IsMergQAPollsrelayprovider: false
85
+ }
86
+
87
+ defaultFuncs
88
+ .post('https://www.facebook.com/api/graphql/', ctx.jar, {
89
+ fb_api_req_friendly_name: 'ComposerLinkAttachmentPreviewQuery',
90
+ variables: JSON.stringify(vari),
91
+ server_timestamps: true,
92
+ doc_id: 6549975235094234
93
+ })
94
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
95
+ .then(function (res) {
96
+ var res = (res[0] || res).data.link_preview;
97
+ if (JSON.parse(res.share_scrape_data).share_type == 400)
98
+ throw { error: 'url is not accepted' }
99
+
100
+ form.input.attachments.push({
101
+ link: {
102
+ share_scrape_data: res.share_scrape_data
103
+ }
104
+ });
105
+
106
+ return cb();
107
+ })
108
+ .catch(cb);
109
+ }
110
+
111
+ return rt;
112
+ }
113
+
114
+ function handleMention(msg, form) {
115
+ if (!msg.mentions) return;
116
+
117
+ msg.mentions = Array.isArray(msg.mentions) ? msg.mentions : [msg.mentions];
118
+ for (let mention of msg.mentions) {
119
+ var { id, tag, fromIndex } = mention;
120
+
121
+ if (typeof tag != 'string')
122
+ throw 'Mention tag must be string';
123
+ if (!id)
124
+ throw 'id must be string';
125
+ var offset = msg.body.indexOf(tag, fromIndex || 0);
126
+ if (offset < 0)
127
+ throw 'Mention for "' + tag + '" not found in message string.';
128
+ form.input.message.ranges.push({
129
+ entity: { id },
130
+ length: tag.length,
131
+ offset
132
+ });
133
+ }
134
+ }
135
+
136
+ function createContent(vari) {
137
+ var cb;
138
+ var rt = new Promise(function (resolve, reject) {
139
+ cb = (error, postData) => error ? reject(error) : resolve(postData);
140
+ });
141
+
142
+ var form = {
143
+ fb_api_req_friendly_name: 'ComposerStoryCreateMutation',
144
+ variables: JSON.stringify(vari),
145
+ server_timestamps: true,
146
+ doc_id: 6255089511280268
147
+ }
148
+
149
+ defaultFuncs
150
+ .post('https://www.facebook.com/api/graphql/', ctx.jar, form)
151
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
152
+ .then(res => cb(null, res))
153
+ .catch(cb);
154
+
155
+ return rt;
156
+ }
157
+
158
+ return function createPost(msg, callback) {
159
+ var cb;
160
+ var rt = new Promise(function (resolve, reject) {
161
+ cb = (error, url) => url ? resolve(url) : reject(error);
162
+ });
163
+
164
+ if (typeof msg == 'function') {
165
+ var error = 'Msg must be a string or object and not function';
166
+ utils.error('createPost', error);
167
+ return msg(error);
168
+ }
169
+ if (typeof callback == 'function') cb = callback;
170
+
171
+ var typeMsg = utils.getType(msg);
172
+ if (!['Object', 'String'].includes(typeMsg)) {
173
+ var error = 'Msg must be a string or object and not ' + typeMsg;
174
+ utils.error('createPost', error);
175
+ return cb(error);
176
+ } else if (typeMsg == 'String') msg = { body: msg };
177
+ msg.allowUserID = msg.allowUserID ? !Array.isArray(msg.allowUserID) ? [msg.allowUserID] : msg.allowUserID : null;
178
+
179
+ var sessionID = utils.getGUID();
180
+ var base = [
181
+ 'EVERYONE',
182
+ 'FRIENDS',
183
+ 'SELF'
184
+ ];
185
+ var form = {
186
+ input: {
187
+ composer_entry_point: !msg.groupID && msg.url ? 'share_modal' : "inline_composer",
188
+ composer_source_surface: !msg.groupID && msg.url ? 'feed_story' : msg.groupID ? "group" : "timeline",
189
+ composer_type: !msg.groupID && msg.url ? 'share' : msg.groupID ? "group" : "timeline",
190
+ idempotence_token: sessionID + "_FEED",
191
+ source: "WWW",
192
+ attachments: [],
193
+ audience: msg.groupID ? {
194
+ to_id: msg.groupID
195
+ } : {
196
+ privacy: {
197
+ allow: msg.allowUserID ? msg.allowUserID : [],
198
+ base_state: msg.allowUserID && msg.allowUserID.length > 0 ? base[2] : (base[msg.baseState - 1] || base[0]),
199
+ deny: [],
200
+ tag_expansion_state: "UNSPECIFIED"
201
+ }
202
+ },
203
+ message: {
204
+ ranges: [],
205
+ text: msg.body ? typeof msg.body == 'object' ? JSON.stringify(msg.body, null, 2) : msg.body : ''
206
+ },
207
+ with_tags_ids: [],
208
+ inline_activities: [],
209
+ explicit_place_id: 0,
210
+ text_format_preset_id: 0,
211
+ logging: {
212
+ composer_session_id: sessionID
213
+ },
214
+ navigation_data: {
215
+ attribution_id_v2: msg.groupID ? "CometGroupDiscussionRoot.react,comet.group,tap_search_bar," + Date.now() + ",909538,2361831622," : "ProfileCometTimelineListViewRoot.react,comet.profile.timeline.list,via_cold_start," + Date.now() + ",796829,190055527696468,"
216
+ },
217
+ is_tracking_encrypted: !!msg.url,
218
+ tracking: [],
219
+ event_share_metadata: {
220
+ surface: "newsfeed"
221
+ },
222
+ actor_id: ctx.globalOptions.pageID || ctx.userID,
223
+ client_mutation_id: Math.round(Math.random() * 19).toString()
224
+ },
225
+ displayCommentsFeedbackContext: null,
226
+ displayCommentsContextEnableComment: null,
227
+ displayCommentsContextIsAdPreview: null,
228
+ displayCommentsContextIsAggregatedShare: null,
229
+ displayCommentsContextIsStorySet: null,
230
+ feedLocation: msg.groupID ? "GROUP" : "TIMELINE",
231
+ feedbackSource: 0,
232
+ focusCommentID: null,
233
+ gridMediaWidth: 230,
234
+ groupID: null,
235
+ scale: 1,
236
+ privacySelectorRenderLocation: "COMET_STREAM",
237
+ renderLocation: msg.groupID ? "group" : "timeline",
238
+ useDefaultActor: false,
239
+ inviteShortLinkKey: null,
240
+ isFeed: false,
241
+ isFundraiser: false,
242
+ isFunFactPost: false,
243
+ isGroup: !!msg.groupID,
244
+ isEvent: false,
245
+ isTimeline: !msg.groupID,
246
+ isSocialLearning: false,
247
+ isPageNewsFeed: !!ctx.globalOptions.pageID,
248
+ isProfileReviews: false,
249
+ isWorkSharedDraft: false,
250
+ UFI2CommentsProvider_commentsKey: msg.groupID ? "CometGroupDiscussionRootSuccessQuery" : "ProfileCometTimelineRoute",
251
+ hashtag: null,
252
+ canUserManageOffers: false,
253
+ __relay_internal__pv__CometUFIIsRTAEnabledrelayprovider: false,
254
+ __relay_internal__pv__IsWorkUserrelayprovider: false,
255
+ __relay_internal__pv__IsMergQAPollsrelayprovider: false,
256
+ __relay_internal__pv__StoriesArmadilloReplyEnabledrelayprovider: false,
257
+ __relay_internal__pv__StoriesRingrelayprovider: false
258
+ }
259
+
260
+ handleUpload(msg, form)
261
+ .then(_ => handleUrl(msg, form))
262
+ .then(_ => handleMention(msg, form))
263
+ .then(_ => createContent(form))
264
+ .then((res) => {
265
+ if (res.error || res.errors) throw res;
266
+ return cb(null, (res[0] || res).data.story_create.story.url);
267
+ })
268
+ .catch((err) => {
269
+ //utils.error('createPost', err);
270
+ return cb(err);
271
+ });
272
+
273
+ return rt;
274
+ }
275
+ }
@@ -0,0 +1 @@
1
+ []
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+
3
+ const utils = require("../utils");
4
+ // @NethWs3Dev
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ return function deleteMessage(messageOrMessages, callback) {
8
+ let resolveFunc = function () {};
9
+ let rejectFunc = function () {};
10
+ const returnPromise = new Promise(function (resolve, reject) {
11
+ resolveFunc = resolve;
12
+ rejectFunc = reject;
13
+ });
14
+ if (!callback) {
15
+ callback = function (err) {
16
+ if (err) {
17
+ return rejectFunc(err);
18
+ }
19
+ resolveFunc();
20
+ };
21
+ }
22
+
23
+ const form = {
24
+ client: "mercury",
25
+ };
26
+
27
+ if (utils.getType(messageOrMessages) !== "Array") {
28
+ messageOrMessages = [messageOrMessages];
29
+ }
30
+
31
+ for (let i = 0; i < messageOrMessages.length; i++) {
32
+ form["message_ids[" + i + "]"] = messageOrMessages[i];
33
+ }
34
+
35
+ defaultFuncs
36
+ .post(
37
+ "https://www.facebook.com/ajax/mercury/delete_messages.php",
38
+ ctx.jar,
39
+ form,
40
+ )
41
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
42
+ .then(function (resData) {
43
+ if (resData.error) {
44
+ throw resData;
45
+ }
46
+
47
+ return callback();
48
+ })
49
+ .catch(function (err) {
50
+ utils.error("deleteMessage", err);
51
+ return callback(err);
52
+ });
53
+
54
+ return returnPromise;
55
+ };
56
+ };
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+
3
+ const utils = require("../utils");
4
+ // @NethWs3Dev
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ return function deleteThread(threadOrThreads, callback) {
8
+ let resolveFunc = function () {};
9
+ let rejectFunc = function () {};
10
+ const returnPromise = new Promise(function (resolve, reject) {
11
+ resolveFunc = resolve;
12
+ rejectFunc = reject;
13
+ });
14
+ if (!callback) {
15
+ callback = function (err) {
16
+ if (err) {
17
+ return rejectFunc(err);
18
+ }
19
+ resolveFunc();
20
+ };
21
+ }
22
+
23
+ const form = {
24
+ client: "mercury",
25
+ };
26
+
27
+ if (utils.getType(threadOrThreads) !== "Array") {
28
+ threadOrThreads = [threadOrThreads];
29
+ }
30
+
31
+ for (let i = 0; i < threadOrThreads.length; i++) {
32
+ form["ids[" + i + "]"] = threadOrThreads[i];
33
+ }
34
+
35
+ defaultFuncs
36
+ .post(
37
+ "https://www.facebook.com/ajax/mercury/delete_thread.php",
38
+ ctx.jar,
39
+ form,
40
+ )
41
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
42
+ .then(function (resData) {
43
+ if (resData.error) {
44
+ throw resData;
45
+ }
46
+
47
+ return callback();
48
+ })
49
+ .catch(function (err) {
50
+ utils.error("deleteThread", err);
51
+ return callback(err);
52
+ });
53
+
54
+ return returnPromise;
55
+ };
56
+ };
@@ -0,0 +1,76 @@
1
+ "use_strict";
2
+
3
+ // 02-14-2025
4
+
5
+ /*
6
+ Feature: Add callback function for editMessage #6 Merged
7
+ NethWs3Dev merged 1 commit into NethWs3Dev:main from VangBanLaNhat:Pull_requests
8
+ */
9
+
10
+ // I improved some code.
11
+ const utils = require("../utils");
12
+ module.exports = (defaultFuncs, api, ctx) => {
13
+ return (text, messageID, callback) => {
14
+ let reqID = ctx.wsReqNumber + 1;
15
+ var resolveFunc = () => {};
16
+ var rejectFunc = () => {};
17
+ var returnPromise = new Promise((resolve, reject) => {
18
+ resolveFunc = resolve;
19
+ rejectFunc = reject;
20
+ });
21
+ if (!callback) {
22
+ callback = (err, data) => {
23
+ if (err) {
24
+ return rejectFunc(err);
25
+ }
26
+ resolveFunc(data);
27
+ };
28
+ }
29
+ const content = {
30
+ app_id: '2220391788200892',
31
+ payload: JSON.stringify({
32
+ data_trace_id: null,
33
+ epoch_id: parseInt(utils.generateOfflineThreadingID()),
34
+ tasks: [{
35
+ failure_count: null,
36
+ label: '742',
37
+ payload: JSON.stringify({
38
+ message_id: messageID,
39
+ text: text,
40
+ }),
41
+ queue_name: 'edit_message',
42
+ task_id: ++ctx.wsTaskNumber,
43
+ }],
44
+ version_id: '6903494529735864',
45
+ }),
46
+ request_id: ++ctx.wsReqNumber,
47
+ type: 3
48
+ }
49
+ ctx.mqttClient.publish('/ls_req', JSON.stringify(content), {
50
+ qos: 1,
51
+ retain: false
52
+ });
53
+ const handleRes = (topic, message) => {
54
+ if (topic === "/ls_resp") {
55
+ let jsonMsg = JSON.parse(message.toString());
56
+ jsonMsg.payload = JSON.parse(jsonMsg.payload);
57
+ if (jsonMsg.request_id != reqID) return;
58
+ ctx.mqttClient.removeListener('message', handleRes);
59
+ let msgID = jsonMsg.payload.step[1][2][2][1][2];
60
+ let msgReplace = jsonMsg.payload.step[1][2][2][1][4];
61
+ const bodies = {
62
+ body: msgReplace,
63
+ messageID: msgID
64
+ };
65
+ if (msgReplace != text) {
66
+ return callback({
67
+ error: "The message is too old or not from you!"
68
+ }, bodies);
69
+ }
70
+ return callback(undefined, bodies);
71
+ }
72
+ }
73
+ ctx.mqttClient.on('message', handleRes);
74
+ return returnPromise;
75
+ };
76
+ }
package/src/follow.js ADDED
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Author @YanMaglinte
5
+ * https://github.com/YANDEVA
6
+ *
7
+ * Example:
8
+ * api.follow("100090794779367", true); // Set true to follow, false if otherwise.
9
+ */
10
+
11
+ //Fixed by Neth
12
+
13
+ module.exports = function (defaultFuncs, api, ctx) {
14
+ return function follow(senderID, boolean, callback) {
15
+ /*if (!ctx.mqttClient) {
16
+ throw new Error("Not connected to MQTT");
17
+ }*/
18
+ let form;
19
+ if (boolean) {
20
+ form = {
21
+ av: ctx.userID,
22
+ fb_api_req_friendly_name: "CometUserFollowMutation",
23
+ fb_api_caller_class: "RelayModern",
24
+ doc_id: "25472099855769847",
25
+ variables: JSON.stringify({
26
+ input: {
27
+ attribution_id_v2:
28
+ "ProfileCometTimelineListViewRoot.react,comet.profile.timeline.list,via_cold_start,1717249218695,723451,250100865708545,,",
29
+ is_tracking_encrypted: true,
30
+ subscribe_location: "PROFILE",
31
+ subscribee_id: senderID,
32
+ tracking: null,
33
+ actor_id: ctx.userID,
34
+ client_mutation_id: "1",
35
+ },
36
+ scale: 1,
37
+ }),
38
+ };
39
+ } else {
40
+ form = {
41
+ av: ctx.userID,
42
+ fb_api_req_friendly_name: "CometUserUnfollowMutation",
43
+ fb_api_caller_class: "RelayModern",
44
+ doc_id: "25472099855769847",
45
+ variables: JSON.stringify({
46
+ action_render_location: "WWW_COMET_FRIEND_MENU",
47
+ input: {
48
+ attribution_id_v2:
49
+ "ProfileCometTimelineListViewRoot.react,comet.profile.timeline.list,tap_search_bar,1717294006136,602597,250100865708545,,",
50
+ is_tracking_encrypted: true,
51
+ subscribe_location: "PROFILE",
52
+ tracking: null,
53
+ unsubscribee_id: senderID,
54
+ actor_id: ctx.userID,
55
+ client_mutation_id: "10",
56
+ },
57
+ scale: 1,
58
+ }),
59
+ };
60
+ }
61
+
62
+ api.httpPost("https://www.facebook.com/api/graphql/", form, (err, data) => {
63
+ if (err) {
64
+ if (typeof callback === "function") {
65
+ callback(err);
66
+ }
67
+ } else {
68
+ if (typeof callback === "function") {
69
+ callback(null, data);
70
+ }
71
+ }
72
+ });
73
+ };
74
+ };