alicezetion 1.6.9 → 1.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) 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 +182 -495
  5. package/package.json +10 -8
  6. package/replit.nix +4 -6
  7. package/src/addExternalModule.js +15 -0
  8. package/{leiamnash → src}/addUserToGroup.js +16 -52
  9. package/src/changeAdminStatus.js +47 -0
  10. package/src/changeArchivedStatus.js +41 -0
  11. package/{leiamnash → src}/changeBio.js +6 -19
  12. package/{leiamnash → src}/changeBlockedStatus.js +3 -14
  13. package/{leiamnash → src}/changeGroupImage.js +16 -40
  14. package/src/changeNickname.js +43 -0
  15. package/{leiamnash → src}/changeThreadColor.js +10 -20
  16. package/src/changeThreadEmoji.js +41 -0
  17. package/src/chat.js +315 -0
  18. package/{leiamnash → src}/createNewGroup.js +12 -28
  19. package/{leiamnash → src}/createPoll.js +13 -25
  20. package/src/deleteMessage.js +44 -0
  21. package/src/deleteThread.js +42 -0
  22. package/src/forwardAttachment.js +47 -0
  23. package/src/forwardMessage.js +0 -0
  24. package/{leiamnash → src}/getCurrentUserID.js +1 -1
  25. package/{leiamnash → src}/getEmojiUrl.js +2 -4
  26. package/{leiamnash → src}/getFriendsList.js +10 -21
  27. package/{leiamnash → src}/getThreadHistory.js +58 -166
  28. package/{leiamnash → src}/getThreadHistoryDeprecated.js +20 -42
  29. package/src/getThreadInfo.js +171 -0
  30. package/src/getThreadInfoDeprecated.js +56 -0
  31. package/{leiamnash → src}/getThreadList.js +41 -66
  32. package/src/getThreadListDeprecated.js +46 -0
  33. package/src/getThreadPictures.js +59 -0
  34. package/{leiamnash → src}/getUserID.js +9 -14
  35. package/{leiamnash → src}/getUserInfo.js +12 -18
  36. package/src/handleFriendRequest.js +46 -0
  37. package/src/handleMessageRequest.js +47 -0
  38. package/{leiamnash → src}/httpGet.js +12 -17
  39. package/{leiamnash → src}/httpPost.js +12 -17
  40. package/src/listen.js +553 -0
  41. package/src/listenMqtt-Test.js +687 -0
  42. package/src/listenMqtt.js +677 -0
  43. package/{leiamnash → src}/logout.js +13 -20
  44. package/{leiamnash → src}/markAsDelivered.js +11 -22
  45. package/{leiamnash → src}/markAsRead.js +11 -21
  46. package/{leiamnash → src}/markAsReadAll.js +10 -20
  47. package/{leiamnash → src}/markAsSeen.js +7 -18
  48. package/{leiamnash → src}/muteThread.js +11 -18
  49. package/src/removeUserFromGroup.js +45 -0
  50. package/{leiamnash → src}/resolvePhotoUrl.js +8 -17
  51. package/{leiamnash → src}/searchForThread.js +10 -21
  52. package/src/sendMessage.js +315 -0
  53. package/{leiamnash → src}/sendTypingIndicator.js +14 -47
  54. package/{leiamnash → src}/setMessageReaction.js +12 -26
  55. package/{leiamnash → src}/setPostReaction.js +13 -26
  56. package/{leiamnash → src}/setTitle.js +13 -29
  57. package/src/threadColors.js +41 -0
  58. package/{leiamnash → src}/unfriend.js +9 -19
  59. package/{leiamnash → src}/unsendMessage.js +9 -19
  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 +1021 -1238
  68. package/leiamnash/addExternalModule.js +0 -19
  69. package/leiamnash/changeAdminStatus.js +0 -79
  70. package/leiamnash/changeApprovalMode.js +0 -80
  71. package/leiamnash/changeArchivedStatus.js +0 -55
  72. package/leiamnash/changeNickname.js +0 -59
  73. package/leiamnash/changeThreadEmoji.js +0 -55
  74. package/leiamnash/chat.js +0 -447
  75. package/leiamnash/deleteMessage.js +0 -56
  76. package/leiamnash/deleteThread.js +0 -56
  77. package/leiamnash/forwardAttachment.js +0 -60
  78. package/leiamnash/getThreadInfo.js +0 -212
  79. package/leiamnash/getThreadInfoDeprecated.js +0 -80
  80. package/leiamnash/getThreadListDeprecated.js +0 -75
  81. package/leiamnash/getThreadPictures.js +0 -79
  82. package/leiamnash/handleFriendRequest.js +0 -61
  83. package/leiamnash/handleMessageRequest.js +0 -65
  84. package/leiamnash/listenMqtt.js +0 -1129
  85. package/leiamnash/removeUserFromGroup.js +0 -79
  86. package/leiamnash/threadColors.js +0 -57
@@ -1,212 +0,0 @@
1
- "use strict";
2
-
3
- var utils = require("../utils");
4
- var log = require("npmlog");
5
-
6
- function formatEventReminders(reminder) {
7
- return {
8
- reminderID: reminder.id,
9
- eventCreatorID: reminder.lightweight_event_creator.id,
10
- time: reminder.time,
11
- eventType: reminder.lightweight_event_type.toLowerCase(),
12
- locationName: reminder.location_name,
13
- // @TODO verify this
14
- locationCoordinates: reminder.location_coordinates,
15
- locationPage: reminder.location_page,
16
- eventStatus: reminder.lightweight_event_status.toLowerCase(),
17
- note: reminder.note,
18
- repeatMode: reminder.repeat_mode.toLowerCase(),
19
- eventTitle: reminder.event_title,
20
- triggerMessage: reminder.trigger_message,
21
- secondsToNotifyBefore: reminder.seconds_to_notify_before,
22
- allowsRsvp: reminder.allows_rsvp,
23
- relatedEvent: reminder.related_event,
24
- members: reminder.event_reminder_members.edges.map(function(member) {
25
- return {
26
- memberID: member.node.id,
27
- state: member.guest_list_state.toLowerCase(),
28
- };
29
- }),
30
- };
31
- }
32
-
33
- function formatThreadGraphQLResponse(data) {
34
- var messageThread = data.o0.data.message_thread;
35
- var threadID = messageThread.thread_key.thread_fbid
36
- ? messageThread.thread_key.thread_fbid
37
- : messageThread.thread_key.other_user_id;
38
-
39
- // Remove me
40
- var lastM = messageThread.last_message;
41
- var snippetID =
42
- lastM &&
43
- lastM.nodes &&
44
- lastM.nodes[0] &&
45
- lastM.nodes[0].message_sender &&
46
- lastM.nodes[0].message_sender.messaging_actor
47
- ? lastM.nodes[0].message_sender.messaging_actor.id
48
- : null;
49
- var snippetText =
50
- lastM && lastM.nodes && lastM.nodes[0] ? lastM.nodes[0].snippet : null;
51
- var lastR = messageThread.last_read_receipt;
52
- var lastReadTimestamp =
53
- lastR &&
54
- lastR.nodes &&
55
- lastR.nodes[0] &&
56
- lastR.nodes[0].timestamp_precise
57
- ? lastR.nodes[0].timestamp_precise
58
- : null;
59
-
60
- return {
61
- threadID: threadID,
62
- threadName: messageThread.name,
63
- participantIDs: messageThread.all_participants.edges.map(
64
- (d) => d.node.messaging_actor.id
65
- ),
66
- userInfo: messageThread.all_participants.edges.map((d) => ({
67
- id: d.node.messaging_actor.id,
68
- name: d.node.messaging_actor.name,
69
- firstName: d.node.messaging_actor.short_name,
70
- vanity: d.node.messaging_actor.username,
71
- thumbSrc: d.node.messaging_actor.big_image_src.uri,
72
- profileUrl: d.node.messaging_actor.url,
73
- gender: d.node.messaging_actor.gender,
74
- type: d.node.messaging_actor.__typename,
75
- isFriend: d.node.messaging_actor.is_viewer_friend,
76
- isBirthday: !!d.node.messaging_actor.is_birthday, //not sure?
77
- })),
78
- unreadCount: messageThread.unread_count,
79
- messageCount: messageThread.messages_count,
80
- timestamp: messageThread.updated_time_precise,
81
- muteUntil: messageThread.mute_until,
82
- isGroup: messageThread.thread_type == "GROUP",
83
- isSubscribed: messageThread.is_viewer_subscribed,
84
- isArchived: messageThread.has_viewer_archived,
85
- folder: messageThread.folder,
86
- cannotReplyReason: messageThread.cannot_reply_reason,
87
- eventReminders: messageThread.event_reminders
88
- ? messageThread.event_reminders.nodes.map(formatEventReminders)
89
- : null,
90
- emoji: messageThread.customization_info
91
- ? messageThread.customization_info.emoji
92
- : null,
93
- color:
94
- messageThread.customization_info &&
95
- messageThread.customization_info.outgoing_bubble_color
96
- ? messageThread.customization_info.outgoing_bubble_color.slice(
97
- 2
98
- )
99
- : null,
100
- nicknames:
101
- messageThread.customization_info &&
102
- messageThread.customization_info.participant_customizations
103
- ? messageThread.customization_info.participant_customizations.reduce(
104
- function(res, val) {
105
- if (val.nickname)
106
- res[val.participant_id] = val.nickname;
107
- return res;
108
- },
109
- {}
110
- )
111
- : {},
112
- adminIDs: messageThread.thread_admins.map((el) => el.id),
113
- approvalMode: Boolean(messageThread.approval_mode),
114
- approvalQueue: messageThread.group_approval_queue.nodes.map((a) => ({
115
- inviterID: a.inviter.id,
116
- requesterID: a.requester.id,
117
- timestamp: a.request_timestamp,
118
- request_source: a.request_source, // @Undocumented
119
- })),
120
-
121
- // @Undocumented
122
- reactionsMuteMode: messageThread.reactions_mute_mode.toLowerCase(),
123
- mentionsMuteMode: messageThread.mentions_mute_mode.toLowerCase(),
124
- isPinProtected: messageThread.is_pin_protected,
125
- relatedPageThread: messageThread.related_page_thread,
126
-
127
- // @Legacy
128
- name: messageThread.name,
129
- snippet: snippetText,
130
- snippetSender: snippetID,
131
- snippetAttachments: [],
132
- serverTimestamp: messageThread.updated_time_precise,
133
- imageSrc: messageThread.image ? messageThread.image.uri : null,
134
- isCanonicalUser: messageThread.is_canonical_neo_user,
135
- isCanonical: messageThread.thread_type != "GROUP",
136
- recipientsLoadable: true,
137
- hasEmailParticipant: false,
138
- readOnly: false,
139
- canReply: messageThread.cannot_reply_reason == null,
140
- lastMessageTimestamp: messageThread.last_message
141
- ? messageThread.last_message.timestamp_precise
142
- : null,
143
- lastMessageType: "message",
144
- lastReadTimestamp: lastReadTimestamp,
145
- threadType: messageThread.thread_type == "GROUP" ? 2 : 1,
146
- };
147
- }
148
-
149
- module.exports = function(defaultFuncs, api, ctx) {
150
- return function getThreadInfoGraphQL(threadID, callback) {
151
- var resolveFunc = function() {};
152
- var rejectFunc = function() {};
153
- var returnPromise = new Promise(function(resolve, reject) {
154
- resolveFunc = resolve;
155
- rejectFunc = reject;
156
- });
157
-
158
- if (
159
- utils.getType(callback) != "Function" &&
160
- utils.getType(callback) != "AsyncFunction"
161
- ) {
162
- callback = function(err, data) {
163
- if (err) {
164
- return rejectFunc(err);
165
- }
166
- resolveFunc(data);
167
- };
168
- }
169
-
170
- // `queries` has to be a string. I couldn't tell from the dev console. This
171
- // took me a really long time to figure out. I deserve a cookie for this.
172
- var form = {
173
- queries: JSON.stringify({
174
- o0: {
175
- // This doc_id is valid as of July 20th, 2020
176
- doc_id: "3449967031715030",
177
- query_params: {
178
- id: threadID,
179
- message_limit: 0,
180
- load_messages: false,
181
- load_read_receipts: false,
182
- before: null,
183
- },
184
- },
185
- }),
186
- batch_name: "MessengerGraphQLThreadFetcher",
187
- };
188
-
189
- defaultFuncs
190
- .post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
191
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
192
- .then(function(resData) {
193
- if (resData.error) {
194
- throw resData;
195
- }
196
- // This returns us an array of things. The last one is the success /
197
- // failure one.
198
- // @TODO What do we do in this case?
199
- if (resData[resData.length - 1].error_results !== 0) {
200
- throw new Error("well darn there was an error_result");
201
- }
202
-
203
- callback(null, formatThreadGraphQLResponse(resData[0]));
204
- })
205
- .catch(function(err) {
206
- log.error("getThreadInfoGraphQL", err);
207
- return callback(err);
208
- });
209
-
210
- return returnPromise;
211
- };
212
- };
@@ -1,80 +0,0 @@
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 getThreadInfo(threadID, 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
-
15
- if (!callback) {
16
- callback = function (err, friendList) {
17
- if (err) {
18
- return rejectFunc(err);
19
- }
20
- resolveFunc(friendList);
21
- };
22
- }
23
-
24
- var form = {
25
- client: "mercury"
26
- };
27
-
28
- api.getUserInfo(threadID, function(err, userRes) {
29
- if (err) {
30
- return callback(err);
31
- }
32
- var key = Object.keys(userRes).length > 0 ? "user_ids" : "thread_fbids";
33
- form["threads[" + key + "][0]"] = threadID;
34
-
35
- if (ctx.globalOptions.pageId)
36
- form.request_user_id = ctx.globalOptions.pageId;
37
-
38
- defaultFuncs
39
- .post(
40
- "https://www.facebook.com/ajax/mercury/thread_info.php",
41
- ctx.jar,
42
- form
43
- )
44
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
45
- .then(function(resData) {
46
- if (resData.error) {
47
- throw resData;
48
- } else if (!resData.payload) {
49
- throw {
50
- error: "Could not retrieve thread Info."
51
- };
52
- }
53
- var threadData = resData.payload.threads[0];
54
- var userData = userRes[threadID];
55
-
56
- if (threadData == null) {
57
- throw {
58
- error: "ThreadData is null"
59
- };
60
- }
61
-
62
- threadData.name =
63
- userData != null && userData.name != null
64
- ? userData.name
65
- : threadData.name;
66
- threadData.image_src =
67
- userData != null && userData.thumbSrc != null
68
- ? userData.thumbSrc
69
- : threadData.image_src;
70
-
71
- callback(null, utils.formatThread(threadData));
72
- })
73
- .catch(function(err) {
74
- log.error("getThreadInfo", err);
75
- return callback(err);
76
- });
77
- });
78
- return returnPromise;
79
- };
80
- };
@@ -1,75 +0,0 @@
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 getThreadList(start, end, type, callback) {
8
- if (utils.getType(callback) === "Undefined") {
9
- if (utils.getType(end) !== "Number") {
10
- throw {
11
- error: "Please pass a number as a second argument."
12
- };
13
- } else if (
14
- utils.getType(type) === "Function" ||
15
- utils.getType(type) === "AsyncFunction"
16
- ) {
17
- callback = type;
18
- type = "inbox"; //default to inbox
19
- } else if (utils.getType(type) !== "String") {
20
- throw {
21
- error:
22
- "Please pass a String as a third argument. Your options are: inbox, pending, and archived"
23
- };
24
- } else {
25
- throw {
26
- error: "getThreadList: need callback"
27
- };
28
- }
29
- }
30
-
31
- if (type === "archived") {
32
- type = "action:archived";
33
- } else if (type !== "inbox" && type !== "pending" && type !== "other") {
34
- throw {
35
- error:
36
- "type can only be one of the following: inbox, pending, archived, other"
37
- };
38
- }
39
-
40
- if (end <= start) end = start + 20;
41
-
42
- var form = {
43
- client: "mercury"
44
- };
45
-
46
- form[type + "[offset]"] = start;
47
- form[type + "[limit]"] = end - start;
48
-
49
- if (ctx.globalOptions.pageID) {
50
- form.request_user_id = ctx.globalOptions.pageID;
51
- }
52
-
53
- defaultFuncs
54
- .post(
55
- "https://www.facebook.com/ajax/mercury/threadlist_info.php",
56
- ctx.jar,
57
- form
58
- )
59
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
60
- .then(function(resData) {
61
- if (resData.error) {
62
- throw resData;
63
- }
64
- log.verbose("getThreadList", JSON.stringify(resData.payload.threads));
65
- return callback(
66
- null,
67
- (resData.payload.threads || []).map(utils.formatThread)
68
- );
69
- })
70
- .catch(function(err) {
71
- log.error("getThreadList", err);
72
- return callback(err);
73
- });
74
- };
75
- };
@@ -1,79 +0,0 @@
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 getThreadPictures(threadID, offset, limit, 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
-
15
- if (!callback) {
16
- callback = function (err, friendList) {
17
- if (err) {
18
- return rejectFunc(err);
19
- }
20
- resolveFunc(friendList);
21
- };
22
- }
23
-
24
- var form = {
25
- thread_id: threadID,
26
- offset: offset,
27
- limit: limit
28
- };
29
-
30
- defaultFuncs
31
- .post(
32
- "https://www.facebook.com/ajax/messaging/attachments/sharedphotos.php",
33
- ctx.jar,
34
- form
35
- )
36
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
37
- .then(function(resData) {
38
- if (resData.error) {
39
- throw resData;
40
- }
41
- return Promise.all(
42
- resData.payload.imagesData.map(function(image) {
43
- form = {
44
- thread_id: threadID,
45
- image_id: image.fbid
46
- };
47
- return defaultFuncs
48
- .post(
49
- "https://www.facebook.com/ajax/messaging/attachments/sharedphotos.php",
50
- ctx.jar,
51
- form
52
- )
53
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
54
- .then(function(resData) {
55
- if (resData.error) {
56
- throw resData;
57
- }
58
- // the response is pretty messy
59
- var queryThreadID =
60
- resData.jsmods.require[0][3][1].query_metadata.query_path[0]
61
- .message_thread;
62
- var imageData =
63
- resData.jsmods.require[0][3][1].query_results[queryThreadID]
64
- .message_images.edges[0].node.image2;
65
- return imageData;
66
- });
67
- })
68
- );
69
- })
70
- .then(function(resData) {
71
- callback(null, resData);
72
- })
73
- .catch(function(err) {
74
- log.error("Error in getThreadPictures", err);
75
- callback(err);
76
- });
77
- return returnPromise;
78
- };
79
- };
@@ -1,61 +0,0 @@
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 handleFriendRequest(userID, accept, callback) {
8
- if (utils.getType(accept) !== "Boolean") {
9
- throw {
10
- error: "Please pass a boolean as a second argument."
11
- };
12
- }
13
-
14
- var resolveFunc = function(){};
15
- var rejectFunc = function(){};
16
- var returnPromise = new Promise(function (resolve, reject) {
17
- resolveFunc = resolve;
18
- rejectFunc = reject;
19
- });
20
-
21
- if (!callback) {
22
- callback = function (err, friendList) {
23
- if (err) {
24
- return rejectFunc(err);
25
- }
26
- resolveFunc(friendList);
27
- };
28
- }
29
-
30
- var form = {
31
- viewer_id: ctx.userID,
32
- "frefs[0]": "jwl",
33
- floc: "friend_center_requests",
34
- ref: "/reqs.php",
35
- action: (accept ? "confirm" : "reject")
36
- };
37
-
38
- defaultFuncs
39
- .post(
40
- "https://www.facebook.com/requests/friends/ajax/",
41
- ctx.jar,
42
- form
43
- )
44
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
45
- .then(function(resData) {
46
- if (resData.payload.err) {
47
- throw {
48
- err: resData.payload.err
49
- };
50
- }
51
-
52
- return callback();
53
- })
54
- .catch(function(err) {
55
- log.error("handleFriendRequest", err);
56
- return callback(err);
57
- });
58
-
59
- return returnPromise;
60
- };
61
- };
@@ -1,65 +0,0 @@
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 handleMessageRequest(threadID, accept, callback) {
8
- if (utils.getType(accept) !== "Boolean") {
9
- throw {
10
- error: "Please pass a boolean as a second argument."
11
- };
12
- }
13
-
14
- var resolveFunc = function(){};
15
- var rejectFunc = function(){};
16
- var returnPromise = new Promise(function (resolve, reject) {
17
- resolveFunc = resolve;
18
- rejectFunc = reject;
19
- });
20
-
21
- if (!callback) {
22
- callback = function (err, friendList) {
23
- if (err) {
24
- return rejectFunc(err);
25
- }
26
- resolveFunc(friendList);
27
- };
28
- }
29
-
30
- var form = {
31
- client: "mercury"
32
- };
33
-
34
- if (utils.getType(threadID) !== "Array") {
35
- threadID = [threadID];
36
- }
37
-
38
- var messageBox = accept ? "inbox" : "other";
39
-
40
- for (var i = 0; i < threadID.length; i++) {
41
- form[messageBox + "[" + i + "]"] = threadID[i];
42
- }
43
-
44
- defaultFuncs
45
- .post(
46
- "https://www.facebook.com/ajax/mercury/move_thread.php",
47
- ctx.jar,
48
- form
49
- )
50
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
51
- .then(function(resData) {
52
- if (resData.error) {
53
- throw resData;
54
- }
55
-
56
- return callback();
57
- })
58
- .catch(function(err) {
59
- log.error("handleMessageRequest", err);
60
- return callback(err);
61
- });
62
-
63
- return returnPromise;
64
- };
65
- };