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