alicezetion 1.7.5 → 1.7.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. package/.cache/replit/__replit_disk_meta.json +1 -1
  2. package/.cache/replit/nix/env.json +1 -1
  3. package/.travis.yml +6 -0
  4. package/index.js +120 -655
  5. package/package.json +25 -37
  6. package/replit.nix +4 -3
  7. package/src/addExternalModule.js +5 -13
  8. package/src/addUserToGroup.js +12 -36
  9. package/src/changeAdminStatus.js +37 -85
  10. package/src/changeArchivedStatus.js +9 -15
  11. package/src/changeBio.js +8 -13
  12. package/src/changeBlockedStatus.js +8 -14
  13. package/src/changeGroupImage.js +13 -28
  14. package/src/changeNickname.js +11 -22
  15. package/src/changeThreadColor.js +10 -16
  16. package/src/changeThreadEmoji.js +9 -18
  17. package/src/chat.js +280 -401
  18. package/src/createNewGroup.js +10 -18
  19. package/src/createPoll.js +11 -17
  20. package/src/deleteMessage.js +10 -17
  21. package/src/deleteThread.js +10 -17
  22. package/src/forwardAttachment.js +9 -15
  23. package/src/forwardMessage.js +0 -0
  24. package/src/getCurrentUserID.js +1 -1
  25. package/src/getEmojiUrl.js +2 -3
  26. package/src/getFriendsList.js +10 -18
  27. package/src/getThreadHistory.js +59 -156
  28. package/src/getThreadHistoryDeprecated.js +15 -26
  29. package/src/getThreadInfo.js +42 -68
  30. package/src/getThreadInfoDeprecated.js +13 -25
  31. package/src/getThreadList.js +53 -112
  32. package/src/getThreadListDeprecated.js +12 -30
  33. package/src/getThreadPictures.js +13 -25
  34. package/src/getUserID.js +7 -9
  35. package/src/getUserInfo.js +10 -12
  36. package/src/handleFriendRequest.js +35 -36
  37. package/src/handleMessageRequest.js +10 -18
  38. package/src/httpGet.js +13 -20
  39. package/src/httpPost.js +13 -19
  40. package/src/listen.js +553 -0
  41. package/src/listenMqtt-Test.js +687 -0
  42. package/src/listenMqtt.js +621 -1224
  43. package/src/logout.js +13 -18
  44. package/src/markAsDelivered.js +10 -17
  45. package/src/markAsRead.js +24 -36
  46. package/src/{seen.js → markAsReadAll.js} +10 -17
  47. package/src/markAsSeen.js +12 -22
  48. package/src/muteThread.js +9 -15
  49. package/src/removeUserFromGroup.js +11 -38
  50. package/src/resolvePhotoUrl.js +6 -9
  51. package/src/searchForThread.js +8 -14
  52. package/src/sendMessage.js +315 -0
  53. package/src/sendTypingIndicator.js +19 -44
  54. package/src/{react.js → setMessageReaction.js} +9 -20
  55. package/src/setPostReaction.js +22 -63
  56. package/src/setTitle.js +12 -22
  57. package/src/threadColors.js +19 -17
  58. package/src/unfriend.js +9 -15
  59. package/src/{unsend.js → unsendMessage.js} +8 -9
  60. package/test/data/shareAttach.js +146 -0
  61. package/test/data/something.mov +0 -0
  62. package/test/data/test.png +0 -0
  63. package/test/data/test.txt +7 -0
  64. package/test/example-config.json +18 -0
  65. package/test/test-page.js +140 -0
  66. package/test/test.js +385 -0
  67. package/utils.js +27 -120
  68. package/Extra/Database/index.js +0 -399
  69. package/Extra/Database/methods.js +0 -286
  70. package/Extra/ExtraAddons.js +0 -213
  71. package/Extra/ExtraGetThread.js +0 -1
  72. package/Extra/ExtraUptimeRobot.js +0 -59
  73. package/Extra/PM2/ecosystem.config.js +0 -23
  74. package/Extra/Src/Last-Run.js +0 -48
  75. package/Language/index.json +0 -151
  76. package/StateCrypt.js +0 -22
  77. package/broadcast.js +0 -42
  78. package/logger.js +0 -21
  79. package/src/changeAvt.js +0 -91
  80. package/src/getAccessToken.js +0 -32
  81. package/src/getMessage.js +0 -84
  82. package/src/getUserInfoV2.js +0 -35
  83. package/src/httpPostFormData.js +0 -46
@@ -5,13 +5,11 @@ const log = require("npmlog");
5
5
 
6
6
  function createProfileUrl(url, username, id) {
7
7
  if (url) return url;
8
- return (
9
- "https://www.facebook.com/" + (username || utils.formatID(id.toString()))
10
- );
8
+ return "https://www.facebook.com/" + (username || utils.formatID(id.toString()));
11
9
  }
12
10
 
13
11
  function formatParticipants(participants) {
14
- return participants.edges.map(p => {
12
+ return participants.edges.map((p) => {
15
13
  p = p.node.messaging_actor;
16
14
  switch (p["__typename"]) {
17
15
  case "User":
@@ -23,7 +21,7 @@ function formatParticipants(participants) {
23
21
  gender: p.gender,
24
22
  url: p.url, // how about making it profileURL
25
23
  profilePicture: p.big_image_src.uri,
26
- username: p.username || null,
24
+ username: (p.username || null),
27
25
  // TODO: maybe better names for these?
28
26
  isViewerFriend: p.is_viewer_friend, // true/false
29
27
  isMessengerUser: p.is_messenger_user, // true/false
@@ -39,13 +37,13 @@ function formatParticipants(participants) {
39
37
  name: p.name,
40
38
  url: p.url,
41
39
  profilePicture: p.big_image_src.uri,
42
- username: p.username || null,
40
+ username: (p.username || null),
43
41
  // uhm... better names maybe?
44
42
  acceptsMessengerUserFeedback: p.accepts_messenger_user_feedback, // true/false
45
43
  isMessengerUser: p.is_messenger_user, // true/false
46
44
  isVerified: p.is_verified, // true/false
47
45
  isMessengerPlatformBot: p.is_messenger_platform_bot, // true/false
48
- isMessageBlockedByViewer: p.is_message_blocked_by_viewer // true/false
46
+ isMessageBlockedByViewer: p.is_message_blocked_by_viewer, // true/false
49
47
  };
50
48
  case "ReducedMessagingActor":
51
49
  case "UnavailableMessagingActor":
@@ -55,19 +53,15 @@ function formatParticipants(participants) {
55
53
  name: p.name,
56
54
  url: createProfileUrl(p.url, p.username, p.id), // in this case p.url is null all the time
57
55
  profilePicture: p.big_image_src.uri, // in this case it is default facebook photo, we could determine gender using it
58
- username: p.username || null, // maybe we could use it to generate profile URL?
59
- isMessageBlockedByViewer: p.is_message_blocked_by_viewer // true/false
56
+ username: (p.username || null), // maybe we could use it to generate profile URL?
57
+ isMessageBlockedByViewer: p.is_message_blocked_by_viewer, // true/false
60
58
  };
61
59
  default:
62
- log.warn(
63
- "getThreadList",
64
- "Found participant with unsupported typename. Please open an issue at https://github.com/Schmavery/facebook-chat-api/issues\n" +
65
- JSON.stringify(p, null, 2)
66
- );
60
+ log.warn("getThreadList", "Found participant with unsupported typename. Please open an issue at https://github.com/Schmavery/facebook-chat-api/issues\n" + JSON.stringify(p, null, 2));
67
61
  return {
68
62
  accountType: p["__typename"],
69
63
  userID: utils.formatID(p.id.toString()),
70
- name: p.name || `[unknown ${p["__typename"]}]` // probably it will always be something... but fallback to [unknown], just in case
64
+ name: p.name || `[unknown ${p["__typename"]}]`, // probably it will always be something... but fallback to [unknown], just in case
71
65
  };
72
66
  }
73
67
  });
@@ -84,40 +78,30 @@ function getThreadName(t) {
84
78
 
85
79
  for (let po of t.all_participants.edges) {
86
80
  let p = po.node;
87
- if (p.messaging_actor.id === t.thread_key.other_user_id)
88
- return p.messaging_actor.name;
81
+ if (p.messaging_actor.id === t.thread_key.other_user_id) return p.messaging_actor.name;
89
82
  }
90
83
  }
91
84
 
92
85
  function mapNicknames(customizationInfo) {
93
- return customizationInfo && customizationInfo.participant_customizations
94
- ? customizationInfo.participant_customizations.map(u => {
95
- return {
96
- userID: u.participant_id,
97
- nickname: u.nickname
98
- };
99
- })
100
- : [];
86
+ return (customizationInfo && customizationInfo.participant_customizations) ? customizationInfo.participant_customizations.map(u => {
87
+ return {
88
+ "userID": u.participant_id,
89
+ "nickname": u.nickname
90
+ };
91
+ }) : [];
101
92
  }
102
93
 
103
94
  function formatThreadList(data) {
104
95
  return data.map(t => {
105
- let lastMessageNode =
106
- t.last_message && t.last_message.nodes && t.last_message.nodes.length > 0
107
- ? t.last_message.nodes[0]
108
- : null;
96
+ let lastMessageNode = (t.last_message && t.last_message.nodes && t.last_message.nodes.length > 0) ? t.last_message.nodes[0] : null;
109
97
  return {
110
- threadID: t.thread_key
111
- ? utils.formatID(t.thread_key.thread_fbid || t.thread_key.other_user_id)
112
- : null, // shall never be null
98
+ threadID: t.thread_key ? utils.formatID(t.thread_key.thread_fbid || t.thread_key.other_user_id) : null, // shall never be null
113
99
  name: getThreadName(t),
114
100
  unreadCount: t.unread_count,
115
101
  messageCount: t.messages_count,
116
102
  imageSrc: t.image ? t.image.uri : null,
117
103
  emoji: t.customization_info ? t.customization_info.emoji : null,
118
- color: formatColor(
119
- t.customization_info ? t.customization_info.outgoing_bubble_color : null
120
- ),
104
+ color: formatColor(t.customization_info ? t.customization_info.outgoing_bubble_color : null),
121
105
  nicknames: mapNicknames(t.customization_info),
122
106
  muteUntil: t.mute_until,
123
107
  participants: formatParticipants(t.all_participants),
@@ -128,9 +112,7 @@ function formatThreadList(data) {
128
112
  // isPinProtected: t.is_pin_protected, // feature from future? always false (2018-04-04)
129
113
  customizationEnabled: t.customization_enabled, // false for ONE_TO_ONE with Page or ReducedMessagingActor
130
114
  participantAddMode: t.participant_add_mode_as_string, // "ADD" if "GROUP" and null if "ONE_TO_ONE"
131
- montageThread: t.montage_thread
132
- ? Buffer.from(t.montage_thread.id, "base64").toString()
133
- : null, // base64 encoded string "message_thread:0000000000000000"
115
+ montageThread: t.montage_thread ? Buffer.from(t.montage_thread.id, "base64").toString() : null, // base64 encoded string "message_thread:0000000000000000"
134
116
  // it is not userID nor any other ID known to me...
135
117
  // can somebody inspect it? where is it used?
136
118
  // probably Messenger Day uses it
@@ -142,109 +124,74 @@ function formatThreadList(data) {
142
124
  // isCanonicalUser: t.is_canonical_neo_user, // is it always false?
143
125
  // TODO: how about putting snippet in another object? current implementation does not handle every possibile message type etc.
144
126
  snippet: lastMessageNode ? lastMessageNode.snippet : null,
145
- snippetAttachments: lastMessageNode
146
- ? lastMessageNode.extensible_attachment
147
- : null, // TODO: not sure if it works
148
- snippetSender: lastMessageNode
149
- ? utils.formatID(
150
- (lastMessageNode.message_sender.messaging_actor.id || "").toString()
151
- )
152
- : null,
153
- lastMessageTimestamp: lastMessageNode
154
- ? lastMessageNode.timestamp_precise
127
+ snippetAttachments: lastMessageNode ? lastMessageNode.extensible_attachment : null, // TODO: not sure if it works
128
+ snippetSender: lastMessageNode ? utils.formatID((lastMessageNode.message_sender.messaging_actor.id || "").toString()) : null,
129
+ lastMessageTimestamp: lastMessageNode ? lastMessageNode.timestamp_precise : null, // timestamp in miliseconds
130
+ lastReadTimestamp: (t.last_read_receipt && t.last_read_receipt.nodes.length > 0)
131
+ ? (t.last_read_receipt.nodes[0] ? t.last_read_receipt.nodes[0].timestamp_precise : null)
155
132
  : null, // timestamp in miliseconds
156
- lastReadTimestamp:
157
- t.last_read_receipt && t.last_read_receipt.nodes.length > 0
158
- ? t.last_read_receipt.nodes[0]
159
- ? t.last_read_receipt.nodes[0].timestamp_precise
160
- : null
161
- : null, // timestamp in miliseconds
162
133
  cannotReplyReason: t.cannot_reply_reason, // TODO: inspect possible values
163
134
  approvalMode: Boolean(t.approval_mode),
164
135
 
165
136
  // @Legacy
166
- participantIDs: formatParticipants(t.all_participants).map(
167
- participant => participant.userID
168
- ),
137
+ participantIDs: formatParticipants(t.all_participants).map(participant => participant.userID),
169
138
  threadType: t.thread_type === "GROUP" ? 2 : 1 // "GROUP" or "ONE_TO_ONE"
170
139
  };
171
140
  });
172
141
  }
173
142
 
174
- module.exports = function(defaultFuncs, api, ctx) {
143
+ module.exports = function (defaultFuncs, api, ctx) {
175
144
  return function getThreadList(limit, timestamp, tags, callback) {
176
- if (
177
- !callback &&
178
- (utils.getType(tags) === "Function" ||
179
- utils.getType(tags) === "AsyncFunction")
180
- ) {
145
+ if (!callback && (utils.getType(tags) === "Function" || utils.getType(tags) === "AsyncFunction")) {
181
146
  callback = tags;
182
147
  tags = [""];
183
148
  }
184
- if (
185
- utils.getType(limit) !== "Number" ||
186
- !Number.isInteger(limit) ||
187
- limit <= 0
188
- )
189
- throw { error: "getThreadList: limit must be a positive integer" };
149
+ if (utils.getType(limit) !== "Number" || !Number.isInteger(limit) || limit <= 0) throw { error: "getThreadList: limit must be a positive integer" };
190
150
 
191
- if (
192
- utils.getType(timestamp) !== "Null" &&
193
- (utils.getType(timestamp) !== "Number" || !Number.isInteger(timestamp))
194
- )
195
- throw { error: "getThreadList: timestamp must be an integer or null" };
151
+ if (utils.getType(timestamp) !== "Null" && (utils.getType(timestamp) !== "Number" || !Number.isInteger(timestamp))) throw { error: "getThreadList: timestamp must be an integer or null" };
196
152
 
197
153
  if (utils.getType(tags) === "String") tags = [tags];
198
- if (utils.getType(tags) !== "Array")
199
- throw { error: "getThreadList: tags must be an array" };
154
+ if (utils.getType(tags) !== "Array") throw { error: "getThreadList: tags must be an array" };
200
155
 
201
- var resolveFunc = function() {};
202
- var rejectFunc = function() {};
203
- var returnPromise = new Promise(function(resolve, reject) {
156
+ var resolveFunc = function () { };
157
+ var rejectFunc = function () { };
158
+ var returnPromise = new Promise(function (resolve, reject) {
204
159
  resolveFunc = resolve;
205
160
  rejectFunc = reject;
206
161
  });
207
162
 
208
- if (
209
- utils.getType(callback) !== "Function" &&
210
- utils.getType(callback) !== "AsyncFunction"
211
- ) {
212
- callback = function(err, data) {
163
+ if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
164
+ callback = function (err, data) {
213
165
  if (err) return rejectFunc(err);
214
166
  resolveFunc(data);
215
167
  };
216
168
  }
217
169
 
218
170
  const form = {
219
- av: ctx.globalOptions.pageID,
220
- queries: JSON.stringify({
221
- o0: {
171
+ "av": ctx.globalOptions.pageID,
172
+ "queries": JSON.stringify({
173
+ "o0": {
222
174
  // This doc_id was valid on 2020-07-20
223
- doc_id: "3336396659757871",
224
- query_params: {
225
- limit: limit + (timestamp ? 1 : 0),
226
- before: timestamp,
227
- tags: tags,
228
- includeDeliveryReceipts: true,
229
- includeSeqID: false
175
+ "doc_id": "3336396659757871",
176
+ "query_params": {
177
+ "limit": limit + (timestamp ? 1 : 0),
178
+ "before": timestamp,
179
+ "tags": tags,
180
+ "includeDeliveryReceipts": true,
181
+ "includeSeqID": false
230
182
  }
231
183
  }
232
184
  }),
233
- batch_name: "MessengerGraphQLThreadlistFetcher"
185
+ "batch_name": "MessengerGraphQLThreadlistFetcher"
234
186
  };
235
187
 
236
188
  defaultFuncs
237
189
  .post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
238
190
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
239
- .then(resData => {
240
- if (resData[resData.length - 1].error_results > 0)
241
- throw resData[0].o0.errors;
191
+ .then((resData) => {
192
+ if (resData[resData.length - 1].error_results > 0) throw resData[0].o0.errors;
242
193
 
243
- if (resData[resData.length - 1].successful_results === 0)
244
- throw {
245
- error: "getThreadList: there was no successful_results",
246
- res: resData
247
- };
194
+ if (resData[resData.length - 1].successful_results === 0) throw { error: "getThreadList: there was no successful_results", res: resData };
248
195
 
249
196
  // When we ask for threads using timestamp from the previous request,
250
197
  // we are getting the last thread repeated as the first thread in this response.
@@ -254,16 +201,10 @@ module.exports = function(defaultFuncs, api, ctx) {
254
201
  // but after removing the duplicated one, it is again 10
255
202
  if (timestamp) resData[0].o0.data.viewer.message_threads.nodes.shift();
256
203
 
257
- callback(
258
- null,
259
- formatThreadList(resData[0].o0.data.viewer.message_threads.nodes)
260
- );
204
+ callback(null, formatThreadList(resData[0].o0.data.viewer.message_threads.nodes));
261
205
  })
262
- .catch(err => {
263
- log.error(
264
- "getThreadList",
265
- "Lỗi: getThreadList Có Thể Do Bạn Spam Quá Nhiều, Hãy Thử Lại !"
266
- );
206
+ .catch((err) => {
207
+ log.error("getThreadList", "ParseAndCheckLogin got status code: 404. Bailing out of trying to parse response.");
267
208
  return callback(err);
268
209
  });
269
210
 
@@ -3,31 +3,21 @@
3
3
  var utils = require("../utils");
4
4
  var log = require("npmlog");
5
5
 
6
- module.exports = function(defaultFuncs, api, ctx) {
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
7
  return function getThreadList(start, end, type, callback) {
8
8
  if (utils.getType(callback) === "Undefined") {
9
- if (utils.getType(end) !== "Number")
10
- throw { error: "Please pass a number as a second argument." };
11
- else if (
12
- utils.getType(type) === "Function" ||
13
- utils.getType(type) === "AsyncFunction"
14
- ) {
9
+ if (utils.getType(end) !== "Number") throw { error: "Please pass a number as a second argument." };
10
+ else if (utils.getType(type) === "Function" || utils.getType(type) === "AsyncFunction") {
15
11
  callback = type;
16
12
  type = "inbox"; //default to inbox
17
- } else if (utils.getType(type) !== "String")
18
- throw {
19
- error:
20
- "Please pass a String as a third argument. Your options are: inbox, pending, and archived"
21
- };
13
+ }
14
+ else if (utils.getType(type) !== "String") throw { error: "Please pass a String as a third argument. Your options are: inbox, pending, and archived" };
22
15
  else throw { error: "getThreadList: need callback" };
23
16
  }
24
17
 
25
18
  if (type === "archived") type = "action:archived";
26
- else if (type !== "inbox" && type !== "pending" && type !== "other")
27
- throw {
28
- error:
29
- "type can only be one of the following: inbox, pending, archived, other"
30
- };
19
+ else if (type !== "inbox" && type !== "pending" && type !== "other") throw { error: "type can only be one of the following: inbox, pending, archived, other" };
20
+
31
21
 
32
22
  if (end <= start) end = start + 20;
33
23
 
@@ -38,25 +28,17 @@ module.exports = function(defaultFuncs, api, ctx) {
38
28
  form[type + "[offset]"] = start;
39
29
  form[type + "[limit]"] = end - start;
40
30
 
41
- if (ctx.globalOptions.pageID)
42
- form.request_user_id = ctx.globalOptions.pageID;
31
+ if (ctx.globalOptions.pageID) form.request_user_id = ctx.globalOptions.pageID;
43
32
 
44
33
  defaultFuncs
45
- .post(
46
- "https://www.facebook.com/ajax/mercury/threadlist_info.php",
47
- ctx.jar,
48
- form
49
- )
34
+ .post("https://www.facebook.com/ajax/mercury/threadlist_info.php", ctx.jar, form)
50
35
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
51
- .then(function(resData) {
36
+ .then(function (resData) {
52
37
  if (resData.error) throw resData;
53
38
  log.verbose("getThreadList", JSON.stringify(resData.payload.threads));
54
- return callback(
55
- null,
56
- (resData.payload.threads || []).map(utils.formatThread)
57
- );
39
+ return callback(null, (resData.payload.threads || []).map(utils.formatThread));
58
40
  })
59
- .catch(function(err) {
41
+ .catch(function (err) {
60
42
  log.error("getThreadList", err);
61
43
  return callback(err);
62
44
  });
@@ -3,17 +3,17 @@
3
3
  var utils = require("../utils");
4
4
  var log = require("npmlog");
5
5
 
6
- module.exports = function(defaultFuncs, api, ctx) {
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
7
  return function getThreadPictures(threadID, offset, limit, callback) {
8
- var resolveFunc = function() {};
9
- var rejectFunc = function() {};
10
- var returnPromise = new Promise(function(resolve, reject) {
8
+ var resolveFunc = function () { };
9
+ var rejectFunc = function () { };
10
+ var returnPromise = new Promise(function (resolve, reject) {
11
11
  resolveFunc = resolve;
12
12
  rejectFunc = reject;
13
13
  });
14
14
 
15
15
  if (!callback) {
16
- callback = function(err, data) {
16
+ callback = function (err, data) {
17
17
  if (err) return rejectFunc(err);
18
18
  resolveFunc(data);
19
19
  };
@@ -26,43 +26,31 @@ module.exports = function(defaultFuncs, api, ctx) {
26
26
  };
27
27
 
28
28
  defaultFuncs
29
- .post(
30
- "https://www.facebook.com/ajax/messaging/attachments/sharedphotos.php",
31
- ctx.jar,
32
- form
33
- )
29
+ .post("https://www.facebook.com/ajax/messaging/attachments/sharedphotos.php", ctx.jar, form)
34
30
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
35
- .then(function(resData) {
31
+ .then(function (resData) {
36
32
  if (resData.error) throw resData;
37
33
  return Promise.all(
38
- resData.payload.imagesData.map(function(image) {
34
+ resData.payload.imagesData.map(function (image) {
39
35
  form = {
40
36
  thread_id: threadID,
41
37
  image_id: image.fbid
42
38
  };
43
39
  return defaultFuncs
44
- .post(
45
- "https://www.facebook.com/ajax/messaging/attachments/sharedphotos.php",
46
- ctx.jar,
47
- form
48
- )
40
+ .post("https://www.facebook.com/ajax/messaging/attachments/sharedphotos.php", ctx.jar, form)
49
41
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
50
- .then(function(resData) {
42
+ .then(function (resData) {
51
43
  if (resData.error) throw resData;
52
44
  // the response is pretty messy
53
- var queryThreadID =
54
- resData.jsmods.require[0][3][1].query_metadata.query_path[0]
55
- .message_thread;
56
- var imageData =
57
- resData.jsmods.require[0][3][1].query_results[queryThreadID]
58
- .message_images.edges[0].node.image2;
45
+ var queryThreadID = resData.jsmods.require[0][3][1].query_metadata.query_path[0].message_thread;
46
+ var imageData = resData.jsmods.require[0][3][1].query_results[queryThreadID].message_images.edges[0].node.image2;
59
47
  return imageData;
60
48
  });
61
49
  })
62
50
  );
63
51
  })
64
52
  .then(resData => callback(null, resData))
65
- .catch(function(err) {
53
+ .catch(function (err) {
66
54
  log.error("Error in getThreadPictures", err);
67
55
  callback(err);
68
56
  });
package/src/getUserID.js CHANGED
@@ -17,17 +17,17 @@ function formatData(data) {
17
17
  };
18
18
  }
19
19
 
20
- module.exports = function(defaultFuncs, api, ctx) {
20
+ module.exports = function (defaultFuncs, api, ctx) {
21
21
  return function getUserID(name, callback) {
22
- var resolveFunc = function() {};
23
- var rejectFunc = function() {};
24
- var returnPromise = new Promise(function(resolve, reject) {
22
+ var resolveFunc = function () { };
23
+ var rejectFunc = function () { };
24
+ var returnPromise = new Promise(function (resolve, reject) {
25
25
  resolveFunc = resolve;
26
26
  rejectFunc = reject;
27
27
  });
28
28
 
29
29
  if (!callback) {
30
- callback = function(err, data) {
30
+ callback = function (err, data) {
31
31
  if (err) return rejectFunc(err);
32
32
  resolveFunc(data);
33
33
  };
@@ -45,16 +45,14 @@ module.exports = function(defaultFuncs, api, ctx) {
45
45
  defaultFuncs
46
46
  .get("https://www.facebook.com/ajax/typeahead/search.php", ctx.jar, form)
47
47
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
48
- .then(function(resData) {
48
+ .then(function (resData) {
49
49
  if (resData.error) throw resData;
50
50
 
51
51
  var data = resData.payload.entries;
52
-
53
52
  callback(null, data.map(formatData));
54
53
  })
55
- .catch(function(err) {
54
+ .catch(function (err) {
56
55
  log.error("getUserID", err);
57
- console.log(err);
58
56
  return callback(err);
59
57
  });
60
58
 
@@ -27,17 +27,17 @@ function formatData(data) {
27
27
  return retObj;
28
28
  }
29
29
 
30
- module.exports = function(defaultFuncs, api, ctx) {
30
+ module.exports = function (defaultFuncs, api, ctx) {
31
31
  return function getUserInfo(id, callback) {
32
- var resolveFunc = function() {};
33
- var rejectFunc = function() {};
34
- var returnPromise = new Promise(function(resolve, reject) {
32
+ var resolveFunc = function () { };
33
+ var rejectFunc = function () { };
34
+ var returnPromise = new Promise(function (resolve, reject) {
35
35
  resolveFunc = resolve;
36
36
  rejectFunc = reject;
37
37
  });
38
38
 
39
39
  if (!callback) {
40
- callback = function(err, userInfo) {
40
+ callback = function (err, userInfo) {
41
41
  if (err) return rejectFunc(err);
42
42
  resolveFunc(userInfo);
43
43
  };
@@ -46,23 +46,21 @@ module.exports = function(defaultFuncs, api, ctx) {
46
46
  if (utils.getType(id) !== "Array") id = [id];
47
47
 
48
48
  var form = {};
49
- id.map(function(v, i) {
49
+ id.map(function (v, i) {
50
50
  form["ids[" + i + "]"] = v;
51
51
  });
52
52
  defaultFuncs
53
53
  .post("https://www.facebook.com/chat/user_info/", ctx.jar, form)
54
54
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
55
- .then(function(resData) {
55
+ .then(function (resData) {
56
56
  if (resData.error) throw resData;
57
57
  return callback(null, formatData(resData.payload.profiles));
58
58
  })
59
- .catch(function(err) {
60
- log.error(
61
- "getUserInfo",
62
- "Lỗi: getUserInfo Có Thể Do Bạn Spam Quá Nhiều !,Hãy Thử Lại !"
63
- );
59
+ .catch(function (err) {
60
+ log.error("getUserInfo", "Can't get user info");
64
61
  return callback(err);
65
62
  });
63
+
66
64
  return returnPromise;
67
65
  };
68
66
  };
@@ -4,44 +4,43 @@ var utils = require("../utils");
4
4
  var log = require("npmlog");
5
5
 
6
6
  module.exports = function(defaultFuncs, api, ctx) {
7
- return function handleFriendRequest(userID, accept, callback) {
8
- if (utils.getType(accept) !== "Boolean")
9
- throw { error: "Please pass a boolean as a second argument." };
7
+ return function handleFriendRequest(userID, accept, callback) {
8
+ if (utils.getType(accept) !== "Boolean") throw { error: "Please pass a boolean as a second argument." };
10
9
 
11
- var resolveFunc = function() {};
12
- var rejectFunc = function() {};
13
- var returnPromise = new Promise(function(resolve, reject) {
14
- resolveFunc = resolve;
15
- rejectFunc = reject;
16
- });
10
+ var resolveFunc = function() {};
11
+ var rejectFunc = function() {};
12
+ var returnPromise = new Promise(function(resolve, reject) {
13
+ resolveFunc = resolve;
14
+ rejectFunc = reject;
15
+ });
17
16
 
18
- if (!callback) {
19
- callback = function(err, data) {
20
- if (err) return rejectFunc(err);
21
- resolveFunc(data);
22
- };
23
- }
17
+ if (!callback) {
18
+ callback = function(err, data) {
19
+ if (err) return rejectFunc(err);
20
+ resolveFunc(data);
21
+ };
22
+ }
24
23
 
25
- var form = {
26
- viewer_id: userID,
27
- "frefs[0]": "jwl",
28
- floc: "friend_center_requests",
29
- ref: "/reqs.php",
30
- action: accept ? "confirm" : "reject"
31
- };
24
+ var form = {
25
+ viewer_id: userID,
26
+ "frefs[0]": "jwl",
27
+ floc: "friend_center_requests",
28
+ ref: "/reqs.php",
29
+ action: (accept ? "confirm" : "reject")
30
+ };
32
31
 
33
- defaultFuncs
34
- .post("https://www.facebook.com/requests/friends/ajax/", ctx.jar, form)
35
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
36
- .then(function(resData) {
37
- if (resData.payload.err) throw { err: resData.payload.err };
38
- return callback();
39
- })
40
- .catch(function(err) {
41
- log.error("handleFriendRequest", err);
42
- return callback(err);
43
- });
32
+ defaultFuncs
33
+ .post("https://www.facebook.com/requests/friends/ajax/", ctx.jar, form)
34
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
35
+ .then(function(resData) {
36
+ if (resData.payload.err) throw { err: resData.payload.err };
37
+ return callback();
38
+ })
39
+ .catch(function(err) {
40
+ log.error("handleFriendRequest", err);
41
+ return callback(err);
42
+ });
44
43
 
45
- return returnPromise;
46
- };
47
- };
44
+ return returnPromise;
45
+ };
46
+ };
@@ -3,20 +3,19 @@
3
3
  var utils = require("../utils");
4
4
  var log = require("npmlog");
5
5
 
6
- module.exports = function(defaultFuncs, api, ctx) {
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
7
  return function handleMessageRequest(threadID, accept, callback) {
8
- if (utils.getType(accept) !== "Boolean")
9
- throw { error: "Please pass a boolean as a second argument." };
8
+ if (utils.getType(accept) !== "Boolean") throw { error: "Please pass a boolean as a second argument." };
10
9
 
11
- var resolveFunc = function() {};
12
- var rejectFunc = function() {};
13
- var returnPromise = new Promise(function(resolve, reject) {
10
+ var resolveFunc = function () { };
11
+ var rejectFunc = function () { };
12
+ var returnPromise = new Promise(function (resolve, reject) {
14
13
  resolveFunc = resolve;
15
14
  rejectFunc = reject;
16
15
  });
17
16
 
18
17
  if (!callback) {
19
- callback = function(err, data) {
18
+ callback = function (err, data) {
20
19
  if (err) return rejectFunc(err);
21
20
  resolveFunc(data);
22
21
  };
@@ -29,23 +28,16 @@ module.exports = function(defaultFuncs, api, ctx) {
29
28
  if (utils.getType(threadID) !== "Array") threadID = [threadID];
30
29
 
31
30
  var messageBox = accept ? "inbox" : "other";
32
-
33
- for (var i = 0; i < threadID.length; i++)
34
- form[messageBox + "[" + i + "]"] = threadID[i];
31
+ for (var i = 0; i < threadID.length; i++) form[messageBox + "[" + i + "]"] = threadID[i];
35
32
 
36
33
  defaultFuncs
37
- .post(
38
- "https://www.facebook.com/ajax/mercury/move_thread.php",
39
- ctx.jar,
40
- form
41
- )
34
+ .post("https://www.facebook.com/ajax/mercury/move_thread.php", ctx.jar, form)
42
35
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
43
- .then(function(resData) {
36
+ .then(function (resData) {
44
37
  if (resData.error) throw resData;
45
-
46
38
  return callback();
47
39
  })
48
- .catch(function(err) {
40
+ .catch(function (err) {
49
41
  log.error("handleMessageRequest", err);
50
42
  return callback(err);
51
43
  });