@dongdev/fca-unofficial 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/.travis.yml +6 -6
- package/CHANGELOG.md +1 -1
- package/DOCS.md +1738 -1738
- package/LICENSE-MIT +21 -21
- package/README.md +219 -219
- package/index.js +267 -569
- package/lib/login.js +0 -0
- package/package.json +3 -3
- package/src/addExternalModule.js +19 -15
- package/src/addUserToGroup.js +113 -77
- package/src/changeAdminStatus.js +79 -47
- package/src/changeArchivedStatus.js +55 -41
- package/src/changeAvatar.js +126 -0
- package/src/changeBio.js +66 -54
- package/src/changeBlockedStatus.js +40 -29
- package/src/changeGroupImage.js +127 -101
- package/src/changeNickname.js +50 -36
- package/src/changeThreadColor.js +65 -61
- package/src/changeThreadEmoji.js +55 -41
- package/src/createNewGroup.js +86 -70
- package/src/createPoll.js +71 -59
- package/src/deleteMessage.js +56 -44
- package/src/deleteThread.js +56 -42
- package/src/forwardAttachment.js +60 -47
- package/src/getCurrentUserID.js +7 -7
- package/src/getEmojiUrl.js +29 -27
- package/src/getFriendsList.js +83 -73
- package/src/getMessage.js +796 -0
- package/src/getThreadHistory.js +666 -537
- package/src/getThreadInfo.js +232 -171
- package/src/getThreadList.js +241 -213
- package/src/getThreadPictures.js +79 -59
- package/src/getUserID.js +66 -61
- package/src/getUserInfo.js +74 -66
- package/src/handleFriendRequest.js +61 -46
- package/src/handleMessageRequest.js +65 -47
- package/src/httpGet.js +52 -44
- package/src/httpPost.js +52 -43
- package/src/httpPostFormData.js +63 -0
- package/src/listenMqtt.js +877 -709
- package/src/logout.js +62 -55
- package/src/markAsDelivered.js +58 -47
- package/src/markAsRead.js +80 -70
- package/src/markAsReadAll.js +49 -39
- package/src/markAsSeen.js +59 -48
- package/src/muteThread.js +52 -45
- package/src/postFormData.js +46 -0
- package/src/refreshFb_dtsg.js +81 -0
- package/src/removeUserFromGroup.js +79 -45
- package/src/resolvePhotoUrl.js +45 -36
- package/src/searchForThread.js +53 -42
- package/src/sendMessage.js +328 -328
- package/src/sendMessageMqtt.js +316 -0
- package/src/sendTypingIndicator.js +103 -70
- package/src/setMessageReaction.js +106 -98
- package/src/setPostReaction.js +102 -95
- package/src/setTitle.js +86 -70
- package/src/threadColors.js +131 -41
- package/src/unfriend.js +52 -42
- package/src/unsendMessage.js +49 -39
- package/src/uploadAttachment.js +95 -0
- package/utils.js +1470 -1196
- package/.gitattributes +0 -2
- package/src/Screenshot.js +0 -83
- package/src/changeAvt.js +0 -85
- package/src/getThreadHistoryDeprecated.js +0 -71
- package/src/getThreadInfoDeprecated.js +0 -56
- package/src/getThreadListDeprecated.js +0 -46
- package/src/shareContact.js +0 -46
- package/test/data/shareAttach.js +0 -146
- package/test/data/something.mov +0 -0
- package/test/data/test.png +0 -0
- package/test/data/test.txt +0 -7
- package/test/example-config.json +0 -18
- package/test/test-page.js +0 -140
- package/test/test.js +0 -385
@@ -0,0 +1,316 @@
|
|
1
|
+
var utils = require("../utils");
|
2
|
+
var log = require("npmlog");
|
3
|
+
var bluebird = require("bluebird");
|
4
|
+
|
5
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
6
|
+
function uploadAttachment(attachments, callback) {
|
7
|
+
callback = callback || function () { };
|
8
|
+
var uploads = [];
|
9
|
+
|
10
|
+
// create an array of promises
|
11
|
+
for (var i = 0; i < attachments.length; i++) {
|
12
|
+
if (!utils.isReadableStream(attachments[i])) {
|
13
|
+
throw {
|
14
|
+
error:
|
15
|
+
"Attachment should be a readable stream and not " +
|
16
|
+
utils.getType(attachments[i]) +
|
17
|
+
"."
|
18
|
+
};
|
19
|
+
}
|
20
|
+
|
21
|
+
var form = {
|
22
|
+
upload_1024: attachments[i],
|
23
|
+
voice_clip: "true"
|
24
|
+
};
|
25
|
+
|
26
|
+
uploads.push(
|
27
|
+
defaultFuncs
|
28
|
+
.postFormData(
|
29
|
+
"https://upload.facebook.com/ajax/mercury/upload.php",
|
30
|
+
ctx.jar,
|
31
|
+
form,
|
32
|
+
{}
|
33
|
+
)
|
34
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
35
|
+
.then(function (resData) {
|
36
|
+
if (resData.error) {
|
37
|
+
throw resData;
|
38
|
+
}
|
39
|
+
|
40
|
+
// We have to return the data unformatted unless we want to change it
|
41
|
+
// back in sendMessage.
|
42
|
+
return resData.payload.metadata[0];
|
43
|
+
})
|
44
|
+
);
|
45
|
+
}
|
46
|
+
|
47
|
+
// resolve all promises
|
48
|
+
bluebird
|
49
|
+
.all(uploads)
|
50
|
+
.then(function (resData) {
|
51
|
+
callback(null, resData);
|
52
|
+
})
|
53
|
+
.catch(function (err) {
|
54
|
+
log.error("uploadAttachment", err);
|
55
|
+
return callback(err);
|
56
|
+
});
|
57
|
+
}
|
58
|
+
|
59
|
+
let variance = 0;
|
60
|
+
const epoch_id = () => Math.floor(Date.now() * (4194304 + (variance = (variance + 0.1) % 5)));
|
61
|
+
const emojiSizes = {
|
62
|
+
small: 1,
|
63
|
+
medium: 2,
|
64
|
+
large: 3
|
65
|
+
};
|
66
|
+
|
67
|
+
function handleEmoji(msg, form, callback, cb) {
|
68
|
+
if (msg.emojiSize != null && msg.emoji == null) {
|
69
|
+
return callback({ error: "emoji property is empty" });
|
70
|
+
}
|
71
|
+
if (msg.emoji) {
|
72
|
+
if (!msg.emojiSize) {
|
73
|
+
msg.emojiSize = "small";
|
74
|
+
}
|
75
|
+
if (
|
76
|
+
msg.emojiSize !== "small" &&
|
77
|
+
msg.emojiSize !== "medium" &&
|
78
|
+
msg.emojiSize !== "large" &&
|
79
|
+
(isNaN(msg.emojiSize) || msg.emojiSize < 1 || msg.emojiSize > 3)
|
80
|
+
) {
|
81
|
+
return callback({ error: "emojiSize property is invalid" });
|
82
|
+
}
|
83
|
+
|
84
|
+
form.payload.tasks[0].payload.send_type = 1;
|
85
|
+
form.payload.tasks[0].payload.text = msg.emoji;
|
86
|
+
form.payload.tasks[0].payload.hot_emoji_size = !isNaN(msg.emojiSize) ? msg.emojiSize : emojiSizes[msg.emojiSize];
|
87
|
+
}
|
88
|
+
cb();
|
89
|
+
}
|
90
|
+
|
91
|
+
function handleSticker(msg, form, callback, cb) {
|
92
|
+
if (msg.sticker) {
|
93
|
+
form.payload.tasks[0].payload.send_type = 2;
|
94
|
+
form.payload.tasks[0].payload.sticker_id = msg.sticker;
|
95
|
+
}
|
96
|
+
cb();
|
97
|
+
}
|
98
|
+
|
99
|
+
function handleAttachment(msg, form, callback, cb) {
|
100
|
+
if (msg.attachment) {
|
101
|
+
form.payload.tasks[0].payload.send_type = 3;
|
102
|
+
form.payload.tasks[0].payload.attachment_fbids = [];
|
103
|
+
if (form.payload.tasks[0].payload.text == "")
|
104
|
+
form.payload.tasks[0].payload.text = null;
|
105
|
+
if (utils.getType(msg.attachment) !== "Array") {
|
106
|
+
msg.attachment = [msg.attachment];
|
107
|
+
}
|
108
|
+
|
109
|
+
uploadAttachment(msg.attachment, function (err, files) {
|
110
|
+
if (err) {
|
111
|
+
return callback(err);
|
112
|
+
}
|
113
|
+
|
114
|
+
files.forEach(function (file) {
|
115
|
+
var key = Object.keys(file);
|
116
|
+
var type = key[0]; // image_id, file_id, etc
|
117
|
+
form.payload.tasks[0].payload.attachment_fbids.push(file[type]); // push the id
|
118
|
+
});
|
119
|
+
cb();
|
120
|
+
});
|
121
|
+
} else {
|
122
|
+
cb();
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
|
127
|
+
function handleMention(msg, form, callback, cb) {
|
128
|
+
if (msg.mentions) {
|
129
|
+
form.payload.tasks[0].payload.send_type = 1;
|
130
|
+
|
131
|
+
const arrayIds = [];
|
132
|
+
const arrayOffsets = [];
|
133
|
+
const arrayLengths = [];
|
134
|
+
const mention_types = [];
|
135
|
+
|
136
|
+
for (let i = 0; i < msg.mentions.length; i++) {
|
137
|
+
const mention = msg.mentions[i];
|
138
|
+
|
139
|
+
const tag = mention.tag;
|
140
|
+
if (typeof tag !== "string") {
|
141
|
+
return callback({ error: "Mention tags must be strings." });
|
142
|
+
}
|
143
|
+
|
144
|
+
const offset = msg.body.indexOf(tag, mention.fromIndex || 0);
|
145
|
+
|
146
|
+
if (offset < 0) {
|
147
|
+
log.warn(
|
148
|
+
"handleMention",
|
149
|
+
'Mention for "' + tag + '" not found in message string.'
|
150
|
+
);
|
151
|
+
}
|
152
|
+
|
153
|
+
if (mention.id == null) {
|
154
|
+
log.warn("handleMention", "Mention id should be non-null.");
|
155
|
+
}
|
156
|
+
|
157
|
+
const id = mention.id || 0;
|
158
|
+
arrayIds.push(id);
|
159
|
+
arrayOffsets.push(offset);
|
160
|
+
arrayLengths.push(tag.length);
|
161
|
+
mention_types.push("p");
|
162
|
+
}
|
163
|
+
|
164
|
+
form.payload.tasks[0].payload.mention_data = {
|
165
|
+
mention_ids: arrayIds.join(","),
|
166
|
+
mention_offsets: arrayOffsets.join(","),
|
167
|
+
mention_lengths: arrayLengths.join(","),
|
168
|
+
mention_types: mention_types.join(",")
|
169
|
+
};
|
170
|
+
}
|
171
|
+
cb();
|
172
|
+
}
|
173
|
+
|
174
|
+
function handleLocation(msg, form, callback, cb) {
|
175
|
+
// this is not working yet
|
176
|
+
if (msg.location) {
|
177
|
+
if (msg.location.latitude == null || msg.location.longitude == null) {
|
178
|
+
return callback({ error: "location property needs both latitude and longitude" });
|
179
|
+
}
|
180
|
+
|
181
|
+
form.payload.tasks[0].payload.send_type = 1;
|
182
|
+
form.payload.tasks[0].payload.location_data = {
|
183
|
+
coordinates: {
|
184
|
+
latitude: msg.location.latitude,
|
185
|
+
longitude: msg.location.longitude
|
186
|
+
},
|
187
|
+
is_current_location: !!msg.location.current,
|
188
|
+
is_live_location: !!msg.location.live
|
189
|
+
};
|
190
|
+
}
|
191
|
+
|
192
|
+
cb();
|
193
|
+
}
|
194
|
+
|
195
|
+
function send(form, threadID, callback, replyToMessage) {
|
196
|
+
if (replyToMessage) {
|
197
|
+
form.payload.tasks[0].payload.reply_metadata = {
|
198
|
+
reply_source_id: replyToMessage,
|
199
|
+
reply_source_type: 1,
|
200
|
+
reply_type: 0
|
201
|
+
};
|
202
|
+
}
|
203
|
+
const mqttClient = ctx.mqttClient;
|
204
|
+
form.payload.tasks.forEach((task) => {
|
205
|
+
task.payload = JSON.stringify(task.payload);
|
206
|
+
});
|
207
|
+
form.payload = JSON.stringify(form.payload);
|
208
|
+
console.log(global.jsonStringifyColor(form, null, 2));
|
209
|
+
|
210
|
+
return mqttClient.publish("/ls_req", JSON.stringify(form), function (err, data) {
|
211
|
+
if (err) {
|
212
|
+
console.error('Error publishing message: ', err);
|
213
|
+
callback(err);
|
214
|
+
} else {
|
215
|
+
console.log('Message published successfully with data: ', data);
|
216
|
+
callback(null, data);
|
217
|
+
}
|
218
|
+
});
|
219
|
+
}
|
220
|
+
|
221
|
+
return function sendMessageMqtt(msg, threadID, callback, replyToMessage) {
|
222
|
+
if (
|
223
|
+
!callback &&
|
224
|
+
(utils.getType(threadID) === "Function" ||
|
225
|
+
utils.getType(threadID) === "AsyncFunction")
|
226
|
+
) {
|
227
|
+
return threadID({ error: "Pass a threadID as a second argument." });
|
228
|
+
}
|
229
|
+
if (
|
230
|
+
!replyToMessage &&
|
231
|
+
utils.getType(callback) === "String"
|
232
|
+
) {
|
233
|
+
replyToMessage = callback;
|
234
|
+
callback = function () { };
|
235
|
+
}
|
236
|
+
|
237
|
+
|
238
|
+
if (!callback) {
|
239
|
+
callback = function (err, friendList) {
|
240
|
+
};
|
241
|
+
}
|
242
|
+
|
243
|
+
var msgType = utils.getType(msg);
|
244
|
+
var threadIDType = utils.getType(threadID);
|
245
|
+
var messageIDType = utils.getType(replyToMessage);
|
246
|
+
|
247
|
+
if (msgType !== "String" && msgType !== "Object") {
|
248
|
+
return callback({
|
249
|
+
error:
|
250
|
+
"Message should be of type string or object and not " + msgType + "."
|
251
|
+
});
|
252
|
+
}
|
253
|
+
|
254
|
+
if (msgType === "String") {
|
255
|
+
msg = { body: msg };
|
256
|
+
}
|
257
|
+
|
258
|
+
const timestamp = Date.now();
|
259
|
+
// get full date time
|
260
|
+
const epoch = timestamp << 22;
|
261
|
+
//const otid = epoch + 0; // TODO replace with randomInt(0, 2**22)
|
262
|
+
const otid = epoch + Math.floor(Math.random() * 4194304);
|
263
|
+
|
264
|
+
const form = {
|
265
|
+
app_id: "2220391788200892",
|
266
|
+
payload: {
|
267
|
+
tasks: [
|
268
|
+
{
|
269
|
+
label: "46",
|
270
|
+
payload: {
|
271
|
+
thread_id: threadID.toString(),
|
272
|
+
otid: otid.toString(),
|
273
|
+
source: 0,
|
274
|
+
send_type: 1,
|
275
|
+
sync_group: 1,
|
276
|
+
text: msg.body != null && msg.body != undefined ? msg.body.toString() : "",
|
277
|
+
initiating_source: 1,
|
278
|
+
skip_url_preview_gen: 0
|
279
|
+
},
|
280
|
+
queue_name: threadID.toString(),
|
281
|
+
task_id: 0,
|
282
|
+
failure_count: null
|
283
|
+
},
|
284
|
+
{
|
285
|
+
label: "21",
|
286
|
+
payload: {
|
287
|
+
thread_id: threadID.toString(),
|
288
|
+
last_read_watermark_ts: Date.now(),
|
289
|
+
sync_group: 1
|
290
|
+
},
|
291
|
+
queue_name: threadID.toString(),
|
292
|
+
task_id: 1,
|
293
|
+
failure_count: null
|
294
|
+
}
|
295
|
+
],
|
296
|
+
epoch_id: epoch_id(),
|
297
|
+
version_id: "6120284488008082",
|
298
|
+
data_trace_id: null
|
299
|
+
},
|
300
|
+
request_id: 1,
|
301
|
+
type: 3
|
302
|
+
};
|
303
|
+
|
304
|
+
handleEmoji(msg, form, callback, function () {
|
305
|
+
handleLocation(msg, form, callback, function () {
|
306
|
+
handleMention(msg, form, callback, function () {
|
307
|
+
handleSticker(msg, form, callback, function () {
|
308
|
+
handleAttachment(msg, form, callback, function () {
|
309
|
+
send(form, threadID, callback, replyToMessage);
|
310
|
+
});
|
311
|
+
});
|
312
|
+
});
|
313
|
+
});
|
314
|
+
});
|
315
|
+
};
|
316
|
+
};
|
@@ -1,70 +1,103 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
module.exports = function (defaultFuncs, api, ctx) {
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
const utils = require("../utils");
|
4
|
+
const log = require("npmlog");
|
5
|
+
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
7
|
+
function makeTypingIndicator(typ, threadID, callback, isGroup) {
|
8
|
+
const form = {
|
9
|
+
typ: +typ,
|
10
|
+
to: "",
|
11
|
+
source: "mercury-chat",
|
12
|
+
thread: threadID
|
13
|
+
};
|
14
|
+
|
15
|
+
// Check if thread is a single person chat or a group chat
|
16
|
+
// More info on this is in api.sendMessage
|
17
|
+
if (utils.getType(isGroup) == "Boolean") {
|
18
|
+
if (!isGroup) {
|
19
|
+
form.to = threadID;
|
20
|
+
}
|
21
|
+
defaultFuncs
|
22
|
+
.post("https://www.facebook.com/ajax/messaging/typ.php", ctx.jar, form)
|
23
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
24
|
+
.then(function (resData) {
|
25
|
+
if (resData.error) {
|
26
|
+
throw resData;
|
27
|
+
}
|
28
|
+
|
29
|
+
return callback();
|
30
|
+
})
|
31
|
+
.catch(function (err) {
|
32
|
+
log.error("sendTypingIndicator", err);
|
33
|
+
if (utils.getType(err) == "Object" && err.error === "Not logged in") {
|
34
|
+
ctx.loggedIn = false;
|
35
|
+
}
|
36
|
+
return callback(err);
|
37
|
+
});
|
38
|
+
} else {
|
39
|
+
api.getUserInfo(threadID, function (err, res) {
|
40
|
+
if (err) {
|
41
|
+
return callback(err);
|
42
|
+
}
|
43
|
+
|
44
|
+
// If id is single person chat
|
45
|
+
if (Object.keys(res).length > 0) {
|
46
|
+
form.to = threadID;
|
47
|
+
}
|
48
|
+
|
49
|
+
defaultFuncs
|
50
|
+
.post("https://www.facebook.com/ajax/messaging/typ.php", ctx.jar, form)
|
51
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
52
|
+
.then(function (resData) {
|
53
|
+
if (resData.error) {
|
54
|
+
throw resData;
|
55
|
+
}
|
56
|
+
|
57
|
+
return callback();
|
58
|
+
})
|
59
|
+
.catch(function (err) {
|
60
|
+
log.error("sendTypingIndicator", err);
|
61
|
+
if (utils.getType(err) == "Object" && err.error === "Not logged in.") {
|
62
|
+
ctx.loggedIn = false;
|
63
|
+
}
|
64
|
+
return callback(err);
|
65
|
+
});
|
66
|
+
});
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
return function sendTypingIndicator(threadID, callback, isGroup) {
|
71
|
+
if (
|
72
|
+
utils.getType(callback) !== "Function" &&
|
73
|
+
utils.getType(callback) !== "AsyncFunction"
|
74
|
+
) {
|
75
|
+
if (callback) {
|
76
|
+
log.warn(
|
77
|
+
"sendTypingIndicator",
|
78
|
+
"callback is not a function - ignoring."
|
79
|
+
);
|
80
|
+
}
|
81
|
+
callback = () => { };
|
82
|
+
}
|
83
|
+
|
84
|
+
makeTypingIndicator(true, threadID, callback, isGroup);
|
85
|
+
|
86
|
+
return function end(cb) {
|
87
|
+
if (
|
88
|
+
utils.getType(cb) !== "Function" &&
|
89
|
+
utils.getType(cb) !== "AsyncFunction"
|
90
|
+
) {
|
91
|
+
if (cb) {
|
92
|
+
log.warn(
|
93
|
+
"sendTypingIndicator",
|
94
|
+
"callback is not a function - ignoring."
|
95
|
+
);
|
96
|
+
}
|
97
|
+
cb = () => { };
|
98
|
+
}
|
99
|
+
|
100
|
+
makeTypingIndicator(false, threadID, cb, isGroup);
|
101
|
+
};
|
102
|
+
};
|
103
|
+
};
|