alicezetion 1.8.4 → 1.8.6
Sign up to get free protection for your applications and to get access to all the features.
- package/.cache/replit/__replit_disk_meta.json +1 -1
- package/.cache/replit/modules.stamp +1 -0
- package/.cache/replit/nix/env.json +1 -1
- package/index.js +376 -210
- package/leiamnash/addExternalModule.js +15 -0
- package/leiamnash/addUserToGroup.js +77 -0
- package/leiamnash/changeAdminStatus.js +47 -0
- package/leiamnash/changeArchivedStatus.js +41 -0
- package/leiamnash/changeAvatar.js +127 -0
- package/leiamnash/changeBio.js +64 -0
- package/leiamnash/changeBlockedStatus.js +36 -0
- package/leiamnash/changeGroupImage.js +105 -0
- package/leiamnash/changeNickname.js +43 -0
- package/leiamnash/changeThreadColor.js +61 -0
- package/leiamnash/changeThreadEmoji.js +41 -0
- package/{src → leiamnash}/chat.js +3 -28
- package/leiamnash/createNewGroup.js +70 -0
- package/leiamnash/createPoll.js +59 -0
- package/leiamnash/deleteMessage.js +44 -0
- package/leiamnash/deleteThread.js +42 -0
- package/leiamnash/forwardAttachment.js +47 -0
- package/leiamnash/forwardMessage.js +0 -0
- package/leiamnash/getCurrentUserID.js +7 -0
- package/leiamnash/getEmojiUrl.js +27 -0
- package/leiamnash/getFriendsList.js +73 -0
- package/leiamnash/getInfoVideo.js +134 -0
- package/leiamnash/getThreadHistory.js +537 -0
- package/leiamnash/getThreadHistoryDeprecated.js +71 -0
- package/{src → leiamnash}/getThreadInfo.js +54 -70
- package/leiamnash/getThreadInfoDeprecated.js +56 -0
- package/leiamnash/getThreadList.js +213 -0
- package/leiamnash/getThreadListDeprecated.js +46 -0
- package/leiamnash/getThreadPictures.js +59 -0
- package/leiamnash/getUserID.js +61 -0
- package/leiamnash/getUserInfo.js +66 -0
- package/leiamnash/handleFriendRequest.js +46 -0
- package/leiamnash/handleMessageRequest.js +47 -0
- package/leiamnash/httpGet.js +47 -0
- package/leiamnash/httpPost.js +47 -0
- package/leiamnash/httpPostFormData.js +42 -0
- package/{src → leiamnash}/listenMqtt.js +6 -16
- package/leiamnash/logout.js +68 -0
- package/leiamnash/markAsDelivered.js +47 -0
- package/leiamnash/markAsRead.js +70 -0
- package/leiamnash/markAsReadAll.js +40 -0
- package/leiamnash/markAsSeen.js +48 -0
- package/leiamnash/muteThread.js +45 -0
- package/leiamnash/react.js +109 -0
- package/{src → leiamnash}/refreshFb_dtsg.js +1 -1
- package/leiamnash/removeUserFromGroup.js +45 -0
- package/leiamnash/resolvePhotoUrl.js +36 -0
- package/leiamnash/searchForThread.js +42 -0
- package/leiamnash/seen.js +40 -0
- package/leiamnash/sendMessage.js +315 -0
- package/leiamnash/sendTypingIndicator.js +70 -0
- package/leiamnash/setMessageReaction.js +103 -0
- package/leiamnash/setPostReaction.js +63 -0
- package/leiamnash/setTitle.js +70 -0
- package/leiamnash/threadColors.js +41 -0
- package/{src/getAccess.js → leiamnash/token.js} +2 -2
- package/leiamnash/unfriend.js +42 -0
- package/leiamnash/unsendMessage.js +39 -0
- package/leiamnash/uploadAttachment.js +96 -0
- package/package.json +3 -6
- package/replit.nix +4 -4
- package/utils.js +176 -119
- package/src/addExternalModule.js +0 -17
- package/src/addUserToGroup.js +0 -113
- package/src/changeAdminStatus.js +0 -79
- package/src/changeArchivedStatus.js +0 -55
- package/src/changeAvatar.js +0 -93
- package/src/changeBio.js +0 -77
- package/src/changeBlockedStatus.js +0 -47
- package/src/changeCover.js +0 -73
- package/src/changeGroupImage.js +0 -132
- package/src/changeName.js +0 -79
- package/src/changeNickname.js +0 -59
- package/src/changeThreadColor.js +0 -65
- package/src/changeThreadEmoji.js +0 -55
- package/src/createNewGroup.js +0 -86
- package/src/createPoll.js +0 -71
- package/src/data/getThreadInfo.json +0 -1
- package/src/deleteMessage.js +0 -56
- package/src/deleteThread.js +0 -56
- package/src/forwardAttachment.js +0 -60
- package/src/getAvatarUser.js +0 -78
- package/src/getCurrentUserID.js +0 -7
- package/src/getEmojiUrl.js +0 -29
- package/src/getFriendsList.js +0 -83
- package/src/getThreadHistory.js +0 -666
- package/src/getThreadList.js +0 -237
- package/src/getThreadPictures.js +0 -79
- package/src/getUserID.js +0 -66
- package/src/getUserInfo.js +0 -163
- package/src/handleFriendRequest.js +0 -61
- package/src/handleMessageRequest.js +0 -65
- package/src/httpGet.js +0 -57
- package/src/httpPost.js +0 -57
- package/src/httpPostFormData.js +0 -63
- package/src/listenNotification.js +0 -88
- package/src/logout.js +0 -275
- package/src/markAsDelivered.js +0 -58
- package/src/markAsRead.js +0 -80
- package/src/markAsReadAll.js +0 -50
- package/src/markAsSeen.js +0 -59
- package/src/muteThread.js +0 -52
- package/src/react.js +0 -117
- package/src/removeUserFromGroup.js +0 -79
- package/src/resolvePhotoUrl.js +0 -45
- package/src/searchForThread.js +0 -53
- package/src/searchStickers.js +0 -52
- package/src/seen.js +0 -50
- package/src/sendMessage.js +0 -477
- package/src/sendMessageMqtt.js +0 -316
- package/src/sendTypingIndicator.js +0 -103
- package/src/setMessageReaction.js +0 -117
- package/src/setPostReaction.js +0 -109
- package/src/setTitle.js +0 -86
- package/src/threadColors.js +0 -131
- package/src/unfriend.js +0 -52
- package/src/unsendMessage.js +0 -49
- /package/{src → leiamnash}/getMessage.js +0 -0
package/utils.js
CHANGED
@@ -1,23 +1,39 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
|
3
|
+
const bluebird = require("bluebird");
|
4
|
+
let request = bluebird.promisify(require("request").defaults({ jar: true, proxy: process.env.FB_PROXY }));
|
4
5
|
const stream = require("stream");
|
5
6
|
const log = require("npmlog");
|
6
7
|
const querystring = require("querystring");
|
7
8
|
const url = require("url");
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
class CustomError extends Error {
|
11
|
+
constructor(obj) {
|
12
|
+
if (typeof obj === 'string')
|
13
|
+
obj = { message: obj };
|
14
|
+
if (typeof obj !== 'object' || obj === null)
|
15
|
+
throw new TypeError('Object required');
|
16
|
+
obj.message ? super(obj.message) : super();
|
17
|
+
Object.assign(this, obj);
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
function setProxy(url) {
|
22
|
+
if (typeof url == "undefined")
|
23
|
+
return request = bluebird.promisify(require("request").defaults({
|
24
|
+
jar: true
|
25
|
+
}));
|
26
|
+
return request = bluebird.promisify(require("request").defaults({
|
27
|
+
jar: true,
|
28
|
+
proxy: url
|
29
|
+
}));
|
14
30
|
}
|
15
31
|
|
16
32
|
function getHeaders(url, options, ctx, customHeader) {
|
17
|
-
|
33
|
+
const headers = {
|
18
34
|
"Content-Type": "application/x-www-form-urlencoded",
|
19
35
|
Referer: "https://www.facebook.com/",
|
20
|
-
Host:
|
36
|
+
Host: url.replace("https://", "").split("/")[0],
|
21
37
|
Origin: "https://www.facebook.com",
|
22
38
|
"User-Agent": options.userAgent,
|
23
39
|
Connection: "keep-alive",
|
@@ -26,10 +42,9 @@ function getHeaders(url, options, ctx, customHeader) {
|
|
26
42
|
if (customHeader) {
|
27
43
|
Object.assign(headers, customHeader);
|
28
44
|
}
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
headers["X-MSGR-Region"] = ctx.region;
|
45
|
+
if (ctx && ctx.region) {
|
46
|
+
headers["X-MSGR-Region"] = ctx.region;
|
47
|
+
}
|
33
48
|
|
34
49
|
return headers;
|
35
50
|
}
|
@@ -43,7 +58,7 @@ function isReadableStream(obj) {
|
|
43
58
|
);
|
44
59
|
}
|
45
60
|
|
46
|
-
function get(url, jar, qs, options, ctx
|
61
|
+
function get(url, jar, qs, options, ctx) {
|
47
62
|
// I'm still confused about this
|
48
63
|
if (getType(qs) === "Object") {
|
49
64
|
for (const prop in qs) {
|
@@ -53,7 +68,7 @@ function get(url, jar, qs, options, ctx, customHeader) {
|
|
53
68
|
}
|
54
69
|
}
|
55
70
|
const op = {
|
56
|
-
headers: getHeaders(url, options, ctx
|
71
|
+
headers: getHeaders(url, options, ctx),
|
57
72
|
timeout: 60000,
|
58
73
|
qs: qs,
|
59
74
|
url: url,
|
@@ -62,39 +77,31 @@ function get(url, jar, qs, options, ctx, customHeader) {
|
|
62
77
|
gzip: true
|
63
78
|
};
|
64
79
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
});
|
69
|
-
request(op, callback);
|
70
|
-
|
71
|
-
return returnPromise;
|
80
|
+
return request(op).then(function (res) {
|
81
|
+
return Array.isArray(res) ? res[0] : res;
|
82
|
+
});
|
72
83
|
}
|
73
84
|
|
74
85
|
function post(url, jar, form, options, ctx, customHeader) {
|
75
|
-
|
76
|
-
|
77
|
-
|
86
|
+
const op = {
|
87
|
+
headers: getHeaders(url, options, ctx, customHeader),
|
88
|
+
timeout: 60000,
|
78
89
|
url: url,
|
79
90
|
method: "POST",
|
80
91
|
form: form,
|
81
92
|
jar: jar,
|
82
93
|
gzip: true
|
83
|
-
}
|
84
|
-
|
85
|
-
var callback;
|
86
|
-
var returnPromise = new Promise(function (resolve, reject) {
|
87
|
-
callback = (error, data) => error != null ? reject(error) : resolve(data);
|
88
|
-
});
|
89
|
-
request(op, callback);
|
94
|
+
};
|
90
95
|
|
91
|
-
return
|
96
|
+
return request(op).then(function (res) {
|
97
|
+
return Array.isArray(res) ? res[0] : res;
|
98
|
+
});
|
92
99
|
}
|
93
100
|
|
94
101
|
function postFormData(url, jar, form, qs, options, ctx) {
|
95
|
-
|
102
|
+
const headers = getHeaders(url, options, ctx);
|
96
103
|
headers["Content-Type"] = "multipart/form-data";
|
97
|
-
|
104
|
+
const op = {
|
98
105
|
headers: headers,
|
99
106
|
timeout: 60000,
|
100
107
|
url: url,
|
@@ -105,13 +112,9 @@ function postFormData(url, jar, form, qs, options, ctx) {
|
|
105
112
|
gzip: true
|
106
113
|
};
|
107
114
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
});
|
112
|
-
request(op, callback);
|
113
|
-
|
114
|
-
return returnPromise;
|
115
|
+
return request(op).then(function (res) {
|
116
|
+
return Array.isArray(res) ? res[0] : res;
|
117
|
+
});
|
115
118
|
}
|
116
119
|
|
117
120
|
function padZeros(val, len) {
|
@@ -748,7 +751,6 @@ function formatDeltaMessage(m) {
|
|
748
751
|
m_offset[i] + m_length[i]
|
749
752
|
);
|
750
753
|
}
|
751
|
-
|
752
754
|
return {
|
753
755
|
type: "message",
|
754
756
|
senderID: formatID(md.actorFbId.toString()),
|
@@ -761,7 +763,7 @@ function formatDeltaMessage(m) {
|
|
761
763
|
mentions: mentions,
|
762
764
|
timestamp: md.timestamp,
|
763
765
|
isGroup: !!md.threadKey.threadFbId,
|
764
|
-
|
766
|
+
participantIDs: m.delta.participants || (md.cid ? md.cid.canonicalParticipantFbids : []) || []
|
765
767
|
};
|
766
768
|
}
|
767
769
|
|
@@ -857,10 +859,6 @@ function formatHistoryMessage(m) {
|
|
857
859
|
// Get a more readable message type for AdminTextMessages
|
858
860
|
function getAdminTextMessageType(type) {
|
859
861
|
switch (type) {
|
860
|
-
case 'unpin_messages_v2':
|
861
|
-
return 'log:unpin-message';
|
862
|
-
case 'pin_messages_v2':
|
863
|
-
return 'log:pin-message';
|
864
862
|
case "change_thread_theme":
|
865
863
|
return "log:thread-color";
|
866
864
|
case "change_thread_icon":
|
@@ -935,7 +933,7 @@ function formatDeltaEvent(m) {
|
|
935
933
|
logMessageBody: m.messageMetadata.adminText,
|
936
934
|
timestamp: m.messageMetadata.timestamp,
|
937
935
|
author: m.messageMetadata.actorFbId,
|
938
|
-
|
936
|
+
participantIDs: (m.participants || []).map(p => p.toString())
|
939
937
|
};
|
940
938
|
}
|
941
939
|
|
@@ -996,7 +994,7 @@ function getFrom(str, startToken, endToken) {
|
|
996
994
|
const lastHalf = str.substring(start);
|
997
995
|
const end = lastHalf.indexOf(endToken);
|
998
996
|
if (end === -1) {
|
999
|
-
throw Error(
|
997
|
+
throw new Error(
|
1000
998
|
"Could not find endTime `" + endToken + "` in the given string."
|
1001
999
|
);
|
1002
1000
|
}
|
@@ -1086,17 +1084,16 @@ function makeDefaults(html, userID, ctx) {
|
|
1086
1084
|
//
|
1087
1085
|
// Ben - July 15th 2017
|
1088
1086
|
const newObj = {
|
1089
|
-
av: userID,
|
1090
1087
|
__user: userID,
|
1091
1088
|
__req: (reqCounter++).toString(36),
|
1092
1089
|
__rev: revision,
|
1093
1090
|
__a: 1,
|
1094
|
-
//__af: siteData.features,
|
1091
|
+
// __af: siteData.features,
|
1095
1092
|
fb_dtsg: ctx.fb_dtsg ? ctx.fb_dtsg : fb_dtsg,
|
1096
1093
|
jazoest: ctx.ttstamp ? ctx.ttstamp : ttstamp
|
1097
|
-
//__spin_r: siteData.__spin_r,
|
1098
|
-
//__spin_b: siteData.__spin_b,
|
1099
|
-
//__spin_t: siteData.__spin_t,
|
1094
|
+
// __spin_r: siteData.__spin_r,
|
1095
|
+
// __spin_b: siteData.__spin_b,
|
1096
|
+
// __spin_t: siteData.__spin_t,
|
1100
1097
|
};
|
1101
1098
|
|
1102
1099
|
// @TODO this is probably not needed.
|
@@ -1147,78 +1144,118 @@ function makeDefaults(html, userID, ctx) {
|
|
1147
1144
|
};
|
1148
1145
|
}
|
1149
1146
|
|
1150
|
-
function parseAndCheckLogin(ctx,
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1147
|
+
function parseAndCheckLogin(ctx, defaultFuncs, retryCount, sourceCall) {
|
1148
|
+
if (retryCount == undefined) {
|
1149
|
+
retryCount = 0;
|
1150
|
+
}
|
1151
|
+
if (sourceCall == undefined) {
|
1152
|
+
try {
|
1153
|
+
throw new Error();
|
1154
|
+
}
|
1155
|
+
catch (e) {
|
1156
|
+
sourceCall = e;
|
1157
|
+
}
|
1158
|
+
}
|
1161
1159
|
return function (data) {
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
const
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1192
|
-
|
1193
|
-
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1160
|
+
return bluebird.try(function () {
|
1161
|
+
log.verbose("parseAndCheckLogin", data.body);
|
1162
|
+
if (data.statusCode >= 500 && data.statusCode < 600) {
|
1163
|
+
if (retryCount >= 5) {
|
1164
|
+
throw new CustomError({
|
1165
|
+
message: "Request retry failed. Check the `res` and `statusCode` property on this error.",
|
1166
|
+
statusCode: data.statusCode,
|
1167
|
+
res: data.body,
|
1168
|
+
error: "Request retry failed. Check the `res` and `statusCode` property on this error.",
|
1169
|
+
sourceCall: sourceCall
|
1170
|
+
});
|
1171
|
+
}
|
1172
|
+
retryCount++;
|
1173
|
+
const retryTime = Math.floor(Math.random() * 5000);
|
1174
|
+
log.warn(
|
1175
|
+
"parseAndCheckLogin",
|
1176
|
+
"Got status code " +
|
1177
|
+
data.statusCode +
|
1178
|
+
" - " +
|
1179
|
+
retryCount +
|
1180
|
+
". attempt to retry in " +
|
1181
|
+
retryTime +
|
1182
|
+
" milliseconds..."
|
1183
|
+
);
|
1184
|
+
const url =
|
1185
|
+
data.request.uri.protocol +
|
1186
|
+
"//" +
|
1187
|
+
data.request.uri.hostname +
|
1188
|
+
data.request.uri.pathname;
|
1189
|
+
if (
|
1190
|
+
data.request.headers["Content-Type"].split(";")[0] ===
|
1191
|
+
"multipart/form-data"
|
1192
|
+
) {
|
1193
|
+
return bluebird
|
1194
|
+
.delay(retryTime)
|
1195
|
+
.then(function () {
|
1196
|
+
return defaultFuncs.postFormData(
|
1197
|
+
url,
|
1198
|
+
ctx.jar,
|
1199
|
+
data.request.formData,
|
1200
|
+
{}
|
1201
|
+
);
|
1202
|
+
})
|
1203
|
+
.then(parseAndCheckLogin(ctx, defaultFuncs, retryCount, sourceCall));
|
1204
|
+
}
|
1205
|
+
else {
|
1206
|
+
return bluebird
|
1207
|
+
.delay(retryTime)
|
1208
|
+
.then(function () {
|
1209
|
+
return defaultFuncs.post(url, ctx.jar, data.request.formData);
|
1210
|
+
})
|
1211
|
+
.then(parseAndCheckLogin(ctx, defaultFuncs, retryCount, sourceCall));
|
1212
|
+
}
|
1213
|
+
}
|
1214
|
+
if (data.statusCode !== 200)
|
1215
|
+
throw new CustomError({
|
1216
|
+
message: "parseAndCheckLogin got status code: " + data.statusCode + ". Bailing out of trying to parse response.",
|
1217
|
+
statusCode: data.statusCode,
|
1218
|
+
res: data.body,
|
1219
|
+
error: "parseAndCheckLogin got status code: " + data.statusCode + ". Bailing out of trying to parse response.",
|
1220
|
+
sourceCall: sourceCall
|
1221
|
+
});
|
1222
|
+
|
1223
|
+
let res = null;
|
1197
1224
|
try {
|
1198
1225
|
res = JSON.parse(makeParsable(data.body));
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1226
|
+
} catch (e) {
|
1227
|
+
throw new CustomError({
|
1228
|
+
message: "JSON.parse error. Check the `detail` property on this error.",
|
1229
|
+
detail: e,
|
1230
|
+
res: data.body,
|
1231
|
+
error: "JSON.parse error. Check the `detail` property on this error.",
|
1232
|
+
sourceCall: sourceCall
|
1233
|
+
});
|
1205
1234
|
}
|
1206
1235
|
|
1207
1236
|
// In some cases the response contains only a redirect URL which should be followed
|
1208
1237
|
if (res.redirect && data.request.method === "GET") {
|
1209
|
-
return
|
1238
|
+
return defaultFuncs
|
1210
1239
|
.get(res.redirect, ctx.jar)
|
1211
|
-
.then(parseAndCheckLogin(ctx,
|
1212
|
-
|
1240
|
+
.then(parseAndCheckLogin(ctx, defaultFuncs, undefined, sourceCall));
|
1241
|
+
}
|
1213
1242
|
|
1214
1243
|
// TODO: handle multiple cookies?
|
1215
|
-
if (
|
1216
|
-
|
1217
|
-
|
1244
|
+
if (
|
1245
|
+
res.jsmods &&
|
1246
|
+
res.jsmods.require &&
|
1247
|
+
Array.isArray(res.jsmods.require[0]) &&
|
1248
|
+
res.jsmods.require[0][0] === "Cookie"
|
1249
|
+
) {
|
1250
|
+
res.jsmods.require[0][3][0] = res.jsmods.require[0][3][0].replace(
|
1251
|
+
"_js_",
|
1252
|
+
""
|
1253
|
+
);
|
1254
|
+
const cookie = formatCookie(res.jsmods.require[0][3], "facebook");
|
1218
1255
|
const cookie2 = formatCookie(res.jsmods.require[0][3], "messenger");
|
1219
1256
|
ctx.jar.setCookie(cookie, "https://www.facebook.com");
|
1220
1257
|
ctx.jar.setCookie(cookie2, "https://www.messenger.com");
|
1221
|
-
|
1258
|
+
}
|
1222
1259
|
|
1223
1260
|
// On every request we check if we got a DTSG and we mutate the context so that we use the latest
|
1224
1261
|
// one for the next requests.
|
@@ -1238,16 +1275,33 @@ function parseAndCheckLogin(ctx, http, retryCount) {
|
|
1238
1275
|
}
|
1239
1276
|
|
1240
1277
|
if (res.error === 1357001) {
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1278
|
+
throw new CustomError({
|
1279
|
+
message: "Facebook blocked login. Please visit https://facebook.com and check your account.",
|
1280
|
+
error: "Not logged in.",
|
1281
|
+
res: res,
|
1282
|
+
statusCode: data.statusCode,
|
1283
|
+
sourceCall: sourceCall
|
1284
|
+
});
|
1244
1285
|
}
|
1245
1286
|
return res;
|
1246
|
-
}
|
1247
|
-
return _try(any);
|
1287
|
+
});
|
1248
1288
|
};
|
1249
1289
|
}
|
1250
1290
|
|
1291
|
+
function checkLiveCookie(ctx, defaultFuncs) {
|
1292
|
+
return defaultFuncs
|
1293
|
+
.get("https://m.facebook.com/me", ctx.jar)
|
1294
|
+
.then(function (res) {
|
1295
|
+
if (res.body.indexOf(ctx.i_userID || ctx.userID) === -1) {
|
1296
|
+
throw new CustomError({
|
1297
|
+
message: "Not logged in.",
|
1298
|
+
error: "Not logged in."
|
1299
|
+
});
|
1300
|
+
}
|
1301
|
+
return true;
|
1302
|
+
});
|
1303
|
+
}
|
1304
|
+
|
1251
1305
|
function saveCookies(jar) {
|
1252
1306
|
return function (res) {
|
1253
1307
|
const cookies = res.headers["set-cookie"] || [];
|
@@ -1379,6 +1433,7 @@ function decodeClientPayload(payload) {
|
|
1379
1433
|
function getAppState(jar) {
|
1380
1434
|
return jar
|
1381
1435
|
.getCookies("https://www.facebook.com")
|
1436
|
+
.concat(jar.getCookies("https://facebook.com"))
|
1382
1437
|
.concat(jar.getCookies("https://www.messenger.com"));
|
1383
1438
|
}
|
1384
1439
|
|
@@ -1396,8 +1451,9 @@ function createAccess_token(jar, globalOptions) {
|
|
1396
1451
|
})
|
1397
1452
|
}
|
1398
1453
|
}
|
1399
|
-
|
1454
|
+
|
1400
1455
|
module.exports = {
|
1456
|
+
CustomError,
|
1401
1457
|
isReadableStream,
|
1402
1458
|
get,
|
1403
1459
|
post,
|
@@ -1436,5 +1492,6 @@ module.exports = {
|
|
1436
1492
|
getAppState,
|
1437
1493
|
getAdminTextMessageType,
|
1438
1494
|
setProxy,
|
1495
|
+
checkLiveCookie,
|
1439
1496
|
createAccess_token
|
1440
1497
|
}
|
package/src/addExternalModule.js
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
var utils = require('../utils');
|
4
|
-
|
5
|
-
module.exports = function (http, api, ctx) {
|
6
|
-
return function addExternalModule(moduleObj) {
|
7
|
-
if (utils.getType(moduleObj) == 'Object') {
|
8
|
-
for (let name in moduleObj) {
|
9
|
-
if (utils.getType(moduleObj[name]) == 'Function')
|
10
|
-
api[name] = moduleObj[name](http, api, ctx);
|
11
|
-
else
|
12
|
-
throw new Error(`Item "${name}" in moduleObj must be a function, not ${utils.getType(moduleObj[name])}!`);
|
13
|
-
}
|
14
|
-
} else
|
15
|
-
throw new Error(`moduleObj must be an object, not ` + utils.getType(moduleObj) + `!`);
|
16
|
-
}
|
17
|
-
}
|
package/src/addUserToGroup.js
DELETED
@@ -1,113 +0,0 @@
|
|
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 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
|
-
|
15
|
-
if (
|
16
|
-
!callback &&
|
17
|
-
(utils.getType(threadID) === "Function" ||
|
18
|
-
utils.getType(threadID) === "AsyncFunction")
|
19
|
-
) {
|
20
|
-
throw new utils.CustomError({ error: "please pass a threadID as a second argument." });
|
21
|
-
}
|
22
|
-
|
23
|
-
if (!callback) {
|
24
|
-
callback = function (err) {
|
25
|
-
if (err) {
|
26
|
-
return rejectFunc(err);
|
27
|
-
}
|
28
|
-
resolveFunc();
|
29
|
-
};
|
30
|
-
}
|
31
|
-
|
32
|
-
if (
|
33
|
-
utils.getType(threadID) !== "Number" &&
|
34
|
-
utils.getType(threadID) !== "String"
|
35
|
-
) {
|
36
|
-
throw new utils.CustomError({
|
37
|
-
error:
|
38
|
-
"ThreadID should be of type Number or String and not " +
|
39
|
-
utils.getType(threadID) +
|
40
|
-
"."
|
41
|
-
});
|
42
|
-
}
|
43
|
-
|
44
|
-
if (utils.getType(userID) !== "Array") {
|
45
|
-
userID = [userID];
|
46
|
-
}
|
47
|
-
|
48
|
-
const messageAndOTID = utils.generateOfflineThreadingID();
|
49
|
-
const form = {
|
50
|
-
client: "mercury",
|
51
|
-
action_type: "ma-type:log-message",
|
52
|
-
author: "fbid:" + (ctx.i_userID || ctx.userID),
|
53
|
-
thread_id: "",
|
54
|
-
timestamp: Date.now(),
|
55
|
-
timestamp_absolute: "Today",
|
56
|
-
timestamp_relative: utils.generateTimestampRelative(),
|
57
|
-
timestamp_time_passed: "0",
|
58
|
-
is_unread: false,
|
59
|
-
is_cleared: false,
|
60
|
-
is_forward: false,
|
61
|
-
is_filtered_content: false,
|
62
|
-
is_filtered_content_bh: false,
|
63
|
-
is_filtered_content_account: false,
|
64
|
-
is_spoof_warning: false,
|
65
|
-
source: "source:chat:web",
|
66
|
-
"source_tags[0]": "source:chat",
|
67
|
-
log_message_type: "log:subscribe",
|
68
|
-
status: "0",
|
69
|
-
offline_threading_id: messageAndOTID,
|
70
|
-
message_id: messageAndOTID,
|
71
|
-
threading_id: utils.generateThreadingID(ctx.clientID),
|
72
|
-
manual_retry_cnt: "0",
|
73
|
-
thread_fbid: threadID
|
74
|
-
};
|
75
|
-
|
76
|
-
for (let i = 0; i < userID.length; i++) {
|
77
|
-
if (
|
78
|
-
utils.getType(userID[i]) !== "Number" &&
|
79
|
-
utils.getType(userID[i]) !== "String"
|
80
|
-
) {
|
81
|
-
throw new utils.CustomError({
|
82
|
-
error:
|
83
|
-
"Elements of userID should be of type Number or String and not " +
|
84
|
-
utils.getType(userID[i]) +
|
85
|
-
"."
|
86
|
-
});
|
87
|
-
}
|
88
|
-
|
89
|
-
form["log_message_data[added_participants][" + i + "]"] =
|
90
|
-
"fbid:" + userID[i];
|
91
|
-
}
|
92
|
-
|
93
|
-
defaultFuncs
|
94
|
-
.post("https://www.facebook.com/messaging/send/", ctx.jar, form)
|
95
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
96
|
-
.then(function (resData) {
|
97
|
-
if (!resData) {
|
98
|
-
throw new utils.CustomError({ error: "Add to group failed." });
|
99
|
-
}
|
100
|
-
if (resData.error) {
|
101
|
-
throw new utils.CustomError(resData);
|
102
|
-
}
|
103
|
-
|
104
|
-
return callback();
|
105
|
-
})
|
106
|
-
.catch(function (err) {
|
107
|
-
log.error("addUserToGroup", err);
|
108
|
-
return callback(err);
|
109
|
-
});
|
110
|
-
|
111
|
-
return returnPromise;
|
112
|
-
};
|
113
|
-
};
|
package/src/changeAdminStatus.js
DELETED
@@ -1,79 +0,0 @@
|
|
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 changeAdminStatus(threadID, adminIDs, adminStatus, callback) {
|
8
|
-
if (utils.getType(threadID) !== "String") {
|
9
|
-
throw new utils.CustomError({ error: "changeAdminStatus: threadID must be a string" });
|
10
|
-
}
|
11
|
-
|
12
|
-
if (utils.getType(adminIDs) === "String") {
|
13
|
-
adminIDs = [adminIDs];
|
14
|
-
}
|
15
|
-
|
16
|
-
if (utils.getType(adminIDs) !== "Array") {
|
17
|
-
throw new utils.CustomError({ error: "changeAdminStatus: adminIDs must be an array or string" });
|
18
|
-
}
|
19
|
-
|
20
|
-
if (utils.getType(adminStatus) !== "Boolean") {
|
21
|
-
throw new utils.CustomError({ error: "changeAdminStatus: adminStatus must be a string" });
|
22
|
-
}
|
23
|
-
|
24
|
-
let resolveFunc = function () { };
|
25
|
-
let rejectFunc = function () { };
|
26
|
-
const returnPromise = new Promise(function (resolve, reject) {
|
27
|
-
resolveFunc = resolve;
|
28
|
-
rejectFunc = reject;
|
29
|
-
});
|
30
|
-
|
31
|
-
if (!callback) {
|
32
|
-
callback = function (err) {
|
33
|
-
if (err) {
|
34
|
-
return rejectFunc(err);
|
35
|
-
}
|
36
|
-
resolveFunc();
|
37
|
-
};
|
38
|
-
}
|
39
|
-
|
40
|
-
if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
|
41
|
-
throw new utils.CustomError({ error: "changeAdminStatus: callback is not a function" });
|
42
|
-
}
|
43
|
-
|
44
|
-
const form = {
|
45
|
-
"thread_fbid": threadID
|
46
|
-
};
|
47
|
-
|
48
|
-
let i = 0;
|
49
|
-
for (const u of adminIDs) {
|
50
|
-
form[`admin_ids[${i++}]`] = u;
|
51
|
-
}
|
52
|
-
form["add"] = adminStatus;
|
53
|
-
|
54
|
-
defaultFuncs
|
55
|
-
.post("https://www.facebook.com/messaging/save_admins/?dpr=1", ctx.jar, form)
|
56
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
57
|
-
.then(function (resData) {
|
58
|
-
if (resData.error) {
|
59
|
-
switch (resData.error) {
|
60
|
-
case 1976004:
|
61
|
-
throw new utils.CustomError({ error: "Cannot alter admin status: you are not an admin.", rawResponse: resData });
|
62
|
-
case 1357031:
|
63
|
-
throw new utils.CustomError({ error: "Cannot alter admin status: this thread is not a group chat.", rawResponse: resData });
|
64
|
-
default:
|
65
|
-
throw new utils.CustomError({ error: "Cannot alter admin status: unknown error.", rawResponse: resData });
|
66
|
-
}
|
67
|
-
}
|
68
|
-
|
69
|
-
callback();
|
70
|
-
})
|
71
|
-
.catch(function (err) {
|
72
|
-
log.error("changeAdminStatus", err);
|
73
|
-
return callback(err);
|
74
|
-
});
|
75
|
-
|
76
|
-
return returnPromise;
|
77
|
-
};
|
78
|
-
};
|
79
|
-
|