fca-priyansh 10.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/.gitattributes +2 -0
- package/.github/workflows/publish.yml +20 -0
- package/Extra/Database/index.js +360 -0
- package/Extra/ExtraAddons.js +80 -0
- package/Extra/ExtraFindUID.js +60 -0
- package/Extra/ExtraGetThread.js +118 -0
- package/Extra/ExtraScreenShot.js +430 -0
- package/Extra/ExtraUptimeRobot.js +26 -0
- package/Extra/Html/Classic/script.js +119 -0
- package/Extra/Html/Classic/style.css +8 -0
- package/Extra/Security/Index.js +146 -0
- package/Extra/Security/Step_1.js +11 -0
- package/Extra/Security/Step_2.js +20 -0
- package/Extra/Security/Step_3.js +20 -0
- package/Extra/Src/Change_Environment.js +24 -0
- package/Extra/Src/History.js +115 -0
- package/Extra/Src/Last-Run.js +65 -0
- package/Extra/Src/Premium.js +84 -0
- package/Extra/Src/uuid.js +137 -0
- package/Func/AcceptAgreement.js +32 -0
- package/Func/ClearCache.js +64 -0
- package/Func/ReportV1.js +54 -0
- package/LICENSE +24 -0
- package/Language/index.json +177 -0
- package/README.md +1 -0
- package/SECURITY.md +17 -0
- package/broadcast.js +38 -0
- package/gitattributes +2 -0
- package/gitignore.txt +10 -0
- package/index.js +1364 -0
- package/logger.js +66 -0
- package/package.json +91 -0
- package/src/Dev_Horizon_Data.js +125 -0
- package/src/Premium.js +30 -0
- package/src/Screenshot.js +85 -0
- package/src/addExternalModule.js +16 -0
- package/src/addUserToGroup.js +79 -0
- package/src/changeAdminStatus.js +79 -0
- package/src/changeArchivedStatus.js +41 -0
- package/src/changeAvt.js +85 -0
- package/src/changeBio.js +65 -0
- package/src/changeBlockedStatus.js +36 -0
- package/src/changeGroupImage.js +106 -0
- package/src/changeNickname.js +45 -0
- package/src/changeThreadColor.js +62 -0
- package/src/changeThreadEmoji.js +42 -0
- package/src/createNewGroup.js +70 -0
- package/src/createPoll.js +60 -0
- package/src/deleteMessage.js +45 -0
- package/src/deleteThread.js +43 -0
- package/src/forwardAttachment.js +48 -0
- package/src/getAccessToken.js +32 -0
- package/src/getCurrentUserID.js +7 -0
- package/src/getEmojiUrl.js +27 -0
- package/src/getFriendsList.js +73 -0
- package/src/getMessage.js +80 -0
- package/src/getThreadHistory.js +537 -0
- package/src/getThreadInfo.js +348 -0
- package/src/getThreadList.js +213 -0
- package/src/getThreadMain.js +220 -0
- package/src/getThreadPictures.js +59 -0
- package/src/getUID.js +59 -0
- package/src/getUserID.js +62 -0
- package/src/getUserInfo.js +129 -0
- package/src/getUserInfoMain.js +65 -0
- package/src/getUserInfoV2.js +36 -0
- package/src/getUserInfoV3.js +63 -0
- package/src/getUserInfoV4.js +55 -0
- package/src/getUserInfoV5.js +61 -0
- package/src/handleFriendRequest.js +46 -0
- package/src/handleMessageRequest.js +49 -0
- package/src/httpGet.js +49 -0
- package/src/httpPost.js +48 -0
- package/src/httpPostFormData.js +41 -0
- package/src/listenMqtt.js +676 -0
- package/src/logout.js +68 -0
- package/src/markAsDelivered.js +48 -0
- package/src/markAsRead.js +70 -0
- package/src/markAsReadAll.js +43 -0
- package/src/markAsSeen.js +51 -0
- package/src/muteThread.js +47 -0
- package/src/removeUserFromGroup.js +49 -0
- package/src/resolvePhotoUrl.js +37 -0
- package/src/searchForThread.js +43 -0
- package/src/sendMessage.js +334 -0
- package/src/sendTypingIndicator.js +80 -0
- package/src/setMessageReaction.js +109 -0
- package/src/setPostReaction.js +102 -0
- package/src/setTitle.js +74 -0
- package/src/threadColors.js +39 -0
- package/src/unfriend.js +43 -0
- package/src/unsendMessage.js +40 -0
- package/test/data/shareAttach.js +146 -0
- package/test/data/something.mov +0 -0
- package/test/data/test.png +0 -0
- package/test/data/test.txt +7 -0
- package/test/env/.env +0 -0
- package/test/example-config.json +18 -0
- package/test/test-page.js +140 -0
- package/test/test.js +385 -0
- package/test/testv2.js +3 -0
- package/utils.js +1648 -0
@@ -0,0 +1,334 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Được Fix Hay Làm Màu Bởi: @HarryWakazaki
|
5
|
+
* 21/4/2022
|
6
|
+
*/
|
7
|
+
|
8
|
+
var utils = require("../utils");
|
9
|
+
var log = require("npmlog");
|
10
|
+
var bluebird = require("bluebird");
|
11
|
+
|
12
|
+
var allowedProperties = {
|
13
|
+
attachment: true,
|
14
|
+
url: true,
|
15
|
+
sticker: true,
|
16
|
+
emoji: true,
|
17
|
+
emojiSize: true,
|
18
|
+
body: true,
|
19
|
+
mentions: true,
|
20
|
+
location: true,
|
21
|
+
};
|
22
|
+
|
23
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
24
|
+
function uploadAttachment(attachments, callback) {
|
25
|
+
var uploads = [];
|
26
|
+
|
27
|
+
// create an array of promises
|
28
|
+
for (var i = 0; i < attachments.length; i++) {
|
29
|
+
if (!utils.isReadableStream(attachments[i])) throw { error: "Attachment should be a readable stream and not " + utils.getType(attachments[i]) + "." };
|
30
|
+
var form = {
|
31
|
+
upload_1024: attachments[i],
|
32
|
+
voice_clip: "true"
|
33
|
+
};
|
34
|
+
|
35
|
+
uploads.push(
|
36
|
+
defaultFuncs
|
37
|
+
.postFormData("https://upload.facebook.com/ajax/mercury/upload.php", ctx.jar, form, {})
|
38
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
39
|
+
.then(function (resData) {
|
40
|
+
if (resData.error) throw resData;
|
41
|
+
// We have to return the data unformatted unless we want to change it
|
42
|
+
// back in sendMessage.
|
43
|
+
return resData.payload.metadata[0];
|
44
|
+
})
|
45
|
+
);
|
46
|
+
}
|
47
|
+
|
48
|
+
// resolve all promises
|
49
|
+
bluebird
|
50
|
+
.all(uploads)
|
51
|
+
.then(resData => callback(null, resData)
|
52
|
+
)
|
53
|
+
.catch(function (err) {
|
54
|
+
log.error("uploadAttachment", err);
|
55
|
+
return callback(err);
|
56
|
+
});
|
57
|
+
}
|
58
|
+
|
59
|
+
function getUrl(url, callback) {
|
60
|
+
var form = {
|
61
|
+
image_height: 960,
|
62
|
+
image_width: 960,
|
63
|
+
uri: url
|
64
|
+
};
|
65
|
+
|
66
|
+
defaultFuncs
|
67
|
+
.post("https://www.facebook.com/message_share_attachment/fromURI/", ctx.jar, form)
|
68
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
69
|
+
.then(function (resData) {
|
70
|
+
if (resData.error) return callback(resData);
|
71
|
+
if (!resData.payload) return callback({ error: "Invalid url" });
|
72
|
+
callback(null, resData.payload.share_data.share_params);
|
73
|
+
})
|
74
|
+
.catch(function (err) {
|
75
|
+
log.error("getUrl", err);
|
76
|
+
return callback(err);
|
77
|
+
});
|
78
|
+
}
|
79
|
+
|
80
|
+
function sendContent(form, threadID, isSingleUser, messageAndOTID, callback) {
|
81
|
+
// There are three cases here:
|
82
|
+
// 1. threadID is of type array, where we're starting a new group chat with users
|
83
|
+
// specified in the array.
|
84
|
+
// 2. User is sending a message to a specific user.
|
85
|
+
// 3. No additional form params and the message goes to an existing group chat.
|
86
|
+
if (utils.getType(threadID) === "Array") {
|
87
|
+
for (var i = 0; i < threadID.length; i++) form["specific_to_list[" + i + "]"] = "fbid:" + threadID[i];
|
88
|
+
form["specific_to_list[" + threadID.length + "]"] = "fbid:" + ctx.userID;
|
89
|
+
form["client_thread_id"] = "root:" + messageAndOTID;
|
90
|
+
log.info("sendMessage", "Sending message to multiple users: " + threadID);
|
91
|
+
}
|
92
|
+
else {
|
93
|
+
// This means that threadID is the id of a user, and the chat
|
94
|
+
// is a single person chat
|
95
|
+
if (isSingleUser) {
|
96
|
+
form["specific_to_list[0]"] = "fbid:" + threadID;
|
97
|
+
form["specific_to_list[1]"] = "fbid:" + ctx.userID;
|
98
|
+
form["other_user_fbid"] = threadID;
|
99
|
+
}
|
100
|
+
else form["thread_fbid"] = threadID;
|
101
|
+
}
|
102
|
+
|
103
|
+
if (ctx.globalOptions.pageID) {
|
104
|
+
form["author"] = "fbid:" + ctx.globalOptions.pageID;
|
105
|
+
form["specific_to_list[1]"] = "fbid:" + ctx.globalOptions.pageID;
|
106
|
+
form["creator_info[creatorID]"] = ctx.userID;
|
107
|
+
form["creator_info[creatorType]"] = "direct_admin";
|
108
|
+
form["creator_info[labelType]"] = "sent_message";
|
109
|
+
form["creator_info[pageID]"] = ctx.globalOptions.pageID;
|
110
|
+
form["request_user_id"] = ctx.globalOptions.pageID;
|
111
|
+
form["creator_info[profileURI]"] = "https://www.facebook.com/profile.php?id=" + ctx.userID;
|
112
|
+
}
|
113
|
+
|
114
|
+
defaultFuncs
|
115
|
+
.post("https://www.facebook.com/messaging/send/", ctx.jar, form)
|
116
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
117
|
+
.then(function (resData) {
|
118
|
+
if (!resData) return callback({ error: "Send message failed." });
|
119
|
+
if (resData.error) {
|
120
|
+
if (resData.error === 1545012) log.warn("sendMessage", "Got error 1545012. This might mean that you're not part of the conversation " + threadID);
|
121
|
+
return callback(resData);
|
122
|
+
}
|
123
|
+
|
124
|
+
var messageInfo = resData.payload.actions.reduce(function (p, v) {
|
125
|
+
return (
|
126
|
+
{
|
127
|
+
threadID: v.thread_fbid,
|
128
|
+
messageID: v.message_id,
|
129
|
+
timestamp: v.timestamp
|
130
|
+
} || p
|
131
|
+
);
|
132
|
+
}, null);
|
133
|
+
return callback(null, messageInfo);
|
134
|
+
})
|
135
|
+
.catch(function (err) {
|
136
|
+
log.error("sendMessage", err);
|
137
|
+
if (utils.getType(err) == "Object" && err.error === "Not logged in.") ctx.loggedIn = false;
|
138
|
+
return callback(err,null);
|
139
|
+
});
|
140
|
+
}
|
141
|
+
|
142
|
+
function send(form, threadID, messageAndOTID, callback, isGroup) {
|
143
|
+
//Full Fix sendMessage
|
144
|
+
if (utils.getType(threadID) === "Array") sendContent(form, threadID, false, messageAndOTID, callback);
|
145
|
+
else {
|
146
|
+
var THREADFIX = "ThreadID".replace("ThreadID",threadID); // i cũng đôn nâu
|
147
|
+
if (THREADFIX.length <= 15 || global.Fca.isUser.includes(threadID)) sendContent(form, threadID, !isGroup, messageAndOTID, callback);
|
148
|
+
else if (THREADFIX.length >= 15 && THREADFIX.indexOf(1) != 0 || global.Fca.isThread.includes(threadID)) sendContent(form, threadID, threadID.length === 15, messageAndOTID, callback);
|
149
|
+
else {
|
150
|
+
if (global.Fca.Data.event.isGroup) {
|
151
|
+
sendContent(form, threadID, threadID.length === 15, messageAndOTID, callback);
|
152
|
+
global.Fca.isThread.push(threadID);
|
153
|
+
}
|
154
|
+
else {
|
155
|
+
sendContent(form, threadID, !isGroup, messageAndOTID, callback);
|
156
|
+
global.Fca.isUser.push(threadID)
|
157
|
+
}
|
158
|
+
}
|
159
|
+
}
|
160
|
+
}
|
161
|
+
|
162
|
+
function handleUrl(msg, form, callback, cb) {
|
163
|
+
if (msg.url) {
|
164
|
+
form["shareable_attachment[share_type]"] = "100";
|
165
|
+
getUrl(msg.url, function (err, params) {
|
166
|
+
if (err) return callback(err);
|
167
|
+
form["shareable_attachment[share_params]"] = params;
|
168
|
+
cb();
|
169
|
+
});
|
170
|
+
}
|
171
|
+
else cb();
|
172
|
+
}
|
173
|
+
|
174
|
+
function handleLocation(msg, form, callback, cb) {
|
175
|
+
if (msg.location) {
|
176
|
+
if (msg.location.latitude == null || msg.location.longitude == null) return callback({ error: "location property needs both latitude and longitude" });
|
177
|
+
form["location_attachment[coordinates][latitude]"] = msg.location.latitude;
|
178
|
+
form["location_attachment[coordinates][longitude]"] = msg.location.longitude;
|
179
|
+
form["location_attachment[is_current_location]"] = !!msg.location.current;
|
180
|
+
}
|
181
|
+
cb();
|
182
|
+
}
|
183
|
+
|
184
|
+
function handleSticker(msg, form, callback, cb) {
|
185
|
+
if (msg.sticker) form["sticker_id"] = msg.sticker;
|
186
|
+
cb();
|
187
|
+
}
|
188
|
+
|
189
|
+
function handleEmoji(msg, form, callback, cb) {
|
190
|
+
if (msg.emojiSize != null && msg.emoji == null) return callback({ error: "emoji property is empty" });
|
191
|
+
if (msg.emoji) {
|
192
|
+
if (msg.emojiSize == null) msg.emojiSize = "medium";
|
193
|
+
if (msg.emojiSize != "small" && msg.emojiSize != "medium" && msg.emojiSize != "large") return callback({ error: "emojiSize property is invalid" });
|
194
|
+
if (form["body"] != null && form["body"] != "") return callback({ error: "body is not empty" });
|
195
|
+
form["body"] = msg.emoji;
|
196
|
+
form["tags[0]"] = "hot_emoji_size:" + msg.emojiSize;
|
197
|
+
}
|
198
|
+
cb();
|
199
|
+
}
|
200
|
+
|
201
|
+
function handleAttachment(msg, form, callback, cb) {
|
202
|
+
if (msg.attachment) {
|
203
|
+
form["image_ids"] = [];
|
204
|
+
form["gif_ids"] = [];
|
205
|
+
form["file_ids"] = [];
|
206
|
+
form["video_ids"] = [];
|
207
|
+
form["audio_ids"] = [];
|
208
|
+
|
209
|
+
if (utils.getType(msg.attachment) !== "Array") msg.attachment = [msg.attachment];
|
210
|
+
|
211
|
+
uploadAttachment(msg.attachment, function (err, files) {
|
212
|
+
if (err) return callback(err);
|
213
|
+
files.forEach(function (file) {
|
214
|
+
var key = Object.keys(file);
|
215
|
+
var type = key[0]; // image_id, file_id, etc
|
216
|
+
form["" + type + "s"].push(file[type]); // push the id
|
217
|
+
});
|
218
|
+
cb();
|
219
|
+
});
|
220
|
+
}
|
221
|
+
else cb();
|
222
|
+
}
|
223
|
+
|
224
|
+
function handleMention(msg, form, callback, cb) {
|
225
|
+
if (msg.mentions) {
|
226
|
+
for (let i = 0; i < msg.mentions.length; i++) {
|
227
|
+
const mention = msg.mentions[i];
|
228
|
+
const tag = mention.tag;
|
229
|
+
if (typeof tag !== "string") return callback({ error: "Mention tags must be strings." });
|
230
|
+
const offset = msg.body.indexOf(tag, mention.fromIndex || 0);
|
231
|
+
if (offset < 0) log.warn("handleMention", 'Mention for "' + tag + '" not found in message string.');
|
232
|
+
if (mention.id == null) log.warn("handleMention", "Mention id should be non-null.");
|
233
|
+
|
234
|
+
const id = mention.id || 0;
|
235
|
+
const emptyChar = '\u200E';
|
236
|
+
form["body"] = emptyChar + msg.body;
|
237
|
+
form["profile_xmd[" + i + "][offset]"] = offset + 1;
|
238
|
+
form["profile_xmd[" + i + "][length]"] = tag.length;
|
239
|
+
form["profile_xmd[" + i + "][id]"] = id;
|
240
|
+
form["profile_xmd[" + i + "][type]"] = "p";
|
241
|
+
}
|
242
|
+
}
|
243
|
+
cb();
|
244
|
+
}
|
245
|
+
|
246
|
+
return function sendMessage(msg, threadID, callback, replyToMessage, isGroup) {
|
247
|
+
typeof isGroup == "undefined" ? isGroup = null : "";
|
248
|
+
if (!callback && (utils.getType(threadID) === "Function" || utils.getType(threadID) === "AsyncFunction")) return threadID({ error: "Pass a threadID as a second argument." });
|
249
|
+
if (!replyToMessage && utils.getType(callback) === "String") {
|
250
|
+
replyToMessage = callback;
|
251
|
+
callback = function () { };
|
252
|
+
}
|
253
|
+
|
254
|
+
var resolveFunc = function () { };
|
255
|
+
var rejectFunc = function () { };
|
256
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
257
|
+
resolveFunc = resolve;
|
258
|
+
rejectFunc = reject;
|
259
|
+
});
|
260
|
+
|
261
|
+
if (!callback) {
|
262
|
+
callback = function (err, data) {
|
263
|
+
if (err) return rejectFunc(err);
|
264
|
+
resolveFunc(data);
|
265
|
+
};
|
266
|
+
}
|
267
|
+
|
268
|
+
var msgType = utils.getType(msg);
|
269
|
+
var threadIDType = utils.getType(threadID);
|
270
|
+
var messageIDType = utils.getType(replyToMessage);
|
271
|
+
|
272
|
+
if (msgType !== "String" && msgType !== "Object") return callback({ error: "Message should be of type string or object and not " + msgType + "." });
|
273
|
+
|
274
|
+
// Changing this to accomodate an array of users
|
275
|
+
if (threadIDType !== "Array" && threadIDType !== "Number" && threadIDType !== "String") return callback({ error: "ThreadID should be of type number, string, or array and not " + threadIDType + "." });
|
276
|
+
|
277
|
+
if (replyToMessage && messageIDType !== 'String') return callback({ error: "MessageID should be of type string and not " + threadIDType + "." });
|
278
|
+
|
279
|
+
if (msgType === "String") msg = { body: msg };
|
280
|
+
var disallowedProperties = Object.keys(msg).filter(prop => !allowedProperties[prop]);
|
281
|
+
if (disallowedProperties.length > 0) return callback({ error: "Dissallowed props: `" + disallowedProperties.join(", ") + "`" });
|
282
|
+
|
283
|
+
var messageAndOTID = utils.generateOfflineThreadingID();
|
284
|
+
|
285
|
+
var form = {
|
286
|
+
client: "mercury",
|
287
|
+
action_type: "ma-type:user-generated-message",
|
288
|
+
author: "fbid:" + ctx.userID,
|
289
|
+
timestamp: Date.now(),
|
290
|
+
timestamp_absolute: "Today",
|
291
|
+
timestamp_relative: utils.generateTimestampRelative(),
|
292
|
+
timestamp_time_passed: "0",
|
293
|
+
is_unread: false,
|
294
|
+
is_cleared: false,
|
295
|
+
is_forward: false,
|
296
|
+
is_filtered_content: false,
|
297
|
+
is_filtered_content_bh: false,
|
298
|
+
is_filtered_content_account: false,
|
299
|
+
is_filtered_content_quasar: false,
|
300
|
+
is_filtered_content_invalid_app: false,
|
301
|
+
is_spoof_warning: false,
|
302
|
+
source: "source:chat:web",
|
303
|
+
"source_tags[0]": "source:chat",
|
304
|
+
body: msg.body ? msg.body.toString().replace("\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f",' ') : "",
|
305
|
+
html_body: false,
|
306
|
+
ui_push_phase: "V3",
|
307
|
+
status: "0",
|
308
|
+
offline_threading_id: messageAndOTID,
|
309
|
+
message_id: messageAndOTID,
|
310
|
+
threading_id: utils.generateThreadingID(ctx.clientID),
|
311
|
+
"ephemeral_ttl_mode:": "0",
|
312
|
+
manual_retry_cnt: "0",
|
313
|
+
has_attachment: !!(msg.attachment || msg.url || msg.sticker),
|
314
|
+
signatureID: utils.getSignatureID(),
|
315
|
+
replied_to_message_id: replyToMessage
|
316
|
+
};
|
317
|
+
|
318
|
+
handleLocation(msg, form, callback, () =>
|
319
|
+
handleSticker(msg, form, callback, () =>
|
320
|
+
handleAttachment(msg, form, callback, () =>
|
321
|
+
handleUrl(msg, form, callback, () =>
|
322
|
+
handleEmoji(msg, form, callback, () =>
|
323
|
+
handleMention(msg, form, callback, () =>
|
324
|
+
send(form, threadID, messageAndOTID, callback, isGroup)
|
325
|
+
)
|
326
|
+
)
|
327
|
+
)
|
328
|
+
)
|
329
|
+
)
|
330
|
+
);
|
331
|
+
|
332
|
+
return returnPromise;
|
333
|
+
};
|
334
|
+
};
|
@@ -0,0 +1,80 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var utils = require("../utils");
|
4
|
+
var log = require("npmlog");
|
5
|
+
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
7
|
+
function makeTypingIndicator(typ, threadID, callback, isGroup) {
|
8
|
+
var 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) throw resData;
|
26
|
+
return callback();
|
27
|
+
})
|
28
|
+
.catch(function (err) {
|
29
|
+
log.error("sendTypingIndicator", err);
|
30
|
+
if (utils.getType(err) == "Object" && err.error === "Not logged in") {
|
31
|
+
ctx.loggedIn = false;
|
32
|
+
}
|
33
|
+
return callback(err);
|
34
|
+
});
|
35
|
+
}
|
36
|
+
else {
|
37
|
+
api.getUserInfo(threadID, function (err, res) {
|
38
|
+
if (err) return callback(err);
|
39
|
+
// If id is single person chat
|
40
|
+
if (Object.keys(res).length > 0) form.to = threadID;
|
41
|
+
defaultFuncs
|
42
|
+
.post("https://www.facebook.com/ajax/messaging/typ.php", ctx.jar, form)
|
43
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
44
|
+
.then(function (resData) {
|
45
|
+
if (resData.error) throw resData;
|
46
|
+
return callback();
|
47
|
+
})
|
48
|
+
.catch(function (err) {
|
49
|
+
log.error("sendTypingIndicator", err);
|
50
|
+
if (utils.getType(err) == "Object" && err.error === "Not logged in.") ctx.loggedIn = false;
|
51
|
+
return callback(err);
|
52
|
+
});
|
53
|
+
});
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
return function sendTypingIndicator(threadID, callback, isGroup) {
|
58
|
+
if (
|
59
|
+
utils.getType(callback) !== "Function" &&
|
60
|
+
utils.getType(callback) !== "AsyncFunction"
|
61
|
+
) {
|
62
|
+
if (callback) log.warn("sendTypingIndicator", "callback is not a function - ignoring.");
|
63
|
+
callback = () => { };
|
64
|
+
}
|
65
|
+
|
66
|
+
makeTypingIndicator(true, threadID, callback, isGroup);
|
67
|
+
|
68
|
+
return function end(cb) {
|
69
|
+
if (
|
70
|
+
utils.getType(cb) !== "Function" &&
|
71
|
+
utils.getType(cb) !== "AsyncFunction"
|
72
|
+
) {
|
73
|
+
if (cb) log.warn("sendTypingIndicator", "callback is not a function - ignoring.");
|
74
|
+
cb = () => { };
|
75
|
+
}
|
76
|
+
|
77
|
+
makeTypingIndicator(false, threadID, cb, isGroup);
|
78
|
+
};
|
79
|
+
};
|
80
|
+
};
|
@@ -0,0 +1,109 @@
|
|
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 setMessageReaction(reaction, messageID, callback, forceCustomReaction) {
|
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, data) {
|
17
|
+
if (err) return rejectFunc(err);
|
18
|
+
resolveFunc(data);
|
19
|
+
};
|
20
|
+
}
|
21
|
+
|
22
|
+
switch (reaction) {
|
23
|
+
case "\uD83D\uDE0D": //:heart_eyes:
|
24
|
+
case "\uD83D\uDE06": //:laughing:
|
25
|
+
case "\uD83D\uDE2E": //:open_mouth:
|
26
|
+
case "\uD83D\uDE22": //:cry:
|
27
|
+
case "\uD83D\uDE20": //:angry:
|
28
|
+
case "\uD83D\uDC4D": //:thumbsup:
|
29
|
+
case "\uD83D\uDC4E": //:thumbsdown:
|
30
|
+
case "\u2764": //:heart:
|
31
|
+
case "\uD83D\uDC97": //:glowingheart:
|
32
|
+
case "":
|
33
|
+
//valid
|
34
|
+
break;
|
35
|
+
case ":heart_eyes:":
|
36
|
+
case ":love:":
|
37
|
+
reaction = "\uD83D\uDE0D";
|
38
|
+
break;
|
39
|
+
case ":laughing:":
|
40
|
+
case ":haha:":
|
41
|
+
reaction = "\uD83D\uDE06";
|
42
|
+
break;
|
43
|
+
case ":open_mouth:":
|
44
|
+
case ":wow:":
|
45
|
+
reaction = "\uD83D\uDE2E";
|
46
|
+
break;
|
47
|
+
case ":cry:":
|
48
|
+
case ":sad:":
|
49
|
+
reaction = "\uD83D\uDE22";
|
50
|
+
break;
|
51
|
+
case ":angry:":
|
52
|
+
reaction = "\uD83D\uDE20";
|
53
|
+
break;
|
54
|
+
case ":thumbsup:":
|
55
|
+
case ":like:":
|
56
|
+
reaction = "\uD83D\uDC4D";
|
57
|
+
break;
|
58
|
+
case ":thumbsdown:":
|
59
|
+
case ":dislike:":
|
60
|
+
reaction = "\uD83D\uDC4E";
|
61
|
+
break;
|
62
|
+
case ":heart:":
|
63
|
+
reaction = "\u2764";
|
64
|
+
break;
|
65
|
+
case ":glowingheart:":
|
66
|
+
reaction = "\uD83D\uDC97";
|
67
|
+
break;
|
68
|
+
default:
|
69
|
+
if (forceCustomReaction) break;
|
70
|
+
return callback({ error: "Reaction is not a valid emoji." });
|
71
|
+
}
|
72
|
+
|
73
|
+
var variables = {
|
74
|
+
data: {
|
75
|
+
client_mutation_id: ctx.clientMutationId++,
|
76
|
+
actor_id: ctx.userID,
|
77
|
+
action: reaction == "" ? "REMOVE_REACTION" : "ADD_REACTION",
|
78
|
+
message_id: messageID,
|
79
|
+
reaction: reaction
|
80
|
+
}
|
81
|
+
};
|
82
|
+
|
83
|
+
var qs = {
|
84
|
+
doc_id: "1491398900900362",
|
85
|
+
variables: JSON.stringify(variables),
|
86
|
+
dpr: 1
|
87
|
+
};
|
88
|
+
|
89
|
+
defaultFuncs
|
90
|
+
.postFormData(
|
91
|
+
"https://www.facebook.com/webgraphql/mutation/",
|
92
|
+
ctx.jar,
|
93
|
+
{},
|
94
|
+
qs
|
95
|
+
)
|
96
|
+
.then(utils.parseAndCheckLogin(ctx.jar, defaultFuncs))
|
97
|
+
.then(function (resData) {
|
98
|
+
if (!resData) throw { error: "setReaction returned empty object." };
|
99
|
+
if (resData.error) throw resData;
|
100
|
+
callback(null);
|
101
|
+
})
|
102
|
+
.catch(function (err) {
|
103
|
+
log.error("setReaction", err);
|
104
|
+
return callback(err);
|
105
|
+
});
|
106
|
+
|
107
|
+
return returnPromise;
|
108
|
+
};
|
109
|
+
};
|
@@ -0,0 +1,102 @@
|
|
1
|
+
/**
|
2
|
+
* @fix by Priyansh
|
3
|
+
* update as Thursday, 15 Octomber 2023
|
4
|
+
* do not remove the author name to get more updates
|
5
|
+
*/
|
6
|
+
|
7
|
+
"use strict";
|
8
|
+
|
9
|
+
var utils = require("../utils");
|
10
|
+
var 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
|
+
var resolveFunc = function(){};
|
24
|
+
var rejectFunc = function(){};
|
25
|
+
var 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
|
+
var 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
|
+
else {
|
60
|
+
throw {
|
61
|
+
error: "setPostReaction: Invalid reaction type"
|
62
|
+
};
|
63
|
+
}
|
64
|
+
|
65
|
+
var form = {
|
66
|
+
av: ctx.userID,
|
67
|
+
fb_api_caller_class: "RelayModern",
|
68
|
+
fb_api_req_friendly_name: "CometUFIFeedbackReactMutation",
|
69
|
+
doc_id: "4769042373179384",
|
70
|
+
variables: JSON.stringify({
|
71
|
+
input: {
|
72
|
+
actor_id: ctx.userID,
|
73
|
+
feedback_id: (new Buffer.from("feedback:" + postID)).toString("base64"),
|
74
|
+
feedback_reaction: type,
|
75
|
+
feedback_source: "OBJECT",
|
76
|
+
is_tracking_encrypted: true,
|
77
|
+
tracking: [],
|
78
|
+
session_id: "f7dd50dd-db6e-4598-8cd9-561d5002b423",
|
79
|
+
client_mutation_id: Math.round(Math.random() * 19).toString()
|
80
|
+
},
|
81
|
+
useDefaultActor: false,
|
82
|
+
scale: 3
|
83
|
+
})
|
84
|
+
};
|
85
|
+
|
86
|
+
defaultFuncs
|
87
|
+
.post("https://www.facebook.com/api/graphql/", ctx.jar, form)
|
88
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
89
|
+
.then(function(resData) {
|
90
|
+
if (resData.errors) {
|
91
|
+
throw resData;
|
92
|
+
}
|
93
|
+
return callback(null, formatData(resData.data));
|
94
|
+
})
|
95
|
+
.catch(function(err) {
|
96
|
+
log.error("setPostReaction", err);
|
97
|
+
return callback(err);
|
98
|
+
});
|
99
|
+
|
100
|
+
return returnPromise;
|
101
|
+
};
|
102
|
+
};
|
package/src/setTitle.js
ADDED
@@ -0,0 +1,74 @@
|
|
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 setTitle(newTitle, threadID, callback) {
|
8
|
+
if (
|
9
|
+
!callback &&
|
10
|
+
(utils.getType(threadID) === "Function" ||
|
11
|
+
utils.getType(threadID) === "AsyncFunction")
|
12
|
+
) throw { error: "please pass a threadID as a second argument." };
|
13
|
+
|
14
|
+
|
15
|
+
var resolveFunc = function () { };
|
16
|
+
var rejectFunc = function () { };
|
17
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
18
|
+
resolveFunc = resolve;
|
19
|
+
rejectFunc = reject;
|
20
|
+
});
|
21
|
+
|
22
|
+
if (!callback) {
|
23
|
+
callback = function (err, data) {
|
24
|
+
if (err) return rejectFunc(err);
|
25
|
+
resolveFunc(data);
|
26
|
+
};
|
27
|
+
}
|
28
|
+
|
29
|
+
var messageAndOTID = utils.generateOfflineThreadingID();
|
30
|
+
var form = {
|
31
|
+
client: "mercury",
|
32
|
+
action_type: "ma-type:log-message",
|
33
|
+
author: "fbid:" + ctx.userID,
|
34
|
+
author_email: "",
|
35
|
+
coordinates: "",
|
36
|
+
timestamp: Date.now(),
|
37
|
+
timestamp_absolute: "Today",
|
38
|
+
timestamp_relative: utils.generateTimestampRelative(),
|
39
|
+
timestamp_time_passed: "0",
|
40
|
+
is_unread: false,
|
41
|
+
is_cleared: false,
|
42
|
+
is_forward: false,
|
43
|
+
is_filtered_content: false,
|
44
|
+
is_spoof_warning: false,
|
45
|
+
source: "source:chat:web",
|
46
|
+
"source_tags[0]": "source:chat",
|
47
|
+
status: "0",
|
48
|
+
offline_threading_id: messageAndOTID,
|
49
|
+
message_id: messageAndOTID,
|
50
|
+
threading_id: utils.generateThreadingID(ctx.clientID),
|
51
|
+
manual_retry_cnt: "0",
|
52
|
+
thread_fbid: threadID,
|
53
|
+
thread_name: newTitle,
|
54
|
+
thread_id: threadID,
|
55
|
+
log_message_type: "log:thread-name"
|
56
|
+
};
|
57
|
+
|
58
|
+
defaultFuncs
|
59
|
+
.post("https://www.facebook.com/messaging/set_thread_name/", ctx.jar, form)
|
60
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
61
|
+
.then(function (resData) {
|
62
|
+
if (resData.error && resData.error === 1545012) throw { error: "Cannot change chat title: Not member of chat." };
|
63
|
+
if (resData.error && resData.error === 1545003) throw { error: "Cannot set title of single-user chat." };
|
64
|
+
if (resData.error) throw resData;
|
65
|
+
return callback();
|
66
|
+
})
|
67
|
+
.catch(function (err) {
|
68
|
+
log.error("setTitle", err);
|
69
|
+
return callback(err);
|
70
|
+
});
|
71
|
+
|
72
|
+
return returnPromise;
|
73
|
+
};
|
74
|
+
};
|