fca-nino 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of fca-nino might be problematic. Click here for more details.
- package/.gitattributes +2 -0
- package/.travis.yml +6 -0
- package/CHANGELOG.md +2 -0
- package/DOCS.md +1738 -0
- package/LICENSE-MIT +21 -0
- package/README.md +219 -0
- package/index.js +541 -0
- package/package.json +73 -0
- package/replit.nix +5 -0
- package/src/Screenshot.js +83 -0
- package/src/addExternalModule.js +15 -0
- package/src/addUserToGroup.js +77 -0
- package/src/changeAdminStatus.js +47 -0
- package/src/changeArchivedStatus.js +41 -0
- package/src/changeAvt.js +85 -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 +61 -0
- package/src/changeThreadEmoji.js +41 -0
- package/src/createNewGroup.js +70 -0
- package/src/createPoll.js +59 -0
- package/src/deleteMessage.js +44 -0
- package/src/deleteThread.js +42 -0
- package/src/forwardAttachment.js +47 -0
- package/src/getCurrentUserID.js +7 -0
- package/src/getEmojiUrl.js +27 -0
- package/src/getFriendsList.js +73 -0
- package/src/getThreadHistory.js +537 -0
- package/src/getThreadHistoryDeprecated.js +71 -0
- package/src/getThreadInfo.js +171 -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 +61 -0
- package/src/getUserInfo.js +66 -0
- package/src/handleFriendRequest.js +46 -0
- package/src/handleMessageRequest.js +47 -0
- package/src/httpGet.js +49 -0
- package/src/httpPost.js +48 -0
- package/src/listenMqtt.js +701 -0
- package/src/logout.js +68 -0
- package/src/markAsDelivered.js +47 -0
- package/src/markAsRead.js +70 -0
- package/src/markAsReadAll.js +40 -0
- package/src/markAsSeen.js +48 -0
- package/src/muteThread.js +45 -0
- package/src/removeUserFromGroup.js +45 -0
- package/src/resolvePhotoUrl.js +36 -0
- package/src/searchForThread.js +42 -0
- package/src/sendMessage.js +328 -0
- package/src/sendTypingIndicator.js +70 -0
- package/src/setMessageReaction.js +109 -0
- package/src/setPostReaction.js +102 -0
- package/src/setTitle.js +70 -0
- package/src/shareContact.js +46 -0
- package/src/threadColors.js +41 -0
- package/src/unfriend.js +42 -0
- package/src/unsendMessage.js +39 -0
- package/test/data/shareAttach.js +146 -0
- package/test/data/something.mov +0 -0
- package/test/data/test.png +0 -0
- package/test/data/test.txt +7 -0
- package/test/example-config.json +18 -0
- package/test/test-page.js +140 -0
- package/test/test.js +385 -0
- package/utils.js +1196 -0
@@ -0,0 +1,83 @@
|
|
1
|
+
/* eslint-disable linebreak-style */
|
2
|
+
"use strict";
|
3
|
+
|
4
|
+
|
5
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
6
|
+
var Coookie = JSON.parse(JSON.stringify(ctx.jar.getCookies("https://www.facebook.com").concat(ctx.jar.getCookies("https://facebook.com")).concat(ctx.jar.getCookies("https://www.messenger.com"))));
|
7
|
+
for (let i of Coookie) {
|
8
|
+
i.name = i.key;
|
9
|
+
i.domain = 'www.facebook.com';
|
10
|
+
delete i.key;
|
11
|
+
}
|
12
|
+
return function(Link, callback) {
|
13
|
+
var logger = require('../logger');
|
14
|
+
if (process.platform != 'win32') return logger.Error('Not Supported Platform');
|
15
|
+
else try {
|
16
|
+
let i = require('puppeteer');
|
17
|
+
}
|
18
|
+
catch (e) {
|
19
|
+
var { execSync } = require('child_process');
|
20
|
+
execSync('npm i puppeteer', { stdio: 'inherit' });
|
21
|
+
}
|
22
|
+
const Screenshot = require('../Extra/ExtraScreenShot');
|
23
|
+
var resolveFunc = function () { };
|
24
|
+
var rejectFunc = function () { };
|
25
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
26
|
+
resolveFunc = resolve;
|
27
|
+
rejectFunc = reject;
|
28
|
+
});
|
29
|
+
|
30
|
+
if (!callback) {
|
31
|
+
callback = function (err, data) {
|
32
|
+
if (err) return rejectFunc(err);
|
33
|
+
resolveFunc(data);
|
34
|
+
};
|
35
|
+
}
|
36
|
+
if (Link.includes('facebook.com') || Link.includes('Facebook.com') || Link.includes('fb')) {
|
37
|
+
let LinkSplit = Link.split('/');
|
38
|
+
if (LinkSplit.indexOf("https:") == 0) {
|
39
|
+
if (Link.includes('messages')) {
|
40
|
+
Screenshot.buffer(Link, {
|
41
|
+
cookies: Coookie
|
42
|
+
}).then(data => {
|
43
|
+
callback(null,data);
|
44
|
+
});
|
45
|
+
}
|
46
|
+
else if (!isNaN(LinkSplit[3]) && !Link.split('=')[1] && !isNaN(Link.split('=')[1])) {
|
47
|
+
api.sendMessage('Invaild link, format link: facebook.com/Lazic.Kanzu',global.Fca.Data.event.threadID,global.Fca.Data.event.messageID);
|
48
|
+
callback('Error Link', null);
|
49
|
+
}
|
50
|
+
else if (!isNaN(Link.split('=')[1]) && Link.split('=')[1]) {
|
51
|
+
let Format = `https://www.facebook.com/profile.php?id=${Link.split('=')[1]}`;
|
52
|
+
Screenshot.buffer(Format, {
|
53
|
+
cookies: Coookie
|
54
|
+
}).then(data => {
|
55
|
+
callback(null,data);
|
56
|
+
});
|
57
|
+
}
|
58
|
+
else {
|
59
|
+
let Format = `https://www.facebook.com/${LinkSplit[3]}`;
|
60
|
+
Screenshot.buffer(Format, {
|
61
|
+
cookies: Coookie
|
62
|
+
}).then(data => {
|
63
|
+
callback(null,data);
|
64
|
+
});
|
65
|
+
}
|
66
|
+
}
|
67
|
+
else {
|
68
|
+
let Form = `https://www.facebook.com/${LinkSplit[1]}`;
|
69
|
+
Screenshot.buffer(Form, {
|
70
|
+
cookies: Coookie
|
71
|
+
}).then(data => {
|
72
|
+
callback(null,data);
|
73
|
+
});
|
74
|
+
}
|
75
|
+
}
|
76
|
+
else {
|
77
|
+
Screenshot.buffer(Link).then(data => {
|
78
|
+
callback(null,data);
|
79
|
+
});
|
80
|
+
}
|
81
|
+
return returnPromise;
|
82
|
+
};
|
83
|
+
};
|
@@ -0,0 +1,15 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
const utils = require("../utils");
|
4
|
+
|
5
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
6
|
+
return function addExternalModule(moduleObj) {
|
7
|
+
if (utils.getType(moduleObj) == "Object") {
|
8
|
+
for (let apiName in moduleObj) {
|
9
|
+
if (utils.getType(moduleObj[apiName]) == "Function") api[apiName] = moduleObj[apiName](defaultFuncs, api, ctx);
|
10
|
+
else throw new Error(`Item "${apiName}" in moduleObj must be a function, not ${utils.getType(moduleObj[apiName])}!`);
|
11
|
+
}
|
12
|
+
}
|
13
|
+
else throw new Error(`moduleObj must be an object, not ${utils.getType(moduleObj)}!`);
|
14
|
+
};
|
15
|
+
};
|
@@ -0,0 +1,77 @@
|
|
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 addUserToGroup(userID, threadID, callback) {
|
8
|
+
var resolveFunc = function () { };
|
9
|
+
var rejectFunc = function () { };
|
10
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
11
|
+
resolveFunc = resolve;
|
12
|
+
rejectFunc = reject;
|
13
|
+
});
|
14
|
+
|
15
|
+
if (!callback && (utils.getType(threadID) === "Function" || utils.getType(threadID) === "AsyncFunction")) throw { error: "please pass a threadID as a second argument." };
|
16
|
+
|
17
|
+
if (!callback) {
|
18
|
+
callback = function (err) {
|
19
|
+
if (err) return rejectFunc(err);
|
20
|
+
resolveFunc();
|
21
|
+
};
|
22
|
+
}
|
23
|
+
|
24
|
+
if (utils.getType(threadID) !== "Number" && utils.getType(threadID) !== "String") throw { error: "ThreadID should be of type Number or String and not " + utils.getType(threadID) + "." };
|
25
|
+
|
26
|
+
if (utils.getType(userID) !== "Array") userID = [userID];
|
27
|
+
|
28
|
+
var messageAndOTID = utils.generateOfflineThreadingID();
|
29
|
+
var form = {
|
30
|
+
client: "mercury",
|
31
|
+
action_type: "ma-type:log-message",
|
32
|
+
author: "fbid:" + ctx.userID,
|
33
|
+
thread_id: "",
|
34
|
+
timestamp: Date.now(),
|
35
|
+
timestamp_absolute: "Today",
|
36
|
+
timestamp_relative: utils.generateTimestampRelative(),
|
37
|
+
timestamp_time_passed: "0",
|
38
|
+
is_unread: false,
|
39
|
+
is_cleared: false,
|
40
|
+
is_forward: false,
|
41
|
+
is_filtered_content: false,
|
42
|
+
is_filtered_content_bh: false,
|
43
|
+
is_filtered_content_account: false,
|
44
|
+
is_spoof_warning: false,
|
45
|
+
source: "source:chat:web",
|
46
|
+
"source_tags[0]": "source:chat",
|
47
|
+
log_message_type: "log:subscribe",
|
48
|
+
status: "0",
|
49
|
+
offline_threading_id: messageAndOTID,
|
50
|
+
message_id: messageAndOTID,
|
51
|
+
threading_id: utils.generateThreadingID(ctx.clientID),
|
52
|
+
manual_retry_cnt: "0",
|
53
|
+
thread_fbid: threadID
|
54
|
+
};
|
55
|
+
|
56
|
+
for (var i = 0; i < userID.length; i++) {
|
57
|
+
if (utils.getType(userID[i]) !== "Number" && utils.getType(userID[i]) !== "String") throw { error: "Elements of userID should be of type Number or String and not " + utils.getType(userID[i]) + "." };
|
58
|
+
form["log_message_data[added_participants][" + i + "]"] = "fbid:" + userID[i];
|
59
|
+
}
|
60
|
+
|
61
|
+
defaultFuncs
|
62
|
+
.post("https://www.facebook.com/messaging/send/", ctx.jar, form)
|
63
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
64
|
+
.then(function (resData) {
|
65
|
+
if (!resData) throw { error: "Add to group failed." };
|
66
|
+
if (resData.error) throw resData;
|
67
|
+
|
68
|
+
return callback();
|
69
|
+
})
|
70
|
+
.catch(function (err) {
|
71
|
+
log.error("addUserToGroup", err);
|
72
|
+
return callback(err);
|
73
|
+
});
|
74
|
+
|
75
|
+
return returnPromise;
|
76
|
+
};
|
77
|
+
};
|
@@ -0,0 +1,47 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
const utils = require("../utils");
|
4
|
+
|
5
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
6
|
+
return function changeAdminStatus(threadID, adminID, adminStatus) {
|
7
|
+
if (utils.getType(threadID) !== "String") throw { error: "changeAdminStatus: threadID must be a string" };
|
8
|
+
if (utils.getType(adminID) !== "String" && utils.getType(adminID) !== "Array") throw { error: "changeAdminStatus: adminID must be a string or an array" };
|
9
|
+
if (utils.getType(adminStatus) !== "Boolean") throw { error: "changeAdminStatus: adminStatus must be true or false" };
|
10
|
+
|
11
|
+
let wsContent = {
|
12
|
+
request_id: 1,
|
13
|
+
type: 3,
|
14
|
+
payload: {
|
15
|
+
version_id: '3816854585040595',
|
16
|
+
tasks: [],
|
17
|
+
epoch_id: 6763184801413415579,
|
18
|
+
data_trace_id: null
|
19
|
+
},
|
20
|
+
app_id: '772021112871879'
|
21
|
+
}
|
22
|
+
|
23
|
+
if (utils.getType(adminID) === "Array") {
|
24
|
+
for (let i = 0; i < adminID.length; i++) {
|
25
|
+
wsContent.payload.tasks.push({
|
26
|
+
label: '25',
|
27
|
+
payload: JSON.stringify({ thread_key: threadID, contact_id: adminID[i], is_admin: adminStatus }),
|
28
|
+
queue_name: 'admin_status',
|
29
|
+
task_id: i + 1,
|
30
|
+
failure_count: null
|
31
|
+
});
|
32
|
+
}
|
33
|
+
}
|
34
|
+
else {
|
35
|
+
wsContent.payload.tasks.push({
|
36
|
+
label: '25',
|
37
|
+
payload: JSON.stringify({ thread_key: threadID, contact_id: adminID, is_admin: adminStatus }),
|
38
|
+
queue_name: 'admin_status',
|
39
|
+
task_id: 1,
|
40
|
+
failure_count: null
|
41
|
+
});
|
42
|
+
}
|
43
|
+
|
44
|
+
wsContent.payload = JSON.stringify(wsContent.payload);
|
45
|
+
return new Promise((resolve, reject) => ctx.mqttClient && ctx.mqttClient.publish('/ls_req', JSON.stringify(wsContent), {}, (err, _packet) => err ? reject(err) : resolve()));
|
46
|
+
};
|
47
|
+
};
|
@@ -0,0 +1,41 @@
|
|
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 changeArchivedStatus(threadOrThreads, archive, 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) {
|
17
|
+
if (err) return rejectFunc(err);
|
18
|
+
resolveFunc();
|
19
|
+
};
|
20
|
+
}
|
21
|
+
|
22
|
+
var form = {};
|
23
|
+
|
24
|
+
if (utils.getType(threadOrThreads) === "Array") for (var i = 0; i < threadOrThreads.length; i++) form["ids[" + threadOrThreads[i] + "]"] = archive;
|
25
|
+
else form["ids[" + threadOrThreads + "]"] = archive;
|
26
|
+
|
27
|
+
defaultFuncs
|
28
|
+
.post("https://www.facebook.com/ajax/mercury/change_archived_status.php", ctx.jar, form)
|
29
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
30
|
+
.then(function (resData) {
|
31
|
+
if (resData.error) throw resData;
|
32
|
+
return callback();
|
33
|
+
})
|
34
|
+
.catch(function (err) {
|
35
|
+
log.error("changeArchivedStatus", err);
|
36
|
+
return callback(err);
|
37
|
+
});
|
38
|
+
|
39
|
+
return returnPromise;
|
40
|
+
};
|
41
|
+
};
|
package/src/changeAvt.js
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var utils = require("../utils");
|
4
|
+
var log = require("npmlog");
|
5
|
+
/**
|
6
|
+
* It posts an image to a Facebook profile
|
7
|
+
* @param Api - The API object
|
8
|
+
* @param BotID - The ID of the bot you want to post the image to.
|
9
|
+
* @param form - The form data that you want to send.
|
10
|
+
* @returns The JSON.parse(Data.split("for (;;);")[1]); is returning the following:
|
11
|
+
* {"__ar":1,"payload":null,"jsmods":{"require":[["ImageUploader","uploadPhoto",[{"__m":"__elem_0"},{"__m":"__elem_1"},{"__m":"__elem_2"},{"__m":"__
|
12
|
+
*/
|
13
|
+
async function postImage(Api,BotID,form) {
|
14
|
+
var Data = await Api.httpPostFormData(`https://www.facebook.com/profile/picture/upload/?profile_id=${BotID}&photo_source=57&av=${BotID}`, form);
|
15
|
+
return JSON.parse(Data.split("for (;;);")[1]);
|
16
|
+
}
|
17
|
+
|
18
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
19
|
+
/* Changing the profile picture of the bot. */
|
20
|
+
return function changeAvt(link, caption, callback) {
|
21
|
+
var resolveFunc = function() {};
|
22
|
+
var rejectFunc = function() {};
|
23
|
+
var returnPromise = new Promise(function(resolve, reject) {
|
24
|
+
resolveFunc = resolve;
|
25
|
+
rejectFunc = reject;
|
26
|
+
});
|
27
|
+
|
28
|
+
if (!callback) {
|
29
|
+
callback = function(err, data) {
|
30
|
+
if (err) return rejectFunc(err);
|
31
|
+
resolveFunc(data);
|
32
|
+
};
|
33
|
+
}
|
34
|
+
try {
|
35
|
+
var Fetch = require('axios')
|
36
|
+
Fetch.get(link, { responseType: "stream" }).then(data => {
|
37
|
+
postImage(api, ctx.userID, { file: data.data }).then(data => {
|
38
|
+
if (data.error) throw new Error({ error: data.error, des: data.error.errorDescription });
|
39
|
+
var form = {
|
40
|
+
av: ctx.userID,
|
41
|
+
fb_api_req_friendly_name: "ProfileCometProfilePictureSetMutation",
|
42
|
+
fb_api_caller_class: "RelayModern",
|
43
|
+
doc_id: "5066134240065849",
|
44
|
+
variables: JSON.stringify({
|
45
|
+
input: {
|
46
|
+
caption: (caption || ""),
|
47
|
+
existing_photo_id: data.payload.fbid,
|
48
|
+
expiration_time: null,
|
49
|
+
profile_id: ctx.userID,
|
50
|
+
profile_pic_method: "EXISTING",
|
51
|
+
profile_pic_source: "TIMELINE",
|
52
|
+
scaled_crop_rect: {
|
53
|
+
height: 1,
|
54
|
+
width: 1,
|
55
|
+
x: 0,
|
56
|
+
y: 0
|
57
|
+
},
|
58
|
+
skip_cropping: true,
|
59
|
+
actor_id: ctx.userID,
|
60
|
+
client_mutation_id: Math.round(Math.random() * 19).toString()
|
61
|
+
},
|
62
|
+
isPage: false,
|
63
|
+
isProfile: true,
|
64
|
+
scale: 3,
|
65
|
+
})
|
66
|
+
};
|
67
|
+
defaultFuncs
|
68
|
+
.post("https://www.facebook.com/api/graphql/", ctx.jar, form)
|
69
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
70
|
+
.then(function(resData) {
|
71
|
+
if (resData.error) throw resData;
|
72
|
+
else return callback(null,true)
|
73
|
+
})
|
74
|
+
.catch(function(err) {
|
75
|
+
return callback(err);
|
76
|
+
});
|
77
|
+
})
|
78
|
+
})
|
79
|
+
}
|
80
|
+
catch (e) {
|
81
|
+
throw e;
|
82
|
+
}
|
83
|
+
return returnPromise;
|
84
|
+
};
|
85
|
+
};
|
package/src/changeBio.js
ADDED
@@ -0,0 +1,65 @@
|
|
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 changeBio(bio, publish, 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
|
+
if (utils.getType(publish) == "Function" || utils.getType(publish) == "AsyncFunction") callback = publish;
|
17
|
+
else {
|
18
|
+
callback = function (err) {
|
19
|
+
if (err) return rejectFunc(err);
|
20
|
+
resolveFunc();
|
21
|
+
};
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
if (utils.getType(publish) != "Boolean") publish = false;
|
26
|
+
if (utils.getType(bio) != "String") {
|
27
|
+
bio = "";
|
28
|
+
publish = false;
|
29
|
+
}
|
30
|
+
|
31
|
+
var form = {
|
32
|
+
fb_api_caller_class: "RelayModern",
|
33
|
+
fb_api_req_friendly_name: "ProfileCometSetBioMutation",
|
34
|
+
// This doc_is is valid as of May 23, 2020
|
35
|
+
doc_id: "2725043627607610",
|
36
|
+
variables: JSON.stringify({
|
37
|
+
input: {
|
38
|
+
bio: bio,
|
39
|
+
publish_bio_feed_story: publish,
|
40
|
+
actor_id: ctx.userID,
|
41
|
+
client_mutation_id: Math.round(Math.random() * 1024).toString()
|
42
|
+
},
|
43
|
+
hasProfileTileViewID: false,
|
44
|
+
profileTileViewID: null,
|
45
|
+
scale: 1
|
46
|
+
}),
|
47
|
+
av: ctx.userID
|
48
|
+
};
|
49
|
+
|
50
|
+
defaultFuncs
|
51
|
+
.post("https://www.facebook.com/api/graphql/", ctx.jar, form)
|
52
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
53
|
+
.then(function (resData) {
|
54
|
+
if (resData.errors) throw resData;
|
55
|
+
|
56
|
+
return callback();
|
57
|
+
})
|
58
|
+
.catch(function (err) {
|
59
|
+
log.error("changeBio", err);
|
60
|
+
return callback(err);
|
61
|
+
});
|
62
|
+
|
63
|
+
return returnPromise;
|
64
|
+
};
|
65
|
+
};
|
@@ -0,0 +1,36 @@
|
|
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 changeBlockedStatus(userID, block, 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) {
|
17
|
+
if (err) return rejectFunc(err);
|
18
|
+
resolveFunc();
|
19
|
+
};
|
20
|
+
}
|
21
|
+
|
22
|
+
defaultFuncs
|
23
|
+
.post(`https://www.facebook.com/messaging/${block ? "" : "un"}block_messages/`, ctx.jar, { fbid: userID })
|
24
|
+
.then(utils.saveCookies(ctx.jar))
|
25
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
26
|
+
.then(function (resData) {
|
27
|
+
if (resData.error) throw resData;
|
28
|
+
return callback();
|
29
|
+
})
|
30
|
+
.catch(function (err) {
|
31
|
+
log.error("changeBlockedStatus", err);
|
32
|
+
return callback(err);
|
33
|
+
});
|
34
|
+
return returnPromise;
|
35
|
+
};
|
36
|
+
};
|
@@ -0,0 +1,106 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var utils = require("../utils");
|
4
|
+
var log = require("npmlog");
|
5
|
+
var bluebird = require("bluebird");
|
6
|
+
|
7
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
8
|
+
function handleUpload(image, callback) {
|
9
|
+
var uploads = [];
|
10
|
+
|
11
|
+
var form = {
|
12
|
+
images_only: "true",
|
13
|
+
"attachment[]": image
|
14
|
+
};
|
15
|
+
|
16
|
+
uploads.push(
|
17
|
+
defaultFuncs
|
18
|
+
.postFormData("https://upload.facebook.com/ajax/mercury/upload.php", ctx.jar, form, {})
|
19
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
20
|
+
.then(function (resData) {
|
21
|
+
if (resData.error) throw resData;
|
22
|
+
|
23
|
+
return resData.payload.metadata[0];
|
24
|
+
})
|
25
|
+
);
|
26
|
+
|
27
|
+
// resolve all promises
|
28
|
+
bluebird
|
29
|
+
.all(uploads)
|
30
|
+
.then(resData => callback(null, resData))
|
31
|
+
.catch(function (err) {
|
32
|
+
log.error("handleUpload", err);
|
33
|
+
return callback(err);
|
34
|
+
});
|
35
|
+
}
|
36
|
+
|
37
|
+
return function changeGroupImage(image, threadID, callback) {
|
38
|
+
if (!callback && (utils.getType(threadID) === "Function" || utils.getType(threadID) === "AsyncFunction")) throw { error: "please pass a threadID as a second argument." };
|
39
|
+
|
40
|
+
var resolveFunc = function () { };
|
41
|
+
var rejectFunc = function () { };
|
42
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
43
|
+
resolveFunc = resolve;
|
44
|
+
rejectFunc = reject;
|
45
|
+
});
|
46
|
+
|
47
|
+
if (!callback) {
|
48
|
+
callback = function (err) {
|
49
|
+
if (err) return rejectFunc(err);
|
50
|
+
resolveFunc();
|
51
|
+
};
|
52
|
+
}
|
53
|
+
|
54
|
+
var messageAndOTID = utils.generateOfflineThreadingID();
|
55
|
+
var form = {
|
56
|
+
client: "mercury",
|
57
|
+
action_type: "ma-type:log-message",
|
58
|
+
author: "fbid:" + ctx.userID,
|
59
|
+
author_email: "",
|
60
|
+
ephemeral_ttl_mode: "0",
|
61
|
+
is_filtered_content: false,
|
62
|
+
is_filtered_content_account: false,
|
63
|
+
is_filtered_content_bh: false,
|
64
|
+
is_filtered_content_invalid_app: false,
|
65
|
+
is_filtered_content_quasar: false,
|
66
|
+
is_forward: false,
|
67
|
+
is_spoof_warning: false,
|
68
|
+
is_unread: false,
|
69
|
+
log_message_type: "log:thread-image",
|
70
|
+
manual_retry_cnt: "0",
|
71
|
+
message_id: messageAndOTID,
|
72
|
+
offline_threading_id: messageAndOTID,
|
73
|
+
source: "source:chat:web",
|
74
|
+
"source_tags[0]": "source:chat",
|
75
|
+
status: "0",
|
76
|
+
thread_fbid: threadID,
|
77
|
+
thread_id: "",
|
78
|
+
timestamp: Date.now(),
|
79
|
+
timestamp_absolute: "Today",
|
80
|
+
timestamp_relative: utils.generateTimestampRelative(),
|
81
|
+
timestamp_time_passed: "0"
|
82
|
+
};
|
83
|
+
|
84
|
+
handleUpload(image, function (err, payload) {
|
85
|
+
if (err) return callback(err);
|
86
|
+
|
87
|
+
form["thread_image_id"] = payload[0]["image_id"];
|
88
|
+
form["thread_id"] = threadID;
|
89
|
+
|
90
|
+
defaultFuncs
|
91
|
+
.post("https://www.facebook.com/messaging/set_thread_image/", ctx.jar, form)
|
92
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
93
|
+
.then(function (resData) {
|
94
|
+
// check for errors here
|
95
|
+
if (resData.error) throw resData;
|
96
|
+
return callback();
|
97
|
+
})
|
98
|
+
.catch(function (err) {
|
99
|
+
log.error("changeGroupImage", err);
|
100
|
+
return callback(err);
|
101
|
+
});
|
102
|
+
});
|
103
|
+
|
104
|
+
return returnPromise;
|
105
|
+
};
|
106
|
+
};
|
@@ -0,0 +1,45 @@
|
|
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 changeNickname(nickname, threadID, participantID, 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
|
+
if (!callback) {
|
15
|
+
callback = function (err) {
|
16
|
+
if (err) return rejectFunc(err);
|
17
|
+
resolveFunc();
|
18
|
+
};
|
19
|
+
}
|
20
|
+
|
21
|
+
var form = {
|
22
|
+
nickname: nickname,
|
23
|
+
participant_id: participantID,
|
24
|
+
thread_or_other_fbid: threadID
|
25
|
+
};
|
26
|
+
|
27
|
+
defaultFuncs
|
28
|
+
.post("https://www.facebook.com/messaging/save_thread_nickname/?source=thread_settings&dpr=1", ctx.jar, form)
|
29
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
30
|
+
.then(function (resData) {
|
31
|
+
if (resData.error === 1545014) throw { error: "Trying to change nickname of user isn't in thread" };
|
32
|
+
if (resData.error === 1357031) throw { error: "Trying to change user nickname of a thread that doesn't exist. Have at least one message in the thread before trying to change the user nickname." };
|
33
|
+
|
34
|
+
if (resData.error) throw resData;
|
35
|
+
|
36
|
+
return callback();
|
37
|
+
})
|
38
|
+
.catch(function (err) {
|
39
|
+
log.error("changeNickname", err);
|
40
|
+
return callback(err);
|
41
|
+
});
|
42
|
+
|
43
|
+
return returnPromise;
|
44
|
+
};
|
45
|
+
};
|
@@ -0,0 +1,61 @@
|
|
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 changeThreadColor(color, threadID, callback) {
|
8
|
+
var resolveFunc = function () { };
|
9
|
+
var rejectFunc = function () { };
|
10
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
11
|
+
resolveFunc = resolve;
|
12
|
+
rejectFunc = reject;
|
13
|
+
});
|
14
|
+
|
15
|
+
if (!callback) {
|
16
|
+
callback = function (err) {
|
17
|
+
if (err) return rejectFunc(err);
|
18
|
+
resolveFunc(err);
|
19
|
+
};
|
20
|
+
}
|
21
|
+
|
22
|
+
var validatedColor = color !== null ? color.toLowerCase() : color; // API only accepts lowercase letters in hex string
|
23
|
+
var colorList = Object.keys(api.threadColors).map(function (name) {
|
24
|
+
return api.threadColors[name];
|
25
|
+
});
|
26
|
+
if (!colorList.includes(validatedColor)) throw { error: "The color you are trying to use is not a valid thread color. Use api.threadColors to find acceptable values." };
|
27
|
+
|
28
|
+
var form = {
|
29
|
+
dpr: 1,
|
30
|
+
queries: JSON.stringify({
|
31
|
+
o0: {
|
32
|
+
//This doc_id is valid as of January 31, 2020
|
33
|
+
doc_id: "1727493033983591",
|
34
|
+
query_params: {
|
35
|
+
data: {
|
36
|
+
actor_id: ctx.userID,
|
37
|
+
client_mutation_id: "0",
|
38
|
+
source: "SETTINGS",
|
39
|
+
theme_id: validatedColor,
|
40
|
+
thread_id: threadID
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|
44
|
+
})
|
45
|
+
};
|
46
|
+
|
47
|
+
defaultFuncs
|
48
|
+
.post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
|
49
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
50
|
+
.then(function (resData) {
|
51
|
+
if (resData[resData.length - 1].error_results > 0) throw resData[0].o0.errors;
|
52
|
+
return callback();
|
53
|
+
})
|
54
|
+
.catch(function (err) {
|
55
|
+
log.error("changeThreadColor", err);
|
56
|
+
return callback(err);
|
57
|
+
});
|
58
|
+
|
59
|
+
return returnPromise;
|
60
|
+
};
|
61
|
+
};
|