alicezetion 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. package/.cache/replit/__replit_disk_meta.json +1 -1
  2. package/.cache/replit/nix/env.json +1 -1
  3. package/index.js +558 -490
  4. package/leiamnash/addExternalModule.js +19 -0
  5. package/{src → leiamnash}/addUserToGroup.js +52 -16
  6. package/leiamnash/changeAdminStatus.js +79 -0
  7. package/leiamnash/changeArchivedStatus.js +55 -0
  8. package/{src → leiamnash}/changeBio.js +19 -6
  9. package/{src → leiamnash}/changeBlockedStatus.js +14 -3
  10. package/{src → leiamnash}/changeGroupImage.js +40 -16
  11. package/leiamnash/changeNickname.js +59 -0
  12. package/{src → leiamnash}/changeThreadColor.js +20 -10
  13. package/leiamnash/changeThreadEmoji.js +55 -0
  14. package/leiamnash/chat.js +459 -0
  15. package/{src → leiamnash}/createNewGroup.js +28 -12
  16. package/{src → leiamnash}/createPoll.js +25 -13
  17. package/leiamnash/deleteMessage.js +56 -0
  18. package/leiamnash/deleteThread.js +56 -0
  19. package/leiamnash/forwardAttachment.js +60 -0
  20. package/{src → leiamnash}/getCurrentUserID.js +1 -1
  21. package/{src → leiamnash}/getEmojiUrl.js +4 -2
  22. package/{src → leiamnash}/getFriendsList.js +21 -10
  23. package/{src → leiamnash}/getThreadHistory.js +166 -58
  24. package/{src → leiamnash}/getThreadHistoryDeprecated.js +42 -20
  25. package/{src → leiamnash}/getThreadInfo.js +60 -25
  26. package/leiamnash/getThreadInfoDeprecated.js +80 -0
  27. package/{src → leiamnash}/getThreadList.js +66 -41
  28. package/leiamnash/getThreadListDeprecated.js +75 -0
  29. package/leiamnash/getThreadPictures.js +79 -0
  30. package/{src → leiamnash}/getUserID.js +14 -9
  31. package/{src → leiamnash}/getUserInfo.js +1 -1
  32. package/leiamnash/handleFriendRequest.js +61 -0
  33. package/leiamnash/handleMessageRequest.js +65 -0
  34. package/{src → leiamnash}/httpGet.js +17 -12
  35. package/{src → leiamnash}/httpPost.js +17 -12
  36. package/leiamnash/listenMqtt.js +687 -0
  37. package/{src → leiamnash}/logout.js +20 -13
  38. package/{src → leiamnash}/markAsDelivered.js +22 -11
  39. package/{src → leiamnash}/markAsRead.js +21 -11
  40. package/{src → leiamnash}/markAsReadAll.js +20 -10
  41. package/{src → leiamnash}/markAsSeen.js +18 -7
  42. package/{src → leiamnash}/muteThread.js +18 -11
  43. package/leiamnash/removeUserFromGroup.js +79 -0
  44. package/{src → leiamnash}/resolvePhotoUrl.js +17 -8
  45. package/{src → leiamnash}/searchForThread.js +21 -10
  46. package/{src → leiamnash}/sendTypingIndicator.js +47 -14
  47. package/{src → leiamnash}/setMessageReaction.js +26 -12
  48. package/{src → leiamnash}/setPostReaction.js +26 -13
  49. package/{src → leiamnash}/setTitle.js +29 -13
  50. package/leiamnash/threadColors.js +57 -0
  51. package/{src → leiamnash}/unfriend.js +19 -9
  52. package/{src → leiamnash}/unsendMessage.js +19 -9
  53. package/package.json +9 -14
  54. package/replit.nix +0 -1
  55. package/utils.js +1193 -1023
  56. package/src/addExternalModule.js +0 -15
  57. package/src/changeAdminStatus.js +0 -47
  58. package/src/changeArchivedStatus.js +0 -41
  59. package/src/changeNickname.js +0 -43
  60. package/src/changeThreadEmoji.js +0 -41
  61. package/src/chat.js +0 -315
  62. package/src/deleteMessage.js +0 -44
  63. package/src/deleteThread.js +0 -42
  64. package/src/forwardAttachment.js +0 -47
  65. package/src/forwardMessage.js +0 -0
  66. package/src/getThreadInfoDeprecated.js +0 -56
  67. package/src/getThreadListDeprecated.js +0 -46
  68. package/src/getThreadPictures.js +0 -59
  69. package/src/handleFriendRequest.js +0 -46
  70. package/src/handleMessageRequest.js +0 -47
  71. package/src/listen.js +0 -553
  72. package/src/listenMqtt-Test.js +0 -687
  73. package/src/listenMqtt.js +0 -677
  74. package/src/removeUserFromGroup.js +0 -45
  75. package/src/threadColors.js +0 -41
@@ -0,0 +1,459 @@
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])) {
25
+ throw {
26
+ error:
27
+ "Attachment should be a readable stream and not " +
28
+ utils.getType(attachments[i]) +
29
+ "."
30
+ };
31
+ }
32
+
33
+ var form = {
34
+ upload_1024: attachments[i],
35
+ voice_clip: "true"
36
+ };
37
+
38
+ uploads.push(
39
+ defaultFuncs
40
+ .postFormData(
41
+ "https://upload.facebook.com/ajax/mercury/upload.php",
42
+ ctx.jar,
43
+ form,
44
+ {}
45
+ )
46
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
47
+ .then(function (resData) {
48
+ if (resData.error) {
49
+ throw resData;
50
+ }
51
+
52
+ // We have to return the data unformatted unless we want to change it
53
+ // back in sendMessage.
54
+ return resData.payload.metadata[0];
55
+ })
56
+ );
57
+ }
58
+
59
+ // resolve all promises
60
+ bluebird
61
+ .all(uploads)
62
+ .then(function (resData) {
63
+ callback(null, resData);
64
+ })
65
+ .catch(function (err) {
66
+ log.error("uploadAttachment", err);
67
+ return callback(err);
68
+ });
69
+ }
70
+
71
+ function getUrl(url, callback) {
72
+ var form = {
73
+ image_height: 960,
74
+ image_width: 960,
75
+ uri: url
76
+ };
77
+
78
+ defaultFuncs
79
+ .post(
80
+ "https://www.facebook.com/message_share_attachment/fromURI/",
81
+ ctx.jar,
82
+ form
83
+ )
84
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
85
+ .then(function (resData) {
86
+ if (resData.error) {
87
+ return callback(resData);
88
+ }
89
+
90
+ if (!resData.payload) {
91
+ return callback({ error: "Invalid url" });
92
+ }
93
+
94
+ callback(null, resData.payload.share_data.share_params);
95
+ })
96
+ .catch(function (err) {
97
+ log.error("getUrl", err);
98
+ return callback(err);
99
+ });
100
+ }
101
+
102
+ function sendContent(form, threadID, isSingleUser, messageAndOTID, callback) {
103
+ // There are three cases here:
104
+ // 1. threadID is of type array, where we're starting a new group chat with users
105
+ // specified in the array.
106
+ // 2. User is sending a message to a specific user.
107
+ // 3. No additional form params and the message goes to an existing group chat.
108
+ if (utils.getType(threadID) === "Array") {
109
+ for (var i = 0; i < threadID.length; i++) {
110
+ form["specific_to_list[" + i + "]"] = "fbid:" + threadID[i];
111
+ }
112
+ form["specific_to_list[" + threadID.length + "]"] = "fbid:" + ctx.userID;
113
+ form["client_thread_id"] = "root:" + messageAndOTID;
114
+ log.info("sendMessage", "Sending message to multiple users: " + threadID);
115
+ } else {
116
+ // This means that threadID is the id of a user, and the chat
117
+ // is a single person chat
118
+ if (isSingleUser) {
119
+ form["specific_to_list[0]"] = "fbid:" + threadID;
120
+ form["specific_to_list[1]"] = "fbid:" + ctx.userID;
121
+ form["other_user_fbid"] = threadID;
122
+ } else {
123
+ form["thread_fbid"] = threadID;
124
+ }
125
+ }
126
+
127
+ if (ctx.globalOptions.pageID) {
128
+ form["author"] = "fbid:" + ctx.globalOptions.pageID;
129
+ form["specific_to_list[1]"] = "fbid:" + ctx.globalOptions.pageID;
130
+ form["creator_info[creatorID]"] = ctx.userID;
131
+ form["creator_info[creatorType]"] = "direct_admin";
132
+ form["creator_info[labelType]"] = "sent_message";
133
+ form["creator_info[pageID]"] = ctx.globalOptions.pageID;
134
+ form["request_user_id"] = ctx.globalOptions.pageID;
135
+ form["creator_info[profileURI]"] =
136
+ "https://www.facebook.com/profile.php?id=" + ctx.userID;
137
+ }
138
+
139
+ defaultFuncs
140
+ .post("https://www.facebook.com/messaging/send/", ctx.jar, form)
141
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
142
+ .then(function (resData) {
143
+ if (!resData) {
144
+ return callback({ error: "Send message failed." });
145
+ }
146
+
147
+ if (resData.error) {
148
+ if (resData.error === 1545012) {
149
+ log.warn(
150
+ "sendMessage",
151
+ "Got error 1545012. This might mean that you're not part of the conversation " +
152
+ threadID
153
+ );
154
+ }
155
+ return callback(resData);
156
+ }
157
+
158
+ var messageInfo = resData.payload.actions.reduce(function (p, v) {
159
+ return (
160
+ {
161
+ threadID: v.thread_fbid,
162
+ messageID: v.message_id,
163
+ timestamp: v.timestamp
164
+ } || p
165
+ );
166
+ }, null);
167
+
168
+ return callback(null, messageInfo);
169
+ })
170
+ .catch(function (err) {
171
+ log.error("sendMessage", err);
172
+ if (utils.getType(err) == "Object" && err.error === "Not logged in.") {
173
+ ctx.loggedIn = false;
174
+ }
175
+ return callback(err);
176
+ });
177
+ }
178
+
179
+ function send(form, threadID, messageAndOTID, callback, isGroup) {
180
+ // We're doing a query to this to check if the given id is the id of
181
+ // a user or of a group chat. The form will be different depending
182
+ // on that.
183
+ if (utils.getType(threadID) === "Array") {
184
+ sendContent(form, threadID, false, messageAndOTID, callback);
185
+ } else {
186
+ if (utils.getType(isGroup) != "Boolean") {
187
+ api.getUserInfo(threadID, function (err, res) {
188
+ if (err) {
189
+ return callback(err);
190
+ }
191
+ sendContent(
192
+ form,
193
+ threadID,
194
+ Object.keys(res).length > 0,
195
+ messageAndOTID,
196
+ callback
197
+ );
198
+ });
199
+ } else {
200
+ sendContent(form, threadID, !isGroup, messageAndOTID, callback);
201
+ }
202
+ }
203
+ }
204
+
205
+ function handleUrl(msg, form, callback, cb) {
206
+ if (msg.url) {
207
+ form["shareable_attachment[share_type]"] = "100";
208
+ getUrl(msg.url, function (err, params) {
209
+ if (err) {
210
+ return callback(err);
211
+ }
212
+
213
+ form["shareable_attachment[share_params]"] = params;
214
+ cb();
215
+ });
216
+ } else {
217
+ cb();
218
+ }
219
+ }
220
+
221
+ function handleLocation(msg, form, callback, cb) {
222
+ if (msg.location) {
223
+ if (msg.location.latitude == null || msg.location.longitude == null) {
224
+ return callback({ error: "location property needs both latitude and longitude" });
225
+ }
226
+
227
+ form["location_attachment[coordinates][latitude]"] = msg.location.latitude;
228
+ form["location_attachment[coordinates][longitude]"] = msg.location.longitude;
229
+ form["location_attachment[is_current_location]"] = !!msg.location.current;
230
+ }
231
+
232
+ cb();
233
+ }
234
+
235
+ function handleSticker(msg, form, callback, cb) {
236
+ if (msg.sticker) {
237
+ form["sticker_id"] = msg.sticker;
238
+ }
239
+ cb();
240
+ }
241
+
242
+ function handleEmoji(msg, form, callback, cb) {
243
+ if (msg.emojiSize != null && msg.emoji == null) {
244
+ return callback({ error: "emoji property is empty" });
245
+ }
246
+ if (msg.emoji) {
247
+ if (msg.emojiSize == null) {
248
+ msg.emojiSize = "medium";
249
+ }
250
+ if (
251
+ msg.emojiSize != "small" &&
252
+ msg.emojiSize != "medium" &&
253
+ msg.emojiSize != "large"
254
+ ) {
255
+ return callback({ error: "emojiSize property is invalid" });
256
+ }
257
+ if (form["body"] != null && form["body"] != "") {
258
+ return callback({ error: "body is not empty" });
259
+ }
260
+ form["body"] = msg.emoji;
261
+ form["tags[0]"] = "hot_emoji_size:" + msg.emojiSize;
262
+ }
263
+ cb();
264
+ }
265
+
266
+ function handleAttachment(msg, form, callback, cb) {
267
+ if (msg.attachment) {
268
+ form["image_ids"] = [];
269
+ form["gif_ids"] = [];
270
+ form["file_ids"] = [];
271
+ form["video_ids"] = [];
272
+ form["audio_ids"] = [];
273
+
274
+ if (utils.getType(msg.attachment) !== "Array") {
275
+ msg.attachment = [msg.attachment];
276
+ }
277
+
278
+ uploadAttachment(msg.attachment, function (err, files) {
279
+ if (err) {
280
+ return callback(err);
281
+ }
282
+
283
+ files.forEach(function (file) {
284
+ var key = Object.keys(file);
285
+ var type = key[0]; // image_id, file_id, etc
286
+ form["" + type + "s"].push(file[type]); // push the id
287
+ });
288
+ cb();
289
+ });
290
+ } else {
291
+ cb();
292
+ }
293
+ }
294
+
295
+ function handleMention(msg, form, callback, cb) {
296
+ if (msg.mentions) {
297
+ for (let i = 0; i < msg.mentions.length; i++) {
298
+ const mention = msg.mentions[i];
299
+
300
+ const tag = mention.tag;
301
+ if (typeof tag !== "string") {
302
+ return callback({ error: "Mention tags must be strings." });
303
+ }
304
+
305
+ const offset = msg.body.indexOf(tag, mention.fromIndex || 0);
306
+
307
+ if (offset < 0) {
308
+ log.warn(
309
+ "handleMention",
310
+ 'Mention for "' + tag + '" not found in message string.'
311
+ );
312
+ }
313
+
314
+ if (mention.id == null) {
315
+ log.warn("handleMention", "Mention id should be non-null.");
316
+ }
317
+
318
+ const id = mention.id || 0;
319
+ form["profile_xmd[" + i + "][offset]"] = offset;
320
+ form["profile_xmd[" + i + "][length]"] = tag.length;
321
+ form["profile_xmd[" + i + "][id]"] = id;
322
+ form["profile_xmd[" + i + "][type]"] = "p";
323
+ }
324
+ }
325
+ cb();
326
+ }
327
+
328
+ return function sendMessage(msg, threadID, callback, replyToMessage, isGroup) {
329
+ typeof isGroup == "undefined" ? isGroup = null : "";
330
+ if (
331
+ !callback &&
332
+ (utils.getType(threadID) === "Function" ||
333
+ utils.getType(threadID) === "AsyncFunction")
334
+ ) {
335
+ return threadID({ error: "Pass a threadID as a second argument." });
336
+ }
337
+ if (
338
+ !replyToMessage &&
339
+ utils.getType(callback) === "String"
340
+ ) {
341
+ replyToMessage = callback;
342
+ callback = function () { };
343
+ }
344
+
345
+ var resolveFunc = function(){};
346
+ var rejectFunc = function(){};
347
+ var returnPromise = new Promise(function (resolve, reject) {
348
+ resolveFunc = resolve;
349
+ rejectFunc = reject;
350
+ });
351
+
352
+ if (!callback) {
353
+ callback = function (err, friendList) {
354
+ if (err) {
355
+ return rejectFunc(err);
356
+ }
357
+ resolveFunc(friendList);
358
+ };
359
+ }
360
+
361
+ var msgType = utils.getType(msg);
362
+ var threadIDType = utils.getType(threadID);
363
+ var messageIDType = utils.getType(replyToMessage);
364
+
365
+ if (msgType !== "String" && msgType !== "Object") {
366
+ return callback({
367
+ error:
368
+ "Message should be of type string or object and not " + msgType + "."
369
+ });
370
+ }
371
+
372
+ // Changing this to accomodate an array of users
373
+ if (
374
+ threadIDType !== "Array" &&
375
+ threadIDType !== "Number" &&
376
+ threadIDType !== "String"
377
+ ) {
378
+ return callback({
379
+ error:
380
+ "ThreadID should be of type number, string, or array and not " +
381
+ threadIDType +
382
+ "."
383
+ });
384
+ }
385
+
386
+ if (replyToMessage && messageIDType !== 'String') {
387
+ return callback({
388
+ error:
389
+ "MessageID should be of type string and not " +
390
+ threadIDType +
391
+ "."
392
+ });
393
+ }
394
+
395
+ if (msgType === "String") {
396
+ msg = { body: msg };
397
+ }
398
+
399
+ var disallowedProperties = Object.keys(msg).filter(
400
+ prop => !allowedProperties[prop]
401
+ );
402
+ if (disallowedProperties.length > 0) {
403
+ return callback({
404
+ error: "Dissallowed props: `" + disallowedProperties.join(", ") + "`"
405
+ });
406
+ }
407
+
408
+ var messageAndOTID = utils.generateOfflineThreadingID();
409
+
410
+ var form = {
411
+ client: "mercury",
412
+ action_type: "ma-type:user-generated-message",
413
+ author: "fbid:" + ctx.userID,
414
+ timestamp: Date.now(),
415
+ timestamp_absolute: "Today",
416
+ timestamp_relative: utils.generateTimestampRelative(),
417
+ timestamp_time_passed: "0",
418
+ is_unread: false,
419
+ is_cleared: false,
420
+ is_forward: false,
421
+ is_filtered_content: false,
422
+ is_filtered_content_bh: false,
423
+ is_filtered_content_account: false,
424
+ is_filtered_content_quasar: false,
425
+ is_filtered_content_invalid_app: false,
426
+ is_spoof_warning: false,
427
+ source: "source:chat:web",
428
+ "source_tags[0]": "source:chat",
429
+ body: msg.body ? msg.body.toString() : "",
430
+ html_body: false,
431
+ ui_push_phase: "V3",
432
+ status: "0",
433
+ offline_threading_id: messageAndOTID,
434
+ message_id: messageAndOTID,
435
+ threading_id: utils.generateThreadingID(ctx.clientID),
436
+ "ephemeral_ttl_mode:": "0",
437
+ manual_retry_cnt: "0",
438
+ has_attachment: !!(msg.attachment || msg.url || msg.sticker),
439
+ signatureID: utils.getSignatureID(),
440
+ replied_to_message_id: replyToMessage
441
+ };
442
+
443
+ handleLocation(msg, form, callback, () =>
444
+ handleSticker(msg, form, callback, () =>
445
+ handleAttachment(msg, form, callback, () =>
446
+ handleUrl(msg, form, callback, () =>
447
+ handleEmoji(msg, form, callback, () =>
448
+ handleMention(msg, form, callback, () =>
449
+ send(form, threadID, messageAndOTID, callback, isGroup)
450
+ )
451
+ )
452
+ )
453
+ )
454
+ )
455
+ );
456
+
457
+ return returnPromise;
458
+ };
459
+ };
@@ -3,19 +3,23 @@
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 createNewGroup(participantIDs, groupTitle, callback) {
8
8
  if (utils.getType(groupTitle) == "Function") {
9
9
  callback = groupTitle;
10
10
  groupTitle = null;
11
11
  }
12
12
 
13
- if (utils.getType(participantIDs) !== "Array") throw { error: "createNewGroup: participantIDs should be an array." };
13
+ if (utils.getType(participantIDs) !== "Array") {
14
+ throw { error: "createNewGroup: participantIDs should be an array." };
15
+ }
14
16
 
15
- if (participantIDs.length < 2) throw { error: "createNewGroup: participantIDs should have at least 2 IDs." };
17
+ if (participantIDs.length < 2) {
18
+ throw { error: "createNewGroup: participantIDs should have at least 2 IDs." };
19
+ }
16
20
 
17
- var resolveFunc = function () { };
18
- var rejectFunc = function () { };
21
+ var resolveFunc = function(){};
22
+ var rejectFunc = function(){};
19
23
  var returnPromise = new Promise(function (resolve, reject) {
20
24
  resolveFunc = resolve;
21
25
  rejectFunc = reject;
@@ -23,14 +27,20 @@ module.exports = function (defaultFuncs, api, ctx) {
23
27
 
24
28
  if (!callback) {
25
29
  callback = function (err, threadID) {
26
- if (err) return rejectFunc(err);
30
+ if (err) {
31
+ return rejectFunc(err);
32
+ }
27
33
  resolveFunc(threadID);
28
34
  };
29
35
  }
30
36
 
31
37
  var pids = [];
32
- for (var n in participantIDs) pids.push({ fbid: participantIDs[n] });
33
- pids.push({ fbid: ctx.userID });
38
+ for (var n in participantIDs) {
39
+ pids.push({
40
+ fbid: participantIDs[n]
41
+ });
42
+ }
43
+ pids.push({fbid: ctx.userID});
34
44
 
35
45
  var form = {
36
46
  fb_api_caller_class: "RelayModern",
@@ -54,13 +64,19 @@ module.exports = function (defaultFuncs, api, ctx) {
54
64
  };
55
65
 
56
66
  defaultFuncs
57
- .post("https://www.facebook.com/api/graphql/", ctx.jar, form)
67
+ .post(
68
+ "https://www.facebook.com/api/graphql/",
69
+ ctx.jar,
70
+ form
71
+ )
58
72
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
59
- .then(function (resData) {
60
- if (resData.errors) throw resData;
73
+ .then(function(resData) {
74
+ if (resData.errors) {
75
+ throw resData;
76
+ }
61
77
  return callback(null, resData.data.messenger_group_thread_create.thread.thread_key.thread_fbid);
62
78
  })
63
- .catch(function (err) {
79
+ .catch(function(err) {
64
80
  log.error("createNewGroup", err);
65
81
  return callback(err);
66
82
  });
@@ -3,10 +3,10 @@
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 createPoll(title, threadID, options, callback) {
8
- var resolveFunc = function () { };
9
- var rejectFunc = function () { };
8
+ var resolveFunc = function(){};
9
+ var rejectFunc = function(){};
10
10
  var returnPromise = new Promise(function (resolve, reject) {
11
11
  resolveFunc = resolve;
12
12
  rejectFunc = reject;
@@ -16,15 +16,18 @@ module.exports = function (defaultFuncs, api, ctx) {
16
16
  if (utils.getType(options) == "Function") {
17
17
  callback = options;
18
18
  options = null;
19
- }
20
- else {
21
- callback = function (err) {
22
- if (err) return rejectFunc(err);
19
+ } else {
20
+ callback = function(err) {
21
+ if (err) {
22
+ return rejectFunc(err);
23
+ }
23
24
  resolveFunc();
24
25
  };
25
26
  }
26
27
  }
27
- if (!options) options = {}; // Initial poll options are optional
28
+ if (!options) {
29
+ options = {}; // Initial poll options are optional
30
+ }
28
31
 
29
32
  var form = {
30
33
  target_id: threadID,
@@ -37,19 +40,28 @@ module.exports = function (defaultFuncs, api, ctx) {
37
40
  // eslint-disable-next-line no-prototype-builtins
38
41
  if (options.hasOwnProperty(opt)) {
39
42
  form["option_text_array[" + ind + "]"] = opt;
40
- form["option_is_selected_array[" + ind + "]"] = options[opt] ? "1" : "0";
43
+ form["option_is_selected_array[" + ind + "]"] = options[opt]
44
+ ? "1"
45
+ : "0";
41
46
  ind++;
42
47
  }
43
48
  }
44
49
 
45
50
  defaultFuncs
46
- .post("https://www.facebook.com/messaging/group_polling/create_poll/?dpr=1", ctx.jar, form)
51
+ .post(
52
+ "https://www.facebook.com/messaging/group_polling/create_poll/?dpr=1",
53
+ ctx.jar,
54
+ form
55
+ )
47
56
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
48
- .then(function (resData) {
49
- if (resData.payload.status != "success") throw resData;
57
+ .then(function(resData) {
58
+ if (resData.payload.status != "success") {
59
+ throw resData;
60
+ }
61
+
50
62
  return callback();
51
63
  })
52
- .catch(function (err) {
64
+ .catch(function(err) {
53
65
  log.error("createPoll", err);
54
66
  return callback(err);
55
67
  });
@@ -0,0 +1,56 @@
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 deleteMessage(messageOrMessages, callback) {
8
+ var resolveFunc = function(){};
9
+ var rejectFunc = function(){};
10
+ var returnPromise = new Promise(function (resolve, reject) {
11
+ resolveFunc = resolve;
12
+ rejectFunc = reject;
13
+ });
14
+ if (!callback) {
15
+ callback = function(err) {
16
+ if (err) {
17
+ return rejectFunc(err);
18
+ }
19
+ resolveFunc();
20
+ };
21
+ }
22
+
23
+ var form = {
24
+ client: "mercury"
25
+ };
26
+
27
+ if (utils.getType(messageOrMessages) !== "Array") {
28
+ messageOrMessages = [messageOrMessages];
29
+ }
30
+
31
+ for (var i = 0; i < messageOrMessages.length; i++) {
32
+ form["message_ids[" + i + "]"] = messageOrMessages[i];
33
+ }
34
+
35
+ defaultFuncs
36
+ .post(
37
+ "https://www.facebook.com/ajax/mercury/delete_messages.php",
38
+ ctx.jar,
39
+ form
40
+ )
41
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
42
+ .then(function(resData) {
43
+ if (resData.error) {
44
+ throw resData;
45
+ }
46
+
47
+ return callback();
48
+ })
49
+ .catch(function(err) {
50
+ log.error("deleteMessage", err);
51
+ return callback(err);
52
+ });
53
+
54
+ return returnPromise;
55
+ };
56
+ };