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/src/sendMessageMqtt.js
DELETED
@@ -1,316 +0,0 @@
|
|
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,103 +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
|
-
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
|
-
};
|
@@ -1,117 +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 setMessageReaction(reaction, messageID, callback, forceCustomReaction) {
|
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 (!callback) {
|
16
|
-
callback = function (err, friendList) {
|
17
|
-
if (err) {
|
18
|
-
return rejectFunc(err);
|
19
|
-
}
|
20
|
-
resolveFunc(friendList);
|
21
|
-
};
|
22
|
-
}
|
23
|
-
|
24
|
-
switch (reaction) {
|
25
|
-
case "\uD83D\uDE0D": //:heart_eyes:
|
26
|
-
case "\uD83D\uDE06": //:laughing:
|
27
|
-
case "\uD83D\uDE2E": //:open_mouth:
|
28
|
-
case "\uD83D\uDE22": //:cry:
|
29
|
-
case "\uD83D\uDE20": //:angry:
|
30
|
-
case "\uD83D\uDC4D": //:thumbsup:
|
31
|
-
case "\uD83D\uDC4E": //:thumbsdown:
|
32
|
-
case "\u2764": //:heart:
|
33
|
-
case "\uD83D\uDC97": //:glowingheart:
|
34
|
-
case "":
|
35
|
-
//valid
|
36
|
-
break;
|
37
|
-
case ":heart_eyes:":
|
38
|
-
case ":love:":
|
39
|
-
reaction = "\uD83D\uDE0D";
|
40
|
-
break;
|
41
|
-
case ":laughing:":
|
42
|
-
case ":haha:":
|
43
|
-
reaction = "\uD83D\uDE06";
|
44
|
-
break;
|
45
|
-
case ":open_mouth:":
|
46
|
-
case ":wow:":
|
47
|
-
reaction = "\uD83D\uDE2E";
|
48
|
-
break;
|
49
|
-
case ":cry:":
|
50
|
-
case ":sad:":
|
51
|
-
reaction = "\uD83D\uDE22";
|
52
|
-
break;
|
53
|
-
case ":angry:":
|
54
|
-
reaction = "\uD83D\uDE20";
|
55
|
-
break;
|
56
|
-
case ":thumbsup:":
|
57
|
-
case ":like:":
|
58
|
-
reaction = "\uD83D\uDC4D";
|
59
|
-
break;
|
60
|
-
case ":thumbsdown:":
|
61
|
-
case ":dislike:":
|
62
|
-
reaction = "\uD83D\uDC4E";
|
63
|
-
break;
|
64
|
-
case ":heart:":
|
65
|
-
reaction = "\u2764";
|
66
|
-
break;
|
67
|
-
case ":glowingheart:":
|
68
|
-
reaction = "\uD83D\uDC97";
|
69
|
-
break;
|
70
|
-
default:
|
71
|
-
if (forceCustomReaction) {
|
72
|
-
break;
|
73
|
-
}
|
74
|
-
return callback({ error: "Reaction is not a valid emoji." });
|
75
|
-
}
|
76
|
-
|
77
|
-
const variables = {
|
78
|
-
data: {
|
79
|
-
client_mutation_id: ctx.clientMutationId++,
|
80
|
-
actor_id: ctx.i_userID || ctx.userID,
|
81
|
-
action: reaction == "" ? "REMOVE_REACTION" : "ADD_REACTION",
|
82
|
-
message_id: messageID,
|
83
|
-
reaction: reaction
|
84
|
-
}
|
85
|
-
};
|
86
|
-
|
87
|
-
const qs = {
|
88
|
-
doc_id: "1491398900900362",
|
89
|
-
variables: JSON.stringify(variables),
|
90
|
-
dpr: 1
|
91
|
-
};
|
92
|
-
|
93
|
-
defaultFuncs
|
94
|
-
.postFormData(
|
95
|
-
"https://www.facebook.com/webgraphql/mutation/",
|
96
|
-
ctx.jar,
|
97
|
-
{},
|
98
|
-
qs
|
99
|
-
)
|
100
|
-
.then(utils.parseAndCheckLogin(ctx.jar, defaultFuncs))
|
101
|
-
.then(function (resData) {
|
102
|
-
if (!resData) {
|
103
|
-
throw { error: "setReaction returned empty object." };
|
104
|
-
}
|
105
|
-
if (resData.error) {
|
106
|
-
throw resData;
|
107
|
-
}
|
108
|
-
callback(null);
|
109
|
-
})
|
110
|
-
.catch(function (err) {
|
111
|
-
log.error("setReaction", err);
|
112
|
-
return callback(err);
|
113
|
-
});
|
114
|
-
|
115
|
-
return returnPromise;
|
116
|
-
};
|
117
|
-
};
|
package/src/setPostReaction.js
DELETED
@@ -1,109 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @fix by NTKhang
|
3
|
-
* update as Thursday, 10 February 2022
|
4
|
-
* do not remove the author name to get more updates
|
5
|
-
*/
|
6
|
-
|
7
|
-
"use strict";
|
8
|
-
|
9
|
-
const utils = require("../utils");
|
10
|
-
const log = require("npmlog");
|
11
|
-
|
12
|
-
function formatData(resData) {
|
13
|
-
return {
|
14
|
-
viewer_feedback_reaction_info: resData.feedback_react.feedback.viewer_feedback_reaction_info,
|
15
|
-
supported_reactions: resData.feedback_react.feedback.supported_reactions,
|
16
|
-
top_reactions: resData.feedback_react.feedback.top_reactions.edges,
|
17
|
-
reaction_count: resData.feedback_react.feedback.reaction_count
|
18
|
-
};
|
19
|
-
}
|
20
|
-
|
21
|
-
module.exports = function (defaultFuncs, api, ctx) {
|
22
|
-
return function setPostReaction(postID, type, callback) {
|
23
|
-
let resolveFunc = function () { };
|
24
|
-
let rejectFunc = function () { };
|
25
|
-
const returnPromise = new Promise(function (resolve, reject) {
|
26
|
-
resolveFunc = resolve;
|
27
|
-
rejectFunc = reject;
|
28
|
-
});
|
29
|
-
|
30
|
-
if (!callback) {
|
31
|
-
if (utils.getType(type) === "Function" || utils.getType(type) === "AsyncFunction") {
|
32
|
-
callback = type;
|
33
|
-
type = 0;
|
34
|
-
}
|
35
|
-
else {
|
36
|
-
callback = function (err, data) {
|
37
|
-
if (err) {
|
38
|
-
return rejectFunc(err);
|
39
|
-
}
|
40
|
-
resolveFunc(data);
|
41
|
-
};
|
42
|
-
}
|
43
|
-
}
|
44
|
-
|
45
|
-
const map = {
|
46
|
-
unlike: 0,
|
47
|
-
like: 1,
|
48
|
-
heart: 2,
|
49
|
-
love: 16,
|
50
|
-
haha: 4,
|
51
|
-
wow: 3,
|
52
|
-
sad: 7,
|
53
|
-
angry: 8
|
54
|
-
};
|
55
|
-
|
56
|
-
if (utils.getType(type) !== "Number" && utils.getType(type) === "String") {
|
57
|
-
type = map[type.toLowerCase()];
|
58
|
-
}
|
59
|
-
|
60
|
-
if (utils.getType(type) !== "Number" && utils.getType(type) !== "String") {
|
61
|
-
throw {
|
62
|
-
error: "setPostReaction: Invalid reaction type"
|
63
|
-
};
|
64
|
-
}
|
65
|
-
|
66
|
-
if (type != 0 && !type) {
|
67
|
-
throw {
|
68
|
-
error: "setPostReaction: Invalid reaction type"
|
69
|
-
};
|
70
|
-
}
|
71
|
-
|
72
|
-
const form = {
|
73
|
-
av: ctx.i_userID || ctx.userID,
|
74
|
-
fb_api_caller_class: "RelayModern",
|
75
|
-
fb_api_req_friendly_name: "CometUFIFeedbackReactMutation",
|
76
|
-
doc_id: "4769042373179384",
|
77
|
-
variables: JSON.stringify({
|
78
|
-
input: {
|
79
|
-
actor_id: ctx.i_userID || ctx.userID,
|
80
|
-
feedback_id: (new Buffer.from("feedback:" + postID)).toString("base64"),
|
81
|
-
feedback_reaction: type,
|
82
|
-
feedback_source: "OBJECT",
|
83
|
-
is_tracking_encrypted: true,
|
84
|
-
tracking: [],
|
85
|
-
session_id: "f7dd50dd-db6e-4598-8cd9-561d5002b423",
|
86
|
-
client_mutation_id: Math.round(Math.random() * 19).toString()
|
87
|
-
},
|
88
|
-
useDefaultActor: false,
|
89
|
-
scale: 3
|
90
|
-
})
|
91
|
-
};
|
92
|
-
|
93
|
-
defaultFuncs
|
94
|
-
.post("https://www.facebook.com/api/graphql/", ctx.jar, form)
|
95
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
96
|
-
.then(function (resData) {
|
97
|
-
if (resData.errors) {
|
98
|
-
throw resData;
|
99
|
-
}
|
100
|
-
return callback(null, formatData(resData.data));
|
101
|
-
})
|
102
|
-
.catch(function (err) {
|
103
|
-
log.error("setPostReaction", err);
|
104
|
-
return callback(err);
|
105
|
-
});
|
106
|
-
|
107
|
-
return returnPromise;
|
108
|
-
};
|
109
|
-
};
|