nexus-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 +1 -0
- package/DOCS.md +2047 -0
- package/Fca_Database/database.sqlite +0 -0
- package/LICENSE-MIT +21 -0
- package/README.md +240 -0
- package/docs/README.md +9 -0
- package/docs/addExternalModule.md +15 -0
- package/docs/addUserToGroup.md +20 -0
- package/docs/changeAdminStatus.md +21 -0
- package/docs/changeArchivedStatus.md +19 -0
- package/docs/changeAvatar.md +21 -0
- package/docs/changeAvatarV2.md +18 -0
- package/docs/changeBio.md +15 -0
- package/docs/changeBlockedStatus.md +16 -0
- package/docs/changeBlockedStatusMqtt.md +16 -0
- package/docs/changeCover.md +15 -0
- package/docs/changeGroupImage.md +16 -0
- package/docs/changeName.md +18 -0
- package/docs/changeNickname.md +17 -0
- package/docs/changeThreadColor.md +16 -0
- package/docs/changeThreadEmoji.md +16 -0
- package/docs/changeUsername.md +15 -0
- package/docs/createCommentPost.md +16 -0
- package/docs/createNewGroup.md +16 -0
- package/docs/createPoll.md +17 -0
- package/docs/createPost.md +15 -0
- package/docs/deleteMessage.md +15 -0
- package/docs/deleteThread.md +15 -0
- package/docs/editMessage.md +16 -0
- package/docs/follow.md +15 -0
- package/docs/forwardAttachment.md +16 -0
- package/docs/getAccess.md +17 -0
- package/docs/getAvatarUser.md +15 -0
- package/docs/getBotInitialData.md +14 -0
- package/docs/getCtx.md +14 -0
- package/docs/getCurrentUserID.md +12 -0
- package/docs/getEmojiUrl.md +17 -0
- package/docs/getFriendsList.md +14 -0
- package/docs/getMessage.md +15 -0
- package/docs/getOptions.md +14 -0
- package/docs/getRegion.md +14 -0
- package/docs/getThreadHistory.md +17 -0
- package/docs/getThreadHistoryDeprecated.md +17 -0
- package/docs/getThreadInfo.md +15 -0
- package/docs/getThreadInfoDeprecated.md +17 -0
- package/docs/getThreadList.md +17 -0
- package/docs/getThreadListDeprecated.md +17 -0
- package/docs/getThreadPictures.md +17 -0
- package/docs/getUID.md +15 -0
- package/docs/getUserID.md +15 -0
- package/docs/getUserInfo.md +15 -0
- package/docs/handleFriendRequest.md +16 -0
- package/docs/handleMessageRequest.md +16 -0
- package/docs/httpGet.md +15 -0
- package/docs/httpPost.md +16 -0
- package/docs/httpPostFormData.md +16 -0
- package/docs/listenMqtt.md +17 -0
- package/docs/listenNotification.md +14 -0
- package/docs/logout.md +14 -0
- package/docs/markAsDelivered.md +16 -0
- package/docs/markAsRead.md +16 -0
- package/docs/markAsReadAll.md +14 -0
- package/docs/markAsSeen.md +15 -0
- package/docs/muteThread.md +16 -0
- package/docs/pinMessage.md +17 -0
- package/docs/postFormData.md +16 -0
- package/docs/refreshFb_dtsg.md +14 -0
- package/docs/removeUserFromGroup.md +16 -0
- package/docs/resolvePhotoUrl.md +15 -0
- package/docs/searchForThread.md +15 -0
- package/docs/searchStickers.md +15 -0
- package/docs/sendComment.md +16 -0
- package/docs/sendMessage.md +16 -0
- package/docs/sendMessageMqtt.md +16 -0
- package/docs/sendTypingIndicator.md +15 -0
- package/docs/setMessageReaction.md +17 -0
- package/docs/setMessageReactionMqtt.md +16 -0
- package/docs/setPostReaction.md +16 -0
- package/docs/setProfileGuard.md +15 -0
- package/docs/setStoryReaction.md +16 -0
- package/docs/setTitle.md +16 -0
- package/docs/shareContact.md +16 -0
- package/docs/shareLink.md +16 -0
- package/docs/stopListenMqtt.md +8 -0
- package/docs/threadColors.md +11 -0
- package/docs/unfriend.md +15 -0
- package/docs/unsendMessage.md +15 -0
- package/docs/uploadAttachment.md +15 -0
- package/fca-config.json +7 -0
- package/index.d.ts +618 -0
- package/index.js +361 -0
- package/lib/database/models/index.js +47 -0
- package/lib/database/models/thread.js +31 -0
- package/lib/database/threadData.js +93 -0
- package/lib/logger.js +24 -0
- package/lib/login.js +0 -0
- package/package.json +90 -0
- package/src/addExternalModule.js +19 -0
- package/src/addUserToGroup.js +113 -0
- package/src/changeAdminStatus.js +79 -0
- package/src/changeArchivedStatus.js +55 -0
- package/src/changeAvatar.js +126 -0
- package/src/changeAvatarV2.js +77 -0
- package/src/changeBio.js +77 -0
- package/src/changeBlockedStatus.js +47 -0
- package/src/changeBlockedStatusMqtt.js +71 -0
- package/src/changeCover.js +72 -0
- package/src/changeGroupImage.js +132 -0
- package/src/changeName.js +79 -0
- package/src/changeNickname.js +59 -0
- package/src/changeThreadColor.js +65 -0
- package/src/changeThreadEmoji.js +55 -0
- package/src/changeUsername.js +58 -0
- package/src/createCommentPost.js +225 -0
- package/src/createNewGroup.js +86 -0
- package/src/createPoll.js +71 -0
- package/src/createPost.js +276 -0
- package/src/deleteMessage.js +56 -0
- package/src/deleteThread.js +56 -0
- package/src/editMessage.js +57 -0
- package/src/follow.js +54 -0
- package/src/forwardAttachment.js +60 -0
- package/src/getAccess.js +67 -0
- package/src/getAvatarUser.js +56 -0
- package/src/getBotInitialData.js +37 -0
- package/src/getCtx.js +6 -0
- package/src/getCurrentUserID.js +7 -0
- package/src/getEmojiUrl.js +29 -0
- package/src/getFriendsList.js +83 -0
- package/src/getMessage.js +796 -0
- package/src/getOptions.js +6 -0
- package/src/getRegion.js +8 -0
- package/src/getThreadHistory.js +666 -0
- package/src/getThreadHistoryDeprecated.js +55 -0
- package/src/getThreadInfo.js +535 -0
- package/src/getThreadInfoDeprecated.js +49 -0
- package/src/getThreadList.js +192 -0
- package/src/getThreadListDeprecated.js +54 -0
- package/src/getThreadPictures.js +79 -0
- package/src/getUID.js +67 -0
- package/src/getUserID.js +66 -0
- package/src/getUserInfo.js +80 -0
- package/src/handleFriendRequest.js +61 -0
- package/src/handleMessageRequest.js +65 -0
- package/src/httpGet.js +57 -0
- package/src/httpPost.js +57 -0
- package/src/httpPostFormData.js +63 -0
- package/src/listenMqtt.js +1039 -0
- package/src/listenNotification.js +65 -0
- package/src/logout.js +75 -0
- package/src/markAsDelivered.js +58 -0
- package/src/markAsRead.js +80 -0
- package/src/markAsReadAll.js +50 -0
- package/src/markAsSeen.js +59 -0
- package/src/muteThread.js +52 -0
- package/src/pinMessage.js +59 -0
- package/src/postFormData.js +46 -0
- package/src/refreshFb_dtsg.js +66 -0
- package/src/removeUserFromGroup.js +79 -0
- package/src/resolvePhotoUrl.js +45 -0
- package/src/searchForThread.js +53 -0
- package/src/searchStickers.js +51 -0
- package/src/sendComment.js +63 -0
- package/src/sendMessage.js +328 -0
- package/src/sendMessageMqtt.js +316 -0
- package/src/sendTypingIndicator.js +103 -0
- package/src/setMessageReaction.js +119 -0
- package/src/setMessageReactionMqtt.js +61 -0
- package/src/setPostReaction.js +109 -0
- package/src/setProfileGuard.js +45 -0
- package/src/setStoryReaction.js +62 -0
- package/src/setTitle.js +86 -0
- package/src/shareContact.js +49 -0
- package/src/shareLink.js +59 -0
- package/src/stopListenMqtt.js +21 -0
- package/src/threadColors.js +131 -0
- package/src/unfriend.js +52 -0
- package/src/unsendMessage.js +49 -0
- package/src/uploadAttachment.js +95 -0
- package/utils.js +1432 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require("../utils");
|
|
4
|
+
const log = require("npmlog");
|
|
5
|
+
|
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
7
|
+
return function deleteThread(threadOrThreads, callback) {
|
|
8
|
+
let resolveFunc = function () { };
|
|
9
|
+
let rejectFunc = function () { };
|
|
10
|
+
const returnPromise = new Promise(function (resolve, reject) {
|
|
11
|
+
resolveFunc = resolve;
|
|
12
|
+
rejectFunc = reject;
|
|
13
|
+
});
|
|
14
|
+
if (!callback) {
|
|
15
|
+
callback = function (err) {
|
|
16
|
+
if (err) {
|
|
17
|
+
return rejectFunc(err);
|
|
18
|
+
}
|
|
19
|
+
resolveFunc();
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const form = {
|
|
24
|
+
client: "mercury"
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
if (utils.getType(threadOrThreads) !== "Array") {
|
|
28
|
+
threadOrThreads = [threadOrThreads];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
for (let i = 0; i < threadOrThreads.length; i++) {
|
|
32
|
+
form["ids[" + i + "]"] = threadOrThreads[i];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
defaultFuncs
|
|
36
|
+
.post(
|
|
37
|
+
"https://www.facebook.com/ajax/mercury/delete_thread.php",
|
|
38
|
+
ctx.jar,
|
|
39
|
+
form
|
|
40
|
+
)
|
|
41
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
42
|
+
.then(function (resData) {
|
|
43
|
+
if (resData.error) {
|
|
44
|
+
throw resData;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return callback();
|
|
48
|
+
})
|
|
49
|
+
.catch(function (err) {
|
|
50
|
+
log.error("deleteThread", err);
|
|
51
|
+
return callback(err);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return returnPromise;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Nexus-FCA: Advanced and Safe Facebook Chat API
|
|
2
|
+
// editMessage.js - Edit a sent message via MQTT
|
|
3
|
+
|
|
4
|
+
const { generateOfflineThreadingID } = require('../utils');
|
|
5
|
+
|
|
6
|
+
function canBeCalled(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 editMessage(text, messageID, callback) {
|
|
17
|
+
if (!ctx.mqttClient) {
|
|
18
|
+
throw new Error('Not connected to MQTT');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
ctx.wsReqNumber += 1;
|
|
22
|
+
ctx.wsTaskNumber += 1;
|
|
23
|
+
|
|
24
|
+
const queryPayload = {
|
|
25
|
+
message_id: messageID,
|
|
26
|
+
text: text
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const query = {
|
|
30
|
+
failure_count: null,
|
|
31
|
+
label: '742',
|
|
32
|
+
payload: JSON.stringify(queryPayload),
|
|
33
|
+
queue_name: 'edit_message',
|
|
34
|
+
task_id: ctx.wsTaskNumber
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const context = {
|
|
38
|
+
app_id: '2220391788200892',
|
|
39
|
+
payload: JSON.stringify({
|
|
40
|
+
data_trace_id: null,
|
|
41
|
+
epoch_id: parseInt(generateOfflineThreadingID()),
|
|
42
|
+
tasks: [query],
|
|
43
|
+
version_id: '6903494529735864'
|
|
44
|
+
}),
|
|
45
|
+
request_id: ctx.wsReqNumber,
|
|
46
|
+
type: 3
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// if (canBeCalled(callback)) {
|
|
50
|
+
// ctx.reqCallbacks[ctx.wsReqNumber] = callback;
|
|
51
|
+
// }
|
|
52
|
+
|
|
53
|
+
ctx.mqttClient.publish('/ls_req', JSON.stringify(context), {
|
|
54
|
+
qos: 1, retain: false
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
};
|
package/src/follow.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Nexus-FCA: Advanced and Safe Facebook Chat API
|
|
2
|
+
// follow.js - Follow or unfollow a user
|
|
3
|
+
|
|
4
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
5
|
+
return function follow(senderID, boolean, callback) {
|
|
6
|
+
let form;
|
|
7
|
+
if (boolean) {
|
|
8
|
+
form = {
|
|
9
|
+
av: ctx.userID,
|
|
10
|
+
fb_api_req_friendly_name: "CometUserFollowMutation",
|
|
11
|
+
fb_api_caller_class: "RelayModern",
|
|
12
|
+
doc_id: "25472099855769847",
|
|
13
|
+
variables: JSON.stringify({
|
|
14
|
+
input: {
|
|
15
|
+
attribution_id_v2:
|
|
16
|
+
"ProfileCometTimelineListViewRoot.react,comet.profile.timeline.list,via_cold_start,1717249218695,723451,250100865708545,,",
|
|
17
|
+
is_tracking_encrypted: true,
|
|
18
|
+
subscribe_location: "PROFILE",
|
|
19
|
+
subscribee_id: senderID,
|
|
20
|
+
tracking: null,
|
|
21
|
+
actor_id: ctx.userID,
|
|
22
|
+
client_mutation_id: "1",
|
|
23
|
+
},
|
|
24
|
+
scale: 1,
|
|
25
|
+
}),
|
|
26
|
+
};
|
|
27
|
+
} else {
|
|
28
|
+
form = {
|
|
29
|
+
av: ctx.userID,
|
|
30
|
+
fb_api_req_friendly_name: "CometUserUnfollowMutation",
|
|
31
|
+
fb_api_caller_class: "RelayModern",
|
|
32
|
+
doc_id: "25472099855769847",
|
|
33
|
+
variables: JSON.stringify({
|
|
34
|
+
action_render_location: "WWW_COMET_FRIEND_MENU",
|
|
35
|
+
input: {
|
|
36
|
+
attribution_id_v2:
|
|
37
|
+
"ProfileCometTimelineListViewRoot.react,comet.profile.timeline.list,tap_search_bar,1717294006136,602597,250100865708545,,",
|
|
38
|
+
is_tracking_encrypted: true,
|
|
39
|
+
subscribe_location: "PROFILE",
|
|
40
|
+
subscribee_id: senderID,
|
|
41
|
+
tracking: null,
|
|
42
|
+
actor_id: ctx.userID,
|
|
43
|
+
client_mutation_id: "1",
|
|
44
|
+
},
|
|
45
|
+
scale: 1,
|
|
46
|
+
}),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
defaultFuncs
|
|
50
|
+
.post("https://www.facebook.com/api/graphql/", ctx.jar, form)
|
|
51
|
+
.then(() => callback && callback(null, true))
|
|
52
|
+
.catch(err => callback && callback(err, false));
|
|
53
|
+
};
|
|
54
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require("../utils");
|
|
4
|
+
const log = require("npmlog");
|
|
5
|
+
|
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
7
|
+
return function forwardAttachment(attachmentID, userOrUsers, callback) {
|
|
8
|
+
let resolveFunc = function () { };
|
|
9
|
+
let rejectFunc = function () { };
|
|
10
|
+
const returnPromise = new Promise(function (resolve, reject) {
|
|
11
|
+
resolveFunc = resolve;
|
|
12
|
+
rejectFunc = reject;
|
|
13
|
+
});
|
|
14
|
+
if (!callback) {
|
|
15
|
+
callback = function (err) {
|
|
16
|
+
if (err) {
|
|
17
|
+
return rejectFunc(err);
|
|
18
|
+
}
|
|
19
|
+
resolveFunc();
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const form = {
|
|
24
|
+
attachment_id: attachmentID
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
if (utils.getType(userOrUsers) !== "Array") {
|
|
28
|
+
userOrUsers = [userOrUsers];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const timestamp = Math.floor(Date.now() / 1000);
|
|
32
|
+
|
|
33
|
+
for (let i = 0; i < userOrUsers.length; i++) {
|
|
34
|
+
//That's good, the key of the array is really timestmap in seconds + index
|
|
35
|
+
//Probably time when the attachment will be sent?
|
|
36
|
+
form["recipient_map[" + (timestamp + i) + "]"] = userOrUsers[i];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
defaultFuncs
|
|
40
|
+
.post(
|
|
41
|
+
"https://www.facebook.com/mercury/attachments/forward/",
|
|
42
|
+
ctx.jar,
|
|
43
|
+
form
|
|
44
|
+
)
|
|
45
|
+
.then(utils.parseAndCheckLogin(ctx.jar, defaultFuncs))
|
|
46
|
+
.then(function (resData) {
|
|
47
|
+
if (resData.error) {
|
|
48
|
+
throw resData;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return callback();
|
|
52
|
+
})
|
|
53
|
+
.catch(function (err) {
|
|
54
|
+
log.error("forwardAttachment", err);
|
|
55
|
+
return callback(err);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
return returnPromise;
|
|
59
|
+
};
|
|
60
|
+
};
|
package/src/getAccess.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Nexus-FCA: Advanced and Safe Facebook Chat API
|
|
2
|
+
// getAccess.js - Get Facebook access token (with 2FA support)
|
|
3
|
+
|
|
4
|
+
const utils = require('../utils');
|
|
5
|
+
|
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
7
|
+
return function getAccess(authCode = '', callback) {
|
|
8
|
+
let cb;
|
|
9
|
+
const url = 'https://business.facebook.com/';
|
|
10
|
+
const Referer = url + 'security/twofactor/reauth/?twofac_next=' + encodeURIComponent(url + 'content_management') + '&type=avoid_bypass&app_id=0&save_device=0';
|
|
11
|
+
const rt = new Promise(function (resolve, reject) {
|
|
12
|
+
cb = (error, token) => token ? resolve(token) : reject(error);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
if (typeof authCode == 'function') {
|
|
16
|
+
callback = authCode;
|
|
17
|
+
authCode = '';
|
|
18
|
+
}
|
|
19
|
+
if (typeof callback == 'function') cb = callback;
|
|
20
|
+
if (!!ctx.access_token)
|
|
21
|
+
cb(null, ctx.access_token);
|
|
22
|
+
else
|
|
23
|
+
utils
|
|
24
|
+
.get(url + 'content_management', ctx.jar, null, ctx.globalOptions, null, {
|
|
25
|
+
noRef: true,
|
|
26
|
+
Origin: url
|
|
27
|
+
})
|
|
28
|
+
.then(function (res) {
|
|
29
|
+
const html = res.body;
|
|
30
|
+
const lsd = utils.getFrom(html, "[\"LSD\",[],{\"token\":\"", "\"}");
|
|
31
|
+
return lsd;
|
|
32
|
+
})
|
|
33
|
+
.then(function (lsd) {
|
|
34
|
+
function submitCode(code) {
|
|
35
|
+
let pCb;
|
|
36
|
+
const rtPromise = new Promise(function (resolve) {
|
|
37
|
+
pCb = (error, token) => resolve(cb(error, token));
|
|
38
|
+
});
|
|
39
|
+
if (typeof code != 'string')
|
|
40
|
+
pCb({
|
|
41
|
+
error: 'submitCode',
|
|
42
|
+
lerror: 'code must be string',
|
|
43
|
+
continue: submitCode
|
|
44
|
+
});
|
|
45
|
+
else
|
|
46
|
+
defaultFuncs
|
|
47
|
+
.post(url + 'security/twofactor/reauth/enter/', ctx.jar, {
|
|
48
|
+
approvals_code: code,
|
|
49
|
+
save_device: true,
|
|
50
|
+
lsd
|
|
51
|
+
}, ctx.globalOptions, null, {
|
|
52
|
+
Referer,
|
|
53
|
+
Origin: url
|
|
54
|
+
})
|
|
55
|
+
.then(function (res) {
|
|
56
|
+
// ...handle response...
|
|
57
|
+
});
|
|
58
|
+
return rtPromise;
|
|
59
|
+
}
|
|
60
|
+
cb({
|
|
61
|
+
error: '2FA required',
|
|
62
|
+
continue: submitCode
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
return rt;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Nexus-FCA: Advanced and Safe Facebook Chat API
|
|
2
|
+
// getAvatarUser.js - Get user avatar URLs
|
|
3
|
+
|
|
4
|
+
const utils = require('../utils');
|
|
5
|
+
|
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
7
|
+
function handleAvatar(userIDs, height, width) {
|
|
8
|
+
let cb;
|
|
9
|
+
const uploads = [];
|
|
10
|
+
const rtPromise = new Promise(function (resolve, reject) {
|
|
11
|
+
cb = (error, data) => data ? resolve(data) : reject(error);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
userIDs.map(function (v) {
|
|
15
|
+
const mainPromise = defaultFuncs
|
|
16
|
+
.get(`https://graph.facebook.com/${v}/picture?height=${height}&width=${width}&redirect=false&access_token=` + ctx.access_token, ctx.jar)
|
|
17
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
18
|
+
.then(function (res) {
|
|
19
|
+
return {
|
|
20
|
+
userID: v,
|
|
21
|
+
url: res.data.url
|
|
22
|
+
};
|
|
23
|
+
})
|
|
24
|
+
.catch(function (err) {
|
|
25
|
+
return cb(err);
|
|
26
|
+
});
|
|
27
|
+
uploads.push(mainPromise);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
Promise
|
|
31
|
+
.all(uploads)
|
|
32
|
+
.then(function (res) {
|
|
33
|
+
return cb(null, res.reduce(function (Obj, { userID, url }) {
|
|
34
|
+
Obj[userID] = url;
|
|
35
|
+
return Obj;
|
|
36
|
+
}, {}));
|
|
37
|
+
})
|
|
38
|
+
.catch(function (err) {
|
|
39
|
+
return cb(err);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
return rtPromise;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return function getAvatarUser(userIDs, size = [1500, 1500], callback) {
|
|
46
|
+
let cb;
|
|
47
|
+
const rtPromise = new Promise(function (resolve, reject) {
|
|
48
|
+
cb = (err, res) => res ? resolve(res) : reject(err);
|
|
49
|
+
});
|
|
50
|
+
if (!Array.isArray(userIDs)) userIDs = [userIDs];
|
|
51
|
+
handleAvatar(userIDs, size[0], size[1])
|
|
52
|
+
.then(res => cb(null, res))
|
|
53
|
+
.catch(cb);
|
|
54
|
+
return rtPromise;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Nexus-FCA: Advanced and Safe Facebook Chat API
|
|
2
|
+
// getBotInitialData.js - Fetch bot account info for admin/monitoring
|
|
3
|
+
|
|
4
|
+
const utils = require("../utils");
|
|
5
|
+
|
|
6
|
+
module.exports = (defaultFuncs, api, ctx) => {
|
|
7
|
+
return async (callback) => {
|
|
8
|
+
let resolveFunc = () => {};
|
|
9
|
+
let rejectFunc = () => {};
|
|
10
|
+
const returnPromise = new Promise((resolve, reject) => {
|
|
11
|
+
resolveFunc = resolve;
|
|
12
|
+
rejectFunc = reject;
|
|
13
|
+
});
|
|
14
|
+
if (!callback) {
|
|
15
|
+
callback = (err, data) => {
|
|
16
|
+
if (err) return rejectFunc(err);
|
|
17
|
+
resolveFunc(data);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
utils.log("Fetching account info...");
|
|
21
|
+
api.httpGet(`https://www.facebook.com/profile.php?id=${ctx.userID}`, null, {
|
|
22
|
+
customUserAgent: utils.windowsUserAgent
|
|
23
|
+
}, (err, data) => {
|
|
24
|
+
if (err) return callback(err);
|
|
25
|
+
const profileMatch = data.match(/"CurrentUserInitialData",\[\],\{(.*?)\},(.*?)\]/);
|
|
26
|
+
if (profileMatch && profileMatch[1]){
|
|
27
|
+
const accountJson = JSON.parse(`{${profileMatch[1]}}`);
|
|
28
|
+
accountJson.name = accountJson.NAME;
|
|
29
|
+
accountJson.uid = accountJson.USER_ID;
|
|
30
|
+
delete accountJson.NAME;
|
|
31
|
+
delete accountJson.USER_ID;
|
|
32
|
+
return callback(null, { ...accountJson });
|
|
33
|
+
} else return callback(null, { error: "Something went wrong. Maybe its possible that it has a limitation due to spam requests. You can try again later." });
|
|
34
|
+
}, true);
|
|
35
|
+
return returnPromise;
|
|
36
|
+
};
|
|
37
|
+
};
|
package/src/getCtx.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const util = require("util");
|
|
4
|
+
|
|
5
|
+
module.exports = function () {
|
|
6
|
+
return function getEmojiUrl(c, size, pixelRatio) {
|
|
7
|
+
/*
|
|
8
|
+
Resolves Facebook Messenger emoji image asset URL for an emoji character.
|
|
9
|
+
Supported sizes are 32, 64, and 128.
|
|
10
|
+
Supported pixel ratios are '1.0' and '1.5' (possibly more; haven't tested)
|
|
11
|
+
*/
|
|
12
|
+
const baseUrl = "https://static.xx.fbcdn.net/images/emoji.php/v8/z%s/%s";
|
|
13
|
+
pixelRatio = pixelRatio || "1.0";
|
|
14
|
+
|
|
15
|
+
const ending = util.format(
|
|
16
|
+
"%s/%s/%s.png",
|
|
17
|
+
pixelRatio,
|
|
18
|
+
size,
|
|
19
|
+
c.codePointAt(0).toString(16)
|
|
20
|
+
);
|
|
21
|
+
let base = 317426846;
|
|
22
|
+
for (let i = 0; i < ending.length; i++) {
|
|
23
|
+
base = (base << 5) - base + ending.charCodeAt(i);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const hashed = (base & 255).toString(16);
|
|
27
|
+
return util.format(baseUrl, hashed, ending);
|
|
28
|
+
};
|
|
29
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require("../utils");
|
|
4
|
+
const log = require("npmlog");
|
|
5
|
+
|
|
6
|
+
// [almost] copy pasted from one of FB's minified file (GenderConst)
|
|
7
|
+
const GENDERS = {
|
|
8
|
+
0: "unknown",
|
|
9
|
+
1: "female_singular",
|
|
10
|
+
2: "male_singular",
|
|
11
|
+
3: "female_singular_guess",
|
|
12
|
+
4: "male_singular_guess",
|
|
13
|
+
5: "mixed",
|
|
14
|
+
6: "neuter_singular",
|
|
15
|
+
7: "unknown_singular",
|
|
16
|
+
8: "female_plural",
|
|
17
|
+
9: "male_plural",
|
|
18
|
+
10: "neuter_plural",
|
|
19
|
+
11: "unknown_plural"
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function formatData(obj) {
|
|
23
|
+
return Object.keys(obj).map(function (key) {
|
|
24
|
+
const user = obj[key];
|
|
25
|
+
return {
|
|
26
|
+
alternateName: user.alternateName,
|
|
27
|
+
firstName: user.firstName,
|
|
28
|
+
gender: GENDERS[user.gender],
|
|
29
|
+
userID: utils.formatID(user.id.toString()),
|
|
30
|
+
isFriend: user.is_friend != null && user.is_friend ? true : false,
|
|
31
|
+
fullName: user.name,
|
|
32
|
+
profilePicture: user.thumbSrc,
|
|
33
|
+
type: user.type,
|
|
34
|
+
profileUrl: user.uri,
|
|
35
|
+
vanity: user.vanity,
|
|
36
|
+
isBirthday: !!user.is_birthday
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
42
|
+
return function getFriendsList(callback) {
|
|
43
|
+
let resolveFunc = function () { };
|
|
44
|
+
let rejectFunc = function () { };
|
|
45
|
+
const returnPromise = new Promise(function (resolve, reject) {
|
|
46
|
+
resolveFunc = resolve;
|
|
47
|
+
rejectFunc = reject;
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
if (!callback) {
|
|
51
|
+
callback = function (err, friendList) {
|
|
52
|
+
if (err) {
|
|
53
|
+
return rejectFunc(err);
|
|
54
|
+
}
|
|
55
|
+
resolveFunc(friendList);
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
defaultFuncs
|
|
60
|
+
.postFormData(
|
|
61
|
+
"https://www.facebook.com/chat/user_info_all",
|
|
62
|
+
ctx.jar,
|
|
63
|
+
{},
|
|
64
|
+
{ viewer: ctx.i_userID || ctx.userID }
|
|
65
|
+
)
|
|
66
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
67
|
+
.then(function (resData) {
|
|
68
|
+
if (!resData) {
|
|
69
|
+
throw { error: "getFriendsList returned empty object." };
|
|
70
|
+
}
|
|
71
|
+
if (resData.error) {
|
|
72
|
+
throw resData;
|
|
73
|
+
}
|
|
74
|
+
callback(null, formatData(resData.payload));
|
|
75
|
+
})
|
|
76
|
+
.catch(function (err) {
|
|
77
|
+
log.error("getFriendsList", err);
|
|
78
|
+
return callback(err);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
return returnPromise;
|
|
82
|
+
};
|
|
83
|
+
};
|