@lazyneoaz/testfca 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.
- package/CHANGELOG.md +229 -0
- package/COOKIE_LOGIN.md +208 -0
- package/LICENSE +3 -0
- package/README.md +492 -0
- package/index.js +2 -0
- package/package.json +120 -0
- package/scripts/build-go.mjs +54 -0
- package/scripts/detect-platform.mjs +36 -0
- package/scripts/download-prebuilt.mjs +119 -0
- package/scripts/package.mjs +6 -0
- package/scripts/postinstall.mjs +113 -0
- package/src/apis/addExternalModule.js +24 -0
- package/src/apis/addUserToGroup.js +108 -0
- package/src/apis/changeAdminStatus.js +148 -0
- package/src/apis/changeArchivedStatus.js +61 -0
- package/src/apis/changeAvatar.js +103 -0
- package/src/apis/changeBio.js +69 -0
- package/src/apis/changeBlockedStatus.js +54 -0
- package/src/apis/changeGroupImage.js +136 -0
- package/src/apis/changeThreadColor.js +116 -0
- package/src/apis/changeThreadEmoji.js +53 -0
- package/src/apis/comment.js +207 -0
- package/src/apis/createAITheme.js +129 -0
- package/src/apis/createNewGroup.js +79 -0
- package/src/apis/createPoll.js +73 -0
- package/src/apis/deleteMessage.js +52 -0
- package/src/apis/deleteThread.js +52 -0
- package/src/apis/e2ee.js +170 -0
- package/src/apis/editMessage.js +78 -0
- package/src/apis/emoji.js +124 -0
- package/src/apis/fetchThemeData.js +82 -0
- package/src/apis/follow.js +81 -0
- package/src/apis/forwardMessage.js +52 -0
- package/src/apis/friend.js +243 -0
- package/src/apis/gcmember.js +122 -0
- package/src/apis/gcname.js +123 -0
- package/src/apis/gcrule.js +119 -0
- package/src/apis/getAccess.js +111 -0
- package/src/apis/getBotInfo.js +88 -0
- package/src/apis/getBotInitialData.js +43 -0
- package/src/apis/getFriendsList.js +79 -0
- package/src/apis/getMessage.js +423 -0
- package/src/apis/getTheme.js +95 -0
- package/src/apis/getThemeInfo.js +116 -0
- package/src/apis/getThreadHistory.js +239 -0
- package/src/apis/getThreadInfo.js +267 -0
- package/src/apis/getThreadList.js +232 -0
- package/src/apis/getThreadPictures.js +58 -0
- package/src/apis/getUserID.js +117 -0
- package/src/apis/getUserInfo.js +513 -0
- package/src/apis/getUserInfoV2.js +146 -0
- package/src/apis/handleMessageRequest.js +50 -0
- package/src/apis/httpGet.js +63 -0
- package/src/apis/httpPost.js +89 -0
- package/src/apis/httpPostFormData.js +69 -0
- package/src/apis/listenMqtt.js +1236 -0
- package/src/apis/listenSpeed.js +179 -0
- package/src/apis/logout.js +93 -0
- package/src/apis/markAsDelivered.js +47 -0
- package/src/apis/markAsRead.js +115 -0
- package/src/apis/markAsReadAll.js +40 -0
- package/src/apis/markAsSeen.js +70 -0
- package/src/apis/mqttDeltaValue.js +250 -0
- package/src/apis/muteThread.js +45 -0
- package/src/apis/nickname.js +132 -0
- package/src/apis/notes.js +163 -0
- package/src/apis/pinMessage.js +150 -0
- package/src/apis/produceMetaTheme.js +180 -0
- package/src/apis/realtime.js +182 -0
- package/src/apis/removeUserFromGroup.js +117 -0
- package/src/apis/resolvePhotoUrl.js +58 -0
- package/src/apis/searchForThread.js +154 -0
- package/src/apis/sendMessage.js +346 -0
- package/src/apis/sendMessageMqtt.js +248 -0
- package/src/apis/sendTypingIndicator.js +105 -0
- package/src/apis/setMessageReaction.js +38 -0
- package/src/apis/setMessageReactionMqtt.js +61 -0
- package/src/apis/setThreadTheme.js +260 -0
- package/src/apis/setThreadThemeMqtt.js +94 -0
- package/src/apis/share.js +107 -0
- package/src/apis/shareContact.js +66 -0
- package/src/apis/stickers.js +257 -0
- package/src/apis/story.js +181 -0
- package/src/apis/theme.js +233 -0
- package/src/apis/unfriend.js +47 -0
- package/src/apis/unsendMessage.js +25 -0
- package/src/database/appStateBackup.js +298 -0
- package/src/database/models/index.js +56 -0
- package/src/database/models/thread.js +31 -0
- package/src/database/models/user.js +32 -0
- package/src/database/threadData.js +101 -0
- package/src/database/userData.js +90 -0
- package/src/e2ee/bridge.js +275 -0
- package/src/e2ee/index.js +60 -0
- package/src/engine/client.js +95 -0
- package/src/engine/models/buildAPI.js +152 -0
- package/src/engine/models/loginHelper.js +574 -0
- package/src/engine/models/setOptions.js +88 -0
- package/src/types/index.d.ts +574 -0
- package/src/utils/antiSuspension.js +529 -0
- package/src/utils/auth-helpers.js +149 -0
- package/src/utils/autoReLogin.js +336 -0
- package/src/utils/axios.js +436 -0
- package/src/utils/cache.js +54 -0
- package/src/utils/clients.js +282 -0
- package/src/utils/constants.js +410 -0
- package/src/utils/formatters/data/formatAttachment.js +370 -0
- package/src/utils/formatters/data/formatDelta.js +109 -0
- package/src/utils/formatters/index.js +159 -0
- package/src/utils/formatters/value/formatCookie.js +91 -0
- package/src/utils/formatters/value/formatDate.js +36 -0
- package/src/utils/formatters/value/formatID.js +16 -0
- package/src/utils/formatters.js +1373 -0
- package/src/utils/headers.js +235 -0
- package/src/utils/index.js +153 -0
- package/src/utils/monitoring.js +333 -0
- package/src/utils/rateLimiter.js +319 -0
- package/src/utils/tokenRefresh.js +680 -0
- package/src/utils/user-agents.js +238 -0
- package/src/utils/validation.js +157 -0
|
@@ -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,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require('../utils');
|
|
4
|
+
|
|
5
|
+
module.exports = (defaultFuncs, api, ctx) => {
|
|
6
|
+
return async function deleteMessage(messageID, callback) {
|
|
7
|
+
// E2EE routing: deleteMessage({ chatJid, messageId })
|
|
8
|
+
if (utils.getType(messageID) === "Object" && messageID.chatJid && messageID.messageId) {
|
|
9
|
+
if (!api.e2ee || !api.e2ee.isAvailable()) throw new Error("E2EE bridge not available");
|
|
10
|
+
const p = api.e2ee.unsendE2EEMessage(messageID.chatJid, messageID.messageId);
|
|
11
|
+
if (callback) p.then(r => callback(null, r)).catch(callback);
|
|
12
|
+
return p;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let resolveFunc = () => {};
|
|
16
|
+
let rejectFunc = () => {};
|
|
17
|
+
const returnPromise = new Promise((resolve, reject) => {
|
|
18
|
+
resolveFunc = resolve;
|
|
19
|
+
rejectFunc = reject;
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
if (!callback) {
|
|
23
|
+
callback = (err, result) => {
|
|
24
|
+
if (err) return rejectFunc(err);
|
|
25
|
+
resolveFunc(result);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const form = {
|
|
31
|
+
message_id: messageID
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const res = await defaultFuncs.post(
|
|
35
|
+
"https://www.facebook.com/ajax/mercury/delete_messages.php",
|
|
36
|
+
ctx.jar,
|
|
37
|
+
form
|
|
38
|
+
).then(utils.parseAndCheckLogin(ctx, defaultFuncs));
|
|
39
|
+
|
|
40
|
+
if (res && res.error) {
|
|
41
|
+
throw res;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return callback(null, { success: true });
|
|
45
|
+
} catch (err) {
|
|
46
|
+
utils.error("deleteMessage", err);
|
|
47
|
+
callback(err);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return returnPromise;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
@@ -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
|
+
};
|
package/src/apis/e2ee.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { bridge, getOrCreateHandle } = require('../e2ee');
|
|
4
|
+
|
|
5
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
6
|
+
|
|
7
|
+
async function h(opts) {
|
|
8
|
+
return getOrCreateHandle(ctx, opts);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return {
|
|
12
|
+
isAvailable() {
|
|
13
|
+
return bridge.isAvailable();
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
async connect(options) {
|
|
17
|
+
const handle = await h(options);
|
|
18
|
+
return bridge.connect(handle);
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
async connectE2EE(options) {
|
|
22
|
+
const handle = await h(options);
|
|
23
|
+
return bridge.connectE2EE(handle);
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
async disconnect() {
|
|
27
|
+
if (ctx._e2eeBridgeHandle == null) return;
|
|
28
|
+
bridge.disconnect(ctx._e2eeBridgeHandle);
|
|
29
|
+
ctx._e2eeBridgeHandle = null;
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
isConnected() {
|
|
33
|
+
if (ctx._e2eeBridgeHandle == null) return { connected: false, e2eeConnected: false };
|
|
34
|
+
return bridge.isConnected(ctx._e2eeBridgeHandle);
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
getDeviceData() {
|
|
38
|
+
if (ctx._e2eeBridgeHandle == null) throw new Error('E2EE not connected');
|
|
39
|
+
return bridge.getDeviceData(ctx._e2eeBridgeHandle).deviceData;
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
setDeviceData(deviceData) {
|
|
43
|
+
ctx._e2eeDeviceData = deviceData;
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
setDevicePath(devicePath) {
|
|
47
|
+
ctx._e2eeDevicePath = devicePath;
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
pollEvents(timeoutMs) {
|
|
51
|
+
if (ctx._e2eeBridgeHandle == null) throw new Error('E2EE not connected');
|
|
52
|
+
return bridge.pollEvents(ctx._e2eeBridgeHandle, timeoutMs || 5000);
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
sendE2EEMessage(chatJid, text, replyToId, replyToSenderJid) {
|
|
56
|
+
if (ctx._e2eeBridgeHandle == null) throw new Error('E2EE not connected. Call connect() and connectE2EE() first.');
|
|
57
|
+
return bridge.sendE2EEMessage(ctx._e2eeBridgeHandle, chatJid, text, replyToId, replyToSenderJid);
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
sendE2EEReaction(chatJid, messageId, senderJid, emoji) {
|
|
61
|
+
if (ctx._e2eeBridgeHandle == null) throw new Error('E2EE not connected');
|
|
62
|
+
return bridge.sendE2EEReaction(ctx._e2eeBridgeHandle, chatJid, messageId, senderJid, emoji);
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
sendE2EETyping(chatJid, isTyping) {
|
|
66
|
+
if (ctx._e2eeBridgeHandle == null) throw new Error('E2EE not connected');
|
|
67
|
+
return bridge.sendE2EETyping(ctx._e2eeBridgeHandle, chatJid, isTyping);
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
editE2EEMessage(chatJid, messageId, newText) {
|
|
71
|
+
if (ctx._e2eeBridgeHandle == null) throw new Error('E2EE not connected');
|
|
72
|
+
return bridge.editE2EEMessage(ctx._e2eeBridgeHandle, chatJid, messageId, newText);
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
unsendE2EEMessage(chatJid, messageId) {
|
|
76
|
+
if (ctx._e2eeBridgeHandle == null) throw new Error('E2EE not connected');
|
|
77
|
+
return bridge.unsendE2EEMessage(ctx._e2eeBridgeHandle, chatJid, messageId);
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
sendE2EEImage(chatJid, data, mimeType, options) {
|
|
81
|
+
if (ctx._e2eeBridgeHandle == null) throw new Error('E2EE not connected');
|
|
82
|
+
return bridge.sendE2EEImage(ctx._e2eeBridgeHandle, { chatJid, data, mimeType, ...(options || {}) });
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
sendE2EEVideo(chatJid, data, mimeType, options) {
|
|
86
|
+
if (ctx._e2eeBridgeHandle == null) throw new Error('E2EE not connected');
|
|
87
|
+
return bridge.sendE2EEVideo(ctx._e2eeBridgeHandle, { chatJid, data, mimeType, ...(options || {}) });
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
sendE2EEAudio(chatJid, data, mimeType, options) {
|
|
91
|
+
if (ctx._e2eeBridgeHandle == null) throw new Error('E2EE not connected');
|
|
92
|
+
return bridge.sendE2EEAudio(ctx._e2eeBridgeHandle, { chatJid, data, mimeType, ...(options || {}) });
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
sendE2EEDocument(chatJid, data, filename, mimeType, options) {
|
|
96
|
+
if (ctx._e2eeBridgeHandle == null) throw new Error('E2EE not connected');
|
|
97
|
+
return bridge.sendE2EEDocument(ctx._e2eeBridgeHandle, { chatJid, data, filename, mimeType, ...(options || {}) });
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
sendE2EESticker(chatJid, data, mimeType, options) {
|
|
101
|
+
if (ctx._e2eeBridgeHandle == null) throw new Error('E2EE not connected');
|
|
102
|
+
return bridge.sendE2EESticker(ctx._e2eeBridgeHandle, { chatJid, data, mimeType, ...(options || {}) });
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
downloadE2EEMedia(options) {
|
|
106
|
+
if (ctx._e2eeBridgeHandle == null) throw new Error('E2EE not connected');
|
|
107
|
+
return bridge.downloadE2EEMedia(ctx._e2eeBridgeHandle, options);
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
uploadMedia(options) {
|
|
111
|
+
if (ctx._e2eeBridgeHandle == null) throw new Error('E2EE not connected');
|
|
112
|
+
return bridge.uploadMedia(ctx._e2eeBridgeHandle, options);
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
sendImage(chatJid, data, mimeType, options) {
|
|
116
|
+
if (ctx._e2eeBridgeHandle == null) throw new Error('E2EE not connected');
|
|
117
|
+
return bridge.sendImage(ctx._e2eeBridgeHandle, { chatJid, data, mimeType, ...(options || {}) });
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
sendVideo(chatJid, data, mimeType, options) {
|
|
121
|
+
if (ctx._e2eeBridgeHandle == null) throw new Error('E2EE not connected');
|
|
122
|
+
return bridge.sendVideo(ctx._e2eeBridgeHandle, { chatJid, data, mimeType, ...(options || {}) });
|
|
123
|
+
},
|
|
124
|
+
|
|
125
|
+
sendVoice(chatJid, data, mimeType, options) {
|
|
126
|
+
if (ctx._e2eeBridgeHandle == null) throw new Error('E2EE not connected');
|
|
127
|
+
return bridge.sendVoice(ctx._e2eeBridgeHandle, { chatJid, data, mimeType, ...(options || {}) });
|
|
128
|
+
},
|
|
129
|
+
|
|
130
|
+
sendFile(chatJid, data, filename, mimeType, options) {
|
|
131
|
+
if (ctx._e2eeBridgeHandle == null) throw new Error('E2EE not connected');
|
|
132
|
+
return bridge.sendFile(ctx._e2eeBridgeHandle, { chatJid, data, filename, mimeType, ...(options || {}) });
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
sendSticker(chatJid, data, mimeType, options) {
|
|
136
|
+
if (ctx._e2eeBridgeHandle == null) throw new Error('E2EE not connected');
|
|
137
|
+
return bridge.sendSticker(ctx._e2eeBridgeHandle, { chatJid, data, mimeType, ...(options || {}) });
|
|
138
|
+
},
|
|
139
|
+
|
|
140
|
+
getCookies() {
|
|
141
|
+
if (ctx._e2eeBridgeHandle == null) throw new Error('E2EE not connected');
|
|
142
|
+
return bridge.getCookies(ctx._e2eeBridgeHandle).cookies;
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
getUserInfo(userId) {
|
|
146
|
+
if (ctx._e2eeBridgeHandle == null) throw new Error('E2EE not connected');
|
|
147
|
+
return bridge.getUserInfo(ctx._e2eeBridgeHandle, userId);
|
|
148
|
+
},
|
|
149
|
+
|
|
150
|
+
createThread(userId) {
|
|
151
|
+
if (ctx._e2eeBridgeHandle == null) throw new Error('E2EE not connected');
|
|
152
|
+
return bridge.createThread(ctx._e2eeBridgeHandle, userId);
|
|
153
|
+
},
|
|
154
|
+
|
|
155
|
+
searchUsers(query) {
|
|
156
|
+
if (ctx._e2eeBridgeHandle == null) throw new Error('E2EE not connected');
|
|
157
|
+
return bridge.searchUsers(ctx._e2eeBridgeHandle, query);
|
|
158
|
+
},
|
|
159
|
+
|
|
160
|
+
markRead(chatJid, watermarkTs) {
|
|
161
|
+
if (ctx._e2eeBridgeHandle == null) throw new Error('E2EE not connected');
|
|
162
|
+
return bridge.markRead(ctx._e2eeBridgeHandle, chatJid, watermarkTs);
|
|
163
|
+
},
|
|
164
|
+
|
|
165
|
+
unload() {
|
|
166
|
+
bridge.unload();
|
|
167
|
+
ctx._e2eeBridgeHandle = null;
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
// E2EE routing: editMessage(text, { chatJid, messageId }, callback)
|
|
28
|
+
if (utils.getType(messageID) === "Object" && messageID.chatJid && messageID.messageId) {
|
|
29
|
+
if (!api.e2ee || !api.e2ee.isAvailable()) throw new Error("E2EE bridge not available");
|
|
30
|
+
const p = api.e2ee.editE2EEMessage(messageID.chatJid, messageID.messageId, text);
|
|
31
|
+
if (callback) p.then(r => callback(null, r)).catch(callback);
|
|
32
|
+
return p;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (!ctx.mqttClient) {
|
|
36
|
+
throw new Error('Not connected to MQTT');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
ctx.wsReqNumber += 1;
|
|
40
|
+
ctx.wsTaskNumber += 1;
|
|
41
|
+
|
|
42
|
+
const queryPayload = {
|
|
43
|
+
message_id: messageID,
|
|
44
|
+
text
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const query = {
|
|
48
|
+
failure_count: null,
|
|
49
|
+
label: '742',
|
|
50
|
+
payload: JSON.stringify(queryPayload),
|
|
51
|
+
queue_name: 'edit_message',
|
|
52
|
+
task_id: ctx.wsTaskNumber
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const context = {
|
|
56
|
+
app_id: '2220391788200892',
|
|
57
|
+
payload: {
|
|
58
|
+
data_trace_id: null,
|
|
59
|
+
epoch_id: parseInt(utils.generateOfflineThreadingID()),
|
|
60
|
+
tasks: [query],
|
|
61
|
+
version_id: '6903494529735864'
|
|
62
|
+
},
|
|
63
|
+
request_id: ctx.wsReqNumber,
|
|
64
|
+
type: 3
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
context.payload = JSON.stringify(context.payload);
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
ctx.mqttClient.publish('/ls_req', JSON.stringify(context), {
|
|
74
|
+
qos: 1, retain: false
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
|