node-ainzfb 0.0.1-security → 1.2.35
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of node-ainzfb might be problematic. Click here for more details.
- package/.gitattributes +2 -0
- package/.github/dependabot.yml +11 -0
- package/.github/workflows/nodejs.yml +26 -0
- package/.github/workflows/npmpublish.yml +30 -0
- package/CHANGELOG.md +2 -0
- package/DOCS.md +1738 -0
- package/Extra/Database/index.js +399 -0
- package/Extra/Database/methods.js +286 -0
- package/Extra/ExtraAddons.js +213 -0
- package/Extra/ExtraGetThread.js +1 -0
- package/Extra/Src/Last-Run.js +48 -0
- package/LICENSE-MIT +21 -0
- package/Language/index.json +129 -0
- package/README.md +225 -3
- package/StateCrypt.js +22 -0
- package/broadcast.js +42 -0
- package/index.js +1079 -0
- package/logger.js +21 -0
- package/package.json +89 -5
- package/src/addExternalModule.js +16 -0
- package/src/addUserToGroup.js +78 -0
- package/src/changeAdminStatus.js +79 -0
- package/src/changeArchivedStatus.js +41 -0
- package/src/changeBio.js +65 -0
- package/src/changeBlockedStatus.js +36 -0
- package/src/changeGroupImage.js +106 -0
- package/src/changeNickname.js +45 -0
- package/src/changeThreadColor.js +62 -0
- package/src/changeThreadEmoji.js +42 -0
- package/src/createNewGroup.js +70 -0
- package/src/createPoll.js +60 -0
- package/src/deleteMessage.js +45 -0
- package/src/deleteThread.js +43 -0
- package/src/forwardAttachment.js +48 -0
- package/src/getAccessToken.js +31 -0
- package/src/getCurrentUserID.js +7 -0
- package/src/getEmojiUrl.js +27 -0
- package/src/getFriendsList.js +73 -0
- package/src/getMessage.js +80 -0
- package/src/getThreadHistory.js +537 -0
- package/src/getThreadHistoryDeprecated.js +71 -0
- package/src/getThreadInfo.js +197 -0
- package/src/getThreadInfoDeprecated.js +56 -0
- package/src/getThreadList.js +213 -0
- package/src/getThreadListDeprecated.js +46 -0
- package/src/getThreadPictures.js +59 -0
- package/src/getUserID.js +62 -0
- package/src/getUserInfo.js +65 -0
- package/src/getUserInfoV2.js +35 -0
- package/src/handleFriendRequest.js +46 -0
- package/src/handleMessageRequest.js +49 -0
- package/src/httpGet.js +49 -0
- package/src/httpPost.js +48 -0
- package/src/httpPostFormData.js +41 -0
- package/src/listenMqtt.js +633 -0
- package/src/logout.js +68 -0
- package/src/markAsDelivered.js +48 -0
- package/src/markAsRead.js +70 -0
- package/src/markAsReadAll.js +43 -0
- package/src/markAsSeen.js +51 -0
- package/src/muteThread.js +47 -0
- package/src/removeUserFromGroup.js +49 -0
- package/src/resolvePhotoUrl.js +37 -0
- package/src/searchForThread.js +43 -0
- package/src/sendMessage.js +342 -0
- package/src/sendTypingIndicator.js +80 -0
- package/src/setMessageReaction.js +109 -0
- package/src/setPostReaction.js +102 -0
- package/src/setTitle.js +74 -0
- package/src/threadColors.js +39 -0
- package/src/unfriend.js +43 -0
- package/src/unsendMessage.js +40 -0
- package/utils.js +1240 -0
package/src/logout.js
ADDED
@@ -0,0 +1,68 @@
|
|
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 logout(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, friendList) {
|
17
|
+
if (err) return rejectFunc(err);
|
18
|
+
|
19
|
+
resolveFunc(friendList);
|
20
|
+
};
|
21
|
+
}
|
22
|
+
|
23
|
+
var form = {
|
24
|
+
pmid: "0"
|
25
|
+
};
|
26
|
+
|
27
|
+
defaultFuncs
|
28
|
+
.post("https://www.facebook.com/bluebar/modern_settings_menu/?help_type=364455653583099&show_contextual_help=1", ctx.jar, form)
|
29
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
30
|
+
.then(function (resData) {
|
31
|
+
var elem = resData.jsmods.instances[0][2][0].filter(function (v) {
|
32
|
+
return v.value === "logout";
|
33
|
+
})[0];
|
34
|
+
|
35
|
+
var html = resData.jsmods.markup.filter(function (v) {
|
36
|
+
return v[0] === elem.markup.__m;
|
37
|
+
})[0][1].__html;
|
38
|
+
|
39
|
+
var form = {
|
40
|
+
fb_dtsg: utils.getFrom(html, '"fb_dtsg" value="', '"'),
|
41
|
+
ref: utils.getFrom(html, '"ref" value="', '"'),
|
42
|
+
h: utils.getFrom(html, '"h" value="', '"')
|
43
|
+
};
|
44
|
+
|
45
|
+
return defaultFuncs
|
46
|
+
.post("https://www.facebook.com/logout.php", ctx.jar, form)
|
47
|
+
.then(utils.saveCookies(ctx.jar));
|
48
|
+
})
|
49
|
+
.then(function (res) {
|
50
|
+
if (!res.headers) throw { error: "An error occurred when logging out." };
|
51
|
+
|
52
|
+
return defaultFuncs
|
53
|
+
.get(res.headers.location, ctx.jar)
|
54
|
+
.then(utils.saveCookies(ctx.jar));
|
55
|
+
})
|
56
|
+
.then(function () {
|
57
|
+
ctx.loggedIn = false;
|
58
|
+
log.info("logout", "Logged out successfully.");
|
59
|
+
callback();
|
60
|
+
})
|
61
|
+
.catch(function (err) {
|
62
|
+
log.error("logout", err);
|
63
|
+
return callback(err);
|
64
|
+
});
|
65
|
+
|
66
|
+
return returnPromise;
|
67
|
+
};
|
68
|
+
};
|
@@ -0,0 +1,48 @@
|
|
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 markAsDelivered(threadID, messageID, 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
|
+
|
19
|
+
resolveFunc(data);
|
20
|
+
};
|
21
|
+
}
|
22
|
+
|
23
|
+
if (!threadID || !messageID) return callback("Error: messageID or threadID is not defined");
|
24
|
+
|
25
|
+
var form = {};
|
26
|
+
|
27
|
+
form["message_ids[0]"] = messageID;
|
28
|
+
form["thread_ids[" + threadID + "][0]"] = messageID;
|
29
|
+
|
30
|
+
defaultFuncs
|
31
|
+
.post("https://www.facebook.com/ajax/mercury/delivery_receipts.php", ctx.jar, form)
|
32
|
+
.then(utils.saveCookies(ctx.jar))
|
33
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
34
|
+
.then(function (resData) {
|
35
|
+
if (resData.error) throw resData;
|
36
|
+
|
37
|
+
return callback();
|
38
|
+
})
|
39
|
+
.catch(function (err) {
|
40
|
+
log.error("markAsDelivered", err);
|
41
|
+
if (utils.getType(err) == "Object" && err.error === "Not logged in.") ctx.loggedIn = false;
|
42
|
+
|
43
|
+
return callback(err);
|
44
|
+
});
|
45
|
+
|
46
|
+
return returnPromise;
|
47
|
+
};
|
48
|
+
};
|
@@ -0,0 +1,70 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var utils = require("../utils");
|
4
|
+
var log = require("npmlog");
|
5
|
+
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
7
|
+
return async function markAsRead(threadID, read, callback) {
|
8
|
+
if (utils.getType(read) === 'Function' || utils.getType(read) === 'AsyncFunction') {
|
9
|
+
callback = read;
|
10
|
+
read = true;
|
11
|
+
}
|
12
|
+
if (read == undefined) read = true;
|
13
|
+
|
14
|
+
if (!callback) callback = () => { };
|
15
|
+
|
16
|
+
var form = {};
|
17
|
+
|
18
|
+
if (typeof ctx.globalOptions.pageID !== 'undefined') {
|
19
|
+
form["source"] = "PagesManagerMessagesInterface";
|
20
|
+
form["request_user_id"] = ctx.globalOptions.pageID;
|
21
|
+
form["ids[" + threadID + "]"] = read;
|
22
|
+
form["watermarkTimestamp"] = new Date().getTime();
|
23
|
+
form["shouldSendReadReceipt"] = true;
|
24
|
+
form["commerce_last_message_type"] = "";
|
25
|
+
//form["titanOriginatedThreadId"] = utils.generateThreadingID(ctx.clientID);
|
26
|
+
|
27
|
+
let resData;
|
28
|
+
try {
|
29
|
+
resData = await (
|
30
|
+
defaultFuncs
|
31
|
+
.post("https://www.facebook.com/ajax/mercury/change_read_status.php", ctx.jar, form)
|
32
|
+
.then(utils.saveCookies(ctx.jar))
|
33
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
34
|
+
);
|
35
|
+
}
|
36
|
+
catch (e) {
|
37
|
+
callback(e);
|
38
|
+
return e;
|
39
|
+
}
|
40
|
+
|
41
|
+
if (resData.error) {
|
42
|
+
let err = resData.error;
|
43
|
+
log.error("markAsRead", err);
|
44
|
+
if (utils.getType(err) == "Object" && err.error === "Not logged in.") ctx.loggedIn = false;
|
45
|
+
callback(err);
|
46
|
+
return err;
|
47
|
+
}
|
48
|
+
|
49
|
+
callback();
|
50
|
+
return null;
|
51
|
+
}
|
52
|
+
else {
|
53
|
+
try {
|
54
|
+
if (ctx.mqttClient) {
|
55
|
+
let err = await new Promise(r => ctx.mqttClient.publish("/mark_thread", JSON.stringify({
|
56
|
+
threadID,
|
57
|
+
mark: "read",
|
58
|
+
state: read
|
59
|
+
}), { qos: 1, retain: false }, r));
|
60
|
+
if (err) throw err;
|
61
|
+
}
|
62
|
+
else throw { error: "You can only use this function after you start listening." };
|
63
|
+
}
|
64
|
+
catch (e) {
|
65
|
+
callback(e);
|
66
|
+
return e;
|
67
|
+
}
|
68
|
+
}
|
69
|
+
};
|
70
|
+
};
|
@@ -0,0 +1,43 @@
|
|
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 markAsReadAll(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
|
+
|
19
|
+
resolveFunc(data);
|
20
|
+
};
|
21
|
+
}
|
22
|
+
|
23
|
+
var form = {
|
24
|
+
folder: 'inbox'
|
25
|
+
};
|
26
|
+
|
27
|
+
defaultFuncs
|
28
|
+
.post("https://www.facebook.com/ajax/mercury/mark_folder_as_read.php", ctx.jar, form)
|
29
|
+
.then(utils.saveCookies(ctx.jar))
|
30
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
31
|
+
.then(function (resData) {
|
32
|
+
if (resData.error) throw resData;
|
33
|
+
|
34
|
+
return callback();
|
35
|
+
})
|
36
|
+
.catch(function (err) {
|
37
|
+
log.error("markAsReadAll", err);
|
38
|
+
return callback(err);
|
39
|
+
});
|
40
|
+
|
41
|
+
return returnPromise;
|
42
|
+
};
|
43
|
+
};
|
@@ -0,0 +1,51 @@
|
|
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 markAsSeen(seen_timestamp, callback) {
|
8
|
+
if (utils.getType(seen_timestamp) == "Function" ||
|
9
|
+
utils.getType(seen_timestamp) == "AsyncFunction") {
|
10
|
+
callback = seen_timestamp;
|
11
|
+
seen_timestamp = Date.now();
|
12
|
+
}
|
13
|
+
|
14
|
+
var resolveFunc = function () { };
|
15
|
+
var rejectFunc = function () { };
|
16
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
17
|
+
resolveFunc = resolve;
|
18
|
+
rejectFunc = reject;
|
19
|
+
});
|
20
|
+
|
21
|
+
if (!callback) {
|
22
|
+
callback = function (err, data) {
|
23
|
+
if (err) return rejectFunc(err);
|
24
|
+
|
25
|
+
resolveFunc(data);
|
26
|
+
};
|
27
|
+
}
|
28
|
+
|
29
|
+
var form = {
|
30
|
+
seen_timestamp: seen_timestamp
|
31
|
+
};
|
32
|
+
|
33
|
+
defaultFuncs
|
34
|
+
.post("https://www.facebook.com/ajax/mercury/mark_seen.php", ctx.jar, form)
|
35
|
+
.then(utils.saveCookies(ctx.jar))
|
36
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
37
|
+
.then(function (resData) {
|
38
|
+
if (resData.error) throw resData;
|
39
|
+
|
40
|
+
return callback();
|
41
|
+
})
|
42
|
+
.catch(function (err) {
|
43
|
+
log.error("markAsSeen", err);
|
44
|
+
if (utils.getType(err) == "Object" && err.error === "Not logged in.") ctx.loggedIn = false;
|
45
|
+
|
46
|
+
return callback(err);
|
47
|
+
});
|
48
|
+
|
49
|
+
return returnPromise;
|
50
|
+
};
|
51
|
+
};
|
@@ -0,0 +1,47 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var utils = require("../utils");
|
4
|
+
var log = require("npmlog");
|
5
|
+
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
7
|
+
// muteSecond: -1=permanent mute, 0=unmute, 60=one minute, 3600=one hour, etc.
|
8
|
+
return function muteThread(threadID, muteSeconds, callback) {
|
9
|
+
var resolveFunc = function () { };
|
10
|
+
var rejectFunc = function () { };
|
11
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
12
|
+
resolveFunc = resolve;
|
13
|
+
rejectFunc = reject;
|
14
|
+
});
|
15
|
+
|
16
|
+
if (!callback) {
|
17
|
+
callback = function (err, data) {
|
18
|
+
if (err) return rejectFunc(err);
|
19
|
+
|
20
|
+
resolveFunc(data);
|
21
|
+
};
|
22
|
+
}
|
23
|
+
|
24
|
+
var form = {
|
25
|
+
thread_fbid: threadID,
|
26
|
+
mute_settings: muteSeconds
|
27
|
+
};
|
28
|
+
|
29
|
+
defaultFuncs
|
30
|
+
.post("https://www.facebook.com/ajax/mercury/change_mute_thread.php", ctx.jar, form)
|
31
|
+
.then(utils.saveCookies(ctx.jar))
|
32
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
33
|
+
.then(function (resData) {
|
34
|
+
if (resData.error) {
|
35
|
+
throw resData;
|
36
|
+
}
|
37
|
+
|
38
|
+
return callback();
|
39
|
+
})
|
40
|
+
.catch(function (err) {
|
41
|
+
log.error("muteThread", err);
|
42
|
+
return callback(err);
|
43
|
+
});
|
44
|
+
|
45
|
+
return returnPromise;
|
46
|
+
};
|
47
|
+
};
|
@@ -0,0 +1,49 @@
|
|
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 removeUserFromGroup(userID, threadID, callback) {
|
8
|
+
if (!callback && (utils.getType(threadID) === "Function" || utils.getType(threadID) === "AsyncFunction")) throw { error: "please pass a threadID as a second argument." };
|
9
|
+
if (utils.getType(threadID) !== "Number" && utils.getType(threadID) !== "String") throw { error: "threadID should be of type Number or String and not " + utils.getType(threadID) + "." };
|
10
|
+
if (utils.getType(userID) !== "Number" && utils.getType(userID) !== "String") throw { error: "userID should be of type Number or String and not " + utils.getType(userID) + "." };
|
11
|
+
|
12
|
+
var resolveFunc = function () { };
|
13
|
+
var rejectFunc = function () { };
|
14
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
15
|
+
resolveFunc = resolve;
|
16
|
+
rejectFunc = reject;
|
17
|
+
});
|
18
|
+
|
19
|
+
if (!callback) {
|
20
|
+
callback = function (err, data) {
|
21
|
+
if (err) return rejectFunc(err);
|
22
|
+
|
23
|
+
resolveFunc(data);
|
24
|
+
};
|
25
|
+
}
|
26
|
+
|
27
|
+
var form = {
|
28
|
+
uid: userID,
|
29
|
+
tid: threadID
|
30
|
+
};
|
31
|
+
|
32
|
+
defaultFuncs
|
33
|
+
.post("https://www.facebook.com/chat/remove_participants", ctx.jar, form)
|
34
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
35
|
+
.then(function (resData) {
|
36
|
+
if (!resData) throw { error: "Remove from group failed." };
|
37
|
+
|
38
|
+
if (resData.error) throw resData;
|
39
|
+
|
40
|
+
return callback();
|
41
|
+
})
|
42
|
+
.catch(function (err) {
|
43
|
+
log.error("removeUserFromGroup", err);
|
44
|
+
return callback(err);
|
45
|
+
});
|
46
|
+
|
47
|
+
return returnPromise;
|
48
|
+
};
|
49
|
+
};
|
@@ -0,0 +1,37 @@
|
|
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 resolvePhotoUrl(photoID, 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
|
+
defaultFuncs
|
23
|
+
.get("https://www.facebook.com/mercury/attachments/photo", ctx.jar, { photo_id: photoID })
|
24
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
25
|
+
.then(resData => {
|
26
|
+
if (resData.error) throw resData;
|
27
|
+
var photoUrl = resData.jsmods.require[0][3][0];
|
28
|
+
return callback(null, photoUrl);
|
29
|
+
})
|
30
|
+
.catch(err => {
|
31
|
+
log.error("resolvePhotoUrl", err);
|
32
|
+
return callback(err);
|
33
|
+
});
|
34
|
+
|
35
|
+
return returnPromise;
|
36
|
+
};
|
37
|
+
};
|
@@ -0,0 +1,43 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var utils = require("../utils");
|
4
|
+
|
5
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
6
|
+
return function searchForThread(name, callback) {
|
7
|
+
var resolveFunc = function () { };
|
8
|
+
var rejectFunc = function () { };
|
9
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
10
|
+
resolveFunc = resolve;
|
11
|
+
rejectFunc = reject;
|
12
|
+
});
|
13
|
+
|
14
|
+
if (!callback) {
|
15
|
+
callback = function (err, data) {
|
16
|
+
if (err) return rejectFunc(err);
|
17
|
+
resolveFunc(data);
|
18
|
+
};
|
19
|
+
}
|
20
|
+
|
21
|
+
var tmpForm = {
|
22
|
+
client: "web_messenger",
|
23
|
+
query: name,
|
24
|
+
offset: 0,
|
25
|
+
limit: 21,
|
26
|
+
index: "fbid"
|
27
|
+
};
|
28
|
+
|
29
|
+
defaultFuncs
|
30
|
+
.post("https://www.facebook.com/ajax/mercury/search_threads.php", ctx.jar, tmpForm)
|
31
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
32
|
+
.then(function (resData) {
|
33
|
+
if (resData.error) throw resData;
|
34
|
+
if (!resData.payload.mercury_payload.threads) return callback({ error: "Could not find thread `" + name + "`." });
|
35
|
+
return callback(
|
36
|
+
null,
|
37
|
+
resData.payload.mercury_payload.threads.map(utils.formatThread)
|
38
|
+
);
|
39
|
+
});
|
40
|
+
|
41
|
+
return returnPromise;
|
42
|
+
};
|
43
|
+
};
|