@vangbanlanhat/fca-unofficial 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/.gitattributes +2 -0
  2. package/.github/workflows/nodejs.yml +26 -0
  3. package/.github/workflows/npmpublish.yml +30 -0
  4. package/.travis.yml +6 -0
  5. package/CHANGELOG.md +2 -0
  6. package/DOCS.md +1932 -0
  7. package/LICENSE-MIT +21 -0
  8. package/README.md +198 -0
  9. package/jest.config.js +10 -0
  10. package/package.json +86 -0
  11. package/pnpm-workspace.yaml +3 -0
  12. package/src/actions/addExternalModule.js +34 -0
  13. package/src/actions/addUserToGroup.js +113 -0
  14. package/src/actions/changeAdminStatus.js +79 -0
  15. package/src/actions/changeArchivedStatus.js +55 -0
  16. package/src/actions/changeBio.js +77 -0
  17. package/src/actions/changeBlockedStatus.js +47 -0
  18. package/src/actions/changeGroupImage.js +129 -0
  19. package/src/actions/changeNickname.js +59 -0
  20. package/src/actions/changeThreadColor.js +71 -0
  21. package/src/actions/changeThreadEmoji.js +55 -0
  22. package/src/actions/createNewGroup.js +86 -0
  23. package/src/actions/createPoll.js +71 -0
  24. package/src/actions/deleteMessage.js +56 -0
  25. package/src/actions/deleteThread.js +56 -0
  26. package/src/actions/editMessage.js +81 -0
  27. package/src/actions/forwardAttachment.js +60 -0
  28. package/src/actions/getAvatarUser.js +77 -0
  29. package/src/actions/getCurrentUserID.js +11 -0
  30. package/src/actions/getEmojiUrl.js +37 -0
  31. package/src/actions/getFriendsList.js +84 -0
  32. package/src/actions/getMessage.js +833 -0
  33. package/src/actions/getRegion.js +11 -0
  34. package/src/actions/getThreadHistory.js +702 -0
  35. package/src/actions/getThreadHistoryDeprecated.js +93 -0
  36. package/src/actions/getThreadInfo.js +265 -0
  37. package/src/actions/getThreadInfoDeprecated.js +80 -0
  38. package/src/actions/getThreadList.js +274 -0
  39. package/src/actions/getThreadListDeprecated.js +91 -0
  40. package/src/actions/getThreadPictures.js +79 -0
  41. package/src/actions/getUserID.js +66 -0
  42. package/src/actions/getUserInfo.js +92 -0
  43. package/src/actions/handleFriendRequest.js +61 -0
  44. package/src/actions/handleMessageRequest.js +65 -0
  45. package/src/actions/httpGet.js +70 -0
  46. package/src/actions/httpPost.js +70 -0
  47. package/src/actions/index.js +69 -0
  48. package/src/actions/listenMqtt.js +818 -0
  49. package/src/actions/logout.js +136 -0
  50. package/src/actions/markAsDelivered.js +58 -0
  51. package/src/actions/markAsRead.js +92 -0
  52. package/src/actions/markAsReadAll.js +50 -0
  53. package/src/actions/markAsSeen.js +59 -0
  54. package/src/actions/muteThread.js +52 -0
  55. package/src/actions/pinMessage.js +86 -0
  56. package/src/actions/refreshFb_dtsg.js +89 -0
  57. package/src/actions/removeUserFromGroup.js +79 -0
  58. package/src/actions/resolvePhotoUrl.js +45 -0
  59. package/src/actions/searchForThread.js +53 -0
  60. package/src/actions/searchStickers.js +53 -0
  61. package/src/actions/sendMessage.js +490 -0
  62. package/src/actions/sendMessageMqtt.js +235 -0
  63. package/src/actions/sendTypingIndicator.js +59 -0
  64. package/src/actions/setMessageReaction.js +140 -0
  65. package/src/actions/setMessageReactionMqtt.js +72 -0
  66. package/src/actions/setPostReaction.js +76 -0
  67. package/src/actions/setTitle.js +86 -0
  68. package/src/actions/stopListenMqtt.js +63 -0
  69. package/src/actions/threadColors.js +57 -0
  70. package/src/actions/unfriend.js +52 -0
  71. package/src/actions/unsendMessage.js +61 -0
  72. package/src/index.js +659 -0
  73. package/src/service/uploadAttachment.js +318 -0
  74. package/src/utils/base-parts/auth.js +286 -0
  75. package/src/utils/base-parts/formatters.js +751 -0
  76. package/src/utils/base-parts/identity.js +169 -0
  77. package/src/utils/base-parts/network.js +159 -0
  78. package/src/utils/base-parts/parsing.js +53 -0
  79. package/src/utils/base-parts/type.js +9 -0
  80. package/src/utils/base.js +18 -0
  81. package/src/utils/defaults.js +10 -0
  82. package/src/utils/format-attachments.js +7 -0
  83. package/src/utils/format-core.js +8 -0
  84. package/src/utils/format-events.js +11 -0
  85. package/src/utils/format-messages.js +10 -0
  86. package/src/utils/format-presence.js +9 -0
  87. package/src/utils/format-threads.js +8 -0
  88. package/src/utils/formatters.js +18 -0
  89. package/src/utils/identity.js +12 -0
  90. package/src/utils/index.js +15 -0
  91. package/src/utils/network.js +12 -0
  92. package/src/utils/parsing.js +11 -0
  93. package/src/utils.js +3 -0
  94. package/test/config.env.example +30 -0
  95. package/test/data/shareAttach.js +146 -0
  96. package/test/data/something.mov +0 -0
  97. package/test/data/test.png +0 -0
  98. package/test/data/test.txt +7 -0
  99. package/test/example-appstate.txt +11 -0
  100. package/test/integration/actions.appstate.integration.test.js +233 -0
  101. package/test/integration/api.integration.test.js +387 -0
  102. package/test/integration/env-test-config.js +46 -0
  103. package/test/integration/login.appstate.integration.test.js +47 -0
  104. package/test/integration/page.integration.test.js +139 -0
  105. package/test/jest.setup.js +54 -0
  106. package/test/unit/actions/actions.basic.test.js +116 -0
  107. package/test/unit/actions/actions.registry.test.js +36 -0
  108. package/test/unit/index/index.test.js +109 -0
  109. package/test/unit/utils/base-parts/auth.test.js +92 -0
  110. package/test/unit/utils/base-parts/formatters.test.js +53 -0
  111. package/test/unit/utils/base-parts/identity.test.js +43 -0
  112. package/test/unit/utils/base-parts/parsing.test.js +38 -0
  113. package/test/unit/utils/base-parts/type.test.js +23 -0
  114. package/test/unit/utils/base.test.js +35 -0
  115. package/vangbanlanhat-fca-unofficial-1.4.2.tgz +0 -0
@@ -0,0 +1,93 @@
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 getThreadHistory(threadID, amount, timestamp, 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
+ if (!callback) {
25
+ throw { error: "getThreadHistory: need callback" };
26
+ }
27
+
28
+ var form = {
29
+ client: "mercury"
30
+ };
31
+
32
+ api.getUserInfo(threadID, function(err, res) {
33
+ if (err) {
34
+ return callback(err);
35
+ }
36
+ var key = Object.keys(res).length > 0 ? "user_ids" : "thread_fbids";
37
+ form["messages[" + key + "][" + threadID + "][offset]"] = 0;
38
+ form["messages[" + key + "][" + threadID + "][timestamp]"] = timestamp;
39
+ form["messages[" + key + "][" + threadID + "][limit]"] = amount;
40
+
41
+ if (ctx.globalOptions.pageID)
42
+ form.request_user_id = ctx.globalOptions.pageID;
43
+
44
+ defaultFuncs
45
+ .post(
46
+ "https://www.facebook.com/ajax/mercury/thread_info.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
+ } else if (!resData.payload) {
55
+ throw { error: "Could not retrieve thread history." };
56
+ }
57
+
58
+ // Asking for message history from a thread with no message history
59
+ // will return undefined for actions here
60
+ if (!resData.payload.actions) {
61
+ resData.payload.actions = [];
62
+ }
63
+
64
+ var userIDs = {};
65
+ resData.payload.actions.forEach(function(v) {
66
+ userIDs[v.author.split(":").pop()] = "";
67
+ });
68
+
69
+ api.getUserInfo(Object.keys(userIDs), function(err, data) {
70
+ if (err) return callback(err); //callback({error: "Could not retrieve user information in getThreadHistory."});
71
+
72
+ resData.payload.actions.forEach(function(v) {
73
+ var sender = data[v.author.split(":").pop()];
74
+ if (sender) v.sender_name = sender.name;
75
+ else v.sender_name = "Facebook User";
76
+ v.sender_fbid = v.author;
77
+ delete v.author;
78
+ });
79
+
80
+ callback(
81
+ null,
82
+ resData.payload.actions.map(utils.formatHistoryMessage)
83
+ );
84
+ });
85
+ })
86
+ .catch(function(err) {
87
+ log.error("getThreadHistory", err);
88
+ return callback(err);
89
+ });
90
+ });
91
+ return returnPromise;
92
+ };
93
+ };
@@ -0,0 +1,265 @@
1
+ "use strict";
2
+
3
+ var utils = require("../utils");
4
+ var log = require("npmlog");
5
+
6
+ function formatEventReminders(reminder) {
7
+ if (!reminder) {
8
+ return null;
9
+ }
10
+
11
+ var members =
12
+ reminder.event_reminder_members &&
13
+ Array.isArray(reminder.event_reminder_members.edges)
14
+ ? reminder.event_reminder_members.edges
15
+ : [];
16
+
17
+ return {
18
+ reminderID: reminder.id,
19
+ eventCreatorID: reminder.lightweight_event_creator
20
+ ? reminder.lightweight_event_creator.id
21
+ : null,
22
+ time: reminder.time,
23
+ eventType: reminder.lightweight_event_type
24
+ ? reminder.lightweight_event_type.toLowerCase()
25
+ : null,
26
+ locationName: reminder.location_name,
27
+ // @TODO verify this
28
+ locationCoordinates: reminder.location_coordinates,
29
+ locationPage: reminder.location_page,
30
+ eventStatus: reminder.lightweight_event_status
31
+ ? reminder.lightweight_event_status.toLowerCase()
32
+ : null,
33
+ note: reminder.note,
34
+ repeatMode: reminder.repeat_mode ? reminder.repeat_mode.toLowerCase() : null,
35
+ eventTitle: reminder.event_title,
36
+ triggerMessage: reminder.trigger_message,
37
+ secondsToNotifyBefore: reminder.seconds_to_notify_before,
38
+ allowsRsvp: reminder.allows_rsvp,
39
+ relatedEvent: reminder.related_event,
40
+ members: members.map(function(member) {
41
+ return {
42
+ memberID: member && member.node ? member.node.id : null,
43
+ state:
44
+ member && member.guest_list_state
45
+ ? member.guest_list_state.toLowerCase()
46
+ : null
47
+ };
48
+ }).filter(Boolean)
49
+ };
50
+ }
51
+
52
+ function formatThreadGraphQLResponse(data) {
53
+ if (!data) {
54
+ throw { error: "getThreadInfoGraphQL: empty response payload" };
55
+ }
56
+
57
+ var messageThread =
58
+ data.message_thread ||
59
+ (data.o0 && data.o0.data ? data.o0.data.message_thread : null);
60
+
61
+ if (!messageThread || !messageThread.thread_key) {
62
+ throw {
63
+ error: "getThreadInfoGraphQL: invalid thread payload",
64
+ res: data
65
+ };
66
+ }
67
+ var threadID = messageThread.thread_key.thread_fbid
68
+ ? messageThread.thread_key.thread_fbid
69
+ : messageThread.thread_key.other_user_id;
70
+
71
+ // Remove me
72
+ var lastM = messageThread.last_message;
73
+ var snippetID =
74
+ lastM &&
75
+ lastM.nodes &&
76
+ lastM.nodes[0] &&
77
+ lastM.nodes[0].message_sender &&
78
+ lastM.nodes[0].message_sender.messaging_actor
79
+ ? lastM.nodes[0].message_sender.messaging_actor.id
80
+ : null;
81
+ var snippetText =
82
+ lastM && lastM.nodes && lastM.nodes[0] ? lastM.nodes[0].snippet : null;
83
+ var lastR = messageThread.last_read_receipt;
84
+ var lastReadTimestamp =
85
+ lastR && lastR.nodes && lastR.nodes[0] && lastR.nodes[0].timestamp_precise
86
+ ? lastR.nodes[0].timestamp_precise
87
+ : null;
88
+
89
+ return {
90
+ threadID: threadID,
91
+ threadName: messageThread.name,
92
+ participantIDs: (messageThread.all_participants && Array.isArray(messageThread.all_participants.edges)
93
+ ? messageThread.all_participants.edges
94
+ : [])
95
+ .map(function(d) {
96
+ return d && d.node && d.node.messaging_actor
97
+ ? d.node.messaging_actor.id
98
+ : null;
99
+ })
100
+ .filter(Boolean),
101
+ userInfo: (messageThread.all_participants && Array.isArray(messageThread.all_participants.edges)
102
+ ? messageThread.all_participants.edges
103
+ : [])
104
+ .map(function(d) {
105
+ var actor = d && d.node ? d.node.messaging_actor : null;
106
+ if (!actor) return null;
107
+ return {
108
+ id: actor.id,
109
+ name: actor.name,
110
+ firstName: actor.short_name,
111
+ vanity: actor.username,
112
+ thumbSrc: actor.big_image_src ? actor.big_image_src.uri : null,
113
+ profileUrl: actor.big_image_src ? actor.big_image_src.uri : null,
114
+ gender: actor.gender,
115
+ type: actor.__typename,
116
+ isFriend: actor.is_viewer_friend,
117
+ isBirthday: !!actor.is_birthday //not sure?
118
+ };
119
+ })
120
+ .filter(Boolean),
121
+ unreadCount: messageThread.unread_count,
122
+ messageCount: messageThread.messages_count,
123
+ timestamp: messageThread.updated_time_precise,
124
+ muteUntil: messageThread.mute_until,
125
+ isGroup: messageThread.thread_type == "GROUP",
126
+ isSubscribed: messageThread.is_viewer_subscribed,
127
+ isArchived: messageThread.has_viewer_archived,
128
+ folder: messageThread.folder,
129
+ cannotReplyReason: messageThread.cannot_reply_reason,
130
+ eventReminders: messageThread.event_reminders
131
+ ? messageThread.event_reminders.nodes.map(formatEventReminders).filter(Boolean)
132
+ : null,
133
+ emoji: messageThread.customization_info
134
+ ? messageThread.customization_info.emoji
135
+ : null,
136
+ color:
137
+ messageThread.customization_info &&
138
+ messageThread.customization_info.outgoing_bubble_color
139
+ ? messageThread.customization_info.outgoing_bubble_color.slice(2)
140
+ : null,
141
+ nicknames:
142
+ messageThread.customization_info &&
143
+ messageThread.customization_info.participant_customizations
144
+ ? messageThread.customization_info.participant_customizations.reduce(
145
+ function(res, val) {
146
+ if (val.nickname) res[val.participant_id] = val.nickname;
147
+ return res;
148
+ },
149
+ {}
150
+ )
151
+ : {},
152
+ adminIDs: Array.isArray(messageThread.thread_admins) ? messageThread.thread_admins : [],
153
+ approvalMode: Boolean(messageThread.approval_mode),
154
+ approvalQueue:
155
+ messageThread.group_approval_queue && Array.isArray(messageThread.group_approval_queue.nodes)
156
+ ? messageThread.group_approval_queue.nodes.map(function(a) {
157
+ return {
158
+ inviterID: a && a.inviter ? a.inviter.id : null,
159
+ requesterID: a && a.requester ? a.requester.id : null,
160
+ timestamp: a ? a.request_timestamp : null,
161
+ request_source: a ? a.request_source : null // @Undocumented
162
+ };
163
+ })
164
+ : [],
165
+
166
+ // @Undocumented
167
+ reactionsMuteMode: messageThread.reactions_mute_mode
168
+ ? messageThread.reactions_mute_mode.toLowerCase()
169
+ : null,
170
+ mentionsMuteMode: messageThread.mentions_mute_mode
171
+ ? messageThread.mentions_mute_mode.toLowerCase()
172
+ : null,
173
+ isPinProtected: messageThread.is_pin_protected,
174
+ relatedPageThread: messageThread.related_page_thread,
175
+
176
+ // @Legacy
177
+ name: messageThread.name,
178
+ snippet: snippetText,
179
+ snippetSender: snippetID,
180
+ snippetAttachments: [],
181
+ serverTimestamp: messageThread.updated_time_precise,
182
+ imageSrc: messageThread.image ? messageThread.image.uri : null,
183
+ isCanonicalUser: messageThread.is_canonical_neo_user,
184
+ isCanonical: messageThread.thread_type != "GROUP",
185
+ recipientsLoadable: true,
186
+ hasEmailParticipant: false,
187
+ readOnly: false,
188
+ canReply: messageThread.cannot_reply_reason == null,
189
+ lastMessageTimestamp: messageThread.last_message
190
+ ? messageThread.last_message.timestamp_precise
191
+ : null,
192
+ lastMessageType: "message",
193
+ lastReadTimestamp: lastReadTimestamp,
194
+ threadType: messageThread.thread_type == "GROUP" ? 2 : 1
195
+ };
196
+ }
197
+
198
+ module.exports = function(defaultFuncs, api, ctx) {
199
+ return function getThreadInfoGraphQL(threadID, callback) {
200
+ var resolveFunc = function(){};
201
+ var rejectFunc = function(){};
202
+ var returnPromise = new Promise(function (resolve, reject) {
203
+ resolveFunc = resolve;
204
+ rejectFunc = reject;
205
+ });
206
+
207
+ if (utils.getType(callback) != "Function" && utils.getType(callback) != "AsyncFunction") {
208
+ callback = function (err, data) {
209
+ if (err) {
210
+ return rejectFunc(err);
211
+ }
212
+ resolveFunc(data);
213
+ };
214
+ }
215
+
216
+ // `queries` has to be a string. I couldn't tell from the dev console. This
217
+ // took me a really long time to figure out. I deserve a cookie for this.
218
+ var form = {
219
+ queries: JSON.stringify({
220
+ o0: {
221
+ // This doc_id is valid as of July 20th, 2020
222
+ doc_id: "3449967031715030",
223
+ query_params: {
224
+ id: threadID,
225
+ message_limit: 0,
226
+ load_messages: false,
227
+ load_read_receipts: false,
228
+ before: null
229
+ }
230
+ }
231
+ }),
232
+ batch_name: "MessengerGraphQLThreadFetcher"
233
+ };
234
+
235
+ defaultFuncs
236
+ .post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
237
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
238
+ .then(function(resData) {
239
+ if (!Array.isArray(resData) || resData.length === 0) {
240
+ throw {
241
+ error: "getThreadInfoGraphQL: invalid graphql response",
242
+ res: resData
243
+ };
244
+ }
245
+
246
+ if (resData.error) {
247
+ throw resData;
248
+ }
249
+ // This returns us an array of things. The last one is the success /
250
+ // failure one.
251
+ // @TODO What do we do in this case?
252
+ if (resData[resData.length - 1].error_results !== 0) {
253
+ console.error("GetThreadInfo", "Well darn there was an error_result");
254
+ }
255
+
256
+ callback(null, formatThreadGraphQLResponse(resData[0]));
257
+ })
258
+ .catch(function(err) {
259
+ log.error("getThreadInfoGraphQL", err);
260
+ return callback(err);
261
+ });
262
+
263
+ return returnPromise;
264
+ };
265
+ };
@@ -0,0 +1,80 @@
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
+ };