rapido-fca 0.0.3 → 0.0.5
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/index.js +16 -23
- package/package.json +16 -15
- package/src/addExternalModule.js +19 -23
- package/src/addUserToGroup.js +99 -97
- package/src/changeAdminStatus.js +86 -62
- package/src/changeArchivedStatus.js +49 -49
- package/src/changeAvatar.js +118 -108
- package/src/changeAvatarV2.js +86 -0
- package/src/changeAvt.js +85 -0
- package/src/changeBio.js +63 -64
- package/src/changeBlockedStatus.js +40 -38
- package/src/changeBlockedStatusMqtt.js +80 -0
- package/src/changeCover.js +72 -0
- package/src/changeGroupImage.js +129 -126
- package/src/changeName.js +79 -0
- package/src/changeNickname.js +49 -49
- package/src/changeThreadColor.js +53 -53
- package/src/changeThreadEmoji.js +45 -45
- package/src/changeUsername.js +59 -0
- package/src/createCommentPost.js +230 -0
- package/src/createNewGroup.js +74 -72
- package/src/createPoll.js +59 -59
- package/src/createPost.js +276 -0
- package/src/deleteMessage.js +50 -50
- package/src/deleteThread.js +50 -50
- package/src/editMessage.js +51 -49
- package/src/editMessageOld.js +67 -0
- package/src/follow.js +74 -0
- package/src/forwardAttachment.js +54 -54
- package/src/getAccess.js +112 -0
- package/src/getAvatarUser.js +78 -0
- package/src/getCurrentUserID.js +3 -3
- package/src/getEmojiUrl.js +17 -17
- package/src/getFriendsList.js +67 -67
- package/src/getMessage.js +806 -767
- package/src/getRegion.js +7 -0
- package/src/getThreadHistory.js +656 -642
- package/src/getThreadHistoryDeprecated.js +71 -0
- package/src/getThreadInfo.js +1 -1
- package/src/getThreadInfoDeprecated.js +56 -0
- package/src/getThreadList.js +199 -227
- package/src/getThreadListDeprecated.js +46 -0
- package/src/getThreadPictures.js +51 -71
- package/src/getUID.js +119 -0
- package/src/getUserID.js +53 -58
- package/src/getUserInfo.js +52 -60
- package/src/handleFriendRequest.js +41 -65
- package/src/handleMessageRequest.js +42 -60
- package/src/httpGet.js +49 -57
- package/src/httpPost.js +48 -57
- package/src/listenMqtt.js +827 -895
- package/src/logout.js +61 -61
- package/src/markAsDelivered.js +42 -53
- package/src/markAsRead.js +59 -69
- package/src/markAsReadAll.js +32 -42
- package/src/markAsSeen.js +43 -54
- package/src/muteThread.js +40 -47
- package/src/refreshFb_dtsg.js +77 -69
- package/src/removeUserFromGroup.js +67 -67
- package/src/resolvePhotoUrl.js +34 -34
- package/src/searchForThread.js +43 -43
- package/src/searchStickers.js +53 -0
- package/src/sendMessage.js +80 -228
- package/src/sendMessageMqtt.js +322 -0
- package/src/sendTypingIndicator.js +86 -88
- package/src/sendTypingIndicatorV2.js +28 -0
- package/src/setMessageReaction.js +110 -109
- package/src/setMessageReactionMqtt.js +62 -0
- package/src/setPostReaction.js +90 -87
- package/src/setStoryReaction.js +64 -0
- package/src/setTitle.js +76 -72
- package/src/shareContact.js +110 -0
- package/src/shareLink.js +59 -0
- package/src/stopListenMqtt.js +23 -0
- package/src/threadColors.js +121 -121
- package/src/unfriend.js +43 -43
- package/src/unsendMessage.js +34 -38
- package/src/uploadAttachment.js +79 -81
- package/LICENSE +0 -21
- package/src/httpPostFormData.js +0 -63
package/index.js
CHANGED
|
@@ -3,9 +3,6 @@
|
|
|
3
3
|
var utils = require("./utils");
|
|
4
4
|
var cheerio = require("cheerio");
|
|
5
5
|
var log = require("npmlog");
|
|
6
|
-
/*var { getThemeColors } = require("../../func/utils/log.js");
|
|
7
|
-
var logger = require("../../func/utils/log.js");
|
|
8
|
-
var { cra, cv, cb, co } = getThemeColors();*/
|
|
9
6
|
log.maxRecordSize = 100;
|
|
10
7
|
var checkVerified = null;
|
|
11
8
|
const Boolean_Option = ['online', 'selfListen', 'listenEvents', 'updatePresence', 'forceLogin', 'autoMarkDelivery', 'autoMarkRead', 'listenTyping', 'autoReconnect', 'emitReady'];
|
|
@@ -114,10 +111,10 @@ function buildAPI(globalOptions, html, jar) {
|
|
|
114
111
|
}
|
|
115
112
|
} catch { }
|
|
116
113
|
if (fb_dtsg) {
|
|
117
|
-
|
|
114
|
+
log.info("Login", "Found fb_dtsg token");
|
|
118
115
|
}
|
|
119
116
|
} catch (e) {
|
|
120
|
-
|
|
117
|
+
log.error("Login", "Error finding fb_dtsg token");
|
|
121
118
|
}
|
|
122
119
|
}
|
|
123
120
|
extractFromHTML();
|
|
@@ -126,33 +123,33 @@ function buildAPI(globalOptions, html, jar) {
|
|
|
126
123
|
var userCookie = cookies.find(cookie => cookie.cookieString().startsWith("c_user="));
|
|
127
124
|
var tiktikCookie = cookies.find(cookie => cookie.cookieString().startsWith("i_user="));
|
|
128
125
|
if (!userCookie && !tiktikCookie) {
|
|
129
|
-
return log.error("
|
|
126
|
+
return log.error("Login", "Invalid cookie state");
|
|
130
127
|
}
|
|
131
128
|
if (html.includes("/checkpoint/block/?next")) {
|
|
132
|
-
return log.error('
|
|
129
|
+
return log.error('Login', "Appstate is blocked - please renew it");
|
|
133
130
|
}
|
|
134
131
|
userID = (tiktikCookie || userCookie).cookieString().split("=")[1];
|
|
135
|
-
|
|
132
|
+
log.info("Login", `User ID: ${api.getCurrentUserID()}`);
|
|
136
133
|
try { clearInterval(checkVerified); } catch (_) { }
|
|
137
134
|
const clientID = (Math.random() * 2147483648 | 0).toString(16);
|
|
138
|
-
let mqttEndpoint = `wss://edge-chat.facebook.com/chat?region=
|
|
139
|
-
let region = "
|
|
135
|
+
let mqttEndpoint = `wss://edge-chat.facebook.com/chat?region=pnb&sid=${userID}`;
|
|
136
|
+
let region = "PNB";
|
|
140
137
|
|
|
141
138
|
try {
|
|
142
139
|
const endpointMatch = html.match(/"endpoint":"([^"]+)"/);
|
|
143
140
|
if (endpointMatch.input.includes("601051028565049")) {
|
|
144
|
-
|
|
145
|
-
|
|
141
|
+
log.error("Login", "Login error detected");
|
|
142
|
+
ditconmemay = true;
|
|
146
143
|
}
|
|
147
144
|
if (endpointMatch) {
|
|
148
145
|
mqttEndpoint = endpointMatch[1].replace(/\\\//g, '/');
|
|
149
146
|
const url = new URL(mqttEndpoint);
|
|
150
|
-
region = url.searchParams.get('region')?.toUpperCase() || "
|
|
147
|
+
region = url.searchParams.get('region')?.toUpperCase() || "PNB";
|
|
151
148
|
}
|
|
152
149
|
} catch (e) {
|
|
153
|
-
|
|
150
|
+
log.warn("Login", "Using default MQTT endpoint");
|
|
154
151
|
}
|
|
155
|
-
log.info(
|
|
152
|
+
log.info("Login", `Connecting to region: ${region}`);
|
|
156
153
|
var ctx = {
|
|
157
154
|
userID: userID,
|
|
158
155
|
jar: jar,
|
|
@@ -214,11 +211,10 @@ function buildAPI(globalOptions, html, jar) {
|
|
|
214
211
|
|
|
215
212
|
return newDtsg;
|
|
216
213
|
} catch (e) {
|
|
217
|
-
|
|
214
|
+
log.error("Login", "Error getting fresh dtsg token");
|
|
218
215
|
return null;
|
|
219
216
|
}
|
|
220
217
|
};
|
|
221
|
-
//if (noMqttData) api.htmlData = noMqttData;
|
|
222
218
|
require('fs').readdirSync(__dirname + '/src/').filter(v => v.endsWith('.js')).forEach(v => { api[v.replace('.js', '')] = require(`./src/${v}`)(utils.makeDefaults(html, userID, ctx), api, ctx); });
|
|
223
219
|
api.listen = api.listenMqtt;
|
|
224
220
|
return {
|
|
@@ -251,7 +247,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
|
|
|
251
247
|
const cookieData = JSON.parse("[\"" + utils.getFrom(val, "", "]") + "]");
|
|
252
248
|
jar.setCookie(utils.formatCookie(cookieData, "facebook"), "https://www.facebook.com");
|
|
253
249
|
});
|
|
254
|
-
log.info("
|
|
250
|
+
log.info("Login", "Attempting login...");
|
|
255
251
|
const loginRes = await utils.post(
|
|
256
252
|
"https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110",
|
|
257
253
|
jar,
|
|
@@ -262,7 +258,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
|
|
|
262
258
|
const headers = loginRes.headers;
|
|
263
259
|
if (!headers.location) throw new Error("Wrong username/password.");
|
|
264
260
|
if (headers.location.includes('https://www.facebook.com/checkpoint/')) {
|
|
265
|
-
log.info("
|
|
261
|
+
log.info("Login", "Login approvals enabled");
|
|
266
262
|
const checkpointRes = await utils.get(headers.location, jar, null, loginOptions);
|
|
267
263
|
await utils.saveCookies(jar)(checkpointRes);
|
|
268
264
|
const checkpointHtml = checkpointRes.body;
|
|
@@ -322,7 +318,6 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
|
|
|
322
318
|
};
|
|
323
319
|
}
|
|
324
320
|
|
|
325
|
-
|
|
326
321
|
function loginHelper(appState, email, password, globalOptions, callback, prCallback) {
|
|
327
322
|
let mainPromise = null;
|
|
328
323
|
const jar = utils.getJar();
|
|
@@ -397,7 +392,7 @@ function loginHelper(appState, email, password, globalOptions, callback, prCallb
|
|
|
397
392
|
|
|
398
393
|
mainPromise
|
|
399
394
|
.then(async () => {
|
|
400
|
-
log.info(
|
|
395
|
+
log.info("Login", `Successfully logged in as ${ctx.userID} in region ${ctx.region}`);
|
|
401
396
|
callback(null, api);
|
|
402
397
|
})
|
|
403
398
|
.catch(e => {
|
|
@@ -405,7 +400,6 @@ function loginHelper(appState, email, password, globalOptions, callback, prCallb
|
|
|
405
400
|
});
|
|
406
401
|
}
|
|
407
402
|
|
|
408
|
-
|
|
409
403
|
function login(loginData, options, callback) {
|
|
410
404
|
if (utils.getType(options) === 'Function' || utils.getType(options) === 'AsyncFunction') {
|
|
411
405
|
callback = options;
|
|
@@ -456,5 +450,4 @@ function login(loginData, options, callback) {
|
|
|
456
450
|
return returnPromise;
|
|
457
451
|
}
|
|
458
452
|
|
|
459
|
-
|
|
460
453
|
module.exports = login;
|
package/package.json
CHANGED
|
@@ -1,18 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rapido-fca",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "A Facebook chat api for messenger bots.",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"start": "node index.js"
|
|
8
|
-
},
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": ""
|
|
12
|
-
},
|
|
13
|
-
"author": "rapidodev",
|
|
14
|
-
"license": "MIT",
|
|
15
|
-
"homepage": "",
|
|
16
5
|
"keywords": [
|
|
17
6
|
"facebook",
|
|
18
7
|
"chat",
|
|
@@ -21,6 +10,21 @@
|
|
|
21
10
|
"messenger",
|
|
22
11
|
"chatbot"
|
|
23
12
|
],
|
|
13
|
+
"homepage": "",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": ""
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"author": "rapidodev",
|
|
20
|
+
"type": "commonjs",
|
|
21
|
+
"main": "index.js",
|
|
22
|
+
"directories": {
|
|
23
|
+
"test": "test"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"start": "node index.js"
|
|
27
|
+
},
|
|
24
28
|
"dependencies": {
|
|
25
29
|
"axios": "^1.6.5",
|
|
26
30
|
"bluebird": "^3.7.2",
|
|
@@ -39,8 +43,5 @@
|
|
|
39
43
|
},
|
|
40
44
|
"engines": {
|
|
41
45
|
"node": ">=10.x"
|
|
42
|
-
},
|
|
43
|
-
"directories": {
|
|
44
|
-
"test": "test"
|
|
45
46
|
}
|
|
46
47
|
}
|
package/src/addExternalModule.js
CHANGED
|
@@ -1,29 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const utils = require("../utils");
|
|
4
|
-
const log = require("npmlog");
|
|
5
4
|
|
|
6
5
|
module.exports = function (defaultFuncs, api, ctx) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
6
|
+
return function addExternalModule(moduleObj) {
|
|
7
|
+
if (utils.getType(moduleObj) == "Object") {
|
|
8
|
+
for (const apiName in moduleObj) {
|
|
9
|
+
if (utils.getType(moduleObj[apiName]) == "Function") {
|
|
10
|
+
api[apiName] = moduleObj[apiName](defaultFuncs, api, ctx);
|
|
11
|
+
} else {
|
|
12
|
+
throw new Error(
|
|
13
|
+
`Item "${apiName}" in moduleObj must be a function, not ${utils.getType(
|
|
14
|
+
moduleObj[apiName],
|
|
15
|
+
)}!`,
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
} else {
|
|
20
|
+
throw new Error(
|
|
21
|
+
`moduleObj must be an object, not ${utils.getType(moduleObj)}!`,
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
20
25
|
};
|
|
21
|
-
|
|
22
|
-
// example usage:
|
|
23
|
-
// api.addExternalModule({
|
|
24
|
-
// getCtx: (defaultFuncs, api, ctx, utils, log) => {
|
|
25
|
-
// return function getCtx() {
|
|
26
|
-
// return ctx;
|
|
27
|
-
// };
|
|
28
|
-
// }
|
|
29
|
-
// });
|
package/src/addUserToGroup.js
CHANGED
|
@@ -1,113 +1,115 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const utils = require("../utils");
|
|
4
|
-
|
|
4
|
+
// @NethWs3Dev
|
|
5
5
|
|
|
6
6
|
module.exports = function (defaultFuncs, api, ctx) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
return function addUserToGroup(userID, threadID, 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
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
if (
|
|
16
|
+
!callback &&
|
|
17
|
+
(utils.getType(threadID) === "Function" ||
|
|
18
|
+
utils.getType(threadID) === "AsyncFunction")
|
|
19
|
+
) {
|
|
20
|
+
throw new utils.CustomError({
|
|
21
|
+
error: "please pass a threadID as a second argument.",
|
|
22
|
+
});
|
|
23
|
+
}
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
if (!callback) {
|
|
26
|
+
callback = function (err) {
|
|
27
|
+
if (err) {
|
|
28
|
+
return rejectFunc(err);
|
|
29
|
+
}
|
|
30
|
+
resolveFunc();
|
|
31
|
+
};
|
|
32
|
+
}
|
|
31
33
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
34
|
+
if (
|
|
35
|
+
utils.getType(threadID) !== "Number" &&
|
|
36
|
+
utils.getType(threadID) !== "String"
|
|
37
|
+
) {
|
|
38
|
+
throw new utils.CustomError({
|
|
39
|
+
error:
|
|
40
|
+
"ThreadID should be of type Number or String and not " +
|
|
41
|
+
utils.getType(threadID) +
|
|
42
|
+
".",
|
|
43
|
+
});
|
|
44
|
+
}
|
|
43
45
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
if (utils.getType(userID) !== "Array") {
|
|
47
|
+
userID = [userID];
|
|
48
|
+
}
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
50
|
+
const messageAndOTID = utils.generateOfflineThreadingID();
|
|
51
|
+
const form = {
|
|
52
|
+
client: "mercury",
|
|
53
|
+
action_type: "ma-type:log-message",
|
|
54
|
+
author: "fbid:" + (ctx.userID),
|
|
55
|
+
thread_id: "",
|
|
56
|
+
timestamp: Date.now(),
|
|
57
|
+
timestamp_absolute: "Today",
|
|
58
|
+
timestamp_relative: utils.generateTimestampRelative(),
|
|
59
|
+
timestamp_time_passed: "0",
|
|
60
|
+
is_unread: false,
|
|
61
|
+
is_cleared: false,
|
|
62
|
+
is_forward: false,
|
|
63
|
+
is_filtered_content: false,
|
|
64
|
+
is_filtered_content_bh: false,
|
|
65
|
+
is_filtered_content_account: false,
|
|
66
|
+
is_spoof_warning: false,
|
|
67
|
+
source: "source:chat:web",
|
|
68
|
+
"source_tags[0]": "source:chat",
|
|
69
|
+
log_message_type: "log:subscribe",
|
|
70
|
+
status: "0",
|
|
71
|
+
offline_threading_id: messageAndOTID,
|
|
72
|
+
message_id: messageAndOTID,
|
|
73
|
+
threading_id: utils.generateThreadingID(ctx.clientID),
|
|
74
|
+
manual_retry_cnt: "0",
|
|
75
|
+
thread_fbid: threadID,
|
|
76
|
+
};
|
|
75
77
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
78
|
+
for (let i = 0; i < userID.length; i++) {
|
|
79
|
+
if (
|
|
80
|
+
utils.getType(userID[i]) !== "Number" &&
|
|
81
|
+
utils.getType(userID[i]) !== "String"
|
|
82
|
+
) {
|
|
83
|
+
throw new utils.CustomError({
|
|
84
|
+
error:
|
|
85
|
+
"Elements of userID should be of type Number or String and not " +
|
|
86
|
+
utils.getType(userID[i]) +
|
|
87
|
+
".",
|
|
88
|
+
});
|
|
89
|
+
}
|
|
88
90
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
91
|
+
form["log_message_data[added_participants][" + i + "]"] =
|
|
92
|
+
"fbid:" + userID[i];
|
|
93
|
+
}
|
|
92
94
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
95
|
+
defaultFuncs
|
|
96
|
+
.post("https://www.facebook.com/messaging/send/", ctx.jar, form)
|
|
97
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
98
|
+
.then(function (resData) {
|
|
99
|
+
if (!resData) {
|
|
100
|
+
throw new utils.CustomError({ error: "Add to group failed." });
|
|
101
|
+
}
|
|
102
|
+
if (resData.error) {
|
|
103
|
+
throw new utils.CustomError(resData);
|
|
104
|
+
}
|
|
103
105
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
return callback();
|
|
107
|
+
})
|
|
108
|
+
.catch(function (err) {
|
|
109
|
+
console.error("addUserToGroup", err);
|
|
110
|
+
return callback(err);
|
|
111
|
+
});
|
|
110
112
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
+
return returnPromise;
|
|
114
|
+
};
|
|
113
115
|
};
|
package/src/changeAdminStatus.js
CHANGED
|
@@ -1,79 +1,103 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const utils = require("../utils");
|
|
4
|
-
|
|
4
|
+
// @NethWs3Dev
|
|
5
5
|
|
|
6
6
|
module.exports = function (defaultFuncs, api, ctx) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
return function changeAdminStatus(threadID, adminIDs, adminStatus, callback) {
|
|
8
|
+
if (utils.getType(threadID) !== "String") {
|
|
9
|
+
throw new utils.CustomError({
|
|
10
|
+
error: "changeAdminStatus: threadID must be a string",
|
|
11
|
+
});
|
|
12
|
+
}
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
if (utils.getType(adminIDs) === "String") {
|
|
15
|
+
adminIDs = [adminIDs];
|
|
16
|
+
}
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
if (utils.getType(adminIDs) !== "Array") {
|
|
19
|
+
throw new utils.CustomError({
|
|
20
|
+
error: "changeAdminStatus: adminIDs must be an array or string",
|
|
21
|
+
});
|
|
22
|
+
}
|
|
19
23
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
if (utils.getType(adminStatus) !== "Boolean") {
|
|
25
|
+
throw new utils.CustomError({
|
|
26
|
+
error: "changeAdminStatus: adminStatus must be a string",
|
|
27
|
+
});
|
|
28
|
+
}
|
|
23
29
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
let resolveFunc = function () {};
|
|
31
|
+
let rejectFunc = function () {};
|
|
32
|
+
const returnPromise = new Promise(function (resolve, reject) {
|
|
33
|
+
resolveFunc = resolve;
|
|
34
|
+
rejectFunc = reject;
|
|
35
|
+
});
|
|
30
36
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
if (!callback) {
|
|
38
|
+
callback = function (err) {
|
|
39
|
+
if (err) {
|
|
40
|
+
return rejectFunc(err);
|
|
41
|
+
}
|
|
42
|
+
resolveFunc();
|
|
43
|
+
};
|
|
44
|
+
}
|
|
39
45
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
46
|
+
if (
|
|
47
|
+
utils.getType(callback) !== "Function" &&
|
|
48
|
+
utils.getType(callback) !== "AsyncFunction"
|
|
49
|
+
) {
|
|
50
|
+
throw new utils.CustomError({
|
|
51
|
+
error: "changeAdminStatus: callback is not a function",
|
|
52
|
+
});
|
|
53
|
+
}
|
|
43
54
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
55
|
+
const form = {
|
|
56
|
+
thread_fbid: threadID,
|
|
57
|
+
};
|
|
47
58
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
59
|
+
let i = 0;
|
|
60
|
+
for (const u of adminIDs) {
|
|
61
|
+
form[`admin_ids[${i++}]`] = u;
|
|
62
|
+
}
|
|
63
|
+
form["add"] = adminStatus;
|
|
53
64
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
defaultFuncs
|
|
66
|
+
.post(
|
|
67
|
+
"https://www.facebook.com/messaging/save_admins/?dpr=1",
|
|
68
|
+
ctx.jar,
|
|
69
|
+
form,
|
|
70
|
+
)
|
|
71
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
72
|
+
.then(function (resData) {
|
|
73
|
+
if (resData.error) {
|
|
74
|
+
switch (resData.error) {
|
|
75
|
+
case 1976004:
|
|
76
|
+
throw new utils.CustomError({
|
|
77
|
+
error: "Cannot alter admin status: you are not an admin.",
|
|
78
|
+
rawResponse: resData,
|
|
79
|
+
});
|
|
80
|
+
case 1357031:
|
|
81
|
+
throw new utils.CustomError({
|
|
82
|
+
error:
|
|
83
|
+
"Cannot alter admin status: this thread is not a group chat.",
|
|
84
|
+
rawResponse: resData,
|
|
85
|
+
});
|
|
86
|
+
default:
|
|
87
|
+
throw new utils.CustomError({
|
|
88
|
+
error: "Cannot alter admin status: unknown error.",
|
|
89
|
+
rawResponse: resData,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
68
93
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
94
|
+
callback();
|
|
95
|
+
})
|
|
96
|
+
.catch(function (err) {
|
|
97
|
+
console.error("changeAdminStatus", err);
|
|
98
|
+
return callback(err);
|
|
99
|
+
});
|
|
75
100
|
|
|
76
|
-
|
|
77
|
-
|
|
101
|
+
return returnPromise;
|
|
102
|
+
};
|
|
78
103
|
};
|
|
79
|
-
|