@cexy/hoonfca 1.0.0 → 1.0.1
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/LICENSE +3 -0
- package/README.md +451 -43
- package/examples/login-with-cookies.js +102 -0
- package/examples/verify.js +70 -0
- package/index.js +1 -466
- package/package.json +98 -6
- package/src/apis/addExternalModule.js +24 -0
- package/src/apis/addUserToGroup.js +108 -0
- package/src/apis/changeAdminStatus.js +148 -0
- package/src/apis/changeArchivedStatus.js +61 -0
- package/src/apis/changeAvatar.js +103 -0
- package/src/apis/changeBio.js +69 -0
- package/src/apis/changeBlockedStatus.js +54 -0
- package/src/apis/changeGroupImage.js +136 -0
- package/src/apis/changeThreadColor.js +116 -0
- package/src/{changeThreadEmoji.js → apis/changeThreadEmoji.js} +7 -8
- package/src/apis/comment.js +207 -0
- package/src/apis/createAITheme.js +129 -0
- package/src/apis/createNewGroup.js +79 -0
- package/src/apis/createPoll.js +73 -0
- package/src/apis/deleteMessage.js +44 -0
- package/src/apis/deleteThread.js +52 -0
- package/src/apis/e2ee.js +17 -0
- package/src/apis/editMessage.js +70 -0
- package/src/apis/emoji.js +124 -0
- package/src/apis/fetchThemeData.js +82 -0
- package/src/apis/follow.js +81 -0
- package/src/apis/forwardMessage.js +52 -0
- package/src/apis/friend.js +243 -0
- package/src/apis/gcmember.js +122 -0
- package/src/apis/gcname.js +123 -0
- package/src/apis/gcrule.js +119 -0
- package/src/apis/getAccess.js +111 -0
- package/src/apis/getBotInfo.js +88 -0
- package/src/apis/getBotInitialData.js +43 -0
- package/src/apis/getFriendsList.js +79 -0
- package/src/apis/getMessage.js +423 -0
- package/src/apis/getTheme.js +95 -0
- package/src/apis/getThemeInfo.js +116 -0
- package/src/apis/getThreadHistory.js +239 -0
- package/src/apis/getThreadInfo.js +267 -0
- package/src/apis/getThreadList.js +232 -0
- package/src/apis/getThreadPictures.js +58 -0
- package/src/apis/getUserID.js +117 -0
- package/src/apis/getUserInfo.js +513 -0
- package/src/apis/getUserInfoV2.js +146 -0
- package/src/apis/handleMessageRequest.js +50 -0
- package/src/apis/httpGet.js +63 -0
- package/src/apis/httpPost.js +89 -0
- package/src/apis/httpPostFormData.js +69 -0
- package/src/apis/listenMqtt.js +1236 -0
- package/src/apis/listenSpeed.js +179 -0
- package/src/apis/logout.js +87 -0
- package/src/apis/markAsDelivered.js +47 -0
- package/src/apis/markAsRead.js +99 -0
- package/src/apis/markAsReadAll.js +40 -0
- package/src/apis/markAsSeen.js +70 -0
- package/src/apis/mqttDeltaValue.js +278 -0
- package/src/apis/muteThread.js +45 -0
- package/src/apis/nickname.js +132 -0
- package/src/apis/notes.js +163 -0
- package/src/apis/pinMessage.js +150 -0
- package/src/apis/produceMetaTheme.js +180 -0
- package/src/apis/realtime.js +182 -0
- package/src/apis/removeUserFromGroup.js +117 -0
- package/src/apis/resolvePhotoUrl.js +58 -0
- package/src/apis/searchForThread.js +154 -0
- package/src/apis/sendMessage.js +354 -0
- package/src/apis/sendMessageMqtt.js +249 -0
- package/src/apis/sendTypingIndicator.js +91 -0
- package/src/apis/setMessageReaction.js +27 -0
- package/src/apis/setMessageReactionMqtt.js +61 -0
- package/src/apis/setThreadTheme.js +260 -0
- package/src/apis/setThreadThemeMqtt.js +94 -0
- package/src/apis/share.js +107 -0
- package/src/apis/shareContact.js +66 -0
- package/src/apis/stickers.js +257 -0
- package/src/apis/story.js +181 -0
- package/src/apis/theme.js +233 -0
- package/src/apis/unfriend.js +47 -0
- package/src/apis/unsendMessage.js +17 -0
- package/src/engine/client.js +92 -0
- package/src/engine/models/buildAPI.js +152 -0
- package/src/engine/models/loginHelper.js +519 -0
- package/src/engine/models/setOptions.js +88 -0
- package/src/security/e2ee.js +109 -0
- package/src/types/index.d.ts +498 -0
- package/src/utils/antiSuspension.js +506 -0
- package/src/utils/auth-helpers.js +149 -0
- package/src/utils/autoReLogin.js +336 -0
- package/src/utils/axios.js +436 -0
- package/src/utils/cache.js +54 -0
- package/src/utils/clients.js +282 -0
- package/src/utils/constants.js +410 -0
- package/src/utils/formatters/data/formatAttachment.js +370 -0
- package/src/utils/formatters/data/formatDelta.js +109 -0
- package/src/utils/formatters/index.js +159 -0
- package/src/utils/formatters/value/formatCookie.js +91 -0
- package/src/utils/formatters/value/formatDate.js +36 -0
- package/src/utils/formatters/value/formatID.js +16 -0
- package/src/utils/formatters.js +1373 -0
- package/src/utils/headers.js +230 -0
- package/src/utils/index.js +153 -0
- package/src/utils/monitoring.js +333 -0
- package/src/utils/rateLimiter.js +319 -0
- package/src/utils/tokenRefresh.js +657 -0
- package/src/utils/user-agents.js +238 -0
- package/src/utils/validation.js +157 -0
- package/replit.nix +0 -3
- package/src/addExternalModule.js +0 -25
- package/src/addUserToGroup.js +0 -98
- package/src/changeAdminStatus.js +0 -98
- package/src/changeArchivedStatus.js +0 -51
- package/src/changeAvatar.js +0 -89
- package/src/changeBio.js +0 -74
- package/src/changeBlockedStatus.js +0 -45
- package/src/changeBlockedStatusMqtt.js +0 -65
- package/src/changeCover.js +0 -92
- package/src/changeGroupImage.js +0 -110
- package/src/changeName.js +0 -106
- package/src/changeNickname.js +0 -58
- package/src/changeThreadColor.js +0 -62
- package/src/changeUsername.js +0 -80
- package/src/createCommentPost.js +0 -196
- package/src/createNewGroup.js +0 -81
- package/src/createPoll.js +0 -64
- package/src/createPost.js +0 -285
- package/src/data/getThreadInfo.json +0 -1
- package/src/deleteMessage.js +0 -55
- package/src/deleteThread.js +0 -55
- package/src/editMessage.js +0 -66
- package/src/follow.js +0 -71
- package/src/forwardAttachment.js +0 -57
- package/src/getAccess.js +0 -130
- package/src/getAvatarUser.js +0 -88
- package/src/getBotInitialData.js +0 -59
- package/src/getCtx.js +0 -5
- package/src/getCurrentUserID.js +0 -5
- package/src/getEmojiUrl.js +0 -18
- package/src/getFriendsList.js +0 -81
- package/src/getMessage.js +0 -827
- package/src/getOptions.js +0 -5
- package/src/getRegion.js +0 -7
- package/src/getThreadHistory.js +0 -496
- package/src/getThreadHistoryDeprecated.js +0 -95
- package/src/getThreadInfo.js +0 -194
- package/src/getThreadInfoDeprecated.js +0 -77
- package/src/getThreadList.js +0 -219
- package/src/getThreadListDeprecated.js +0 -86
- package/src/getThreadPictures.js +0 -85
- package/src/getUserID.js +0 -67
- package/src/getUserInfo.js +0 -89
- package/src/handleFriendRequest.js +0 -56
- package/src/handleMessageRequest.js +0 -65
- package/src/httpGet.js +0 -53
- package/src/httpPost.js +0 -53
- package/src/httpPostFormData.js +0 -58
- package/src/listenMqtt.js +0 -683
- package/src/listenNotification.js +0 -96
- package/src/logout.js +0 -77
- package/src/markAsDelivered.js +0 -53
- package/src/markAsRead.js +0 -74
- package/src/markAsReadAll.js +0 -46
- package/src/markAsSeen.js +0 -57
- package/src/muteThread.js +0 -49
- package/src/pinMessage.js +0 -60
- package/src/refreshFb_dtsg.js +0 -75
- package/src/removeUserFromGroup.js +0 -59
- package/src/resolvePhotoUrl.js +0 -47
- package/src/searchForThread.js +0 -55
- package/src/searchStickers.js +0 -59
- package/src/sendMessage.js +0 -444
- package/src/sendMessageMqtt.js +0 -326
- package/src/sendTypingIndicator.js +0 -54
- package/src/setMessageReaction.js +0 -126
- package/src/setMessageReactionMqtt.js +0 -74
- package/src/setPostReaction.js +0 -103
- package/src/setProfileGuard.js +0 -66
- package/src/setStoryReaction.js +0 -97
- package/src/setTitle.js +0 -100
- package/src/shareContact.js +0 -101
- package/src/shareLink.js +0 -105
- package/src/stopListenMqtt.js +0 -47
- package/src/threadColors.js +0 -119
- package/src/unfriend.js +0 -58
- package/src/unsendMessage.js +0 -51
- package/src/uploadAttachment.js +0 -98
- package/utils.js +0 -919
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require('../utils');
|
|
4
|
+
const { URL } = require('url');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @namespace api.story
|
|
8
|
+
* @description A collection of functions for interacting with Facebook Stories.
|
|
9
|
+
* @license Ex-it
|
|
10
|
+
* @author Jonell Magallanes, ChoruOfficial
|
|
11
|
+
*/
|
|
12
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* (Internal) Extracts the Story ID from a Facebook story URL.
|
|
16
|
+
* @param {string} url The Facebook story URL.
|
|
17
|
+
* @returns {string|null} The extracted Story ID or null if not found.
|
|
18
|
+
*/
|
|
19
|
+
function getStoryIDFromURL(url) {
|
|
20
|
+
try {
|
|
21
|
+
const urlObject = new URL(url);
|
|
22
|
+
const pathParts = urlObject.pathname.split('/');
|
|
23
|
+
const storiesIndex = pathParts.indexOf('stories');
|
|
24
|
+
if (storiesIndex !== -1 && pathParts.length > storiesIndex + 2) {
|
|
25
|
+
return pathParts[storiesIndex + 2];
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
} catch (e) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* (Internal) The core function to send a reply or reaction to a story.
|
|
35
|
+
* @param {string} storyIdOrUrl The ID or URL of the story.
|
|
36
|
+
* @param {string} message The text message or emoji reaction.
|
|
37
|
+
* @param {boolean} isReaction True if the reply is a lightweight reaction.
|
|
38
|
+
* @returns {Promise<object>} The server's response.
|
|
39
|
+
*/
|
|
40
|
+
async function sendStoryReply(storyIdOrUrl, message, isReaction) {
|
|
41
|
+
try {
|
|
42
|
+
const allowedReactions = ["❤️", "👍", "🤗", "😆", "😡", "😢", "😮"];
|
|
43
|
+
|
|
44
|
+
if (!storyIdOrUrl) throw new Error("Story ID or URL is required.");
|
|
45
|
+
if (!message) throw new Error("A message or reaction is required.");
|
|
46
|
+
|
|
47
|
+
let storyID = getStoryIDFromURL(storyIdOrUrl);
|
|
48
|
+
if (!storyID) storyID = storyIdOrUrl;
|
|
49
|
+
|
|
50
|
+
const variables = {
|
|
51
|
+
input: {
|
|
52
|
+
attribution_id_v2: "StoriesCometSuspenseRoot.react,comet.stories.viewer,via_cold_start",
|
|
53
|
+
message: message,
|
|
54
|
+
story_id: storyID,
|
|
55
|
+
story_reply_type: isReaction ? "LIGHT_WEIGHT" : "TEXT",
|
|
56
|
+
actor_id: ctx.userID,
|
|
57
|
+
client_mutation_id: Math.floor(Math.random() * 10 + 1).toString()
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
if (isReaction) {
|
|
62
|
+
if (!allowedReactions.includes(message)) {
|
|
63
|
+
throw new Error(`Invalid reaction. Please use one of: ${allowedReactions.join(" ")}`);
|
|
64
|
+
}
|
|
65
|
+
variables.input.lightweight_reaction_actions = {
|
|
66
|
+
offsets: [0],
|
|
67
|
+
reaction: message,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const form = {
|
|
72
|
+
av: ctx.userID,
|
|
73
|
+
__user: ctx.userID,
|
|
74
|
+
__a: "1",
|
|
75
|
+
fb_dtsg: ctx.fb_dtsg,
|
|
76
|
+
jazoest: ctx.jazoest,
|
|
77
|
+
fb_api_caller_class: "RelayModern",
|
|
78
|
+
fb_api_req_friendly_name: "useStoriesSendReplyMutation",
|
|
79
|
+
variables: JSON.stringify(variables),
|
|
80
|
+
doc_id: "9697491553691692"
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const res = await defaultFuncs.post("https://www.facebook.com/api/graphql/", ctx.jar, form, {});
|
|
84
|
+
if (res.data.errors) throw new Error(JSON.stringify(res.data.errors));
|
|
85
|
+
|
|
86
|
+
const storyReplyData = res.data?.data?.direct_message_reply;
|
|
87
|
+
if (!storyReplyData) throw new Error("Could not find 'direct_message_reply' in the response data.");
|
|
88
|
+
|
|
89
|
+
return { success: true, result: storyReplyData };
|
|
90
|
+
} catch (err) {
|
|
91
|
+
console.error("Error in story reply API:", err);
|
|
92
|
+
throw err;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Creates a new text-based story.
|
|
98
|
+
* @param {string} message The text content of the story.
|
|
99
|
+
* @param {string} [fontName="classic"] The name of the font to use. Options: `headline`, `classic`, `casual`, `fancy`.
|
|
100
|
+
* @param {string} [backgroundName="blue"] The name of the background to use. Options: `orange`, `blue`, `green`, `modern`.
|
|
101
|
+
* @returns {Promise<{success: boolean, storyID: string}>} A promise that resolves with the new story's ID.
|
|
102
|
+
*/
|
|
103
|
+
async function create(message, fontName = "classic", backgroundName = "blue") {
|
|
104
|
+
const fontMap = {
|
|
105
|
+
headline: "1919119914775364",
|
|
106
|
+
classic: "516266749248495",
|
|
107
|
+
casual: "516266749248495",
|
|
108
|
+
fancy: "1790435664339626"
|
|
109
|
+
};
|
|
110
|
+
const bgMap = {
|
|
111
|
+
orange: "2163607613910521",
|
|
112
|
+
blue: "401372137331149",
|
|
113
|
+
green: "367314917184744",
|
|
114
|
+
modern: "554617635055752"
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const fontId = fontMap[fontName.toLowerCase()] || fontMap.classic;
|
|
118
|
+
const bgId = bgMap[backgroundName.toLowerCase()] || bgMap.blue;
|
|
119
|
+
|
|
120
|
+
const variables = {
|
|
121
|
+
input: {
|
|
122
|
+
audiences: [{ stories: { self: { target_id: ctx.userID } } }],
|
|
123
|
+
audiences_is_complete: true,
|
|
124
|
+
logging: { composer_session_id: "createStoriesText-" + Date.now() },
|
|
125
|
+
navigation_data: { attribution_id_v2: "StoriesCreateRoot.react,comet.stories.create" },
|
|
126
|
+
source: "WWW",
|
|
127
|
+
message: { ranges: [], text: message },
|
|
128
|
+
text_format_metadata: { inspirations_custom_font_id: fontId },
|
|
129
|
+
text_format_preset_id: bgId,
|
|
130
|
+
tracking: [null],
|
|
131
|
+
actor_id: ctx.userID,
|
|
132
|
+
client_mutation_id: "2"
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const form = {
|
|
137
|
+
__a: "1",
|
|
138
|
+
fb_api_caller_class: "RelayModern",
|
|
139
|
+
fb_api_req_friendly_name: "StoriesCreateMutation",
|
|
140
|
+
variables: JSON.stringify(variables),
|
|
141
|
+
doc_id: "24226878183562473"
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
try {
|
|
145
|
+
const res = await defaultFuncs.post("https://www.facebook.com/api/graphql/", ctx.jar, form, {});
|
|
146
|
+
if (res.data.errors) throw new Error(JSON.stringify(res.data.errors));
|
|
147
|
+
|
|
148
|
+
const storyNode = res.data?.data?.story_create?.viewer?.actor?.story_bucket?.nodes[0]?.first_story_to_show;
|
|
149
|
+
if (!storyNode || !storyNode.id) throw new Error("Could not find the storyCardID in the response.");
|
|
150
|
+
|
|
151
|
+
return { success: true, storyID: storyNode.id };
|
|
152
|
+
} catch (error) {
|
|
153
|
+
throw error;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
/**
|
|
159
|
+
* Creates a new text-based story.
|
|
160
|
+
* @param {string} message The text content of the story.
|
|
161
|
+
* @param {string} [fontName="classic"] The font to use (`headline`, `classic`, `fancy`).
|
|
162
|
+
* @param {string} [backgroundName="blue"] The background to use (`orange`, `blue`, `green`, `modern`).
|
|
163
|
+
* @returns {Promise<{success: boolean, storyID: string}>}
|
|
164
|
+
*/
|
|
165
|
+
create,
|
|
166
|
+
/**
|
|
167
|
+
* Reacts to a story with a specific emoji.
|
|
168
|
+
* @param {string} storyIdOrUrl The ID or full URL of the story to react to.
|
|
169
|
+
* @param {string} reaction The emoji to react with. Must be one of: ❤️, 👍, 🤗, 😆, 😡, 😢, 😮.
|
|
170
|
+
* @returns {Promise<{success: boolean, result: object}>}
|
|
171
|
+
*/
|
|
172
|
+
react: (storyIdOrUrl, reaction) => sendStoryReply(storyIdOrUrl, reaction, true),
|
|
173
|
+
/**
|
|
174
|
+
* Sends a text message reply to a story.
|
|
175
|
+
* @param {string} storyIdOrUrl The ID or full URL of the story to reply to.
|
|
176
|
+
* @param {string} message The text message to send.
|
|
177
|
+
* @returns {Promise<{success: boolean, result: object}>}
|
|
178
|
+
*/
|
|
179
|
+
msg: (storyIdOrUrl, message) => sendStoryReply(storyIdOrUrl, message, false)
|
|
180
|
+
};
|
|
181
|
+
};
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require('../utils');
|
|
4
|
+
|
|
5
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
6
|
+
/**
|
|
7
|
+
* Made by Choru Official
|
|
8
|
+
* Mqtt & Graph
|
|
9
|
+
* Manages or sets the custom theme for a Facebook thread.
|
|
10
|
+
* If only a theme name/keyword is provided, it attempts to find and set the matching theme.
|
|
11
|
+
* If "list" is provided as the themeName, it lists available themes.
|
|
12
|
+
*
|
|
13
|
+
* @param {string} themeName The name or partial name of the theme (case-insensitive), or "list" to list themes.
|
|
14
|
+
* @param {string} threadID The ID of the thread.
|
|
15
|
+
* @param {Function} [callback] Optional callback function.
|
|
16
|
+
* @param {string} [initiatorID] The ID of the user who initiated the theme change (e.g., from event.senderID).
|
|
17
|
+
* @returns {Promise<void|Array<object>|object>} A promise that resolves on success (for setting theme, with a detailed event object), or with an array of themes (for listing), or rejects on error.
|
|
18
|
+
*/
|
|
19
|
+
return async function theme(themeName, threadID, callback, initiatorID) {
|
|
20
|
+
let _callback;
|
|
21
|
+
let _initiatorID;
|
|
22
|
+
|
|
23
|
+
let _resolveFunc;
|
|
24
|
+
let _rejectFunc;
|
|
25
|
+
const finalReturnPromise = new Promise((resolve, reject) => {
|
|
26
|
+
_resolveFunc = resolve;
|
|
27
|
+
_rejectFunc = reject;
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
if (utils.getType(callback) === "Function" || utils.getType(callback) === "AsyncFunction") {
|
|
31
|
+
_callback = callback;
|
|
32
|
+
_initiatorID = initiatorID;
|
|
33
|
+
} else if (utils.getType(threadID) === "Function" || utils.getType(threadID) === "AsyncFunction") {
|
|
34
|
+
_callback = threadID;
|
|
35
|
+
threadID = null;
|
|
36
|
+
_initiatorID = callback;
|
|
37
|
+
} else if (utils.getType(callback) === "string") {
|
|
38
|
+
_initiatorID = callback;
|
|
39
|
+
_callback = undefined;
|
|
40
|
+
} else {
|
|
41
|
+
_callback = undefined;
|
|
42
|
+
_initiatorID = undefined;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (!_callback) {
|
|
46
|
+
_callback = function (_err, _data) {
|
|
47
|
+
if (_err) _rejectFunc(_err);
|
|
48
|
+
else _resolveFunc(_data);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
_initiatorID = _initiatorID || ctx.userID;
|
|
53
|
+
|
|
54
|
+
threadID = threadID || ctx.threadID;
|
|
55
|
+
|
|
56
|
+
if (!threadID) {
|
|
57
|
+
return _callback(new Error("threadID is required to manage themes."));
|
|
58
|
+
}
|
|
59
|
+
if (!themeName) {
|
|
60
|
+
return _callback(new Error("themeName (or 'list') is required."));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (!ctx.mqttClient) {
|
|
64
|
+
return _callback(new Error("Not connected to MQTT"));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const fetchThemes = async () => {
|
|
68
|
+
const form = {
|
|
69
|
+
fb_api_caller_class: 'RelayModern',
|
|
70
|
+
fb_api_req_friendly_name: 'MWPThreadThemeQuery_AllThemesQuery',
|
|
71
|
+
variables: JSON.stringify({ version: "default" }),
|
|
72
|
+
server_timestamps: true,
|
|
73
|
+
doc_id: '24474714052117636',
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
const resData = await defaultFuncs
|
|
78
|
+
.post("https://www.facebook.com/api/graphql/", ctx.jar, form, null, {
|
|
79
|
+
"x-fb-friendly-name": "MWPThreadThemeQuery_AllThemesQuery",
|
|
80
|
+
"x-fb-lsd": ctx.lsd,
|
|
81
|
+
"referer": `https://www.facebook.com/messages/t/${threadID}`
|
|
82
|
+
})
|
|
83
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs));
|
|
84
|
+
|
|
85
|
+
if (resData.errors) {
|
|
86
|
+
throw new Error(JSON.stringify(resData.errors));
|
|
87
|
+
}
|
|
88
|
+
if (!resData.data || !resData.data.messenger_thread_themes) {
|
|
89
|
+
throw new Error("Could not retrieve thread themes from response.");
|
|
90
|
+
}
|
|
91
|
+
return resData.data.messenger_thread_themes.map(themeData => {
|
|
92
|
+
if (!themeData || !themeData.id) return null;
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
id: themeData.id,
|
|
96
|
+
name: themeData.accessibility_label,
|
|
97
|
+
description: themeData.description,
|
|
98
|
+
appColorMode: themeData.app_color_mode,
|
|
99
|
+
composerBackgroundColor: themeData.composer_background_color,
|
|
100
|
+
backgroundGradientColors: themeData.background_gradient_colors,
|
|
101
|
+
titleBarButtonTintColor: themeData.title_bar_button_tint_color,
|
|
102
|
+
inboundMessageGradientColors: themeData.inbound_message_gradient_colors,
|
|
103
|
+
titleBarTextColor: themeData.title_bar_text_color,
|
|
104
|
+
composerTintColor: themeData.composer_tint_color,
|
|
105
|
+
titleBarAttributionColor: themeData.title_bar_attribution_color,
|
|
106
|
+
composerInputBackgroundColor: themeData.composer_input_background_color,
|
|
107
|
+
hotLikeColor: themeData.hot_like_color,
|
|
108
|
+
backgroundImage: themeData.background_asset?.image?.uri,
|
|
109
|
+
messageTextColor: themeData.message_text_color,
|
|
110
|
+
inboundMessageTextColor: themeData.inbound_message_text_color,
|
|
111
|
+
primaryButtonBackgroundColor: themeData.primary_button_background_color,
|
|
112
|
+
titleBarBackgroundColor: themeData.title_bar_background_color,
|
|
113
|
+
tertiaryTextColor: themeData.tertiary_text_color,
|
|
114
|
+
reactionPillBackgroundColor: themeData.reaction_pill_background_color,
|
|
115
|
+
secondaryTextColor: themeData.secondary_text_color,
|
|
116
|
+
fallbackColor: themeData.fallback_color,
|
|
117
|
+
gradientColors: themeData.gradient_colors,
|
|
118
|
+
normalThemeId: themeData.normal_theme_id,
|
|
119
|
+
iconAsset: themeData.icon_asset?.image?.uri,
|
|
120
|
+
};
|
|
121
|
+
}).filter(Boolean);
|
|
122
|
+
} catch (fetchErr) {
|
|
123
|
+
throw new Error(`Failed to fetch theme list: ${fetchErr.message || fetchErr}`);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const setThreadTheme = async (themeIDToSet, actualThemeName, initiatorID) => {
|
|
128
|
+
let currentEpochId = parseInt(utils.generateOfflineThreadingID());
|
|
129
|
+
|
|
130
|
+
const createAndPublish = (label, queueName, payload) => {
|
|
131
|
+
currentEpochId = parseInt(utils.generateOfflineThreadingID());
|
|
132
|
+
ctx.wsReqNumber += 1;
|
|
133
|
+
ctx.wsTaskNumber += 1;
|
|
134
|
+
|
|
135
|
+
const request_id = ctx.wsReqNumber;
|
|
136
|
+
|
|
137
|
+
const queryPayload = {
|
|
138
|
+
thread_key: threadID.toString(),
|
|
139
|
+
theme_fbid: themeIDToSet.toString(),
|
|
140
|
+
sync_group: 1,
|
|
141
|
+
...payload
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const query = {
|
|
145
|
+
failure_count: null,
|
|
146
|
+
label: label,
|
|
147
|
+
payload: JSON.stringify(queryPayload),
|
|
148
|
+
queue_name: queueName,
|
|
149
|
+
task_id: ctx.wsTaskNumber,
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const context = {
|
|
153
|
+
app_id: ctx.appID,
|
|
154
|
+
payload: {
|
|
155
|
+
epoch_id: currentEpochId,
|
|
156
|
+
tasks: [query],
|
|
157
|
+
version_id: '24631415369801570',
|
|
158
|
+
},
|
|
159
|
+
request_id: request_id,
|
|
160
|
+
type: 3,
|
|
161
|
+
};
|
|
162
|
+
context.payload = JSON.stringify(context.payload);
|
|
163
|
+
|
|
164
|
+
return new Promise((res, rej) => {
|
|
165
|
+
ctx.mqttClient.publish('/ls_req', JSON.stringify(context), { qos: 1, retain: false }, err => {
|
|
166
|
+
if (err) {
|
|
167
|
+
return rej(new Error(`MQTT publish failed for request ${request_id}: ${err.message}`));
|
|
168
|
+
}
|
|
169
|
+
res();
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
try {
|
|
175
|
+
await Promise.all([
|
|
176
|
+
createAndPublish('1013', `ai_generated_theme`, {}),
|
|
177
|
+
createAndPublish('1037', `msgr_custom_thread_theme`, {}),
|
|
178
|
+
createAndPublish('1028', `thread_theme_writer`, {}),
|
|
179
|
+
createAndPublish('43', `thread_theme`, { source: null, payload: null })
|
|
180
|
+
]);
|
|
181
|
+
|
|
182
|
+
return {
|
|
183
|
+
type: "thread_theme_update",
|
|
184
|
+
threadID: threadID,
|
|
185
|
+
themeID: themeIDToSet,
|
|
186
|
+
themeName: actualThemeName,
|
|
187
|
+
senderID: initiatorID,
|
|
188
|
+
BotID: ctx.userID,
|
|
189
|
+
timestamp: Date.now(),
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
} catch (publishErr) {
|
|
193
|
+
throw new Error(`Failed to publish theme change MQTT messages: ${publishErr.message || publishErr}`);
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
try {
|
|
198
|
+
if (themeName.toLowerCase() === "list") {
|
|
199
|
+
const themes = await fetchThemes();
|
|
200
|
+
_callback(null, themes);
|
|
201
|
+
} else {
|
|
202
|
+
const themes = await fetchThemes();
|
|
203
|
+
const normalizedThemeName = themeName.toLowerCase();
|
|
204
|
+
|
|
205
|
+
let matchedTheme = null;
|
|
206
|
+
|
|
207
|
+
if (!isNaN(normalizedThemeName)) {
|
|
208
|
+
matchedTheme = themes.find(t => t.id === normalizedThemeName);
|
|
209
|
+
}
|
|
210
|
+
if (!matchedTheme) {
|
|
211
|
+
matchedTheme = themes.find(t => t.name.toLowerCase() === normalizedThemeName);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (!matchedTheme) {
|
|
215
|
+
matchedTheme = themes.find(t => t.name.toLowerCase().includes(normalizedThemeName));
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (!matchedTheme) {
|
|
219
|
+
throw new Error(`Theme "${themeName}" not found. Try '/theme list' for available themes.`);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const themeEventObject = await setThreadTheme(matchedTheme.id, matchedTheme.name, _initiatorID);
|
|
223
|
+
|
|
224
|
+
_callback(null, themeEventObject);
|
|
225
|
+
}
|
|
226
|
+
} catch (err) {
|
|
227
|
+
const finalError = err instanceof Error ? err : new Error(err.message || err.error || 'An unknown error occurred during theme operation.');
|
|
228
|
+
_callback(finalError);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return finalReturnPromise;
|
|
232
|
+
};
|
|
233
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require('../utils');
|
|
4
|
+
|
|
5
|
+
module.exports = (defaultFuncs, api, ctx) => {
|
|
6
|
+
return async function unfriend(userID, callback) {
|
|
7
|
+
let resolveFunc = () => {};
|
|
8
|
+
let rejectFunc = () => {};
|
|
9
|
+
const returnPromise = new Promise((resolve, reject) => {
|
|
10
|
+
resolveFunc = resolve;
|
|
11
|
+
rejectFunc = reject;
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
if (!callback) {
|
|
15
|
+
callback = (err, result) => {
|
|
16
|
+
if (err) return rejectFunc(err);
|
|
17
|
+
resolveFunc(result);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
const form = {
|
|
23
|
+
uid: userID,
|
|
24
|
+
unref: "bd_friends_tab",
|
|
25
|
+
floc: "friends_tab",
|
|
26
|
+
"nctr[_mod]": "pagelet_timeline_app_collection_" + ctx.userID + ":2356318349:2"
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const res = await defaultFuncs.post(
|
|
30
|
+
"https://www.facebook.com/ajax/profile/removefriendconfirm.php",
|
|
31
|
+
ctx.jar,
|
|
32
|
+
form
|
|
33
|
+
).then(utils.parseAndCheckLogin(ctx, defaultFuncs));
|
|
34
|
+
|
|
35
|
+
if (res.error) {
|
|
36
|
+
throw res;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
callback(null, true);
|
|
40
|
+
} catch (err) {
|
|
41
|
+
utils.error("unfriend", err);
|
|
42
|
+
callback(err);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return returnPromise;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require('../utils');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
7
|
+
return async (messageID) => {
|
|
8
|
+
const defData = await defaultFuncs.post("https://www.facebook.com/messaging/unsend_message/", ctx.jar, {
|
|
9
|
+
message_id: messageID
|
|
10
|
+
})
|
|
11
|
+
const resData = await utils.parseAndCheckLogin(ctx, defaultFuncs)(defData);
|
|
12
|
+
if (resData.error) {
|
|
13
|
+
throw new Error(resData);
|
|
14
|
+
}
|
|
15
|
+
return resData;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require("../utils");
|
|
4
|
+
const setOptionsModel = require('./models/setOptions');
|
|
5
|
+
const buildAPIModel = require('./models/buildAPI');
|
|
6
|
+
const loginHelperModel = require('./models/loginHelper');
|
|
7
|
+
|
|
8
|
+
let globalOptions = {};
|
|
9
|
+
let ctx = null;
|
|
10
|
+
let defaultFuncs = null;
|
|
11
|
+
let api = null;
|
|
12
|
+
|
|
13
|
+
const fbLink = (ext) => ("https://www.facebook.com" + (ext ? '/' + ext : ''));
|
|
14
|
+
const ERROR_RETRIEVING = "Error retrieving userID. This can be caused by many factors, including being blocked by Facebook for logging in from an unknown location. Try logging in with a browser to verify.";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Initiates the login process for a Facebook account.
|
|
18
|
+
*
|
|
19
|
+
* @param {object} credentials The user's login credentials (e.g., email/password or appState cookies).
|
|
20
|
+
* @param {object} [options={}] Optional login configurations.
|
|
21
|
+
* @param {function} [callback] Optional callback function. If omitted, returns a Promise.
|
|
22
|
+
* @returns {Promise|void} Returns Promise if no callback provided, otherwise void.
|
|
23
|
+
*/
|
|
24
|
+
async function login(credentials, options, callback) {
|
|
25
|
+
if (typeof options === "function") {
|
|
26
|
+
callback = options;
|
|
27
|
+
options = {};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let promiseCallback = null;
|
|
31
|
+
let rejectFunc = null;
|
|
32
|
+
let resolveFunc = null;
|
|
33
|
+
let returnPromise = null;
|
|
34
|
+
|
|
35
|
+
if (typeof callback !== "function") {
|
|
36
|
+
returnPromise = new Promise(function (resolve, reject) {
|
|
37
|
+
resolveFunc = resolve;
|
|
38
|
+
rejectFunc = reject;
|
|
39
|
+
});
|
|
40
|
+
promiseCallback = function (error, api) {
|
|
41
|
+
if (error) return rejectFunc(error);
|
|
42
|
+
return resolveFunc(api);
|
|
43
|
+
};
|
|
44
|
+
callback = promiseCallback;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if ('logging' in options) {
|
|
48
|
+
utils.logOptions(options.logging);
|
|
49
|
+
}
|
|
50
|
+
const defaultOptions = {
|
|
51
|
+
selfListen: false,
|
|
52
|
+
listenEvents: true,
|
|
53
|
+
listenTyping: false,
|
|
54
|
+
simulateTyping: true,
|
|
55
|
+
updatePresence: false,
|
|
56
|
+
forceLogin: false,
|
|
57
|
+
autoMarkDelivery: false,
|
|
58
|
+
autoMarkRead: true,
|
|
59
|
+
autoReconnect: true,
|
|
60
|
+
online: true,
|
|
61
|
+
emitReady: false,
|
|
62
|
+
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36",
|
|
63
|
+
};
|
|
64
|
+
Object.assign(globalOptions, defaultOptions, options);
|
|
65
|
+
|
|
66
|
+
await setOptionsModel(globalOptions, options);
|
|
67
|
+
|
|
68
|
+
loginHelperModel(
|
|
69
|
+
credentials,
|
|
70
|
+
globalOptions,
|
|
71
|
+
(loginError, loginApi) => {
|
|
72
|
+
if (loginError) {
|
|
73
|
+
return callback(loginError);
|
|
74
|
+
}
|
|
75
|
+
api = loginApi;
|
|
76
|
+
ctx = loginApi.ctx;
|
|
77
|
+
defaultFuncs = loginApi.defaultFuncs;
|
|
78
|
+
return callback(null, loginApi);
|
|
79
|
+
},
|
|
80
|
+
setOptionsModel,
|
|
81
|
+
buildAPIModel,
|
|
82
|
+
api,
|
|
83
|
+
fbLink,
|
|
84
|
+
ERROR_RETRIEVING
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
return returnPromise;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
module.exports = {
|
|
91
|
+
login
|
|
92
|
+
};
|