rapido-fca 0.0.1 → 0.0.2

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 (81) hide show
  1. package/index.js +415 -419
  2. package/package.json +1 -1
  3. package/readme.md +39 -237
  4. package/src/addExternalModule.js +23 -19
  5. package/src/addUserToGroup.js +97 -99
  6. package/src/changeAdminStatus.js +62 -86
  7. package/src/changeArchivedStatus.js +49 -49
  8. package/src/changeAvatar.js +108 -118
  9. package/src/changeBio.js +64 -63
  10. package/src/changeBlockedStatus.js +38 -40
  11. package/src/changeGroupImage.js +126 -129
  12. package/src/changeNickname.js +49 -49
  13. package/src/changeThreadColor.js +53 -53
  14. package/src/changeThreadEmoji.js +45 -45
  15. package/src/createNewGroup.js +72 -74
  16. package/src/createPoll.js +59 -59
  17. package/src/deleteMessage.js +50 -50
  18. package/src/deleteThread.js +50 -50
  19. package/src/editMessage.js +49 -51
  20. package/src/forwardAttachment.js +54 -54
  21. package/src/getCurrentUserID.js +3 -3
  22. package/src/getEmojiUrl.js +17 -17
  23. package/src/getFriendsList.js +67 -67
  24. package/src/getMessage.js +767 -806
  25. package/src/getThreadHistory.js +642 -656
  26. package/src/getThreadInfo.js +1 -1
  27. package/src/getThreadList.js +227 -199
  28. package/src/getThreadPictures.js +71 -51
  29. package/src/getUserID.js +58 -53
  30. package/src/getUserInfo.js +60 -52
  31. package/src/handleFriendRequest.js +65 -41
  32. package/src/handleMessageRequest.js +60 -42
  33. package/src/httpGet.js +57 -49
  34. package/src/httpPost.js +57 -48
  35. package/src/httpPostFormData.js +63 -0
  36. package/src/listenMqtt.js +895 -827
  37. package/src/logout.js +61 -61
  38. package/src/markAsDelivered.js +53 -42
  39. package/src/markAsRead.js +69 -59
  40. package/src/markAsReadAll.js +42 -32
  41. package/src/markAsSeen.js +54 -43
  42. package/src/muteThread.js +47 -40
  43. package/src/refreshFb_dtsg.js +69 -77
  44. package/src/removeUserFromGroup.js +67 -67
  45. package/src/resolvePhotoUrl.js +34 -34
  46. package/src/searchForThread.js +43 -43
  47. package/src/sendMessage.js +228 -80
  48. package/src/sendTypingIndicator.js +88 -86
  49. package/src/setMessageReaction.js +109 -110
  50. package/src/setPostReaction.js +87 -90
  51. package/src/setTitle.js +72 -76
  52. package/src/threadColors.js +121 -121
  53. package/src/unfriend.js +43 -43
  54. package/src/unsendMessage.js +38 -34
  55. package/src/uploadAttachment.js +81 -79
  56. package/utils.js +1401 -2732
  57. package/src/changeAvatarV2.js +0 -86
  58. package/src/changeAvt.js +0 -85
  59. package/src/changeBlockedStatusMqtt.js +0 -80
  60. package/src/changeCover.js +0 -72
  61. package/src/changeName.js +0 -79
  62. package/src/changeUsername.js +0 -59
  63. package/src/createCommentPost.js +0 -230
  64. package/src/createPost.js +0 -276
  65. package/src/editMessageOld.js +0 -67
  66. package/src/follow.js +0 -74
  67. package/src/getAccess.js +0 -112
  68. package/src/getAvatarUser.js +0 -78
  69. package/src/getRegion.js +0 -7
  70. package/src/getThreadHistoryDeprecated.js +0 -71
  71. package/src/getThreadInfoDeprecated.js +0 -56
  72. package/src/getThreadListDeprecated.js +0 -46
  73. package/src/getUID.js +0 -119
  74. package/src/searchStickers.js +0 -53
  75. package/src/sendMessageMqtt.js +0 -322
  76. package/src/sendTypingIndicatorV2.js +0 -28
  77. package/src/setMessageReactionMqtt.js +0 -62
  78. package/src/setStoryReaction.js +0 -64
  79. package/src/shareContact.js +0 -110
  80. package/src/shareLink.js +0 -59
  81. package/src/stopListenMqtt.js +0 -23
@@ -1,56 +0,0 @@
1
- "use strict";
2
-
3
- var utils = require("../utils");
4
- var log = require("npmlog");
5
-
6
- module.exports = function (defaultFuncs, api, ctx) {
7
- return function getThreadInfo(threadID, callback) {
8
- var resolveFunc = function () { };
9
- var rejectFunc = function () { };
10
- var returnPromise = new Promise(function (resolve, reject) {
11
- resolveFunc = resolve;
12
- rejectFunc = reject;
13
- });
14
-
15
- if (!callback) {
16
- callback = function (err, data) {
17
- if (err) return rejectFunc(err);
18
- resolveFunc(data);
19
- };
20
- }
21
-
22
- var form = {
23
- client: "mercury"
24
- };
25
-
26
- api.getUserInfo(threadID, function (err, userRes) {
27
- if (err) return callback(err);
28
- var key = Object.keys(userRes).length > 0 ? "user_ids" : "thread_fbids";
29
- form["threads[" + key + "][0]"] = threadID;
30
-
31
- if (ctx.globalOptions.pageId) form.request_user_id = ctx.globalOptions.pageId;
32
-
33
- defaultFuncs
34
- .post("https://www.facebook.com/ajax/mercury/thread_info.php", ctx.jar, form)
35
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
36
- .then(function (resData) {
37
- if (resData.error) throw resData;
38
- else if (!resData.payload) throw { error: "Could not retrieve thread Info." };
39
-
40
- var threadData = resData.payload.threads[0];
41
- var userData = userRes[threadID];
42
-
43
- if (threadData == null) throw { error: "ThreadData is null" };
44
-
45
- threadData.name = userData != null && userData.name != null ? userData.name : threadData.name;
46
- threadData.image_src = userData != null && userData.thumbSrc != null ? userData.thumbSrc : threadData.image_src;
47
- callback(null, utils.formatThread(threadData));
48
- })
49
- .catch(function (err) {
50
- log.error("getThreadInfo", err);
51
- return callback(err);
52
- });
53
- });
54
- return returnPromise;
55
- };
56
- };
@@ -1,46 +0,0 @@
1
- "use strict";
2
-
3
- var utils = require("../utils");
4
- var log = require("npmlog");
5
-
6
- module.exports = function (defaultFuncs, api, ctx) {
7
- return function getThreadList(start, end, type, callback) {
8
- if (utils.getType(callback) === "Undefined") {
9
- if (utils.getType(end) !== "Number") throw { error: "Please pass a number as a second argument." };
10
- else if (utils.getType(type) === "Function" || utils.getType(type) === "AsyncFunction") {
11
- callback = type;
12
- type = "inbox"; //default to inbox
13
- }
14
- else if (utils.getType(type) !== "String") throw { error: "Please pass a String as a third argument. Your options are: inbox, pending, and archived" };
15
- else throw { error: "getThreadList: need callback" };
16
- }
17
-
18
- if (type === "archived") type = "action:archived";
19
- else if (type !== "inbox" && type !== "pending" && type !== "other") throw { error: "type can only be one of the following: inbox, pending, archived, other" };
20
-
21
-
22
- if (end <= start) end = start + 20;
23
-
24
- var form = {
25
- client: "mercury"
26
- };
27
-
28
- form[type + "[offset]"] = start;
29
- form[type + "[limit]"] = end - start;
30
-
31
- if (ctx.globalOptions.pageID) form.request_user_id = ctx.globalOptions.pageID;
32
-
33
- defaultFuncs
34
- .post("https://www.facebook.com/ajax/mercury/threadlist_info.php", ctx.jar, form)
35
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
36
- .then(function (resData) {
37
- if (resData.error) throw resData;
38
- log.verbose("getThreadList", JSON.stringify(resData.payload.threads));
39
- return callback(null, (resData.payload.threads || []).map(utils.formatThread));
40
- })
41
- .catch(function (err) {
42
- log.error("getThreadList", err);
43
- return callback(err);
44
- });
45
- };
46
- };
package/src/getUID.js DELETED
@@ -1,119 +0,0 @@
1
- /* eslint-disable linebreak-style */
2
- "use strict";
3
-
4
- const axios = require('axios');
5
- const FormData = require('form-data');
6
- const { URL } = require('url');
7
- const log = require('npmlog');
8
-
9
- module.exports = function (defaultFuncs, api, ctx) {
10
- return function getUID(link, callback) {
11
- let resolveFunc = function () { };
12
- let rejectFunc = function () { };
13
- let returnPromise = new Promise(function (resolve, reject) {
14
- resolveFunc = resolve;
15
- rejectFunc = reject;
16
- });
17
-
18
- if (!callback) {
19
- callback = function (err, uid) {
20
- if (err) return rejectFunc(err);
21
- resolveFunc(uid);
22
- };
23
- }
24
-
25
- async function getUIDFast(url) {
26
- let Form = new FormData();
27
- let Url = new URL(url);
28
- Form.append('link', Url.href);
29
- try {
30
- let { data } = await axios.post('https://id.traodoisub.com/api.php', Form, {
31
- headers: Form.getHeaders()
32
- });
33
- if (data.error) throw new Error(data.error);
34
- return data.id || "Not found";
35
- } catch (e) {
36
- log.error('getUID', "Error: " + e.message);
37
- throw new Error(e.message);
38
- }
39
- }
40
-
41
- async function getUIDSlow(url) {
42
- let Form = new FormData();
43
- let Url = new URL(url);
44
- Form.append('username', Url.pathname.replace(/\//g, ""));
45
- try {
46
- const userAgentArray = [
47
- "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3",
48
- "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15",
49
- "Mozilla/5.0 (Linux; Android 10; SM-G977N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Mobile Safari/537.36",
50
- "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0",
51
- "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0) Gecko/20100101 Firefox/45.0",
52
- "Mozilla/5.0 (Linux; U; Android 4.4.2; en-us; GT-I9505 Build/KOT49H) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30",
53
- "Mozilla/5.0 (iPhone; CPU iPhone OS 14_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.2 Mobile/15E148 Safari/604.1",
54
- "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0",
55
- "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/601.7.7 (KHTML, like Gecko) Version/9.1.2 Safari/601.7.7",
56
- "Mozilla/5.0 (Linux; Android 8.0.0; SM-G960F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.84 Mobile Safari/537.36",
57
- "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko",
58
- "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.1.2 Safari/603.3.8",
59
- "Mozilla/5.0 (Linux; Android 7.0; SM-G930F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.125 Mobile Safari/537.36",
60
- "Mozilla/5.0 (iPhone; CPU iPhone OS 12_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Mobile/15E148 Safari/604.1",
61
- "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.3",
62
- ];
63
-
64
- const randomUserAgent = userAgentArray[Math.floor(Math.random() * userAgentArray.length)];
65
- let { data } = await axios.post('https://api.findids.net/api/get-uid-from-username', Form, {
66
- headers: {
67
- 'User-Agent': randomUserAgent,
68
- ...Form.getHeaders()
69
- }
70
- });
71
- if (data.status !== 200) throw new Error('Error occurred!');
72
- if (typeof data.error === 'string') throw new Error(data.error);
73
- return data.data.id || "Not found";
74
- } catch (e) {
75
- log.error('getUID', "Error: " + e.message);
76
- throw new Error(e.message);
77
- }
78
- }
79
-
80
- async function getUID(url) {
81
- try {
82
- let uid = await getUIDFast(url);
83
- if (!isNaN(uid)) return uid;
84
- uid = await getUIDSlow(url);
85
- if (!isNaN(uid)) return uid;
86
- throw new Error("Unable to retrieve UID");
87
- } catch (e) {
88
- log.error('getUID', "Error: " + e.message);
89
- throw new Error(e.message);
90
- }
91
- }
92
-
93
- try {
94
- let Link = String(link);
95
- if (Link.includes('facebook.com') || Link.includes('Facebook.com') || Link.includes('fb')) {
96
- let LinkSplit = Link.split('/');
97
- if (LinkSplit.indexOf("https:") == 0) {
98
- if (!isNaN(LinkSplit[3]) && !Link.split('=')[1] && !isNaN(Link.split('=')[1])) {
99
- throw new Error('Invalid link format. The correct format should be: facebook.com/username');
100
- } else if (!isNaN(Link.split('=')[1]) && Link.split('=')[1]) {
101
- let Format = `https://www.facebook.com/profile.php?id=${Link.split('=')[1]}`;
102
- getUID(Format).then(data => callback(null, data)).catch(err => callback(err));
103
- } else {
104
- getUID(Link).then(data => callback(null, data)).catch(err => callback(err));
105
- }
106
- } else {
107
- let Form = `https://www.facebook.com/${LinkSplit[1]}`;
108
- getUID(Form).then(data => callback(null, data)).catch(err => callback(err));
109
- }
110
- } else {
111
- throw new Error('Invalid link. The link should be a Facebook link.');
112
- }
113
- } catch (e) {
114
- log.error('getUID', "Error: " + e.message);
115
- return callback(null, e);
116
- }
117
- return returnPromise;
118
- };
119
- };
@@ -1,53 +0,0 @@
1
-
2
- 'use strict';
3
-
4
- var utils = require('../utils.js');
5
- var log = require('npmlog');
6
-
7
- module.exports = function (http, api, ctx) {
8
- function formatData(res) {
9
- return {
10
- id: res.node.id,
11
- image: res.node.image,
12
- package: res.node.pack != null ? {
13
- name: res.node.pack.name,
14
- id: res.node.pack.id
15
- } : {},
16
- label: res.node.label
17
- };
18
- }
19
-
20
- return function searchStickers(query = '', callback) {
21
- var cb;
22
- var returnPromise = new Promise(function (resolve, reject) {
23
- cb = function (error, data) {
24
- data ? resolve(data) : reject(error);
25
- }
26
- });
27
-
28
- if (typeof callback == 'function') cb = callback;
29
-
30
- var form = {
31
- fb_api_req_friendly_name: 'StickersFlyoutTagSelectorQuery',
32
- variables: JSON.stringify({
33
- stickerWidth: 64,
34
- stickerHeight: 64,
35
- stickerInterface: 'messages',
36
- query
37
- }),
38
- doc_id: '4642836929159953'
39
- }
40
- http
41
- .post('https://www.facebook.com/api/graphql/', ctx.jar, form)
42
- .then(utils.parseAndCheckLogin(ctx, http))
43
- .then(function (res) {
44
- return cb(null, res.data.sticker_search.sticker_results.edges.map(formatData));
45
- })
46
- .catch(function (err) {
47
- console.error('searchStickers', err);
48
- return cb(err);
49
- });
50
- return returnPromise;
51
- }
52
- }
53
-
@@ -1,322 +0,0 @@
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,28 +0,0 @@
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
- };
@@ -1,62 +0,0 @@
1
-
2
- 'use strict';
3
-
4
- const { generateOfflineThreadingID } = require('../utils');
5
-
6
- function isCallable(func) {
7
- try {
8
- Reflect.apply(func, null, []);
9
- return true;
10
- } catch (error) {
11
- return false;
12
- }
13
- }
14
-
15
- module.exports = function (defaultFuncs, api, ctx) {
16
- return function setMessageReactionMqtt(reaction, messageID, threadID, callback) {
17
- if (!ctx.mqttClient) {
18
- throw new Error('Not connected to MQTT');
19
- }
20
-
21
-
22
- ctx.wsReqNumber += 1;
23
- ctx.wsTaskNumber += 1;
24
-
25
- const taskPayload = {
26
- thread_key: threadID,
27
- timestamp_ms: Date.now(),
28
- message_id: messageID,
29
- reaction: reaction,
30
- actor_id: ctx.userID,
31
- reaction_style: null,
32
- sync_group: 1,
33
- send_attribution: Math.random() < 0.5 ? 65537 : 524289
34
- };
35
-
36
- const task = {
37
- failure_count: null,
38
- label: '29',
39
- payload: JSON.stringify(taskPayload),
40
- queue_name: JSON.stringify(['reaction', messageID]),
41
- task_id: ctx.wsTaskNumber,
42
- };
43
-
44
- const content = {
45
- app_id: '2220391788200892',
46
- payload: JSON.stringify({
47
- data_trace_id: null,
48
- epoch_id: parseInt(generateOfflineThreadingID()),
49
- tasks: [task],
50
- version_id: '7158486590867448',
51
- }),
52
- request_id: ctx.wsReqNumber,
53
- type: 3,
54
- };
55
-
56
- if (isCallable(callback)) {
57
- ctx.reqCallbacks[ctx.wsReqNumber] = callback;
58
- }
59
-
60
- ctx.mqttClient.publish('/ls_req', JSON.stringify(content), { qos: 1, retain: false });
61
- };
62
- };