alicezetion 1.8.2 → 1.8.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) 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 +210 -375
  4. package/package.json +6 -3
  5. package/replit.nix +4 -4
  6. package/src/addExternalModule.js +17 -0
  7. package/src/addUserToGroup.js +113 -0
  8. package/src/changeAdminStatus.js +79 -0
  9. package/src/changeArchivedStatus.js +55 -0
  10. package/src/changeAvatar.js +93 -0
  11. package/src/changeBio.js +77 -0
  12. package/src/changeBlockedStatus.js +47 -0
  13. package/src/changeCover.js +73 -0
  14. package/src/changeGroupImage.js +132 -0
  15. package/src/changeName.js +79 -0
  16. package/src/changeNickname.js +59 -0
  17. package/src/changeThreadColor.js +65 -0
  18. package/src/changeThreadEmoji.js +55 -0
  19. package/{leiamnash → src}/chat.js +28 -3
  20. package/src/createNewGroup.js +86 -0
  21. package/src/createPoll.js +71 -0
  22. package/src/data/getThreadInfo.json +1 -0
  23. package/src/deleteMessage.js +56 -0
  24. package/src/deleteThread.js +56 -0
  25. package/src/forwardAttachment.js +60 -0
  26. package/src/getAccess.js +112 -0
  27. package/src/getAvatarUser.js +78 -0
  28. package/src/getCurrentUserID.js +7 -0
  29. package/src/getEmojiUrl.js +29 -0
  30. package/src/getFriendsList.js +83 -0
  31. package/src/getThreadHistory.js +666 -0
  32. package/{leiamnash → src}/getThreadInfo.js +70 -54
  33. package/src/getThreadList.js +237 -0
  34. package/src/getThreadPictures.js +79 -0
  35. package/src/getUserID.js +66 -0
  36. package/src/getUserInfo.js +163 -0
  37. package/src/handleFriendRequest.js +61 -0
  38. package/src/handleMessageRequest.js +65 -0
  39. package/src/httpGet.js +57 -0
  40. package/src/httpPost.js +57 -0
  41. package/src/httpPostFormData.js +63 -0
  42. package/{leiamnash → src}/listenMqtt.js +16 -6
  43. package/src/listenNotification.js +88 -0
  44. package/src/logout.js +275 -0
  45. package/src/markAsDelivered.js +58 -0
  46. package/src/markAsRead.js +80 -0
  47. package/src/markAsReadAll.js +50 -0
  48. package/src/markAsSeen.js +59 -0
  49. package/src/muteThread.js +52 -0
  50. package/src/react.js +117 -0
  51. package/{leiamnash → src}/refreshFb_dtsg.js +1 -1
  52. package/src/removeUserFromGroup.js +79 -0
  53. package/src/resolvePhotoUrl.js +45 -0
  54. package/src/searchForThread.js +53 -0
  55. package/src/searchStickers.js +52 -0
  56. package/src/seen.js +50 -0
  57. package/src/sendMessage.js +477 -0
  58. package/src/sendMessageMqtt.js +316 -0
  59. package/src/sendTypingIndicator.js +103 -0
  60. package/src/setMessageReaction.js +117 -0
  61. package/src/setPostReaction.js +109 -0
  62. package/src/setTitle.js +86 -0
  63. package/src/threadColors.js +131 -0
  64. package/src/unfriend.js +52 -0
  65. package/src/unsendMessage.js +49 -0
  66. package/utils.js +135 -176
  67. package/.cache/replit/modules.stamp +0 -1
  68. package/leiamnash/addExternalModule.js +0 -15
  69. package/leiamnash/addUserToGroup.js +0 -77
  70. package/leiamnash/changeAdminStatus.js +0 -47
  71. package/leiamnash/changeArchivedStatus.js +0 -41
  72. package/leiamnash/changeAvatar.js +0 -127
  73. package/leiamnash/changeBio.js +0 -64
  74. package/leiamnash/changeBlockedStatus.js +0 -36
  75. package/leiamnash/changeGroupImage.js +0 -105
  76. package/leiamnash/changeNickname.js +0 -43
  77. package/leiamnash/changeThreadColor.js +0 -61
  78. package/leiamnash/changeThreadEmoji.js +0 -41
  79. package/leiamnash/createNewGroup.js +0 -70
  80. package/leiamnash/createPoll.js +0 -59
  81. package/leiamnash/deleteMessage.js +0 -44
  82. package/leiamnash/deleteThread.js +0 -42
  83. package/leiamnash/forwardAttachment.js +0 -47
  84. package/leiamnash/forwardMessage.js +0 -0
  85. package/leiamnash/getCurrentUserID.js +0 -7
  86. package/leiamnash/getEmojiUrl.js +0 -27
  87. package/leiamnash/getFriendsList.js +0 -73
  88. package/leiamnash/getInfoVideo.js +0 -134
  89. package/leiamnash/getThreadHistory.js +0 -537
  90. package/leiamnash/getThreadHistoryDeprecated.js +0 -71
  91. package/leiamnash/getThreadInfoDeprecated.js +0 -56
  92. package/leiamnash/getThreadList.js +0 -213
  93. package/leiamnash/getThreadListDeprecated.js +0 -46
  94. package/leiamnash/getThreadPictures.js +0 -59
  95. package/leiamnash/getUserID.js +0 -61
  96. package/leiamnash/getUserInfo.js +0 -66
  97. package/leiamnash/handleFriendRequest.js +0 -46
  98. package/leiamnash/handleMessageRequest.js +0 -47
  99. package/leiamnash/httpGet.js +0 -47
  100. package/leiamnash/httpPost.js +0 -47
  101. package/leiamnash/logout.js +0 -68
  102. package/leiamnash/markAsDelivered.js +0 -47
  103. package/leiamnash/markAsRead.js +0 -70
  104. package/leiamnash/markAsReadAll.js +0 -40
  105. package/leiamnash/markAsSeen.js +0 -48
  106. package/leiamnash/muteThread.js +0 -45
  107. package/leiamnash/react.js +0 -109
  108. package/leiamnash/removeUserFromGroup.js +0 -45
  109. package/leiamnash/resolvePhotoUrl.js +0 -36
  110. package/leiamnash/searchForThread.js +0 -42
  111. package/leiamnash/seen.js +0 -40
  112. package/leiamnash/sendMessage.js +0 -315
  113. package/leiamnash/sendTypingIndicator.js +0 -70
  114. package/leiamnash/setMessageReaction.js +0 -103
  115. package/leiamnash/setPostReaction.js +0 -63
  116. package/leiamnash/setTitle.js +0 -70
  117. package/leiamnash/threadColors.js +0 -41
  118. package/leiamnash/unfriend.js +0 -42
  119. package/leiamnash/unsendMessage.js +0 -39
  120. /package/{leiamnash → src}/getMessage.js +0 -0
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+
3
+ const utils = require("../utils");
4
+ const log = require("npmlog");
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ function handleUpload(image, callback) {
8
+ const uploads = [];
9
+
10
+ const form = {
11
+ images_only: "true",
12
+ "attachment[]": image
13
+ };
14
+
15
+ uploads.push(
16
+ defaultFuncs
17
+ .postFormData(
18
+ "https://upload.facebook.com/ajax/mercury/upload.php",
19
+ ctx.jar,
20
+ form,
21
+ {}
22
+ )
23
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
24
+ .then(function (resData) {
25
+ if (resData.error) {
26
+ throw resData;
27
+ }
28
+
29
+ return resData.payload.metadata[0];
30
+ })
31
+ );
32
+
33
+ // resolve all promises
34
+ Promise
35
+ .all(uploads)
36
+ .then(function (resData) {
37
+ callback(null, resData);
38
+ })
39
+ .catch(function (err) {
40
+ log.error("handleUpload", err);
41
+ return callback(err);
42
+ });
43
+ }
44
+
45
+ return function changeGroupImage(image, threadID, callback) {
46
+ if (
47
+ !callback &&
48
+ (utils.getType(threadID) === "Function" ||
49
+ utils.getType(threadID) === "AsyncFunction")
50
+ ) {
51
+ throw { error: "please pass a threadID as a second argument." };
52
+ }
53
+
54
+ if (!utils.isReadableStream(image)) {
55
+ throw { error: "please pass a readable stream as a first argument." };
56
+ }
57
+
58
+ let resolveFunc = function () { };
59
+ let rejectFunc = function () { };
60
+ const returnPromise = new Promise(function (resolve, reject) {
61
+ resolveFunc = resolve;
62
+ rejectFunc = reject;
63
+ });
64
+
65
+ if (!callback) {
66
+ callback = function (err) {
67
+ if (err) {
68
+ return rejectFunc(err);
69
+ }
70
+ resolveFunc();
71
+ };
72
+ }
73
+
74
+ const messageAndOTID = utils.generateOfflineThreadingID();
75
+ const form = {
76
+ client: "mercury",
77
+ action_type: "ma-type:log-message",
78
+ author: "fbid:" + (ctx.i_userID || ctx.userID),
79
+ author_email: "",
80
+ ephemeral_ttl_mode: "0",
81
+ is_filtered_content: false,
82
+ is_filtered_content_account: false,
83
+ is_filtered_content_bh: false,
84
+ is_filtered_content_invalid_app: false,
85
+ is_filtered_content_quasar: false,
86
+ is_forward: false,
87
+ is_spoof_warning: false,
88
+ is_unread: false,
89
+ log_message_type: "log:thread-image",
90
+ manual_retry_cnt: "0",
91
+ message_id: messageAndOTID,
92
+ offline_threading_id: messageAndOTID,
93
+ source: "source:chat:web",
94
+ "source_tags[0]": "source:chat",
95
+ status: "0",
96
+ thread_fbid: threadID,
97
+ thread_id: "",
98
+ timestamp: Date.now(),
99
+ timestamp_absolute: "Today",
100
+ timestamp_relative: utils.generateTimestampRelative(),
101
+ timestamp_time_passed: "0"
102
+ };
103
+
104
+ handleUpload(image, function (err, payload) {
105
+ if (err) {
106
+ return callback(err);
107
+ }
108
+
109
+ form["thread_image_id"] = payload[0]["image_id"];
110
+ form["thread_id"] = threadID;
111
+
112
+ defaultFuncs
113
+ .post("https://www.facebook.com/messaging/set_thread_image/", ctx.jar, form)
114
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
115
+ .then(function (resData) {
116
+ // check for errors here
117
+
118
+ if (resData.error) {
119
+ throw resData;
120
+ }
121
+
122
+ return callback();
123
+ })
124
+ .catch(function (err) {
125
+ log.error("changeGroupImage", err);
126
+ return callback(err);
127
+ });
128
+ });
129
+
130
+ return returnPromise;
131
+ };
132
+ };
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+
3
+ var utils = require('./../utils.js');
4
+ var log = require('npmlog');
5
+
6
+ module.exports = function (http, api, ctx) {
7
+ return function changeName(input, format, callback) {
8
+ var cb;
9
+ var rt = new Promise(function (resolve, reject) {
10
+ cb = error => error ? reject(error) : resolve();
11
+ });
12
+
13
+ if (typeof input == 'function') {
14
+ callback = input;
15
+ input = null;
16
+ }
17
+ if (typeof format == 'function') {
18
+ callback = format;
19
+ format = 'complete';
20
+ }
21
+ if (typeof callback == 'function') cb = callback;
22
+ if (utils.getType(input) != 'Object') {
23
+ var error = 'name must be an object, not ' + utils.getType(input);
24
+ log('changeName', error);
25
+ return cb(error);
26
+ }
27
+
28
+ var { first_name, middle_name, last_name } = input;
29
+ if (!first_name || !last_name) {
30
+ log.error('changeName', 'name is not be accepted');
31
+ return cb('name is not be accepted');
32
+ }
33
+
34
+ middle_name = middle_name || '';
35
+
36
+ var full_name =
37
+ format == 'complete' ? last_name + ' ' + (middle_name != '' ? middle_name + ' ' : '') + first_name :
38
+ format == 'standard' ? last_name + ' ' + first_name :
39
+ format == 'reversed' ? first_name + ' ' + (middle_name != '' ? middle_name + ' ' : '') + last_name :
40
+ last_name + ' ' + (middle_name != '' ? middle_name + ' ' : '') + first_name;
41
+
42
+ var form = {
43
+ fb_api_caller_class: 'RelayModern',
44
+ fb_api_req_friendly_name: 'useFXIMUpdateNameMutation',
45
+ variables: JSON.stringify({
46
+ client_mutation_id: utils.getGUID(),
47
+ family_device_id: "device_id_fetch_datr",
48
+ identity_ids: [ctx.userID],
49
+ full_name,
50
+ first_name,
51
+ middle_name,
52
+ last_name,
53
+ interface: 'FB_WEB'
54
+ }),
55
+ server_timestamps: true,
56
+ doc_id: '5763510853763960'
57
+ }
58
+
59
+ http
60
+ .post('https://accountscenter.facebook.com/api/graphql/', ctx.jar, form, null, null, {
61
+ Origin: 'https://accountscenter.facebook.com',
62
+ Referer: `https://accountscenter.facebook.com/profiles/${ctx.userID}/name`
63
+ })
64
+ .then(utils.parseAndCheckLogin(ctx, http))
65
+ .then(function (res) {
66
+ if (res.errors)
67
+ throw res;
68
+ else if (res.data.fxim_update_identity_name.error)
69
+ throw res.data.fxim_update_identity_name.error;
70
+ return cb();
71
+ })
72
+ .catch(function (err) {
73
+ log.error('changeName', err);
74
+ return cb(err);
75
+ });
76
+
77
+ return rt;
78
+ }
79
+ }
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ const utils = require("../utils");
4
+ const log = require("npmlog");
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ return function changeNickname(nickname, threadID, participantID, callback) {
8
+ let resolveFunc = function () { };
9
+ let rejectFunc = function () { };
10
+ const 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
+ const form = {
24
+ nickname: nickname,
25
+ participant_id: participantID,
26
+ thread_or_other_fbid: threadID
27
+ };
28
+
29
+ defaultFuncs
30
+ .post(
31
+ "https://www.facebook.com/messaging/save_thread_nickname/?source=thread_settings&dpr=1",
32
+ ctx.jar,
33
+ form
34
+ )
35
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
36
+ .then(function (resData) {
37
+ if (resData.error === 1545014) {
38
+ throw { error: "Trying to change nickname of user isn't in thread" };
39
+ }
40
+ if (resData.error === 1357031) {
41
+ throw {
42
+ error:
43
+ "Trying to change user nickname of a thread that doesn't exist. Have at least one message in the thread before trying to change the user nickname."
44
+ };
45
+ }
46
+ if (resData.error) {
47
+ throw resData;
48
+ }
49
+
50
+ return callback();
51
+ })
52
+ .catch(function (err) {
53
+ log.error("changeNickname", err);
54
+ return callback(err);
55
+ });
56
+
57
+ return returnPromise;
58
+ };
59
+ };
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ const utils = require("../utils");
4
+ const log = require("npmlog");
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ return function changeThreadColor(color, threadID, callback) {
8
+ let resolveFunc = function () { };
9
+ let rejectFunc = function () { };
10
+ const returnPromise = new Promise(function (resolve, reject) {
11
+ resolveFunc = resolve;
12
+ rejectFunc = reject;
13
+ });
14
+
15
+ if (!callback) {
16
+ callback = function (err) {
17
+ if (err) {
18
+ return rejectFunc(err);
19
+ }
20
+ resolveFunc(err);
21
+ };
22
+ }
23
+
24
+ if (!isNaN(color)) {
25
+ color = color.toString();
26
+ }
27
+ const validatedColor = color !== null ? color.toLowerCase() : color; // API only accepts lowercase letters in hex string
28
+
29
+ const form = {
30
+ dpr: 1,
31
+ queries: JSON.stringify({
32
+ o0: {
33
+ //This doc_id is valid as of January 31, 2020
34
+ doc_id: "1727493033983591",
35
+ query_params: {
36
+ data: {
37
+ actor_id: ctx.i_userID || ctx.userID,
38
+ client_mutation_id: "0",
39
+ source: "SETTINGS",
40
+ theme_id: validatedColor,
41
+ thread_id: threadID
42
+ }
43
+ }
44
+ }
45
+ })
46
+ };
47
+
48
+ defaultFuncs
49
+ .post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
50
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
51
+ .then(function (resData) {
52
+ if (resData[resData.length - 1].error_results > 0) {
53
+ throw new utils.CustomError(resData[0].o0.errors);
54
+ }
55
+
56
+ return callback();
57
+ })
58
+ .catch(function (err) {
59
+ log.error("changeThreadColor", err);
60
+ return callback(err);
61
+ });
62
+
63
+ return returnPromise;
64
+ };
65
+ };
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ const utils = require("../utils");
4
+ const log = require("npmlog");
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ return function changeThreadEmoji(emoji, threadID, callback) {
8
+ let resolveFunc = function () { };
9
+ let rejectFunc = function () { };
10
+ const returnPromise = new Promise(function (resolve, reject) {
11
+ resolveFunc = resolve;
12
+ rejectFunc = reject;
13
+ });
14
+
15
+ if (!callback) {
16
+ callback = function (err) {
17
+ if (err) {
18
+ return rejectFunc(err);
19
+ }
20
+ resolveFunc();
21
+ };
22
+ }
23
+ const form = {
24
+ emoji_choice: emoji,
25
+ thread_or_other_fbid: threadID
26
+ };
27
+
28
+ defaultFuncs
29
+ .post(
30
+ "https://www.facebook.com/messaging/save_thread_emoji/?source=thread_settings&__pc=EXP1%3Amessengerdotcom_pkg",
31
+ ctx.jar,
32
+ form
33
+ )
34
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
35
+ .then(function (resData) {
36
+ if (resData.error === 1357031) {
37
+ throw {
38
+ error:
39
+ "Trying to change emoji of a chat that doesn't exist. Have at least one message in the thread before trying to change the emoji."
40
+ };
41
+ }
42
+ if (resData.error) {
43
+ throw resData;
44
+ }
45
+
46
+ return callback();
47
+ })
48
+ .catch(function (err) {
49
+ log.error("changeThreadEmoji", err);
50
+ return callback(err);
51
+ });
52
+
53
+ return returnPromise;
54
+ };
55
+ };
@@ -2,7 +2,6 @@
2
2
 
3
3
  const utils = require("../utils");
4
4
  const log = require("npmlog");
5
- const bluebird = require("bluebird");
6
5
 
7
6
  const allowedProperties = {
8
7
  attachment: true,
@@ -15,6 +14,28 @@ const allowedProperties = {
15
14
  location: true
16
15
  };
17
16
 
17
+ function removeSpecialChar(inputString) { // remove char banned by facebook
18
+ if (typeof inputString !== "string")
19
+ return inputString;
20
+ // Convert string to Buffer
21
+ const buffer = Buffer.from(inputString, 'utf8');
22
+
23
+ // Filter buffer start with ef b8 8f
24
+ let filteredBuffer = Buffer.alloc(0);
25
+ for (let i = 0; i < buffer.length; i++) {
26
+ if (buffer[i] === 0xEF && buffer[i + 1] === 0xB8 && buffer[i + 2] === 0x8F) {
27
+ i += 2; // Skip 3 bytes of buffer starting with ef b8 8f
28
+ } else {
29
+ filteredBuffer = Buffer.concat([filteredBuffer, buffer.slice(i, i + 1)]);
30
+ }
31
+ }
32
+
33
+ // Convert filtered buffer to string
34
+ const convertedString = filteredBuffer.toString('utf8');
35
+
36
+ return convertedString;
37
+ }
38
+
18
39
  module.exports = function (defaultFuncs, api, ctx) {
19
40
  function uploadAttachment(attachments, callback) {
20
41
  const uploads = [];
@@ -57,7 +78,7 @@ module.exports = function (defaultFuncs, api, ctx) {
57
78
  }
58
79
 
59
80
  // resolve all promises
60
- bluebird
81
+ Promise
61
82
  .all(uploads)
62
83
  .then(function (resData) {
63
84
  callback(null, resData);
@@ -155,7 +176,7 @@ module.exports = function (defaultFuncs, api, ctx) {
155
176
  else {
156
177
  log.error("sendMessage", resData);
157
178
  }
158
- return callback(null, resData);
179
+ return callback(resData);
159
180
  }
160
181
 
161
182
  const messageInfo = resData.payload.actions.reduce(function (p, v) {
@@ -389,6 +410,10 @@ module.exports = function (defaultFuncs, api, ctx) {
389
410
  msg = { body: msg };
390
411
  }
391
412
 
413
+ if (utils.getType(msg.body) === "String") {
414
+ msg.body = removeSpecialChar(msg.body);
415
+ }
416
+
392
417
  const disallowedProperties = Object.keys(msg).filter(
393
418
  prop => !allowedProperties[prop]
394
419
  );
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+
3
+ const utils = require("../utils");
4
+ const log = require("npmlog");
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ return function createNewGroup(participantIDs, groupTitle, callback) {
8
+ if (utils.getType(groupTitle) == "Function") {
9
+ callback = groupTitle;
10
+ groupTitle = null;
11
+ }
12
+
13
+ if (utils.getType(participantIDs) !== "Array") {
14
+ throw { error: "createNewGroup: participantIDs should be an array." };
15
+ }
16
+
17
+ if (participantIDs.length < 2) {
18
+ throw { error: "createNewGroup: participantIDs should have at least 2 IDs." };
19
+ }
20
+
21
+ let resolveFunc = function () { };
22
+ let rejectFunc = function () { };
23
+ const returnPromise = new Promise(function (resolve, reject) {
24
+ resolveFunc = resolve;
25
+ rejectFunc = reject;
26
+ });
27
+
28
+ if (!callback) {
29
+ callback = function (err, threadID) {
30
+ if (err) {
31
+ return rejectFunc(err);
32
+ }
33
+ resolveFunc(threadID);
34
+ };
35
+ }
36
+
37
+ const pids = [];
38
+ for (const n in participantIDs) {
39
+ pids.push({
40
+ fbid: participantIDs[n]
41
+ });
42
+ }
43
+ pids.push({ fbid: ctx.i_userID || ctx.userID });
44
+
45
+ const form = {
46
+ fb_api_caller_class: "RelayModern",
47
+ fb_api_req_friendly_name: "MessengerGroupCreateMutation",
48
+ av: ctx.i_userID || ctx.userID,
49
+ //This doc_id is valid as of January 11th, 2020
50
+ doc_id: "577041672419534",
51
+ variables: JSON.stringify({
52
+ input: {
53
+ entry_point: "jewel_new_group",
54
+ actor_id: ctx.i_userID || ctx.userID,
55
+ participants: pids,
56
+ client_mutation_id: Math.round(Math.random() * 1024).toString(),
57
+ thread_settings: {
58
+ name: groupTitle,
59
+ joinable_mode: "PRIVATE",
60
+ thread_image_fbid: null
61
+ }
62
+ }
63
+ })
64
+ };
65
+
66
+ defaultFuncs
67
+ .post(
68
+ "https://www.facebook.com/api/graphql/",
69
+ ctx.jar,
70
+ form
71
+ )
72
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
73
+ .then(function (resData) {
74
+ if (resData.errors) {
75
+ throw resData;
76
+ }
77
+ return callback(null, resData.data.messenger_group_thread_create.thread.thread_key.thread_fbid);
78
+ })
79
+ .catch(function (err) {
80
+ log.error("createNewGroup", err);
81
+ return callback(err);
82
+ });
83
+
84
+ return returnPromise;
85
+ };
86
+ };
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+
3
+ const utils = require("../utils");
4
+ const log = require("npmlog");
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ return function createPoll(title, threadID, options, callback) {
8
+ let resolveFunc = function () { };
9
+ let rejectFunc = function () { };
10
+ const returnPromise = new Promise(function (resolve, reject) {
11
+ resolveFunc = resolve;
12
+ rejectFunc = reject;
13
+ });
14
+
15
+ if (!callback) {
16
+ if (utils.getType(options) == "Function") {
17
+ callback = options;
18
+ options = null;
19
+ } else {
20
+ callback = function (err) {
21
+ if (err) {
22
+ return rejectFunc(err);
23
+ }
24
+ resolveFunc();
25
+ };
26
+ }
27
+ }
28
+ if (!options) {
29
+ options = {}; // Initial poll options are optional
30
+ }
31
+
32
+ const form = {
33
+ target_id: threadID,
34
+ question_text: title
35
+ };
36
+
37
+ // Set fields for options (and whether they are selected initially by the posting user)
38
+ let ind = 0;
39
+ for (const opt in options) {
40
+ // eslint-disable-next-line no-prototype-builtins
41
+ if (options.hasOwnProperty(opt)) {
42
+ form["option_text_array[" + ind + "]"] = opt;
43
+ form["option_is_selected_array[" + ind + "]"] = options[opt]
44
+ ? "1"
45
+ : "0";
46
+ ind++;
47
+ }
48
+ }
49
+
50
+ defaultFuncs
51
+ .post(
52
+ "https://www.facebook.com/messaging/group_polling/create_poll/?dpr=1",
53
+ ctx.jar,
54
+ form
55
+ )
56
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
57
+ .then(function (resData) {
58
+ if (resData.payload.status != "success") {
59
+ throw resData;
60
+ }
61
+
62
+ return callback();
63
+ })
64
+ .catch(function (err) {
65
+ log.error("createPoll", err);
66
+ return callback(err);
67
+ });
68
+
69
+ return returnPromise;
70
+ };
71
+ };
@@ -0,0 +1 @@
1
+ []
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+
3
+ const utils = require("../utils");
4
+ const log = require("npmlog");
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ return function deleteMessage(messageOrMessages, callback) {
8
+ let resolveFunc = function () { };
9
+ let rejectFunc = function () { };
10
+ const 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
+ const form = {
24
+ client: "mercury"
25
+ };
26
+
27
+ if (utils.getType(messageOrMessages) !== "Array") {
28
+ messageOrMessages = [messageOrMessages];
29
+ }
30
+
31
+ for (let 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
+ };