@cexy/hoonfca 1.0.1 → 1.0.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.
- package/.travis.yml +6 -0
- package/LICENSE-MIT +21 -0
- package/index.d.ts +620 -0
- package/index.js +778 -1
- package/package.json +31 -84
- package/src/{apis/addExternalModule.js → addExternalModule.js} +4 -5
- package/src/addUserToGroup.js +113 -0
- package/src/changeAdminStatus.js +95 -0
- package/src/changeApprovalMode.js +79 -0
- package/src/changeArchivedStatus.js +55 -0
- package/src/changeBio.js +76 -0
- package/src/changeBlockedStatus.js +47 -0
- package/src/changeBlockedStatusMqtt.js +86 -0
- package/src/changeGroupImage.js +133 -0
- package/src/changeNickname.js +59 -0
- package/src/changeThreadColor.js +71 -0
- package/src/{apis/changeThreadEmoji.js → changeThreadEmoji.js} +8 -6
- package/src/createNewGroup.js +88 -0
- package/src/createPoll.js +130 -0
- package/src/deleteMessage.js +56 -0
- package/src/deleteThread.js +56 -0
- package/src/editMessage.js +63 -0
- package/src/forwardAttachment.js +60 -0
- package/src/forwardMessage.js +63 -0
- package/src/getCurrentUserID.js +7 -0
- package/src/getEmojiUrl.js +29 -0
- package/src/getFriendsList.js +84 -0
- package/src/getGroupsList.js +83 -0
- package/src/getMarketplace.js +84 -0
- package/src/getNotifications.js +86 -0
- package/src/getPagesList.js +83 -0
- package/src/getStories.js +88 -0
- package/src/getThreadHistory.js +647 -0
- package/src/getThreadInfo.js +222 -0
- package/src/getThreadList.js +292 -0
- package/src/getThreadPictures.js +79 -0
- package/src/getUserID.js +66 -0
- package/src/getUserInfo.js +128 -0
- package/src/handleFriendRequest.js +57 -0
- package/src/handleMessageRequest.js +65 -0
- package/src/{apis/httpGet.js → httpGet.js} +15 -20
- package/src/httpPost.js +58 -0
- package/src/listenMqtt.js +1018 -0
- package/src/logout.js +75 -0
- package/src/markAsDelivered.js +58 -0
- package/src/{apis/markAsRead.js → markAsRead.js} +19 -30
- package/src/markAsReadAll.js +50 -0
- package/src/markAsSeen.js +61 -0
- package/src/muteThread.js +52 -0
- package/src/pinMessage.js +61 -0
- package/src/removeUserFromGroup.js +79 -0
- package/src/resolvePhotoUrl.js +45 -0
- package/src/searchForThread.js +53 -0
- package/src/searchUsers.js +89 -0
- package/src/sendComment.js +161 -0
- package/src/sendMessage.js +457 -0
- package/src/sendTypingIndicator.js +179 -0
- package/src/setBio.js +86 -0
- package/src/setMessageReaction.js +186 -0
- package/src/setPostReaction.js +71 -0
- package/src/setTheme.js +313 -0
- package/src/setTitle.js +90 -0
- package/src/shareContact.js +53 -0
- package/src/shareLink.js +62 -0
- package/src/threadColors.js +57 -0
- package/src/unfriend.js +53 -0
- package/src/unsendMessage.js +104 -0
- package/utils.js +1447 -0
- package/LICENSE +0 -3
- package/README.md +0 -491
- package/examples/login-with-cookies.js +0 -102
- package/examples/verify.js +0 -70
- package/src/apis/addUserToGroup.js +0 -108
- package/src/apis/changeAdminStatus.js +0 -148
- package/src/apis/changeArchivedStatus.js +0 -61
- package/src/apis/changeAvatar.js +0 -103
- package/src/apis/changeBio.js +0 -69
- package/src/apis/changeBlockedStatus.js +0 -54
- package/src/apis/changeGroupImage.js +0 -136
- package/src/apis/changeThreadColor.js +0 -116
- package/src/apis/comment.js +0 -207
- package/src/apis/createAITheme.js +0 -129
- package/src/apis/createNewGroup.js +0 -79
- package/src/apis/createPoll.js +0 -73
- package/src/apis/deleteMessage.js +0 -44
- package/src/apis/deleteThread.js +0 -52
- package/src/apis/e2ee.js +0 -17
- package/src/apis/editMessage.js +0 -70
- package/src/apis/emoji.js +0 -124
- package/src/apis/fetchThemeData.js +0 -82
- package/src/apis/follow.js +0 -81
- package/src/apis/forwardMessage.js +0 -52
- package/src/apis/friend.js +0 -243
- package/src/apis/gcmember.js +0 -122
- package/src/apis/gcname.js +0 -123
- package/src/apis/gcrule.js +0 -119
- package/src/apis/getAccess.js +0 -111
- package/src/apis/getBotInfo.js +0 -88
- package/src/apis/getBotInitialData.js +0 -43
- package/src/apis/getFriendsList.js +0 -79
- package/src/apis/getMessage.js +0 -423
- package/src/apis/getTheme.js +0 -95
- package/src/apis/getThemeInfo.js +0 -116
- package/src/apis/getThreadHistory.js +0 -239
- package/src/apis/getThreadInfo.js +0 -267
- package/src/apis/getThreadList.js +0 -232
- package/src/apis/getThreadPictures.js +0 -58
- package/src/apis/getUserID.js +0 -117
- package/src/apis/getUserInfo.js +0 -513
- package/src/apis/getUserInfoV2.js +0 -146
- package/src/apis/handleMessageRequest.js +0 -50
- package/src/apis/httpPost.js +0 -89
- package/src/apis/httpPostFormData.js +0 -69
- package/src/apis/listenMqtt.js +0 -1236
- package/src/apis/listenSpeed.js +0 -179
- package/src/apis/logout.js +0 -87
- package/src/apis/markAsDelivered.js +0 -47
- package/src/apis/markAsReadAll.js +0 -40
- package/src/apis/markAsSeen.js +0 -70
- package/src/apis/mqttDeltaValue.js +0 -278
- package/src/apis/muteThread.js +0 -45
- package/src/apis/nickname.js +0 -132
- package/src/apis/notes.js +0 -163
- package/src/apis/pinMessage.js +0 -150
- package/src/apis/produceMetaTheme.js +0 -180
- package/src/apis/realtime.js +0 -182
- package/src/apis/removeUserFromGroup.js +0 -117
- package/src/apis/resolvePhotoUrl.js +0 -58
- package/src/apis/searchForThread.js +0 -154
- package/src/apis/sendMessage.js +0 -354
- package/src/apis/sendMessageMqtt.js +0 -249
- package/src/apis/sendTypingIndicator.js +0 -91
- package/src/apis/setMessageReaction.js +0 -27
- package/src/apis/setMessageReactionMqtt.js +0 -61
- package/src/apis/setThreadTheme.js +0 -260
- package/src/apis/setThreadThemeMqtt.js +0 -94
- package/src/apis/share.js +0 -107
- package/src/apis/shareContact.js +0 -66
- package/src/apis/stickers.js +0 -257
- package/src/apis/story.js +0 -181
- package/src/apis/theme.js +0 -233
- package/src/apis/unfriend.js +0 -47
- package/src/apis/unsendMessage.js +0 -17
- package/src/engine/client.js +0 -92
- package/src/engine/models/buildAPI.js +0 -152
- package/src/engine/models/loginHelper.js +0 -519
- package/src/engine/models/setOptions.js +0 -88
- package/src/security/e2ee.js +0 -109
- package/src/types/index.d.ts +0 -498
- package/src/utils/antiSuspension.js +0 -506
- package/src/utils/auth-helpers.js +0 -149
- package/src/utils/autoReLogin.js +0 -336
- package/src/utils/axios.js +0 -436
- package/src/utils/cache.js +0 -54
- package/src/utils/clients.js +0 -282
- package/src/utils/constants.js +0 -410
- package/src/utils/formatters/data/formatAttachment.js +0 -370
- package/src/utils/formatters/data/formatDelta.js +0 -109
- package/src/utils/formatters/index.js +0 -159
- package/src/utils/formatters/value/formatCookie.js +0 -91
- package/src/utils/formatters/value/formatDate.js +0 -36
- package/src/utils/formatters/value/formatID.js +0 -16
- package/src/utils/formatters.js +0 -1373
- package/src/utils/headers.js +0 -230
- package/src/utils/index.js +0 -153
- package/src/utils/monitoring.js +0 -333
- package/src/utils/rateLimiter.js +0 -319
- package/src/utils/tokenRefresh.js +0 -657
- package/src/utils/user-agents.js +0 -238
- package/src/utils/validation.js +0 -157
package/src/apis/getMessage.js
DELETED
|
@@ -1,423 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const utils = require('../utils');
|
|
4
|
-
const { _formatAttachment } = require('../utils/formatters/data/formatAttachment');
|
|
5
|
-
|
|
6
|
-
const THEME_COLORS = [
|
|
7
|
-
{ theme_color: "FF000000", theme_id: "788274591712841", theme_emoji: "🖤", gradient: '["FFF0F0F0"]', should_show_icon: "", theme_name_with_subtitle: "Monochrome" },
|
|
8
|
-
{ theme_color: "FFFF5CA1", theme_id: "169463077092846", theme_emoji: null, gradient: null, should_show_icon: "1", theme_name_with_subtitle: "Hot Pink" },
|
|
9
|
-
{ theme_color: "FF2825B5", theme_id: "271607034185782", theme_emoji: null, gradient: '["FF5E007E","FF331290","FF2825B5"]', should_show_icon: "1", theme_name_with_subtitle: "Shadow" },
|
|
10
|
-
{ theme_color: "FFD9A900", theme_id: "2533652183614000", theme_emoji: null, gradient: '["FF550029","FFAA3232","FFD9A900"]', should_show_icon: "1", theme_name_with_subtitle: "Maple" },
|
|
11
|
-
{ theme_color: "FFFB45DE", theme_id: "2873642949430623", theme_emoji: null, gradient: null, should_show_icon: "1", theme_name_with_subtitle: "Tulip" },
|
|
12
|
-
{ theme_color: "FF5E007E", theme_id: "193497045377796", theme_emoji: null, gradient: null, should_show_icon: "1", theme_name_with_subtitle: "Grape" },
|
|
13
|
-
{ theme_color: "FF7AA286", theme_id: "1455149831518874", theme_emoji: "🌑", gradient: '["FF25C0E1","FFCE832A"]', should_show_icon: "", theme_name_with_subtitle: "Dune" },
|
|
14
|
-
{ theme_color: "FFFAAF00", theme_id: "672058580051520", theme_emoji: null, gradient: null, should_show_icon: "1", theme_name_with_subtitle: "Honey" },
|
|
15
|
-
{ theme_color: "FF0084FF", theme_id: "196241301102133", theme_emoji: null, gradient: null, should_show_icon: "1", theme_name_with_subtitle: "Default Blue" },
|
|
16
|
-
{ theme_color: "FFFFC300", theme_id: "174636906462322", theme_emoji: null, gradient: null, should_show_icon: "1", theme_name_with_subtitle: "Yellow" },
|
|
17
|
-
{ theme_color: "FF44BEC7", theme_id: "1928399724138152", theme_emoji: null, gradient: null, should_show_icon: "1", theme_name_with_subtitle: "Teal Blue" },
|
|
18
|
-
{ theme_color: "FF7646FF", theme_id: "234137870477637", theme_emoji: null, gradient: null, should_show_icon: "1", theme_name_with_subtitle: "Bright Purple" },
|
|
19
|
-
{ theme_color: "FFF25C54", theme_id: "3022526817824329", theme_emoji: null, gradient: null, should_show_icon: "1", theme_name_with_subtitle: "Peach" },
|
|
20
|
-
{ theme_color: "FFF01D6A", theme_id: "724096885023603", theme_emoji: null, gradient: '["FF005FFF","FF9200FF","FFFF2E19"]', should_show_icon: "1", theme_name_with_subtitle: "Berry" },
|
|
21
|
-
{ theme_color: "FFFF7CA8", theme_id: "624266884847972", theme_emoji: null, gradient: '["FFFF8FB2","FFA797FF","FF00E5FF"]', should_show_icon: "1", theme_name_with_subtitle: "Candy" },
|
|
22
|
-
{ theme_color: "FF0084FF", theme_id: "196241301102133", theme_emoji: null, gradient: null, should_show_icon: "1", theme_name_with_subtitle: "Classic" },
|
|
23
|
-
{ theme_color: "FF0099FF", theme_id: "3273938616164733", theme_emoji: null, gradient: null, should_show_icon: "1", theme_name_with_subtitle: "Classic" },
|
|
24
|
-
{ theme_color: "FFFA3C4C", theme_id: "2129984390566328", theme_emoji: null, gradient: null, should_show_icon: "1", theme_name_with_subtitle: "Red" },
|
|
25
|
-
{ theme_color: "FF13CF13", theme_id: "2136751179887052", theme_emoji: null, gradient: null, should_show_icon: "1", theme_name_with_subtitle: "Green" },
|
|
26
|
-
{ theme_color: "FFFF7E29", theme_id: "175615189761153", theme_emoji: null, gradient: null, should_show_icon: "1", theme_name_with_subtitle: "Orange" }
|
|
27
|
-
];
|
|
28
|
-
|
|
29
|
-
function formatMessage(threadID, data) {
|
|
30
|
-
const baseMessage = {
|
|
31
|
-
threadID: threadID,
|
|
32
|
-
messageID: data.message_id,
|
|
33
|
-
timestamp: data.timestamp_precise,
|
|
34
|
-
author: data.message_sender ? data.message_sender.id : null
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
switch (data.__typename) {
|
|
38
|
-
case "ThreadNameMessage":
|
|
39
|
-
return {
|
|
40
|
-
...baseMessage,
|
|
41
|
-
type: "event",
|
|
42
|
-
logMessageType: "log:thread-name",
|
|
43
|
-
logMessageData: { name: data.thread_name },
|
|
44
|
-
logMessageBody: data.snippet
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
case "ThreadImageMessage":
|
|
48
|
-
const metadata = data.image_with_metadata;
|
|
49
|
-
return {
|
|
50
|
-
...baseMessage,
|
|
51
|
-
type: "event",
|
|
52
|
-
logMessageType: "log:thread-image",
|
|
53
|
-
logMessageData: metadata ? {
|
|
54
|
-
attachmentID: metadata.legacy_attachment_id,
|
|
55
|
-
width: metadata.original_dimensions.x,
|
|
56
|
-
height: metadata.original_dimensions.y,
|
|
57
|
-
url: metadata.preview.uri
|
|
58
|
-
} : null,
|
|
59
|
-
logMessageBody: data.snippet
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
case "GenericAdminTextMessage":
|
|
63
|
-
const adminType = data.extensible_message_admin_text_type;
|
|
64
|
-
|
|
65
|
-
if (adminType === "CHANGE_THREAD_THEME") {
|
|
66
|
-
const themeColor = data.extensible_message_admin_text.theme_color;
|
|
67
|
-
const colorMatch = THEME_COLORS.find(color => color.theme_color === themeColor);
|
|
68
|
-
|
|
69
|
-
return {
|
|
70
|
-
...baseMessage,
|
|
71
|
-
type: "event",
|
|
72
|
-
logMessageType: "log:thread-color",
|
|
73
|
-
logMessageData: colorMatch || {
|
|
74
|
-
theme_color: themeColor,
|
|
75
|
-
theme_id: null,
|
|
76
|
-
theme_emoji: null,
|
|
77
|
-
gradient: null,
|
|
78
|
-
should_show_icon: null,
|
|
79
|
-
theme_name_with_subtitle: null
|
|
80
|
-
},
|
|
81
|
-
logMessageBody: data.snippet
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (adminType === "CHANGE_THREAD_ICON") {
|
|
86
|
-
const thread_icon = data.extensible_message_admin_text?.thread_icon;
|
|
87
|
-
let iconUrl = null;
|
|
88
|
-
|
|
89
|
-
if (thread_icon) {
|
|
90
|
-
try {
|
|
91
|
-
iconUrl = `https://static.xx.fbcdn.net/images/emoji.php/v9/t3c/1/16/${thread_icon.codePointAt(0).toString(16)}.png`;
|
|
92
|
-
} catch (err) {
|
|
93
|
-
utils.warn(`getMessage: Error generating icon URL: ${err.message}`);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return {
|
|
98
|
-
...baseMessage,
|
|
99
|
-
type: "event",
|
|
100
|
-
logMessageType: "log:thread-icon",
|
|
101
|
-
logMessageData: {
|
|
102
|
-
thread_icon: thread_icon || null,
|
|
103
|
-
thread_icon_url: iconUrl
|
|
104
|
-
},
|
|
105
|
-
logMessageBody: data.snippet
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (adminType === "CHANGE_THREAD_NICKNAME") {
|
|
110
|
-
return {
|
|
111
|
-
...baseMessage,
|
|
112
|
-
type: "event",
|
|
113
|
-
logMessageType: "log:user-nickname",
|
|
114
|
-
logMessageData: {
|
|
115
|
-
nickname: data.extensible_message_admin_text?.nickname || null,
|
|
116
|
-
participant_id: data.extensible_message_admin_text?.participant_id || null
|
|
117
|
-
},
|
|
118
|
-
logMessageBody: data.snippet
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (adminType === "GROUP_POLL") {
|
|
123
|
-
const question = data.extensible_message_admin_text?.question;
|
|
124
|
-
if (!question) {
|
|
125
|
-
return {
|
|
126
|
-
...baseMessage,
|
|
127
|
-
type: "event",
|
|
128
|
-
logMessageType: "log:thread-poll",
|
|
129
|
-
logMessageData: { error: "Missing poll question data" },
|
|
130
|
-
logMessageBody: data.snippet
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return {
|
|
135
|
-
...baseMessage,
|
|
136
|
-
type: "event",
|
|
137
|
-
logMessageType: "log:thread-poll",
|
|
138
|
-
logMessageData: {
|
|
139
|
-
question_json: JSON.stringify({
|
|
140
|
-
id: question.id,
|
|
141
|
-
text: question.text,
|
|
142
|
-
total_count: data.extensible_message_admin_text.total_count || 0,
|
|
143
|
-
viewer_has_voted: question.viewer_has_voted || false,
|
|
144
|
-
question_type: "",
|
|
145
|
-
creator_id: data.message_sender ? data.message_sender.id : null,
|
|
146
|
-
options: (question.options?.nodes || []).map(option => ({
|
|
147
|
-
id: option.id,
|
|
148
|
-
text: option.text,
|
|
149
|
-
total_count: (option.voters?.nodes || []).length,
|
|
150
|
-
viewer_has_voted: option.viewer_has_voted || false,
|
|
151
|
-
voters: (option.voters?.nodes || []).map(voter => voter.id)
|
|
152
|
-
}))
|
|
153
|
-
}),
|
|
154
|
-
event_type: (data.extensible_message_admin_text.event_type || "").toLowerCase(),
|
|
155
|
-
question_id: question.id
|
|
156
|
-
},
|
|
157
|
-
logMessageBody: data.snippet
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (adminType === "CHANGE_THREAD_QUICK_REACTION") {
|
|
162
|
-
return {
|
|
163
|
-
...baseMessage,
|
|
164
|
-
type: "event",
|
|
165
|
-
logMessageType: "log:thread-icon",
|
|
166
|
-
logMessageData: {
|
|
167
|
-
thread_quick_reaction: data.extensible_message_admin_text?.thread_quick_reaction || null
|
|
168
|
-
},
|
|
169
|
-
logMessageBody: data.snippet
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
if (adminType === "CHANGE_THREAD_ADMINS") {
|
|
174
|
-
return {
|
|
175
|
-
...baseMessage,
|
|
176
|
-
type: "event",
|
|
177
|
-
logMessageType: "log:thread-admins",
|
|
178
|
-
logMessageData: {
|
|
179
|
-
admin_type: data.extensible_message_admin_text?.admin_type || null,
|
|
180
|
-
target_id: data.extensible_message_admin_text?.target_id || null
|
|
181
|
-
},
|
|
182
|
-
logMessageBody: data.snippet
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
if (adminType === "CHANGE_THREAD_APPROVAL_MODE") {
|
|
187
|
-
return {
|
|
188
|
-
...baseMessage,
|
|
189
|
-
type: "event",
|
|
190
|
-
logMessageType: "log:thread-approval-mode",
|
|
191
|
-
logMessageData: {
|
|
192
|
-
approval_mode: data.extensible_message_admin_text?.approval_mode || null
|
|
193
|
-
},
|
|
194
|
-
logMessageBody: data.snippet
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
if (adminType === "MESSENGER_CALL_LOG" || adminType === "PARTICIPANT_JOINED_GROUP_CALL") {
|
|
199
|
-
return {
|
|
200
|
-
...baseMessage,
|
|
201
|
-
type: "event",
|
|
202
|
-
logMessageType: "log:thread-call",
|
|
203
|
-
logMessageData: {
|
|
204
|
-
event_type: adminType,
|
|
205
|
-
call_duration: data.extensible_message_admin_text?.call_duration || 0
|
|
206
|
-
},
|
|
207
|
-
logMessageBody: data.snippet
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
if (adminType === "PIN_MESSAGES_V2") {
|
|
212
|
-
return {
|
|
213
|
-
...baseMessage,
|
|
214
|
-
type: "event",
|
|
215
|
-
logMessageType: "log:thread-pinned",
|
|
216
|
-
logMessageData: {
|
|
217
|
-
pinned_message_id: data.extensible_message_admin_text?.pinned_message_id || null
|
|
218
|
-
},
|
|
219
|
-
logMessageBody: data.snippet
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
if (adminType === "UNPIN_MESSAGES_V2") {
|
|
224
|
-
return {
|
|
225
|
-
...baseMessage,
|
|
226
|
-
type: "event",
|
|
227
|
-
logMessageType: "log:unpin-message",
|
|
228
|
-
logMessageData: {
|
|
229
|
-
unpinned_message_id: data.extensible_message_admin_text?.unpinned_message_id || null
|
|
230
|
-
},
|
|
231
|
-
logMessageBody: data.snippet
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
if (adminType === "JOINABLE_GROUP_LINK_MODE_CHANGE") {
|
|
236
|
-
return {
|
|
237
|
-
...baseMessage,
|
|
238
|
-
type: "event",
|
|
239
|
-
logMessageType: "log:link-status",
|
|
240
|
-
logMessageData: {
|
|
241
|
-
link_status: data.extensible_message_admin_text?.joinable_mode || null
|
|
242
|
-
},
|
|
243
|
-
logMessageBody: data.snippet
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
if (adminType === "MAGIC_WORDS") {
|
|
248
|
-
return {
|
|
249
|
-
...baseMessage,
|
|
250
|
-
type: "event",
|
|
251
|
-
logMessageType: "log:magic-words",
|
|
252
|
-
logMessageData: {
|
|
253
|
-
magic_word: data.extensible_message_admin_text?.magic_word || null
|
|
254
|
-
},
|
|
255
|
-
logMessageBody: data.snippet
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
return {
|
|
260
|
-
...baseMessage,
|
|
261
|
-
type: "event",
|
|
262
|
-
logMessageType: "log:generic-admin",
|
|
263
|
-
logMessageData: { admin_type: adminType },
|
|
264
|
-
logMessageBody: data.snippet
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
case "UserMessage":
|
|
268
|
-
const attachments = [];
|
|
269
|
-
|
|
270
|
-
if (data.blob_attachments && data.blob_attachments.length > 0) {
|
|
271
|
-
data.blob_attachments.forEach(att => {
|
|
272
|
-
try {
|
|
273
|
-
const formatted = _formatAttachment(att);
|
|
274
|
-
attachments.push(formatted);
|
|
275
|
-
} catch (ex) {
|
|
276
|
-
attachments.push({
|
|
277
|
-
type: "unknown",
|
|
278
|
-
error: ex.message || ex,
|
|
279
|
-
rawAttachment: att
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
} else if (data.extensible_attachment && Object.keys(data.extensible_attachment).length > 0) {
|
|
284
|
-
try {
|
|
285
|
-
const formatted = _formatAttachment({ extensible_attachment: data.extensible_attachment });
|
|
286
|
-
attachments.push(formatted);
|
|
287
|
-
} catch (ex) {
|
|
288
|
-
const storyAtt = data.extensible_attachment.story_attachment || {};
|
|
289
|
-
attachments.push({
|
|
290
|
-
type: "share",
|
|
291
|
-
ID: data.extensible_attachment.legacy_attachment_id,
|
|
292
|
-
url: storyAtt.url,
|
|
293
|
-
title: storyAtt.title_with_entities ? storyAtt.title_with_entities.text : null,
|
|
294
|
-
description: storyAtt.description ? storyAtt.description.text : null,
|
|
295
|
-
source: storyAtt.source ? storyAtt.source.text : null,
|
|
296
|
-
image: storyAtt.media && storyAtt.media.image ? storyAtt.media.image.uri : null,
|
|
297
|
-
width: storyAtt.media && storyAtt.media.image ? storyAtt.media.image.width : null,
|
|
298
|
-
height: storyAtt.media && storyAtt.media.image ? storyAtt.media.image.height : null,
|
|
299
|
-
playable: storyAtt.media ? storyAtt.media.is_playable || false : false,
|
|
300
|
-
duration: storyAtt.media ? storyAtt.media.playable_duration_in_ms || 0 : 0,
|
|
301
|
-
playableUrl: storyAtt.media && storyAtt.media.playable_url ? storyAtt.media.playable_url : null,
|
|
302
|
-
subattachments: data.extensible_attachment.subattachments,
|
|
303
|
-
properties: storyAtt.properties || {}
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
const mentions = {};
|
|
309
|
-
if (data.message && data.message.ranges) {
|
|
310
|
-
data.message.ranges.forEach(mention => {
|
|
311
|
-
if (mention.entity && mention.entity.id && data.message.text) {
|
|
312
|
-
mentions[mention.entity.id] = data.message.text.substring(
|
|
313
|
-
mention.offset,
|
|
314
|
-
mention.offset + mention.length
|
|
315
|
-
);
|
|
316
|
-
}
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
return {
|
|
321
|
-
type: "message",
|
|
322
|
-
senderID: data.message_sender ? data.message_sender.id : null,
|
|
323
|
-
body: data.message && data.message.text ? data.message.text : "",
|
|
324
|
-
threadID: threadID,
|
|
325
|
-
messageID: data.message_id,
|
|
326
|
-
reactions: data.message_reactions ? data.message_reactions.map(r => ({ [r.user.id]: r.reaction })) : [],
|
|
327
|
-
attachments: attachments,
|
|
328
|
-
mentions: mentions,
|
|
329
|
-
timestamp: data.timestamp_precise
|
|
330
|
-
};
|
|
331
|
-
|
|
332
|
-
default:
|
|
333
|
-
utils.warn(`getMessage: Unknown message type "${data.__typename}"`);
|
|
334
|
-
return {
|
|
335
|
-
...baseMessage,
|
|
336
|
-
type: "unknown",
|
|
337
|
-
data: data
|
|
338
|
-
};
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
function parseDelta(threadID, delta) {
|
|
343
|
-
if (delta.replied_to_message) {
|
|
344
|
-
return {
|
|
345
|
-
type: "message_reply",
|
|
346
|
-
...formatMessage(threadID, delta),
|
|
347
|
-
messageReply: formatMessage(threadID, delta.replied_to_message.message)
|
|
348
|
-
};
|
|
349
|
-
} else {
|
|
350
|
-
return formatMessage(threadID, delta);
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
module.exports = function(defaultFuncs, api, ctx) {
|
|
355
|
-
return function getMessage(threadID, messageID, callback) {
|
|
356
|
-
let resolveFunc = function() {};
|
|
357
|
-
let rejectFunc = function() {};
|
|
358
|
-
const returnPromise = new Promise(function(resolve, reject) {
|
|
359
|
-
resolveFunc = resolve;
|
|
360
|
-
rejectFunc = reject;
|
|
361
|
-
});
|
|
362
|
-
|
|
363
|
-
if (!callback) {
|
|
364
|
-
callback = function(err, info) {
|
|
365
|
-
if (err) return rejectFunc(err);
|
|
366
|
-
resolveFunc(info);
|
|
367
|
-
};
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
if (!threadID || !messageID) {
|
|
371
|
-
return callback({ error: "getMessage: need threadID and messageID" });
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
const form = {
|
|
375
|
-
av: ctx.userID,
|
|
376
|
-
fb_dtsg: ctx.fb_dtsg,
|
|
377
|
-
queries: JSON.stringify({
|
|
378
|
-
o0: {
|
|
379
|
-
doc_id: "1768656253222505",
|
|
380
|
-
query_params: {
|
|
381
|
-
thread_and_message_id: {
|
|
382
|
-
thread_id: threadID,
|
|
383
|
-
message_id: messageID
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
})
|
|
388
|
-
};
|
|
389
|
-
|
|
390
|
-
defaultFuncs
|
|
391
|
-
.post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
|
|
392
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
393
|
-
.then(resData => {
|
|
394
|
-
if (!resData || resData.length === 0) {
|
|
395
|
-
throw { error: "getMessage: no response data" };
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
if (resData[resData.length - 1].error_results > 0) {
|
|
399
|
-
throw resData[0].o0.errors;
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
if (resData[resData.length - 1].successful_results === 0) {
|
|
403
|
-
throw {
|
|
404
|
-
error: "getMessage: there was no successful_results",
|
|
405
|
-
res: resData
|
|
406
|
-
};
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
const fetchData = resData[0].o0.data.message;
|
|
410
|
-
if (fetchData) {
|
|
411
|
-
callback(null, parseDelta(threadID, fetchData));
|
|
412
|
-
} else {
|
|
413
|
-
throw { error: "getMessage: message data not found" };
|
|
414
|
-
}
|
|
415
|
-
})
|
|
416
|
-
.catch(err => {
|
|
417
|
-
utils.error("getMessage", err);
|
|
418
|
-
callback(err);
|
|
419
|
-
});
|
|
420
|
-
|
|
421
|
-
return returnPromise;
|
|
422
|
-
};
|
|
423
|
-
};
|
package/src/apis/getTheme.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const utils = require('../utils');
|
|
4
|
-
|
|
5
|
-
module.exports = function (defaultFuncs, api, ctx) {
|
|
6
|
-
return async function getTheme(threadID, callback) {
|
|
7
|
-
if (!threadID) {
|
|
8
|
-
const error = new Error("threadID is required");
|
|
9
|
-
if (callback) return callback(error);
|
|
10
|
-
throw error;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
let resolveFunc, rejectFunc;
|
|
14
|
-
const promise = new Promise((resolve, reject) => {
|
|
15
|
-
resolveFunc = resolve;
|
|
16
|
-
rejectFunc = reject;
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
const form = {
|
|
20
|
-
fb_api_caller_class: 'RelayModern',
|
|
21
|
-
fb_api_req_friendly_name: 'MWPThreadThemeQuery_AllThemesQuery',
|
|
22
|
-
variables: JSON.stringify({ version: "default" }),
|
|
23
|
-
server_timestamps: true,
|
|
24
|
-
doc_id: '24474714052117636',
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
try {
|
|
28
|
-
const resData = await defaultFuncs
|
|
29
|
-
.post("https://www.facebook.com/api/graphql/", ctx.jar, form, null, {
|
|
30
|
-
"x-fb-friendly-name": "MWPThreadThemeQuery_AllThemesQuery",
|
|
31
|
-
"x-fb-lsd": ctx.lsd,
|
|
32
|
-
"referer": `https://www.facebook.com/messages/t/${threadID}`
|
|
33
|
-
})
|
|
34
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs));
|
|
35
|
-
|
|
36
|
-
if (resData.errors) {
|
|
37
|
-
throw new Error(JSON.stringify(resData.errors));
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (!resData.data || !resData.data.messenger_thread_themes) {
|
|
41
|
-
throw new Error("Could not retrieve thread themes from response.");
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const extractUrl = (obj) => {
|
|
45
|
-
if (!obj) return null;
|
|
46
|
-
if (typeof obj === 'string') return obj;
|
|
47
|
-
return obj.uri || obj.url || null;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const baseThemes = resData.data.messenger_thread_themes.map(themeData => {
|
|
51
|
-
if (!themeData || !themeData.id) return null;
|
|
52
|
-
|
|
53
|
-
return {
|
|
54
|
-
id: themeData.id,
|
|
55
|
-
name: themeData.name || '',
|
|
56
|
-
theme_idx: themeData.theme_idx,
|
|
57
|
-
accessibility_label: themeData.accessibility_label || themeData.name || ''
|
|
58
|
-
};
|
|
59
|
-
}).filter(t => t !== null);
|
|
60
|
-
|
|
61
|
-
const themesWithPreviews = await Promise.all(
|
|
62
|
-
baseThemes.map(async (baseTheme) => {
|
|
63
|
-
try {
|
|
64
|
-
const detailedTheme = await api.fetchThemeData(baseTheme.id);
|
|
65
|
-
|
|
66
|
-
const theme = {
|
|
67
|
-
...baseTheme,
|
|
68
|
-
...detailedTheme
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
return theme;
|
|
72
|
-
} catch (fetchErr) {
|
|
73
|
-
utils.error("getTheme - fetchThemeData", `Failed to fetch details for theme ${baseTheme.id}: ${fetchErr.message}`);
|
|
74
|
-
return baseTheme;
|
|
75
|
-
}
|
|
76
|
-
})
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
if (callback) {
|
|
80
|
-
callback(null, themesWithPreviews);
|
|
81
|
-
} else {
|
|
82
|
-
resolveFunc(themesWithPreviews);
|
|
83
|
-
}
|
|
84
|
-
} catch (err) {
|
|
85
|
-
utils.error("getTheme", err);
|
|
86
|
-
if (callback) {
|
|
87
|
-
callback(err);
|
|
88
|
-
} else {
|
|
89
|
-
rejectFunc(err);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return promise;
|
|
94
|
-
};
|
|
95
|
-
};
|
package/src/apis/getThemeInfo.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const utils = require('../utils');
|
|
4
|
-
|
|
5
|
-
module.exports = function (defaultFuncs, api, ctx) {
|
|
6
|
-
return async function getThemeInfo(identifier, callback) {
|
|
7
|
-
if (!identifier) {
|
|
8
|
-
const error = new Error("identifier is required (threadID or themeID)");
|
|
9
|
-
if (callback) return callback(error);
|
|
10
|
-
throw error;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
let resolveFunc, rejectFunc;
|
|
14
|
-
const promise = new Promise((resolve, reject) => {
|
|
15
|
-
resolveFunc = resolve;
|
|
16
|
-
rejectFunc = reject;
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
// Check if identifier looks like a theme ID (long numeric string)
|
|
20
|
-
const isThemeID = /^\d{10,}$/.test(identifier.toString());
|
|
21
|
-
|
|
22
|
-
if (isThemeID) {
|
|
23
|
-
// Treat as theme ID and fetch detailed theme data
|
|
24
|
-
try {
|
|
25
|
-
const themeData = await api.fetchThemeData(identifier);
|
|
26
|
-
if (callback) {
|
|
27
|
-
callback(null, themeData);
|
|
28
|
-
} else {
|
|
29
|
-
resolveFunc(themeData);
|
|
30
|
-
}
|
|
31
|
-
return promise;
|
|
32
|
-
} catch (err) {
|
|
33
|
-
utils.error("getThemeInfo - fetchThemeData", err);
|
|
34
|
-
// Fall back to thread logic if theme fetch fails
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Original logic for threadID
|
|
39
|
-
try {
|
|
40
|
-
let threadInfo;
|
|
41
|
-
try {
|
|
42
|
-
threadInfo = await api.getThreadInfo(identifier);
|
|
43
|
-
} catch (getInfoErr) {
|
|
44
|
-
// If getThreadInfo fails, thread might not exist or access is restricted
|
|
45
|
-
// Return a basic theme info object with defaults
|
|
46
|
-
const themeInfo = {
|
|
47
|
-
threadID: identifier,
|
|
48
|
-
threadName: '',
|
|
49
|
-
color: null,
|
|
50
|
-
emoji: '👍',
|
|
51
|
-
theme_id: null,
|
|
52
|
-
theme_color: null,
|
|
53
|
-
gradient_colors: null,
|
|
54
|
-
is_default: true,
|
|
55
|
-
error: getInfoErr.message || 'Could not retrieve full thread info'
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
if (callback) {
|
|
59
|
-
return callback(null, themeInfo);
|
|
60
|
-
} else {
|
|
61
|
-
return resolveFunc(themeInfo);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (!threadInfo || threadInfo.length === 0) {
|
|
66
|
-
// Thread exists but no info returned - return defaults
|
|
67
|
-
const themeInfo = {
|
|
68
|
-
threadID: identifier,
|
|
69
|
-
threadName: '',
|
|
70
|
-
color: null,
|
|
71
|
-
emoji: '👍',
|
|
72
|
-
theme_id: null,
|
|
73
|
-
theme_color: null,
|
|
74
|
-
gradient_colors: null,
|
|
75
|
-
is_default: true
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
if (callback) {
|
|
79
|
-
return callback(null, themeInfo);
|
|
80
|
-
} else {
|
|
81
|
-
return resolveFunc(themeInfo);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const info = Array.isArray(threadInfo) ? threadInfo[0] : threadInfo;
|
|
86
|
-
|
|
87
|
-
const themeInfo = {
|
|
88
|
-
threadID: identifier,
|
|
89
|
-
threadName: info.threadName || info.name || '',
|
|
90
|
-
color: info.color || null,
|
|
91
|
-
emoji: info.emoji || '👍',
|
|
92
|
-
theme_id: info.theme_id || info.themeID || null,
|
|
93
|
-
theme_color: info.theme_color || info.color || null,
|
|
94
|
-
gradient_colors: info.gradient_colors || null,
|
|
95
|
-
is_default: !info.color && !info.theme_id
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
if (callback) {
|
|
99
|
-
callback(null, themeInfo);
|
|
100
|
-
} else {
|
|
101
|
-
resolveFunc(themeInfo);
|
|
102
|
-
}
|
|
103
|
-
} catch (err) {
|
|
104
|
-
// Preserve the original error message from getThreadInfo
|
|
105
|
-
// Don't override with generic "Could not retrieve thread info"
|
|
106
|
-
utils.error("getThemeInfo", err);
|
|
107
|
-
if (callback) {
|
|
108
|
-
callback(err);
|
|
109
|
-
} else {
|
|
110
|
-
rejectFunc(err);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return promise;
|
|
115
|
-
};
|
|
116
|
-
};
|