fca-luxury 1.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of fca-luxury might be problematic. Click here for more details.

Files changed (66) hide show
  1. package/DOCS.md +1686 -0
  2. package/README.md +220 -0
  3. package/index.js +544 -0
  4. package/package.json +73 -0
  5. package/src/Screenshot.js +83 -0
  6. package/src/addExternalModule.js +15 -0
  7. package/src/addUserToGroup.js +77 -0
  8. package/src/changeAdminStatus.js +47 -0
  9. package/src/changeArchivedStatus.js +41 -0
  10. package/src/changeAvt.js +85 -0
  11. package/src/changeBio.js +65 -0
  12. package/src/changeBlockedStatus.js +36 -0
  13. package/src/changeGroupImage.js +106 -0
  14. package/src/changeNickname.js +45 -0
  15. package/src/changeThreadColor.js +61 -0
  16. package/src/changeThreadEmoji.js +41 -0
  17. package/src/createNewGroup.js +70 -0
  18. package/src/createPoll.js +59 -0
  19. package/src/deleteMessage.js +44 -0
  20. package/src/deleteThread.js +42 -0
  21. package/src/editMessage.js +55 -0
  22. package/src/forwardAttachment.js +47 -0
  23. package/src/getCurrentUserID.js +7 -0
  24. package/src/getEmojiUrl.js +27 -0
  25. package/src/getFriendsList.js +73 -0
  26. package/src/getThreadHistory.js +537 -0
  27. package/src/getThreadHistoryDeprecated.js +71 -0
  28. package/src/getThreadInfo.js +171 -0
  29. package/src/getThreadInfoDeprecated.js +56 -0
  30. package/src/getThreadList.js +213 -0
  31. package/src/getThreadListDeprecated.js +46 -0
  32. package/src/getThreadPictures.js +59 -0
  33. package/src/getUserID.js +61 -0
  34. package/src/getUserInfo.js +66 -0
  35. package/src/handleFriendRequest.js +46 -0
  36. package/src/handleMessageRequest.js +47 -0
  37. package/src/httpGet.js +49 -0
  38. package/src/httpPost.js +48 -0
  39. package/src/listenMqtt.js +701 -0
  40. package/src/logout.js +68 -0
  41. package/src/markAsDelivered.js +47 -0
  42. package/src/markAsRead.js +70 -0
  43. package/src/markAsReadAll.js +40 -0
  44. package/src/markAsSeen.js +48 -0
  45. package/src/muteThread.js +45 -0
  46. package/src/removeUserFromGroup.js +45 -0
  47. package/src/resolvePhotoUrl.js +36 -0
  48. package/src/searchForThread.js +42 -0
  49. package/src/sendMessage.js +328 -0
  50. package/src/sendTypingIndicator.js +70 -0
  51. package/src/setMessageReaction.js +109 -0
  52. package/src/setPostReaction.js +102 -0
  53. package/src/setTitle.js +70 -0
  54. package/src/shareContact.js +46 -0
  55. package/src/shareLink.js +55 -0
  56. package/src/threadColors.js +41 -0
  57. package/src/unfriend.js +42 -0
  58. package/src/unsendMessage.js +39 -0
  59. package/test/data/shareAttach.js +146 -0
  60. package/test/data/something.mov +0 -0
  61. package/test/data/test.png +0 -0
  62. package/test/data/test.txt +7 -0
  63. package/test/example-config.json +18 -0
  64. package/test/test-page.js +140 -0
  65. package/test/test.js +385 -0
  66. package/utils.js +1196 -0
@@ -0,0 +1,328 @@
1
+ "use strict";
2
+
3
+ var utils = require("../utils");
4
+ var log = require("npmlog");
5
+ var bluebird = require("bluebird");
6
+
7
+ var allowedProperties = {
8
+ attachment: true,
9
+ url: true,
10
+ sticker: true,
11
+ emoji: true,
12
+ emojiSize: true,
13
+ body: true,
14
+ mentions: true,
15
+ location: true,
16
+ };
17
+
18
+ module.exports = function (defaultFuncs, api, ctx) {
19
+ function uploadAttachment(attachments, callback) {
20
+ var uploads = [];
21
+
22
+ // create an array of promises
23
+ for (var i = 0; i < attachments.length; i++) {
24
+ if (!utils.isReadableStream(attachments[i])) throw { error: "Attachment should be a readable stream and not " + utils.getType(attachments[i]) + "." };
25
+ var form = {
26
+ upload_1024: attachments[i],
27
+ voice_clip: "true"
28
+ };
29
+
30
+ uploads.push(
31
+ defaultFuncs
32
+ .postFormData("https://upload.facebook.com/ajax/mercury/upload.php", ctx.jar, form, {}, {})
33
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
34
+ .then(function (resData) {
35
+ if (resData.error) throw resData;
36
+ // We have to return the data unformatted unless we want to change it
37
+ // back in sendMessage.
38
+ return resData.payload.metadata[0];
39
+ })
40
+ );
41
+ }
42
+
43
+ // resolve all promises
44
+ bluebird
45
+ .all(uploads)
46
+ .then(resData => callback(null, resData))
47
+ .catch(function (err) {
48
+ log.error("uploadAttachment", err);
49
+ return callback(err);
50
+ });
51
+ }
52
+
53
+ function getUrl(url, callback) {
54
+ var form = {
55
+ image_height: 960,
56
+ image_width: 960,
57
+ uri: url
58
+ };
59
+
60
+ defaultFuncs
61
+ .post("https://www.facebook.com/message_share_attachment/fromURI/", ctx.jar, form)
62
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
63
+ .then(function (resData) {
64
+ if (resData.error) return callback(resData);
65
+ if (!resData.payload) return callback({ error: "Invalid url" });
66
+ callback(null, resData.payload.share_data.share_params);
67
+ })
68
+ .catch(function (err) {
69
+ log.error("getUrl", err);
70
+ return callback(err);
71
+ });
72
+ }
73
+
74
+ function sendContent(form, threadID, isSingleUser, messageAndOTID, callback) {
75
+ // There are three cases here:
76
+ // 1. threadID is of type array, where we're starting a new group chat with users
77
+ // specified in the array.
78
+ // 2. User is sending a message to a specific user.
79
+ // 3. No additional form params and the message goes to an existing group chat.
80
+ if (utils.getType(threadID) === "Array") {
81
+ for (var i = 0; i < threadID.length; i++) form["specific_to_list[" + i + "]"] = "fbid:" + threadID[i];
82
+ form["specific_to_list[" + threadID.length + "]"] = "fbid:" + ctx.userID;
83
+ form["client_thread_id"] = "root:" + messageAndOTID;
84
+ log.info("sendMessage", "Sending message to multiple users: " + threadID);
85
+ }
86
+ else {
87
+ // This means that threadID is the id of a user, and the chat
88
+ // is a single person chat
89
+ if (isSingleUser) {
90
+ form["specific_to_list[0]"] = "fbid:" + threadID;
91
+ form["specific_to_list[1]"] = "fbid:" + ctx.userID;
92
+ form["other_user_fbid"] = threadID;
93
+ }
94
+ else form["thread_fbid"] = threadID;
95
+ }
96
+
97
+ if (ctx.globalOptions.pageID) {
98
+ form["author"] = "fbid:" + ctx.globalOptions.pageID;
99
+ form["specific_to_list[1]"] = "fbid:" + ctx.globalOptions.pageID;
100
+ form["creator_info[creatorID]"] = ctx.userID;
101
+ form["creator_info[creatorType]"] = "direct_admin";
102
+ form["creator_info[labelType]"] = "sent_message";
103
+ form["creator_info[pageID]"] = ctx.globalOptions.pageID;
104
+ form["request_user_id"] = ctx.globalOptions.pageID;
105
+ form["creator_info[profileURI]"] = "https://www.facebook.com/profile.php?id=" + ctx.userID;
106
+ }
107
+
108
+ defaultFuncs
109
+ .post("https://www.facebook.com/messaging/send/", ctx.jar, form)
110
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
111
+ .then(function (resData) {
112
+ if (!resData) return callback({ error: "Send message failed." });
113
+ if (resData.error) {
114
+ if (resData.error === 1545012) {
115
+ log.warn("sendMessage", "Got error 1545012. This might mean that you're not part of the conversation " + threadID);
116
+ }
117
+ else {
118
+ log.error("sendMessage", resData);
119
+ }
120
+ return callback(resData);
121
+ }
122
+
123
+ var messageInfo = resData.payload.actions.reduce(function (p, v) {
124
+ return (
125
+ {
126
+ threadID: v.thread_fbid,
127
+ messageID: v.message_id,
128
+ timestamp: v.timestamp
129
+ } || p
130
+ );
131
+ }, null);
132
+
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);
139
+ });
140
+ }
141
+
142
+ function send(form, threadID, messageAndOTID, callback, isGroup) {
143
+ // We're doing a query to this to check if the given id is the id of
144
+ // a user or of a group chat. The form will be different depending
145
+ // on that.
146
+ if (utils.getType(threadID) === "Array") sendContent(form, threadID, false, messageAndOTID, callback);
147
+ else {
148
+ if (utils.getType(isGroup) != "Boolean") sendContent(form, threadID, threadID.length === 15, messageAndOTID, callback);
149
+ else sendContent(form, threadID, !isGroup, messageAndOTID, callback);
150
+ }
151
+ }
152
+
153
+ function handleUrl(msg, form, callback, cb) {
154
+ if (msg.url) {
155
+ form["shareable_attachment[share_type]"] = "100";
156
+ getUrl(msg.url, function (err, params) {
157
+ if (err) return callback(err);
158
+ form["shareable_attachment[share_params]"] = params;
159
+ cb();
160
+ });
161
+ }
162
+ else cb();
163
+ }
164
+
165
+ function handleLocation(msg, form, callback, cb) {
166
+ if (msg.location) {
167
+ if (msg.location.latitude == null || msg.location.longitude == null) return callback({ error: "location property needs both latitude and longitude" });
168
+ form["location_attachment[coordinates][latitude]"] = msg.location.latitude;
169
+ form["location_attachment[coordinates][longitude]"] = msg.location.longitude;
170
+ form["location_attachment[is_current_location]"] = !!msg.location.current;
171
+ }
172
+ cb();
173
+ }
174
+
175
+ function handleSticker(msg, form, callback, cb) {
176
+ if (msg.sticker) form["sticker_id"] = msg.sticker;
177
+ cb();
178
+ }
179
+
180
+ function handleEmoji(msg, form, callback, cb) {
181
+ if (msg.emojiSize != null && msg.emoji == null) return callback({ error: "emoji property is empty" });
182
+ if (msg.emoji) {
183
+ if (msg.emojiSize == null) msg.emojiSize = "medium";
184
+ if (msg.emojiSize != "small" && msg.emojiSize != "medium" && msg.emojiSize != "large") return callback({ error: "emojiSize property is invalid" });
185
+ if (form["body"] != null && form["body"] != "") return callback({ error: "body is not empty" });
186
+ form["body"] = msg.emoji;
187
+ form["tags[0]"] = "hot_emoji_size:" + msg.emojiSize;
188
+ }
189
+ cb();
190
+ }
191
+
192
+ function handleAttachment(msg, form, callback, cb) {
193
+ if (msg.attachment) {
194
+ form["image_ids"] = [];
195
+ form["gif_ids"] = [];
196
+ form["file_ids"] = [];
197
+ form["video_ids"] = [];
198
+ form["audio_ids"] = [];
199
+
200
+ if (utils.getType(msg.attachment) !== "Array") msg.attachment = [msg.attachment];
201
+ if (msg.attachment.every(e=>/_id$/.test(e[0]))) {
202
+ //console.log(msg.attachment)
203
+ msg.attachment.map(e=>form[`${e[0]}s`].push(e[1]));
204
+ return cb();
205
+ }
206
+ uploadAttachment(msg.attachment, function (err, files) {
207
+ if (err) return callback(err);
208
+ files.forEach(function (file) {
209
+ var key = Object.keys(file);
210
+ var type = key[0]; // image_id, file_id, etc
211
+ form["" + type + "s"].push(file[type]); // push the id
212
+ });
213
+ cb();
214
+ });
215
+ }
216
+ else cb();
217
+ }
218
+
219
+ function handleMention(msg, form, callback, cb) {
220
+ if (msg.mentions) {
221
+ for (let i = 0; i < msg.mentions.length; i++) {
222
+ const mention = msg.mentions[i];
223
+ const tag = mention.tag;
224
+ if (typeof tag !== "string") return callback({ error: "Mention tags must be strings." });
225
+ const offset = msg.body.indexOf(tag, mention.fromIndex || 0);
226
+ if (offset < 0) log.warn("handleMention", 'Mention for "' + tag + '" not found in message string.');
227
+ if (mention.id == null) log.warn("handleMention", "Mention id should be non-null.");
228
+
229
+ const id = mention.id || 0;
230
+ const emptyChar = '\u200E';
231
+ form["body"] = emptyChar + msg.body;
232
+ form["profile_xmd[" + i + "][offset]"] = offset + 1;
233
+ form["profile_xmd[" + i + "][length]"] = tag.length;
234
+ form["profile_xmd[" + i + "][id]"] = id;
235
+ form["profile_xmd[" + i + "][type]"] = "p";
236
+ }
237
+ }
238
+ cb();
239
+ }
240
+
241
+ return function sendMessage(msg, threadID, callback, replyToMessage, isGroup) {
242
+ typeof isGroup == "undefined" ? isGroup = null : "";
243
+ if (!callback && (utils.getType(threadID) === "Function" || utils.getType(threadID) === "AsyncFunction")) return threadID({ error: "Pass a threadID as a second argument." });
244
+ if (!replyToMessage && utils.getType(callback) === "String") {
245
+ replyToMessage = callback;
246
+ callback = function () { };
247
+ }
248
+
249
+ var resolveFunc = function () { };
250
+ var rejectFunc = function () { };
251
+ var returnPromise = new Promise(function (resolve, reject) {
252
+ resolveFunc = resolve;
253
+ rejectFunc = reject;
254
+ });
255
+
256
+ if (!callback) {
257
+ callback = function (err, data) {
258
+ if (err) return rejectFunc(err);
259
+ resolveFunc(data);
260
+ };
261
+ }
262
+
263
+ var msgType = utils.getType(msg);
264
+ var threadIDType = utils.getType(threadID);
265
+ var messageIDType = utils.getType(replyToMessage);
266
+
267
+ if (msgType !== "String" && msgType !== "Object") return callback({ error: "Message should be of type string or object and not " + msgType + "." });
268
+
269
+ // Changing this to accomodate an array of users
270
+ if (threadIDType !== "Array" && threadIDType !== "Number" && threadIDType !== "String") return callback({ error: "ThreadID should be of type number, string, or array and not " + threadIDType + "." });
271
+
272
+ if (replyToMessage && messageIDType !== 'String') return callback({ error: "MessageID should be of type string and not " + threadIDType + "." });
273
+
274
+ if (msgType === "String") msg = { body: msg };
275
+ var disallowedProperties = Object.keys(msg).filter(prop => !allowedProperties[prop]);
276
+ if (disallowedProperties.length > 0) return callback({ error: "Dissallowed props: `" + disallowedProperties.join(", ") + "`" });
277
+
278
+ var messageAndOTID = utils.generateOfflineThreadingID();
279
+
280
+ var form = {
281
+ client: "mercury",
282
+ action_type: "ma-type:user-generated-message",
283
+ author: "fbid:" + ctx.userID,
284
+ timestamp: Date.now(),
285
+ timestamp_absolute: "Today",
286
+ timestamp_relative: utils.generateTimestampRelative(),
287
+ timestamp_time_passed: "0",
288
+ is_unread: false,
289
+ is_cleared: false,
290
+ is_forward: false,
291
+ is_filtered_content: false,
292
+ is_filtered_content_bh: false,
293
+ is_filtered_content_account: false,
294
+ is_filtered_content_quasar: false,
295
+ is_filtered_content_invalid_app: false,
296
+ is_spoof_warning: false,
297
+ source: "source:chat:web",
298
+ "source_tags[0]": "source:chat",
299
+ body: msg.body ? msg.body.toString() : "",
300
+ html_body: false,
301
+ ui_push_phase: "V3",
302
+ status: "0",
303
+ offline_threading_id: messageAndOTID,
304
+ message_id: messageAndOTID,
305
+ threading_id: utils.generateThreadingID(ctx.clientID),
306
+ "ephemeral_ttl_mode:": "0",
307
+ manual_retry_cnt: "0",
308
+ has_attachment: !!(msg.attachment || msg.url || msg.sticker),
309
+ signatureID: utils.getSignatureID(),
310
+ replied_to_message_id: replyToMessage
311
+ };
312
+
313
+ handleLocation(msg, form, callback, () =>
314
+ handleSticker(msg, form, callback, () =>
315
+ handleAttachment(msg, form, callback, () =>
316
+ handleUrl(msg, form, callback, () =>
317
+ handleEmoji(msg, form, callback, () =>
318
+ handleMention(msg, form, callback, () =>
319
+ send(form, threadID, messageAndOTID, callback, isGroup)
320
+ )
321
+ )
322
+ )
323
+ )
324
+ )
325
+ );
326
+ return returnPromise;
327
+ };
328
+ };
@@ -0,0 +1,70 @@
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) form.to = threadID;
19
+
20
+ defaultFuncs
21
+ .post("https://www.facebook.com/ajax/messaging/typ.php", ctx.jar, form)
22
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
23
+ .then(function (resData) {
24
+ if (resData.error) throw resData;
25
+ return callback();
26
+ })
27
+ .catch(function (err) {
28
+ log.error("sendTypingIndicator", err);
29
+ if (utils.getType(err) == "Object" && err.error === "Not logged in") ctx.loggedIn = false;
30
+ return callback(err);
31
+ });
32
+ }
33
+ else {
34
+ api.getUserInfo(threadID, function (err, res) {
35
+ if (err) return callback(err);
36
+ // If id is single person chat
37
+ if (Object.keys(res).length > 0) form.to = threadID;
38
+ defaultFuncs
39
+ .post("https://www.facebook.com/ajax/messaging/typ.php", ctx.jar, form)
40
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
41
+ .then(function (resData) {
42
+ if (resData.error) throw resData;
43
+ return callback();
44
+ })
45
+ .catch(function (err) {
46
+ log.error("sendTypingIndicator", err);
47
+ if (utils.getType(err) == "Object" && err.error === "Not logged in.") ctx.loggedIn = false;
48
+ return callback(err);
49
+ });
50
+ });
51
+ }
52
+ }
53
+
54
+ return function sendTypingIndicator(threadID, callback, isGroup) {
55
+ if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
56
+ if (callback) log.warn("sendTypingIndicator", "callback is not a function - ignoring.");
57
+ callback = () => { };
58
+ }
59
+
60
+ makeTypingIndicator(true, threadID, callback, isGroup);
61
+
62
+ return function end(cb) {
63
+ if (utils.getType(cb) !== "Function" && utils.getType(cb) !== "AsyncFunction") {
64
+ if (cb) log.warn("sendTypingIndicator", "callback is not a function - ignoring.");
65
+ cb = () => { };
66
+ }
67
+ makeTypingIndicator(false, threadID, cb, isGroup);
68
+ };
69
+ };
70
+ };
@@ -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 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
+ 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
+ };
@@ -0,0 +1,70 @@
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 (!callback && (utils.getType(threadID) === "Function" || utils.getType(threadID) === "AsyncFunction"))
9
+ throw { error: "please pass a threadID as a second argument." };
10
+
11
+
12
+ var resolveFunc = function () { };
13
+ var rejectFunc = function () { };
14
+ var returnPromise = new Promise(function (resolve, reject) {
15
+ resolveFunc = resolve;
16
+ rejectFunc = reject;
17
+ });
18
+
19
+ if (!callback) {
20
+ callback = function (err, data) {
21
+ if (err) return rejectFunc(err);
22
+ resolveFunc(data);
23
+ };
24
+ }
25
+
26
+ var messageAndOTID = utils.generateOfflineThreadingID();
27
+ var form = {
28
+ client: "mercury",
29
+ action_type: "ma-type:log-message",
30
+ author: "fbid:" + ctx.userID,
31
+ author_email: "",
32
+ coordinates: "",
33
+ timestamp: Date.now(),
34
+ timestamp_absolute: "Today",
35
+ timestamp_relative: utils.generateTimestampRelative(),
36
+ timestamp_time_passed: "0",
37
+ is_unread: false,
38
+ is_cleared: false,
39
+ is_forward: false,
40
+ is_filtered_content: false,
41
+ is_spoof_warning: false,
42
+ source: "source:chat:web",
43
+ "source_tags[0]": "source:chat",
44
+ status: "0",
45
+ offline_threading_id: messageAndOTID,
46
+ message_id: messageAndOTID,
47
+ threading_id: utils.generateThreadingID(ctx.clientID),
48
+ manual_retry_cnt: "0",
49
+ thread_fbid: threadID,
50
+ thread_name: newTitle,
51
+ thread_id: threadID,
52
+ log_message_type: "log:thread-name"
53
+ };
54
+
55
+ defaultFuncs
56
+ .post("https://www.facebook.com/messaging/set_thread_name/", ctx.jar, form)
57
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
58
+ .then(function (resData) {
59
+ if (resData.error && resData.error === 1545012) throw { error: "Cannot change chat title: Not member of chat." };
60
+ if (resData.error && resData.error === 1545003) throw { error: "Cannot set title of single-user chat." };
61
+ if (resData.error) throw resData;
62
+ return callback();
63
+ })
64
+ .catch(function (err) {
65
+ log.error("setTitle", err);
66
+ return callback(err);
67
+ });
68
+ return returnPromise;
69
+ };
70
+ };