@eryxenx/fca 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 +325 -0
- package/DOCS.md +2712 -0
- package/README.md +455 -0
- package/func/checkUpdate.js +7 -0
- package/func/logAdapter.js +33 -0
- package/func/logger.js +48 -0
- package/index.d.ts +751 -0
- package/index.js +22 -0
- package/module/config.js +40 -0
- package/module/login.js +133 -0
- package/module/loginHelper.js +1365 -0
- package/module/options.js +44 -0
- package/package.json +98 -0
- package/src/api/action/addExternalModule.js +25 -0
- package/src/api/action/changeAvatar.js +137 -0
- package/src/api/action/changeBio.js +75 -0
- package/src/api/action/enableAutoSaveAppState.js +73 -0
- package/src/api/action/getCurrentUserID.js +7 -0
- package/src/api/action/handleFriendRequest.js +57 -0
- package/src/api/action/logout.js +76 -0
- package/src/api/action/refreshFb_dtsg.js +48 -0
- package/src/api/action/setPostReaction.js +106 -0
- package/src/api/action/unfriend.js +54 -0
- package/src/api/http/httpGet.js +46 -0
- package/src/api/http/httpPost.js +52 -0
- package/src/api/http/postFormData.js +47 -0
- package/src/api/messaging/addUserToGroup.js +68 -0
- package/src/api/messaging/changeAdminStatus.js +126 -0
- package/src/api/messaging/changeArchivedStatus.js +55 -0
- package/src/api/messaging/changeBlockedStatus.js +48 -0
- package/src/api/messaging/changeGroupImage.js +91 -0
- package/src/api/messaging/changeNickname.js +70 -0
- package/src/api/messaging/changeThreadColor.js +79 -0
- package/src/api/messaging/changeThreadEmoji.js +111 -0
- package/src/api/messaging/createNewGroup.js +88 -0
- package/src/api/messaging/createPoll.js +46 -0
- package/src/api/messaging/createThemeAI.js +98 -0
- package/src/api/messaging/deleteMessage.js +136 -0
- package/src/api/messaging/deleteThread.js +56 -0
- package/src/api/messaging/editMessage.js +105 -0
- package/src/api/messaging/forwardAttachment.js +57 -0
- package/src/api/messaging/forwardMessage.js +134 -0
- package/src/api/messaging/getEmojiUrl.js +29 -0
- package/src/api/messaging/getFriendsList.js +82 -0
- package/src/api/messaging/getMessage.js +829 -0
- package/src/api/messaging/getThemePictures.js +62 -0
- package/src/api/messaging/handleMessageRequest.js +65 -0
- package/src/api/messaging/markAsDelivered.js +57 -0
- package/src/api/messaging/markAsRead.js +88 -0
- package/src/api/messaging/markAsReadAll.js +56 -0
- package/src/api/messaging/markAsSeen.js +68 -0
- package/src/api/messaging/muteThread.js +50 -0
- package/src/api/messaging/pinMessage.js +115 -0
- package/src/api/messaging/removeUserFromGroup.js +62 -0
- package/src/api/messaging/resolvePhotoUrl.js +43 -0
- package/src/api/messaging/scheduler.js +264 -0
- package/src/api/messaging/searchForThread.js +53 -0
- package/src/api/messaging/sendBroadcast.js +93 -0
- package/src/api/messaging/sendMessage.js +269 -0
- package/src/api/messaging/sendTypingIndicator.js +90 -0
- package/src/api/messaging/sessionGuard.js +130 -0
- package/src/api/messaging/setMessageReaction.js +109 -0
- package/src/api/messaging/setTitle.js +124 -0
- package/src/api/messaging/shareContact.js +98 -0
- package/src/api/messaging/threadColors.js +128 -0
- package/src/api/messaging/unsendMessage.js +105 -0
- package/src/api/messaging/uploadAttachment.js +492 -0
- package/src/api/socket/OldMessage.js +186 -0
- package/src/api/socket/core/connectMqtt.js +269 -0
- package/src/api/socket/core/emitAuth.js +103 -0
- package/src/api/socket/core/getSeqID.js +321 -0
- package/src/api/socket/core/getTaskResponseData.js +25 -0
- package/src/api/socket/core/parseDelta.js +387 -0
- package/src/api/socket/detail/buildStream.js +215 -0
- package/src/api/socket/detail/constants.js +28 -0
- package/src/api/socket/e2ee/crypto.js +173 -0
- package/src/api/socket/e2ee/index.js +925 -0
- package/src/api/socket/e2ee/localMediaServer.js +59 -0
- package/src/api/socket/e2ee/mediaDecode.js +155 -0
- package/src/api/socket/e2ee/native/NOTICE.md +29 -0
- package/src/api/socket/e2ee/native/build/messagix.dll +0 -0
- package/src/api/socket/e2ee/native/build/messagix.so +0 -0
- package/src/api/socket/e2ee/native/lib/index.mjs +1426 -0
- package/src/api/socket/e2ee/native/nativeMediaBridge.js +233 -0
- package/src/api/socket/e2ee/proto/ArmadilloApplication.proto +281 -0
- package/src/api/socket/e2ee/proto/ArmadilloICDC.proto +14 -0
- package/src/api/socket/e2ee/proto/ConsumerApplication.proto +232 -0
- package/src/api/socket/e2ee/proto/MessageApplication.proto +82 -0
- package/src/api/socket/e2ee/proto/MessageTransport.proto +77 -0
- package/src/api/socket/e2ee/proto/WACommon.proto +66 -0
- package/src/api/socket/e2ee/proto/WAMediaTransport.proto +176 -0
- package/src/api/socket/e2ee/proto/proto-writer.ts +76 -0
- package/src/api/socket/e2ee/protocol.js +196 -0
- package/src/api/socket/e2ee/ratchet.js +219 -0
- package/src/api/socket/e2ee/store.js +182 -0
- package/src/api/socket/e2ee/vendor/fme/dist/index.cjs +6477 -0
- package/src/api/socket/e2ee/vendor/fme/proto/ArmadilloApplication.proto +281 -0
- package/src/api/socket/e2ee/vendor/fme/proto/ArmadilloICDC.proto +14 -0
- package/src/api/socket/e2ee/vendor/fme/proto/ConsumerApplication.proto +232 -0
- package/src/api/socket/e2ee/vendor/fme/proto/MessageApplication.proto +82 -0
- package/src/api/socket/e2ee/vendor/fme/proto/MessageTransport.proto +77 -0
- package/src/api/socket/e2ee/vendor/fme/proto/WACommon.proto +66 -0
- package/src/api/socket/e2ee/vendor/fme/proto/WAMediaTransport.proto +176 -0
- package/src/api/socket/listenE2EE.js +75 -0
- package/src/api/socket/listenMqtt.js +436 -0
- package/src/api/socket/middleware/index.js +216 -0
- package/src/api/socket/sendMessage.js +314 -0
- package/src/api/socket/sendMessageMqtt.js +69 -0
- package/src/api/threads/getThreadHistory.js +664 -0
- package/src/api/threads/getThreadInfo.js +329 -0
- package/src/api/threads/getThreadList.js +293 -0
- package/src/api/threads/getThreadPictures.js +78 -0
- package/src/api/users/getUserID.js +65 -0
- package/src/api/users/getUserInfo.js +402 -0
- package/src/api/users/getUserInfoV2.js +134 -0
- package/src/app/MessengerBot.js +209 -0
- package/src/app/MessengerContext.js +32 -0
- package/src/app/createFcaClient.js +136 -0
- package/src/app/threadInfoRealtimeSync.js +284 -0
- package/src/core/sendReqMqtt.js +96 -0
- package/src/database/helpers.js +53 -0
- package/src/database/models/index.js +88 -0
- package/src/database/models/thread.js +50 -0
- package/src/database/models/user.js +46 -0
- package/src/database/threadData.js +94 -0
- package/src/database/userData.js +98 -0
- package/src/remote/remoteClient.js +123 -0
- package/src/utils/broadcast.js +51 -0
- package/src/utils/client.js +10 -0
- package/src/utils/constants.js +23 -0
- package/src/utils/cookies.js +68 -0
- package/src/utils/format/attachment.js +357 -0
- package/src/utils/format/cookie.js +9 -0
- package/src/utils/format/date.js +50 -0
- package/src/utils/format/decode.js +44 -0
- package/src/utils/format/delta.js +194 -0
- package/src/utils/format/ids.js +64 -0
- package/src/utils/format/index.js +64 -0
- package/src/utils/format/message.js +88 -0
- package/src/utils/format/presence.js +132 -0
- package/src/utils/format/readTyp.js +44 -0
- package/src/utils/format/thread.js +42 -0
- package/src/utils/format/utils.js +141 -0
- package/src/utils/headers.js +128 -0
- package/src/utils/loginParser/autoLogin.js +125 -0
- package/src/utils/loginParser/helpers.js +43 -0
- package/src/utils/loginParser/index.js +10 -0
- package/src/utils/loginParser/parseAndCheckLogin.js +220 -0
- package/src/utils/loginParser/textUtils.js +28 -0
- package/src/utils/nexca-logger.js +144 -0
- package/src/utils/nexca-utils.js +686 -0
- package/src/utils/request/client.js +26 -0
- package/src/utils/request/config.js +23 -0
- package/src/utils/request/defaults.js +46 -0
- package/src/utils/request/helpers.js +46 -0
- package/src/utils/request/index.js +17 -0
- package/src/utils/request/methods.js +163 -0
- package/src/utils/request/proxy.js +21 -0
- package/src/utils/request/retry.js +77 -0
- package/src/utils/request/sanitize.js +49 -0
- package/src/utils/versionCheck.js +47 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const { getType } = require("../../utils/format");
|
|
3
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
4
|
+
return function sendTyping(threadID, isTyping, options, callback) {
|
|
5
|
+
var resolveFunc = function () { };
|
|
6
|
+
var rejectFunc = function () { };
|
|
7
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
|
8
|
+
resolveFunc = resolve;
|
|
9
|
+
rejectFunc = reject;
|
|
10
|
+
});
|
|
11
|
+
if (getType(options) == "Function" || getType(options) == "AsyncFunction") {
|
|
12
|
+
callback = options;
|
|
13
|
+
options = {};
|
|
14
|
+
}
|
|
15
|
+
options = options || {};
|
|
16
|
+
if (!callback || getType(callback) != "Function" && getType(callback) != "AsyncFunction") {
|
|
17
|
+
callback = function (err, data) {
|
|
18
|
+
if (err) return rejectFunc(err);
|
|
19
|
+
resolveFunc(data);
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
if (!threadID) {
|
|
23
|
+
return callback(new Error("threadID is required"));
|
|
24
|
+
}
|
|
25
|
+
if (!ctx.mqttClient) {
|
|
26
|
+
const err = new Error("Not connected to MQTT");
|
|
27
|
+
callback(err);
|
|
28
|
+
rejectFunc(err);
|
|
29
|
+
return returnPromise;
|
|
30
|
+
}
|
|
31
|
+
if (typeof ctx.wsReqNumber !== "number") ctx.wsReqNumber = 0;
|
|
32
|
+
const threadIDs = Array.isArray(threadID) ? threadID : [threadID];
|
|
33
|
+
threadIDs.forEach(tid => {
|
|
34
|
+
const isE2EEThread = ctx.threadTypes && ctx.threadTypes[String(tid)] === 'dm' &&
|
|
35
|
+
api.e2ee && typeof api.e2ee.isConnected === "function" && api.e2ee.isConnected();
|
|
36
|
+
|
|
37
|
+
if (isE2EEThread) {
|
|
38
|
+
const sendE2EETyping = (state) => {
|
|
39
|
+
api.e2ee.sendTyping(String(tid), state).catch((err) => {
|
|
40
|
+
console.error("[sendTyping] E2EE typing failed:", err && err.message ? err.message : err);
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
sendE2EETyping(isTyping);
|
|
44
|
+
if (isTyping && (options.autoStop !== false)) {
|
|
45
|
+
setTimeout(() => sendE2EETyping(false), options.duration || 10000);
|
|
46
|
+
}
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
var isGroupThread = getType(tid) === "Array" ? 0 : 1;
|
|
51
|
+
var threadType = isGroupThread ? 2 : 1;
|
|
52
|
+
var duration = options.duration || 10000;
|
|
53
|
+
var autoStop = options.autoStop !== false;
|
|
54
|
+
var attribution = options.type || 0;
|
|
55
|
+
const publishTypingStatus = (isTypingStatus) => {
|
|
56
|
+
ctx.mqttClient.publish('/ls_req',
|
|
57
|
+
JSON.stringify({
|
|
58
|
+
app_id: "772021112871879",
|
|
59
|
+
payload: JSON.stringify({
|
|
60
|
+
label: "3",
|
|
61
|
+
payload: JSON.stringify({
|
|
62
|
+
"thread_key": parseInt(tid),
|
|
63
|
+
"is_group_thread": isGroupThread,
|
|
64
|
+
"is_typing": isTypingStatus ? 1 : 0,
|
|
65
|
+
"attribution": attribution,
|
|
66
|
+
"sync_group": 1,
|
|
67
|
+
"thread_type": threadType
|
|
68
|
+
}),
|
|
69
|
+
version: "8965252033599983"
|
|
70
|
+
}),
|
|
71
|
+
request_id: ++ctx.wsReqNumber,
|
|
72
|
+
type: 4
|
|
73
|
+
}),
|
|
74
|
+
{
|
|
75
|
+
qos: 1,
|
|
76
|
+
retain: false,
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
publishTypingStatus(isTyping);
|
|
81
|
+
if (isTyping && autoStop) {
|
|
82
|
+
setTimeout(() => {
|
|
83
|
+
publishTypingStatus(false);
|
|
84
|
+
}, duration);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
callback(null, true);
|
|
88
|
+
return returnPromise;
|
|
89
|
+
};
|
|
90
|
+
};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* SessionGuard — Protects the appstate (session) from corruption and silent logouts.
|
|
5
|
+
*
|
|
6
|
+
* Features:
|
|
7
|
+
* • Auto-saves appstate to disk periodically (default every 5 min)
|
|
8
|
+
* • Saves on every successful message send (debounced, 30s cooldown)
|
|
9
|
+
* • Backs up the previous appstate before overwriting (.bak file)
|
|
10
|
+
* • Detects logout/checkpoint events from listen stream and alerts
|
|
11
|
+
* • Provides api.saveSession([path]) for manual save at any time
|
|
12
|
+
* • Never overwrites with a shorter/smaller appstate (corruption guard)
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
var fs = require("fs");
|
|
16
|
+
var path = require("path");
|
|
17
|
+
var logger = require("../../utils/nexca-logger");
|
|
18
|
+
|
|
19
|
+
var SAVE_INTERVAL_MS = 5 * 60 * 1000; // 5 minutes
|
|
20
|
+
var DEBOUNCE_MS = 30 * 1000; // 30 seconds cooldown between auto-saves
|
|
21
|
+
var MIN_COOKIES = 5; // minimum cookie count we consider "valid"
|
|
22
|
+
|
|
23
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
24
|
+
|
|
25
|
+
function getState() {
|
|
26
|
+
try { return api.getAppState(); } catch (_) { return null; }
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function saveToDisk(filePath) {
|
|
30
|
+
var state = getState();
|
|
31
|
+
if (!state || !Array.isArray(state) || state.length < MIN_COOKIES) {
|
|
32
|
+
logger.warn("SessionGuard", "Skipped save — state looks empty or invalid (" + (state ? state.length : 0) + " cookies).");
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Corruption guard: never write a smaller appstate than what's already on disk
|
|
37
|
+
if (fs.existsSync(filePath)) {
|
|
38
|
+
try {
|
|
39
|
+
var existing = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
40
|
+
if (Array.isArray(existing) && state.length < existing.length * 0.8) {
|
|
41
|
+
logger.warn("SessionGuard", "Skipped save — new state has " + state.length + " cookies vs " + existing.length + " on disk (possible truncation).");
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
// Backup the current valid state before overwriting
|
|
45
|
+
fs.writeFileSync(filePath + ".bak", JSON.stringify(existing, null, 2), "utf8");
|
|
46
|
+
} catch (_) {}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
fs.writeFileSync(filePath, JSON.stringify(state, null, 2), "utf8");
|
|
50
|
+
logger.success("SessionGuard", "Session saved → " + filePath + " (" + state.length + " cookies)");
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return function sessionGuard(appStatePath, options) {
|
|
55
|
+
options = options || {};
|
|
56
|
+
var interval = options.interval !== undefined ? options.interval : SAVE_INTERVAL_MS;
|
|
57
|
+
var debounce = options.debounce !== undefined ? options.debounce : DEBOUNCE_MS;
|
|
58
|
+
|
|
59
|
+
appStatePath = appStatePath || path.join(process.cwd(), "appstate.json");
|
|
60
|
+
|
|
61
|
+
var lastSave = 0;
|
|
62
|
+
var intervalRef = null;
|
|
63
|
+
|
|
64
|
+
// Periodic save
|
|
65
|
+
if (interval > 0) {
|
|
66
|
+
intervalRef = setInterval(function () {
|
|
67
|
+
logger.info("SessionGuard", "Periodic save...");
|
|
68
|
+
saveToDisk(appStatePath);
|
|
69
|
+
lastSave = Date.now();
|
|
70
|
+
}, interval);
|
|
71
|
+
if (intervalRef.unref) intervalRef.unref(); // don't block process exit
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Debounced on-send save
|
|
75
|
+
// Patch sendMessage to auto-save appstate after a successful send
|
|
76
|
+
var originalSendMessage = api.sendMessage;
|
|
77
|
+
api.sendMessage = function () {
|
|
78
|
+
var result = originalSendMessage.apply(this, arguments);
|
|
79
|
+
// After send, debounce-save
|
|
80
|
+
Promise.resolve(result).then(function () {
|
|
81
|
+
if (Date.now() - lastSave > debounce) {
|
|
82
|
+
saveToDisk(appStatePath);
|
|
83
|
+
lastSave = Date.now();
|
|
84
|
+
}
|
|
85
|
+
}).catch(function () {});
|
|
86
|
+
return result;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// Expose manual save
|
|
90
|
+
api.saveSession = function (customPath) {
|
|
91
|
+
return saveToDisk(customPath || appStatePath);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// Expose restore from backup
|
|
95
|
+
api.restoreSessionBackup = function (customPath) {
|
|
96
|
+
var bakPath = (customPath || appStatePath) + ".bak";
|
|
97
|
+
if (!fs.existsSync(bakPath)) {
|
|
98
|
+
logger.warn("SessionGuard", "No backup file found at " + bakPath);
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
var bak = fs.readFileSync(bakPath, "utf8");
|
|
103
|
+
fs.writeFileSync(customPath || appStatePath, bak, "utf8");
|
|
104
|
+
logger.success("SessionGuard", "Backup restored from " + bakPath);
|
|
105
|
+
return true;
|
|
106
|
+
} catch (e) {
|
|
107
|
+
logger.error("SessionGuard", "Restore failed: " + e.message);
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// Expose stop
|
|
113
|
+
api.stopSessionGuard = function () {
|
|
114
|
+
if (intervalRef) clearInterval(intervalRef);
|
|
115
|
+
api.sendMessage = originalSendMessage;
|
|
116
|
+
logger.info("SessionGuard", "Stopped.");
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
logger.success(
|
|
120
|
+
"SessionGuard",
|
|
121
|
+
"Active — auto-save every " + Math.round(interval / 60000) + " min → " + appStatePath
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
return {
|
|
125
|
+
save: function (p) { return saveToDisk(p || appStatePath); },
|
|
126
|
+
stop: api.stopSessionGuard,
|
|
127
|
+
restore: api.restoreSessionBackup
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const logger = require("../../../func/logger");
|
|
4
|
+
const { generateOfflineThreadingID, getCurrentTimestamp } = require("../../utils/format");
|
|
5
|
+
|
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
7
|
+
return function setMessageReaction(reaction, messageID, threadID, callback, forceCustomReaction) {
|
|
8
|
+
// ✅ EryXenX Fix: threadID is now optional (backward compatible)
|
|
9
|
+
if (typeof threadID === "function") {
|
|
10
|
+
forceCustomReaction = callback;
|
|
11
|
+
callback = threadID;
|
|
12
|
+
threadID = null;
|
|
13
|
+
} else if (typeof threadID === "boolean") {
|
|
14
|
+
forceCustomReaction = threadID;
|
|
15
|
+
callback = undefined;
|
|
16
|
+
threadID = null;
|
|
17
|
+
} else if (typeof callback === "boolean") {
|
|
18
|
+
forceCustomReaction = callback;
|
|
19
|
+
callback = undefined;
|
|
20
|
+
}
|
|
21
|
+
const cb = typeof callback === "function" ? callback : undefined;
|
|
22
|
+
|
|
23
|
+
// threadID না থাকলে e2ee bridge এর ম্যাপ থেকে বের করার চেষ্টা, তারপর ctx fallback
|
|
24
|
+
const resolvedThreadID = threadID ||
|
|
25
|
+
(api.e2ee && typeof api.e2ee.getThreadIdForMessage === "function" ? api.e2ee.getThreadIdForMessage(messageID) : null);
|
|
26
|
+
const finalThreadID = resolvedThreadID || ctx.lastThreadID || "0";
|
|
27
|
+
|
|
28
|
+
const isE2EEDM = ctx.threadTypes && ctx.threadTypes[String(finalThreadID)] === 'dm' &&
|
|
29
|
+
api.e2ee && typeof api.e2ee.isConnected === "function" && api.e2ee.isConnected();
|
|
30
|
+
const isE2EEGroup = typeof api.e2ee?.isKnownE2EEGroup === "function" && api.e2ee.isKnownE2EEGroup(String(finalThreadID)) &&
|
|
31
|
+
api.e2ee && typeof api.e2ee.isConnected === "function" && api.e2ee.isConnected();
|
|
32
|
+
const isE2EEThread = isE2EEDM || isE2EEGroup;
|
|
33
|
+
|
|
34
|
+
if (isE2EEThread) {
|
|
35
|
+
return api.e2ee.sendReaction(String(finalThreadID), messageID, reaction)
|
|
36
|
+
.then((result) => { if (cb) cb(null, result); return result; })
|
|
37
|
+
.catch((err) => { if (cb) cb(err); throw err; });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
if (!ctx.mqttClient) {
|
|
42
|
+
const err = new Error("MQTT client not connected");
|
|
43
|
+
if (cb) cb(err);
|
|
44
|
+
return reject(err);
|
|
45
|
+
}
|
|
46
|
+
if (reaction === undefined || reaction === null || !messageID) {
|
|
47
|
+
const err = new Error("Missing required parameters (reaction, messageID)");
|
|
48
|
+
if (cb) cb(err);
|
|
49
|
+
return reject(err);
|
|
50
|
+
}
|
|
51
|
+
if (typeof ctx.wsReqNumber !== "number") ctx.wsReqNumber = 0;
|
|
52
|
+
if (typeof ctx.wsTaskNumber !== "number") ctx.wsTaskNumber = 0;
|
|
53
|
+
const reqID = ++ctx.wsReqNumber;
|
|
54
|
+
const taskID = ++ctx.wsTaskNumber;
|
|
55
|
+
const taskPayload = {
|
|
56
|
+
thread_key: finalThreadID,
|
|
57
|
+
timestamp_ms: getCurrentTimestamp(),
|
|
58
|
+
message_id: messageID,
|
|
59
|
+
reaction: reaction,
|
|
60
|
+
actor_id: ctx.userID,
|
|
61
|
+
reaction_style: forceCustomReaction ? 1 : null,
|
|
62
|
+
sync_group: 1,
|
|
63
|
+
send_attribution: 65537,
|
|
64
|
+
dataclass_params: null,
|
|
65
|
+
attachment_fbid: null
|
|
66
|
+
};
|
|
67
|
+
const task = {
|
|
68
|
+
failure_count: null,
|
|
69
|
+
label: "29",
|
|
70
|
+
payload: JSON.stringify(taskPayload),
|
|
71
|
+
queue_name: "reaction:" + messageID,
|
|
72
|
+
task_id: taskID,
|
|
73
|
+
};
|
|
74
|
+
const mqttForm = {
|
|
75
|
+
app_id: "2220391788200892",
|
|
76
|
+
payload: JSON.stringify({
|
|
77
|
+
epoch_id: parseInt(generateOfflineThreadingID()),
|
|
78
|
+
tasks: [task],
|
|
79
|
+
version_id: "24585299697835063"
|
|
80
|
+
}),
|
|
81
|
+
request_id: reqID,
|
|
82
|
+
type: 3
|
|
83
|
+
};
|
|
84
|
+
const handleResponse = (topic, message) => {
|
|
85
|
+
if (topic !== "/ls_resp") return;
|
|
86
|
+
let json;
|
|
87
|
+
try {
|
|
88
|
+
json = JSON.parse(message.toString());
|
|
89
|
+
json.payload = JSON.parse(json.payload);
|
|
90
|
+
} catch {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (json.request_id !== reqID) return;
|
|
94
|
+
ctx.mqttClient.removeListener("message", handleResponse);
|
|
95
|
+
if (cb) cb(null, { success: true });
|
|
96
|
+
return resolve({ success: true });
|
|
97
|
+
};
|
|
98
|
+
ctx.mqttClient.on("message", handleResponse);
|
|
99
|
+
ctx.mqttClient.publish("/ls_req", JSON.stringify(mqttForm), { qos: 1, retain: false }, (err) => {
|
|
100
|
+
if (err) {
|
|
101
|
+
ctx.mqttClient.removeListener("message", handleResponse);
|
|
102
|
+
logger("setMessageReaction" + err, "error");
|
|
103
|
+
if (cb) cb(err);
|
|
104
|
+
return reject(err);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { getType, generateOfflineThreadingID, generateTimestampRelative, generateThreadingID, getCurrentTimestamp } = require("../../utils/format");
|
|
4
|
+
const { parseAndCheckLogin } = require("../../utils/client");
|
|
5
|
+
const log = require("../../../func/logAdapter");
|
|
6
|
+
|
|
7
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
8
|
+
function setTitleNoMqtt(newTitle, threadID, callback) {
|
|
9
|
+
if (!callback && (getType(threadID) === "Function" || getType(threadID) === "AsyncFunction")) throw { error: "please pass a threadID as a second argument." };
|
|
10
|
+
var resolveFunc = function () { };
|
|
11
|
+
var rejectFunc = function () { };
|
|
12
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
|
13
|
+
resolveFunc = resolve;
|
|
14
|
+
rejectFunc = reject;
|
|
15
|
+
});
|
|
16
|
+
if (!callback) {
|
|
17
|
+
callback = function (err, data) {
|
|
18
|
+
if (err) return rejectFunc(err);
|
|
19
|
+
resolveFunc(data);
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
var messageAndOTID = generateOfflineThreadingID();
|
|
23
|
+
var form = {
|
|
24
|
+
client: "mercury",
|
|
25
|
+
action_type: "ma-type:log-message",
|
|
26
|
+
author: "fbid:" + ctx.userID,
|
|
27
|
+
author_email: "",
|
|
28
|
+
coordinates: "",
|
|
29
|
+
timestamp: Date.now(),
|
|
30
|
+
timestamp_absolute: "Today",
|
|
31
|
+
timestamp_relative: generateTimestampRelative(),
|
|
32
|
+
timestamp_time_passed: "0",
|
|
33
|
+
is_unread: false,
|
|
34
|
+
is_cleared: false,
|
|
35
|
+
is_forward: false,
|
|
36
|
+
is_filtered_content: false,
|
|
37
|
+
is_spoof_warning: false,
|
|
38
|
+
source: "source:chat:web",
|
|
39
|
+
"source_tags[0]": "source:chat",
|
|
40
|
+
status: "0",
|
|
41
|
+
offline_threading_id: messageAndOTID,
|
|
42
|
+
message_id: messageAndOTID,
|
|
43
|
+
threading_id: generateThreadingID(ctx.clientID),
|
|
44
|
+
manual_retry_cnt: "0",
|
|
45
|
+
thread_fbid: threadID,
|
|
46
|
+
thread_name: newTitle,
|
|
47
|
+
thread_id: threadID,
|
|
48
|
+
log_message_type: "log:thread-name"
|
|
49
|
+
};
|
|
50
|
+
defaultFuncs
|
|
51
|
+
.post("https://www.facebook.com/messaging/set_thread_name/", ctx.jar, form)
|
|
52
|
+
.then(parseAndCheckLogin(ctx, defaultFuncs))
|
|
53
|
+
.then(function (resData) {
|
|
54
|
+
if (resData.error && resData.error === 1545012) throw { error: "Cannot change chat title: Not member of chat." };
|
|
55
|
+
if (resData.error && resData.error === 1545003) throw { error: "Cannot set title of single-user chat." };
|
|
56
|
+
if (resData.error) throw resData;
|
|
57
|
+
return callback();
|
|
58
|
+
})
|
|
59
|
+
.catch(function (err) {
|
|
60
|
+
log.error("setTitle", err);
|
|
61
|
+
return callback(err);
|
|
62
|
+
});
|
|
63
|
+
return returnPromise;
|
|
64
|
+
};
|
|
65
|
+
function setTitleMqtt(newTitle, threadID, callback) {
|
|
66
|
+
if (!ctx.mqttClient) {
|
|
67
|
+
throw new Error("Not connected to MQTT");
|
|
68
|
+
}
|
|
69
|
+
if (typeof ctx.wsReqNumber !== "number") ctx.wsReqNumber = 0;
|
|
70
|
+
const reqID = ++ctx.wsReqNumber;
|
|
71
|
+
var resolveFunc = function () { };
|
|
72
|
+
var rejectFunc = function () { };
|
|
73
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
|
74
|
+
resolveFunc = resolve;
|
|
75
|
+
rejectFunc = reject;
|
|
76
|
+
});
|
|
77
|
+
const done = (err, data) => {
|
|
78
|
+
if (err) {
|
|
79
|
+
if (callback) callback(err);
|
|
80
|
+
return rejectFunc(err);
|
|
81
|
+
}
|
|
82
|
+
if (callback) callback(null, data);
|
|
83
|
+
resolveFunc(data);
|
|
84
|
+
};
|
|
85
|
+
var form = JSON.stringify({
|
|
86
|
+
"app_id": "2220391788200892",
|
|
87
|
+
"payload": JSON.stringify({
|
|
88
|
+
epoch_id: generateOfflineThreadingID(),
|
|
89
|
+
tasks: [
|
|
90
|
+
{
|
|
91
|
+
failure_count: null,
|
|
92
|
+
label: '32',
|
|
93
|
+
payload: JSON.stringify({
|
|
94
|
+
"thread_key": threadID,
|
|
95
|
+
"thread_name": newTitle,
|
|
96
|
+
"sync_group": 1
|
|
97
|
+
}),
|
|
98
|
+
queue_name: threadID,
|
|
99
|
+
task_id: Math.random() * 1001 << 0
|
|
100
|
+
}
|
|
101
|
+
],
|
|
102
|
+
version_id: '8798795233522156'
|
|
103
|
+
}),
|
|
104
|
+
"request_id": reqID,
|
|
105
|
+
"type": 3
|
|
106
|
+
});
|
|
107
|
+
ctx.mqttClient.publish("/ls_req", form, { qos: 1, retain: false }, (err) => {
|
|
108
|
+
if (err) return done(err);
|
|
109
|
+
done(null, { success: true });
|
|
110
|
+
});
|
|
111
|
+
return returnPromise;
|
|
112
|
+
};
|
|
113
|
+
return function setTitle(newTitle, threadID, callback) {
|
|
114
|
+
if (ctx.mqttClient) {
|
|
115
|
+
try {
|
|
116
|
+
return setTitleMqtt(newTitle, threadID, callback);
|
|
117
|
+
} catch (e) {
|
|
118
|
+
return setTitleNoMqtt(newTitle, threadID, callback);
|
|
119
|
+
}
|
|
120
|
+
} else {
|
|
121
|
+
return setTitleNoMqtt(newTitle, threadID, callback);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { generateOfflineThreadingID } = require("../../utils/format");
|
|
4
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
|
5
|
+
return function shareContact(text, senderID, threadID, callback) {
|
|
6
|
+
if (!text) {
|
|
7
|
+
text = "";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Some callers (e.g. GoatBot's uid.js) pass a messageID string in the
|
|
11
|
+
// 4th ("callback") slot to reply to, not an actual callback function.
|
|
12
|
+
var replyToMessageId;
|
|
13
|
+
if (typeof callback !== "function") {
|
|
14
|
+
if (typeof callback === "string" || typeof callback === "number") {
|
|
15
|
+
replyToMessageId = String(callback);
|
|
16
|
+
}
|
|
17
|
+
callback = undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
var resolveFunc = function() {};
|
|
21
|
+
var rejectFunc = function() {};
|
|
22
|
+
var returnPromise = new Promise(function(resolve, reject) {
|
|
23
|
+
resolveFunc = resolve;
|
|
24
|
+
rejectFunc = reject;
|
|
25
|
+
});
|
|
26
|
+
var cb = callback || function(err, data) {
|
|
27
|
+
if (err) return rejectFunc(err);
|
|
28
|
+
resolveFunc(data);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// E2EE threads don't accept this plaintext MQTT task, and there's no
|
|
32
|
+
// native E2EE "contact card" message type in either engine — so degrade
|
|
33
|
+
// gracefully to a plain text message with the contact info instead of
|
|
34
|
+
// silently hanging forever.
|
|
35
|
+
const isE2EEThread = ctx.threadTypes && ctx.threadTypes[String(threadID)] === 'dm' &&
|
|
36
|
+
api.e2ee && typeof api.e2ee.isConnected === "function" && api.e2ee.isConnected();
|
|
37
|
+
|
|
38
|
+
if (isE2EEThread) {
|
|
39
|
+
const fallbackText = (text ? text + "\n" : "") + `👤 Contact ID: ${senderID}\n🔗 https://www.facebook.com/${senderID}`;
|
|
40
|
+
return api.sendMessage(fallbackText, threadID, undefined, replyToMessageId)
|
|
41
|
+
.then((result) => { cb(null, result); return result; })
|
|
42
|
+
.catch((err) => { cb(err); throw err; });
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let count_req = 0;
|
|
46
|
+
var reqID = ++count_req;
|
|
47
|
+
var form = JSON.stringify({
|
|
48
|
+
app_id: "2220391788200892",
|
|
49
|
+
payload: JSON.stringify({
|
|
50
|
+
tasks: [
|
|
51
|
+
{
|
|
52
|
+
label: "359",
|
|
53
|
+
payload: JSON.stringify({
|
|
54
|
+
contact_id: senderID,
|
|
55
|
+
sync_group: 1,
|
|
56
|
+
text: text || "",
|
|
57
|
+
thread_id: threadID
|
|
58
|
+
}),
|
|
59
|
+
queue_name: "messenger_contact_sharing",
|
|
60
|
+
task_id: (Math.random() * 1001) << 0,
|
|
61
|
+
failure_count: null
|
|
62
|
+
}
|
|
63
|
+
],
|
|
64
|
+
epoch_id: generateOfflineThreadingID(),
|
|
65
|
+
version_id: "7214102258676893"
|
|
66
|
+
}),
|
|
67
|
+
request_id: reqID,
|
|
68
|
+
type: 3
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Guard against a response that never arrives (network issue, server
|
|
72
|
+
// silently drops the task, etc.) so callers awaiting this never hang.
|
|
73
|
+
var settled = false;
|
|
74
|
+
var timeout = setTimeout(function () {
|
|
75
|
+
if (settled) return;
|
|
76
|
+
settled = true;
|
|
77
|
+
ctx.mqttClient.removeListener("message", handleResponse);
|
|
78
|
+
cb(null, { success: true, note: "no server ack received (fire-and-forget)" });
|
|
79
|
+
}, 8000);
|
|
80
|
+
|
|
81
|
+
function handleResponse(topic, message) {
|
|
82
|
+
if (topic !== "/ls_resp") return;
|
|
83
|
+
let json;
|
|
84
|
+
try {
|
|
85
|
+
json = JSON.parse(message.toString());
|
|
86
|
+
} catch (_) { return; }
|
|
87
|
+
if (json.request_id !== reqID) return;
|
|
88
|
+
if (settled) return;
|
|
89
|
+
settled = true;
|
|
90
|
+
clearTimeout(timeout);
|
|
91
|
+
ctx.mqttClient.removeListener("message", handleResponse);
|
|
92
|
+
callback(null, { success: true });
|
|
93
|
+
}
|
|
94
|
+
ctx.mqttClient.on("message", handleResponse);
|
|
95
|
+
ctx.mqttClient.publish("/ls_req", form);
|
|
96
|
+
return returnPromise;
|
|
97
|
+
};
|
|
98
|
+
};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
module.exports = function(_defaultFuncs, _api, _ctx) {
|
|
4
|
+
// Currently the only colors that can be passed to api.changeThreadColor(); may change if Facebook adds more
|
|
5
|
+
return {
|
|
6
|
+
//Old hex colors.
|
|
7
|
+
////MessengerBlue: null,
|
|
8
|
+
////Viking: "#44bec7",
|
|
9
|
+
////GoldenPoppy: "#ffc300",
|
|
10
|
+
////RadicalRed: "#fa3c4c",
|
|
11
|
+
////Shocking: "#d696bb",
|
|
12
|
+
////PictonBlue: "#6699cc",
|
|
13
|
+
////FreeSpeechGreen: "#13cf13",
|
|
14
|
+
////Pumpkin: "#ff7e29",
|
|
15
|
+
////LightCoral: "#e68585",
|
|
16
|
+
////MediumSlateBlue: "#7646ff",
|
|
17
|
+
////DeepSkyBlue: "#20cef5",
|
|
18
|
+
////Fern: "#67b868",
|
|
19
|
+
////Cameo: "#d4a88c",
|
|
20
|
+
////BrilliantRose: "#ff5ca1",
|
|
21
|
+
////BilobaFlower: "#a695c7"
|
|
22
|
+
|
|
23
|
+
//#region This part is for backward compatibly
|
|
24
|
+
//trying to match the color one-by-one. kill me plz
|
|
25
|
+
MessengerBlue: "196241301102133", //DefaultBlue
|
|
26
|
+
Viking: "1928399724138152", //TealBlue
|
|
27
|
+
GoldenPoppy: "174636906462322", //Yellow
|
|
28
|
+
RadicalRed: "2129984390566328", //Red
|
|
29
|
+
Shocking: "2058653964378557", //LavenderPurple
|
|
30
|
+
FreeSpeechGreen: "2136751179887052", //Green
|
|
31
|
+
Pumpkin: "175615189761153", //Orange
|
|
32
|
+
LightCoral: "980963458735625", //CoralPink
|
|
33
|
+
MediumSlateBlue: "234137870477637", //BrightPurple
|
|
34
|
+
DeepSkyBlue: "2442142322678320", //AquaBlue
|
|
35
|
+
BrilliantRose: "169463077092846", //HotPink
|
|
36
|
+
DefaultBlue: "196241301102133",
|
|
37
|
+
HotPink: "169463077092846",
|
|
38
|
+
AquaBlue: "2442142322678320",
|
|
39
|
+
BrightPurple: "234137870477637",
|
|
40
|
+
CoralPink: "980963458735625",
|
|
41
|
+
Orange: "175615189761153",
|
|
42
|
+
Green: "2136751179887052",
|
|
43
|
+
LavenderPurple: "2058653964378557",
|
|
44
|
+
Red: "2129984390566328",
|
|
45
|
+
Yellow: "174636906462322",
|
|
46
|
+
TealBlue: "1928399724138152",
|
|
47
|
+
Aqua: "417639218648241",
|
|
48
|
+
Mango: "930060997172551",
|
|
49
|
+
Berry: "164535220883264",
|
|
50
|
+
Citrus: "370940413392601",
|
|
51
|
+
Candy: "205488546921017",
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* July 06, 2022
|
|
55
|
+
* added by @NTKhang
|
|
56
|
+
*/
|
|
57
|
+
Earth: "1833559466821043",
|
|
58
|
+
Support: "365557122117011",
|
|
59
|
+
Music: "339021464972092",
|
|
60
|
+
Pride: "1652456634878319",
|
|
61
|
+
DoctorStrange: "538280997628317",
|
|
62
|
+
LoFi: "1060619084701625",
|
|
63
|
+
Sky: "3190514984517598",
|
|
64
|
+
LunarNewYear: "357833546030778",
|
|
65
|
+
Celebration: "627144732056021",
|
|
66
|
+
Chill: "390127158985345",
|
|
67
|
+
StrangerThings: "1059859811490132",
|
|
68
|
+
Dune: "1455149831518874",
|
|
69
|
+
Care: "275041734441112",
|
|
70
|
+
Astrology: "3082966625307060",
|
|
71
|
+
JBalvin: "184305226956268",
|
|
72
|
+
Birthday: "621630955405500",
|
|
73
|
+
Cottagecore: "539927563794799",
|
|
74
|
+
Ocean: "736591620215564",
|
|
75
|
+
Love: "741311439775765",
|
|
76
|
+
TieDye: "230032715012014",
|
|
77
|
+
Monochrome: "788274591712841",
|
|
78
|
+
Default: "3259963564026002",
|
|
79
|
+
Rocket: "582065306070020",
|
|
80
|
+
Berry2: "724096885023603",
|
|
81
|
+
Candy2: "624266884847972",
|
|
82
|
+
Unicorn: "273728810607574",
|
|
83
|
+
Tropical: "262191918210707",
|
|
84
|
+
Maple: "2533652183614000",
|
|
85
|
+
Sushi: "909695489504566",
|
|
86
|
+
Citrus2: "557344741607350",
|
|
87
|
+
Lollipop: "280333826736184",
|
|
88
|
+
Shadow: "271607034185782",
|
|
89
|
+
Rose: "1257453361255152",
|
|
90
|
+
Lavender: "571193503540759",
|
|
91
|
+
Tulip: "2873642949430623",
|
|
92
|
+
Classic: "3273938616164733",
|
|
93
|
+
Peach: "3022526817824329",
|
|
94
|
+
Honey: "672058580051520",
|
|
95
|
+
Kiwi: "3151463484918004",
|
|
96
|
+
Grape: "193497045377796",
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* July 15, 2022
|
|
100
|
+
* added by @NTKhang
|
|
101
|
+
*/
|
|
102
|
+
NonBinary: "737761000603635",
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* November 25, 2022
|
|
106
|
+
* added by @NTKhang
|
|
107
|
+
*/
|
|
108
|
+
ThankfulForFriends: "1318983195536293",
|
|
109
|
+
Transgender: "504518465021637",
|
|
110
|
+
TaylorSwift: "769129927636836",
|
|
111
|
+
NationalComingOutDay: "788102625833584",
|
|
112
|
+
Autumn: "822549609168155",
|
|
113
|
+
Cyberpunk2077: "780962576430091",
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* May 13, 2023
|
|
117
|
+
*/
|
|
118
|
+
MothersDay: "1288506208402340",
|
|
119
|
+
APAHM: "121771470870245",
|
|
120
|
+
Parenthood: "810978360551741",
|
|
121
|
+
StarWars: "1438011086532622",
|
|
122
|
+
GuardianOfTheGalaxy: "101275642962533",
|
|
123
|
+
Bloom: "158263147151440",
|
|
124
|
+
BubbleTea: "195296273246380",
|
|
125
|
+
Basketball: "6026716157422736",
|
|
126
|
+
ElephantsAndFlowers: "693996545771691"
|
|
127
|
+
};
|
|
128
|
+
};
|