rapido-fca 0.0.3 → 0.0.4

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 (79) hide show
  1. package/package.json +16 -15
  2. package/src/addExternalModule.js +19 -23
  3. package/src/addUserToGroup.js +99 -97
  4. package/src/changeAdminStatus.js +86 -62
  5. package/src/changeArchivedStatus.js +49 -49
  6. package/src/changeAvatar.js +118 -108
  7. package/src/changeAvatarV2.js +86 -0
  8. package/src/changeAvt.js +85 -0
  9. package/src/changeBio.js +63 -64
  10. package/src/changeBlockedStatus.js +40 -38
  11. package/src/changeBlockedStatusMqtt.js +80 -0
  12. package/src/changeCover.js +72 -0
  13. package/src/changeGroupImage.js +129 -126
  14. package/src/changeName.js +79 -0
  15. package/src/changeNickname.js +49 -49
  16. package/src/changeThreadColor.js +53 -53
  17. package/src/changeThreadEmoji.js +45 -45
  18. package/src/changeUsername.js +59 -0
  19. package/src/createCommentPost.js +230 -0
  20. package/src/createNewGroup.js +74 -72
  21. package/src/createPoll.js +59 -59
  22. package/src/createPost.js +276 -0
  23. package/src/deleteMessage.js +50 -50
  24. package/src/deleteThread.js +50 -50
  25. package/src/editMessage.js +51 -49
  26. package/src/editMessageOld.js +67 -0
  27. package/src/follow.js +74 -0
  28. package/src/forwardAttachment.js +54 -54
  29. package/src/getAccess.js +112 -0
  30. package/src/getAvatarUser.js +78 -0
  31. package/src/getCurrentUserID.js +3 -3
  32. package/src/getEmojiUrl.js +17 -17
  33. package/src/getFriendsList.js +67 -67
  34. package/src/getMessage.js +806 -767
  35. package/src/getRegion.js +7 -0
  36. package/src/getThreadHistory.js +656 -642
  37. package/src/getThreadHistoryDeprecated.js +71 -0
  38. package/src/getThreadInfo.js +1 -1
  39. package/src/getThreadInfoDeprecated.js +56 -0
  40. package/src/getThreadList.js +199 -227
  41. package/src/getThreadListDeprecated.js +46 -0
  42. package/src/getThreadPictures.js +51 -71
  43. package/src/getUID.js +119 -0
  44. package/src/getUserID.js +53 -58
  45. package/src/getUserInfo.js +52 -60
  46. package/src/handleFriendRequest.js +41 -65
  47. package/src/handleMessageRequest.js +42 -60
  48. package/src/httpGet.js +49 -57
  49. package/src/httpPost.js +48 -57
  50. package/src/listenMqtt.js +827 -895
  51. package/src/logout.js +61 -61
  52. package/src/markAsDelivered.js +42 -53
  53. package/src/markAsRead.js +59 -69
  54. package/src/markAsReadAll.js +32 -42
  55. package/src/markAsSeen.js +43 -54
  56. package/src/muteThread.js +40 -47
  57. package/src/refreshFb_dtsg.js +77 -69
  58. package/src/removeUserFromGroup.js +67 -67
  59. package/src/resolvePhotoUrl.js +34 -34
  60. package/src/searchForThread.js +43 -43
  61. package/src/searchStickers.js +53 -0
  62. package/src/sendMessage.js +80 -228
  63. package/src/sendMessageMqtt.js +322 -0
  64. package/src/sendTypingIndicator.js +86 -88
  65. package/src/sendTypingIndicatorV2.js +28 -0
  66. package/src/setMessageReaction.js +110 -109
  67. package/src/setMessageReactionMqtt.js +62 -0
  68. package/src/setPostReaction.js +90 -87
  69. package/src/setStoryReaction.js +64 -0
  70. package/src/setTitle.js +76 -72
  71. package/src/shareContact.js +110 -0
  72. package/src/shareLink.js +59 -0
  73. package/src/stopListenMqtt.js +23 -0
  74. package/src/threadColors.js +121 -121
  75. package/src/unfriend.js +43 -43
  76. package/src/unsendMessage.js +34 -38
  77. package/src/uploadAttachment.js +79 -81
  78. package/LICENSE +0 -21
  79. package/src/httpPostFormData.js +0 -63
@@ -0,0 +1,322 @@
1
+ var utils = require("../utils");
2
+ // @NethWs3Dev
3
+ var bluebird = require("bluebird");
4
+
5
+ module.exports = function (defaultFuncs, api, ctx) {
6
+ function uploadAttachment(attachments, callback) {
7
+ callback = callback || function () {};
8
+ var uploads = [];
9
+
10
+ // create an array of promises
11
+ for (var i = 0; i < attachments.length; i++) {
12
+ if (!utils.isReadableStream(attachments[i])) {
13
+ throw {
14
+ error:
15
+ "Attachment should be a readable stream and not " +
16
+ utils.getType(attachments[i]) +
17
+ ".",
18
+ };
19
+ }
20
+
21
+ var form = {
22
+ upload_1024: attachments[i],
23
+ voice_clip: "true",
24
+ };
25
+
26
+ uploads.push(
27
+ defaultFuncs
28
+ .postFormData(
29
+ "https://upload.facebook.com/ajax/mercury/upload.php",
30
+ ctx.jar,
31
+ form,
32
+ {},
33
+ )
34
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
35
+ .then(function (resData) {
36
+ if (resData.error) {
37
+ throw resData;
38
+ }
39
+
40
+ // We have to return the data unformatted unless we want to change it
41
+ // back in sendMessage.
42
+ return resData.payload.metadata[0];
43
+ }),
44
+ );
45
+ }
46
+
47
+ // resolve all promises
48
+ bluebird
49
+ .all(uploads)
50
+ .then(function (resData) {
51
+ callback(null, resData);
52
+ })
53
+ .catch(function (err) {
54
+ console.error("uploadAttachment", err);
55
+ return callback(err);
56
+ });
57
+ }
58
+
59
+ let variance = 0;
60
+ const epoch_id = () =>
61
+ Math.floor(Date.now() * (4194304 + (variance = (variance + 0.1) % 5)));
62
+ const emojiSizes = {
63
+ small: 1,
64
+ medium: 2,
65
+ large: 3,
66
+ };
67
+
68
+ function handleEmoji(msg, form, callback, cb) {
69
+ if (msg.emojiSize != null && msg.emoji == null) {
70
+ return callback({ error: "emoji property is empty" });
71
+ }
72
+ if (msg.emoji) {
73
+ if (!msg.emojiSize) {
74
+ msg.emojiSize = "small";
75
+ }
76
+ if (
77
+ msg.emojiSize !== "small" &&
78
+ msg.emojiSize !== "medium" &&
79
+ msg.emojiSize !== "large" &&
80
+ (isNaN(msg.emojiSize) || msg.emojiSize < 1 || msg.emojiSize > 3)
81
+ ) {
82
+ return callback({ error: "emojiSize property is invalid" });
83
+ }
84
+
85
+ form.payload.tasks[0].payload.send_type = 1;
86
+ form.payload.tasks[0].payload.text = msg.emoji;
87
+ form.payload.tasks[0].payload.hot_emoji_size = !isNaN(msg.emojiSize)
88
+ ? msg.emojiSize
89
+ : emojiSizes[msg.emojiSize];
90
+ }
91
+ cb();
92
+ }
93
+
94
+ function handleSticker(msg, form, callback, cb) {
95
+ if (msg.sticker) {
96
+ form.payload.tasks[0].payload.send_type = 2;
97
+ form.payload.tasks[0].payload.sticker_id = msg.sticker;
98
+ }
99
+ cb();
100
+ }
101
+
102
+ function handleAttachment(msg, form, callback, cb) {
103
+ if (msg.attachment) {
104
+ form.payload.tasks[0].payload.send_type = 3;
105
+ form.payload.tasks[0].payload.attachment_fbids = [];
106
+ if (form.payload.tasks[0].payload.text == "")
107
+ form.payload.tasks[0].payload.text = null;
108
+ if (utils.getType(msg.attachment) !== "Array") {
109
+ msg.attachment = [msg.attachment];
110
+ }
111
+
112
+ uploadAttachment(msg.attachment, function (err, files) {
113
+ if (err) {
114
+ return callback(err);
115
+ }
116
+
117
+ files.forEach(function (file) {
118
+ var key = Object.keys(file);
119
+ var type = key[0]; // image_id, file_id, etc
120
+ form.payload.tasks[0].payload.attachment_fbids.push(file[type]); // push the id
121
+ });
122
+ cb();
123
+ });
124
+ } else {
125
+ cb();
126
+ }
127
+ }
128
+
129
+ function handleMention(msg, form, callback, cb) {
130
+ if (msg.mentions) {
131
+ form.payload.tasks[0].payload.send_type = 1;
132
+
133
+ const arrayIds = [];
134
+ const arrayOffsets = [];
135
+ const arrayLengths = [];
136
+ const mention_types = [];
137
+
138
+ for (let i = 0; i < msg.mentions.length; i++) {
139
+ const mention = msg.mentions[i];
140
+
141
+ const tag = mention.tag;
142
+ if (typeof tag !== "string") {
143
+ return callback({ error: "Mention tags must be strings." });
144
+ }
145
+
146
+ const offset = msg.body.indexOf(tag, mention.fromIndex || 0);
147
+
148
+ if (offset < 0) {
149
+ console.warn(
150
+ "handleMention",
151
+ 'Mention for "' + tag + '" not found in message string.',
152
+ );
153
+ }
154
+
155
+ if (mention.id == null) {
156
+ console.warn("handleMention", "Mention id should be non-null.");
157
+ }
158
+
159
+ const id = mention.id || 0;
160
+ arrayIds.push(id);
161
+ arrayOffsets.push(offset);
162
+ arrayLengths.push(tag.length);
163
+ mention_types.push("p");
164
+ }
165
+
166
+ form.payload.tasks[0].payload.mention_data = {
167
+ mention_ids: arrayIds.join(","),
168
+ mention_offsets: arrayOffsets.join(","),
169
+ mention_lengths: arrayLengths.join(","),
170
+ mention_types: mention_types.join(","),
171
+ };
172
+ }
173
+ cb();
174
+ }
175
+
176
+ function handleLocation(msg, form, callback, cb) {
177
+ // this is not working yet
178
+ if (msg.location) {
179
+ if (msg.location.latitude == null || msg.location.longitude == null) {
180
+ return callback({
181
+ error: "location property needs both latitude and longitude",
182
+ });
183
+ }
184
+
185
+ form.payload.tasks[0].payload.send_type = 1;
186
+ form.payload.tasks[0].payload.location_data = {
187
+ coordinates: {
188
+ latitude: msg.location.latitude,
189
+ longitude: msg.location.longitude,
190
+ },
191
+ is_current_location: !!msg.location.current,
192
+ is_live_location: !!msg.location.live,
193
+ };
194
+ }
195
+
196
+ cb();
197
+ }
198
+
199
+ function send(form, threadID, callback, replyToMessage) {
200
+ if (replyToMessage) {
201
+ form.payload.tasks[0].payload.reply_metadata = {
202
+ reply_source_id: replyToMessage,
203
+ reply_source_type: 1,
204
+ reply_type: 0,
205
+ };
206
+ }
207
+ const mqttClient = ctx.mqttClient;
208
+ form.payload.tasks.forEach((task) => {
209
+ task.payload = JSON.stringify(task.payload);
210
+ });
211
+ form.payload = JSON.stringify(form.payload);
212
+ console.log(global.jsonStringifyColor(form, null, 2));
213
+
214
+ return mqttClient.publish(
215
+ "/ls_req",
216
+ JSON.stringify(form),
217
+ function (err, data) {
218
+ if (err) {
219
+ console.error("Error publishing message: ", err);
220
+ callback(err);
221
+ } else {
222
+ console.log("Message published successfully with data: ", data);
223
+ callback(null, data);
224
+ }
225
+ },
226
+ );
227
+ }
228
+
229
+ return function sendMessageMqtt(msg, threadID, callback, replyToMessage) {
230
+ if (
231
+ !callback &&
232
+ (utils.getType(threadID) === "Function" ||
233
+ utils.getType(threadID) === "AsyncFunction")
234
+ ) {
235
+ return threadID({ error: "Pass a threadID as a second argument." });
236
+ }
237
+ if (!replyToMessage && utils.getType(callback) === "String") {
238
+ replyToMessage = callback;
239
+ callback = function () {};
240
+ }
241
+
242
+ if (!callback) {
243
+ callback = function (err, friendList) {};
244
+ }
245
+
246
+ var msgType = utils.getType(msg);
247
+ var threadIDType = utils.getType(threadID);
248
+ var messageIDType = utils.getType(replyToMessage);
249
+
250
+ if (msgType !== "String" && msgType !== "Object") {
251
+ return callback({
252
+ error:
253
+ "Message should be of type string or object and not " + msgType + ".",
254
+ });
255
+ }
256
+
257
+ if (msgType === "String") {
258
+ msg = { body: msg };
259
+ }
260
+
261
+ const timestamp = Date.now();
262
+ // get full date time
263
+ const epoch = timestamp << 22;
264
+ //const otid = epoch + 0; // TODO replace with randomInt(0, 2**22)
265
+ const otid = epoch + Math.floor(Math.random() * 4194304);
266
+
267
+ const form = {
268
+ app_id: "2220391788200892",
269
+ payload: {
270
+ tasks: [
271
+ {
272
+ label: "46",
273
+ payload: {
274
+ thread_id: threadID.toString(),
275
+ otid: otid.toString(),
276
+ source: 0,
277
+ send_type: 1,
278
+ sync_group: 1,
279
+ text:
280
+ msg.body != null && msg.body != undefined
281
+ ? msg.body.toString()
282
+ : "",
283
+ initiating_source: 1,
284
+ skip_url_preview_gen: 0,
285
+ },
286
+ queue_name: threadID.toString(),
287
+ task_id: 0,
288
+ failure_count: null,
289
+ },
290
+ {
291
+ label: "21",
292
+ payload: {
293
+ thread_id: threadID.toString(),
294
+ last_read_watermark_ts: Date.now(),
295
+ sync_group: 1,
296
+ },
297
+ queue_name: threadID.toString(),
298
+ task_id: 1,
299
+ failure_count: null,
300
+ },
301
+ ],
302
+ epoch_id: epoch_id(),
303
+ version_id: "6120284488008082",
304
+ data_trace_id: null,
305
+ },
306
+ request_id: 1,
307
+ type: 3,
308
+ };
309
+
310
+ handleEmoji(msg, form, callback, function () {
311
+ handleLocation(msg, form, callback, function () {
312
+ handleMention(msg, form, callback, function () {
313
+ handleSticker(msg, form, callback, function () {
314
+ handleAttachment(msg, form, callback, function () {
315
+ send(form, threadID, callback, replyToMessage);
316
+ });
317
+ });
318
+ });
319
+ });
320
+ });
321
+ };
322
+ };
@@ -1,103 +1,101 @@
1
1
  "use strict";
2
2
 
3
3
  const utils = require("../utils");
4
- const log = require("npmlog");
4
+ // @NethWs3Dev
5
5
 
6
6
  module.exports = function (defaultFuncs, api, ctx) {
7
- function makeTypingIndicator(typ, threadID, callback, isGroup) {
8
- const form = {
9
- typ: +typ,
10
- to: "",
11
- source: "mercury-chat",
12
- thread: threadID
13
- };
7
+ function makeTypingIndicator(typ, threadID, callback, isGroup) {
8
+ const form = {
9
+ typ: +typ,
10
+ to: "",
11
+ source: "mercury-chat",
12
+ thread: threadID,
13
+ };
14
14
 
15
- // Check if thread is a single person chat or a group chat
16
- // More info on this is in api.sendMessage
17
- if (utils.getType(isGroup) == "Boolean") {
18
- if (!isGroup) {
19
- form.to = threadID;
20
- }
21
- defaultFuncs
22
- .post("https://www.facebook.com/ajax/messaging/typ.php", ctx.jar, form)
23
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
24
- .then(function (resData) {
25
- if (resData.error) {
26
- throw resData;
27
- }
15
+ // Check if thread is a single person chat or a group chat
16
+ // More info on this is in api.sendMessage
17
+ if (utils.getType(isGroup) == "Boolean") {
18
+ if (!isGroup) {
19
+ form.to = threadID;
20
+ }
21
+ defaultFuncs
22
+ .post("https://www.facebook.com/ajax/messaging/typ.php", ctx.jar, form)
23
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
24
+ .then(function (resData) {
25
+ if (resData.error) {
26
+ throw resData;
27
+ }
28
28
 
29
- return callback();
30
- })
31
- .catch(function (err) {
32
- log.error("sendTypingIndicator", err);
33
- if (utils.getType(err) == "Object" && err.error === "Not logged in") {
34
- ctx.loggedIn = false;
35
- }
36
- return callback(err);
37
- });
38
- } else {
39
- api.getUserInfo(threadID, function (err, res) {
40
- if (err) {
41
- return callback(err);
42
- }
29
+ return callback();
30
+ })
31
+ .catch(function (err) {
32
+ console.error("sendTypingIndicator", err);
33
+ return callback(err);
34
+ });
35
+ } else {
36
+ api.getUserInfo(threadID, function (err, res) {
37
+ if (err) {
38
+ return callback(err);
39
+ }
43
40
 
44
- // If id is single person chat
45
- if (Object.keys(res).length > 0) {
46
- form.to = threadID;
47
- }
41
+ // If id is single person chat
42
+ if (Object.keys(res).length > 0) {
43
+ form.to = threadID;
44
+ }
48
45
 
49
- defaultFuncs
50
- .post("https://www.facebook.com/ajax/messaging/typ.php", ctx.jar, form)
51
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
52
- .then(function (resData) {
53
- if (resData.error) {
54
- throw resData;
55
- }
46
+ defaultFuncs
47
+ .post(
48
+ "https://www.facebook.com/ajax/messaging/typ.php",
49
+ ctx.jar,
50
+ form,
51
+ )
52
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
53
+ .then(function (resData) {
54
+ if (resData.error) {
55
+ throw resData;
56
+ }
56
57
 
57
- return callback();
58
- })
59
- .catch(function (err) {
60
- log.error("sendTypingIndicator", err);
61
- if (utils.getType(err) == "Object" && err.error === "Not logged in.") {
62
- ctx.loggedIn = false;
63
- }
64
- return callback(err);
65
- });
66
- });
67
- }
68
- }
58
+ return callback();
59
+ })
60
+ .catch(function (err) {
61
+ console.error("sendTypingIndicator", err);
62
+ return callback(err);
63
+ });
64
+ });
65
+ }
66
+ }
69
67
 
70
- return function sendTypingIndicator(threadID, callback, isGroup) {
71
- if (
72
- utils.getType(callback) !== "Function" &&
73
- utils.getType(callback) !== "AsyncFunction"
74
- ) {
75
- if (callback) {
76
- log.warn(
77
- "sendTypingIndicator",
78
- "callback is not a function - ignoring."
79
- );
80
- }
81
- callback = () => { };
82
- }
68
+ return function sendTypingIndicator(threadID, callback, isGroup) {
69
+ if (
70
+ utils.getType(callback) !== "Function" &&
71
+ utils.getType(callback) !== "AsyncFunction"
72
+ ) {
73
+ if (callback) {
74
+ console.warn(
75
+ "sendTypingIndicator",
76
+ "callback is not a function - ignoring.",
77
+ );
78
+ }
79
+ callback = () => {};
80
+ }
83
81
 
84
- makeTypingIndicator(true, threadID, callback, isGroup);
82
+ makeTypingIndicator(true, threadID, callback, isGroup);
85
83
 
86
- return function end(cb) {
87
- if (
88
- utils.getType(cb) !== "Function" &&
89
- utils.getType(cb) !== "AsyncFunction"
90
- ) {
91
- if (cb) {
92
- log.warn(
93
- "sendTypingIndicator",
94
- "callback is not a function - ignoring."
95
- );
96
- }
97
- cb = () => { };
98
- }
84
+ return function end(cb) {
85
+ if (
86
+ utils.getType(cb) !== "Function" &&
87
+ utils.getType(cb) !== "AsyncFunction"
88
+ ) {
89
+ if (cb) {
90
+ console.warn(
91
+ "sendTypingIndicator",
92
+ "callback is not a function - ignoring.",
93
+ );
94
+ }
95
+ cb = () => {};
96
+ }
99
97
 
100
- makeTypingIndicator(false, threadID, cb, isGroup);
101
- };
102
- };
98
+ makeTypingIndicator(false, threadID, cb, isGroup);
99
+ };
100
+ };
103
101
  };
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+
4
+
5
+ var utils = require("../utils");
6
+ // @NethWs3Dev
7
+
8
+ module.exports = function (defaultFuncs, api, ctx) {
9
+ return async function sendTypingIndicatorV2(sendTyping,threadID, callback) {
10
+ let count_req = 0
11
+ var wsContent = {
12
+ app_id: 2220391788200892,
13
+ payload: JSON.stringify({
14
+ label: 3,
15
+ payload: JSON.stringify({
16
+ thread_key: threadID.toString(),
17
+ is_group_thread: +(threadID.toString().length >= 16),
18
+ is_typing: +sendTyping,
19
+ attribution: 0
20
+ }),
21
+ version: 5849951561777440
22
+ }),
23
+ request_id: ++count_req,
24
+ type: 4
25
+ };
26
+ await new Promise((resolve, reject) => mqttClient.publish('/ls_req', JSON.stringify(wsContent), {}, (err, _packet) => err ? reject(err) : resolve()));
27
+ };
28
+ };