shadowx-fca 2.4.0 → 2.5.0
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/checkUpdate.js +1 -1
- package/index.js +664 -418
- package/package.json +1 -1
- package/src/GetBotInfo.js +57 -0
- package/src/OldMessage.js +38 -10
- package/src/comment.js +213 -0
- package/src/emoji.js +124 -0
- package/src/friend.js +243 -0
- package/src/gcmember.js +122 -0
- package/src/getUserInfo.js +222 -43
- package/src/listenMqtt.js +9 -116
- package/src/nickname.js +132 -0
- package/src/sendMessage.js +224 -235
- package/src/sendTypingIndicator.js +45 -101
- package/src/share.js +62 -0
- package/src/shareContact.js +17 -61
- package/src/stickers.js +117 -0
- package/src/story.js +181 -0
- package/src/theme.js +233 -0
- package/utils.js +24 -1311
package/src/share.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require('../utils');
|
|
4
|
+
|
|
5
|
+
function formatPreviewResult(data) {
|
|
6
|
+
if (data.errors) {
|
|
7
|
+
throw data.errors[0];
|
|
8
|
+
}
|
|
9
|
+
const previewData = data.data?.xma_preview_data;
|
|
10
|
+
if (!previewData) {
|
|
11
|
+
throw { error: "Could not generate a preview for this post." };
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
postID: previewData.post_id,
|
|
15
|
+
header: previewData.header_title,
|
|
16
|
+
subtitle: previewData.subtitle_text,
|
|
17
|
+
title: previewData.title_text,
|
|
18
|
+
previewImage: previewData.preview_url,
|
|
19
|
+
favicon: previewData.favicon_url,
|
|
20
|
+
headerImage: previewData.header_image_url
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
|
25
|
+
return async function getPostPreview(postID, callback) {
|
|
26
|
+
let cb;
|
|
27
|
+
const returnPromise = new Promise((resolve, reject) => {
|
|
28
|
+
cb = (err, data) => err ? reject(err) : resolve(data);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
if (typeof callback === 'function') cb = callback;
|
|
32
|
+
if (!postID) {
|
|
33
|
+
return cb({ error: "A postID is required to generate a preview." });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const variables = {
|
|
37
|
+
shareable_id: postID.toString(),
|
|
38
|
+
scale: 3,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const form = {
|
|
42
|
+
fb_api_caller_class: 'RelayModern',
|
|
43
|
+
fb_api_req_friendly_name: 'CometXMAProxyShareablePreviewQuery',
|
|
44
|
+
variables: JSON.stringify(variables),
|
|
45
|
+
doc_id: '28939050904374351'
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
const resData = await defaultFuncs
|
|
50
|
+
.post("https://www.facebook.com/api/graphql/", ctx.jar, form)
|
|
51
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs));
|
|
52
|
+
|
|
53
|
+
const result = formatPreviewResult(resData);
|
|
54
|
+
return cb(null, result);
|
|
55
|
+
} catch (err) {
|
|
56
|
+
utils.error("getPostPreview", err);
|
|
57
|
+
return cb(err);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return returnPromise;
|
|
61
|
+
};
|
|
62
|
+
};
|
package/src/shareContact.js
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
/* eslint-disable linebreak-style */
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
const utils = require('../utils');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @module shareContact
|
|
8
|
+
* @param {Object} defaultFuncs - The default functions provided by the API.
|
|
9
|
+
* @param {Object} api - The full API object.
|
|
10
|
+
* @param {Object} ctx - The context object.
|
|
11
|
+
* @returns {function(text: string, senderID: string, threadID: string, callback: Function): void} - A function to share a contact.
|
|
12
|
+
*/
|
|
8
13
|
module.exports = function(defaultFuncs, api, ctx) {
|
|
14
|
+
/**
|
|
15
|
+
* Shares a user's contact information into a specific thread via MQTT.
|
|
16
|
+
* @param {string} [text] - An optional message to send along with the contact card.
|
|
17
|
+
* @param {string} senderID - The Facebook user ID of the contact you want to share.
|
|
18
|
+
* @param {string} threadID - The ID of the thread where the contact will be shared.
|
|
19
|
+
* @param {Function} [callback] - An optional callback function to be executed.
|
|
20
|
+
*/
|
|
9
21
|
return function shareContact(text, senderID, threadID, callback) {
|
|
10
22
|
if (!ctx.mqttClient) {
|
|
11
23
|
throw new Error('Not connected to MQTT');
|
|
@@ -28,7 +40,7 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
|
28
40
|
failure_count: null,
|
|
29
41
|
label: '359',
|
|
30
42
|
payload: JSON.stringify(queryPayload),
|
|
31
|
-
queue_name: 'messenger_contact_sharing'
|
|
43
|
+
queue_name: 'messenger_contact_sharing',
|
|
32
44
|
task_id: Math.random() * 1001 << 0,
|
|
33
45
|
};
|
|
34
46
|
|
|
@@ -52,59 +64,3 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
|
52
64
|
ctx.mqttClient.publish('/ls_req', JSON.stringify(context), { qos: 1, retain: false });
|
|
53
65
|
};
|
|
54
66
|
};
|
|
55
|
-
|
|
56
|
-
/*"use strict";
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
var utils = require("../utils");
|
|
60
|
-
|
|
61
|
-
// @NethWs3Dev
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
module.exports = function (defaultFuncs, api, ctx) {
|
|
65
|
-
return async function shareContact(text, senderID, threadID, callback) {
|
|
66
|
-
await utils.parseAndCheckLogin(ctx, defaultFuncs);
|
|
67
|
-
const mqttClient = ctx.mqttClient;
|
|
68
|
-
|
|
69
|
-
if (!mqttClient) {
|
|
70
|
-
throw new Error("Not connected to MQTT");
|
|
71
|
-
}
|
|
72
|
-
var resolveFunc = function () { };
|
|
73
|
-
var rejectFunc = function () { };
|
|
74
|
-
var returnPromise = new Promise(function (resolve, reject) {
|
|
75
|
-
resolveFunc = resolve;
|
|
76
|
-
rejectFunc = reject;
|
|
77
|
-
});
|
|
78
|
-
if (!callback) {
|
|
79
|
-
callback = function (err, data) {
|
|
80
|
-
if (err) return rejectFunc(err);
|
|
81
|
-
resolveFunc(data);
|
|
82
|
-
data };
|
|
83
|
-
}
|
|
84
|
-
let count_req = 0
|
|
85
|
-
var form = JSON.stringify({
|
|
86
|
-
"app_id": "2220391788200892",
|
|
87
|
-
"payload": JSON.stringify({
|
|
88
|
-
tasks: [{
|
|
89
|
-
label: '359',
|
|
90
|
-
payload: JSON.stringify({
|
|
91
|
-
"contact_id": senderID,
|
|
92
|
-
"sync_group": 1,
|
|
93
|
-
"text": text || "",
|
|
94
|
-
"thread_id": threadID
|
|
95
|
-
}),
|
|
96
|
-
queue_name: 'messenger_contact_sharing',
|
|
97
|
-
task_id: Math.random() * 1001 << 0,
|
|
98
|
-
failure_count: null,
|
|
99
|
-
}],
|
|
100
|
-
epoch_id: utils.generateOfflineThreadingID(),
|
|
101
|
-
version_id: '7214102258676893',
|
|
102
|
-
}),
|
|
103
|
-
"request_id": ++count_req,
|
|
104
|
-
"type": 3
|
|
105
|
-
});
|
|
106
|
-
mqttClient.publish('/ls_req',form)
|
|
107
|
-
|
|
108
|
-
return returnPromise;
|
|
109
|
-
};
|
|
110
|
-
};*/
|
package/src/stickers.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// sahilchat-fca — Sticker API
|
|
3
|
+
// Author: S4hiilAns4ri (github.com/S4hiilAns4ri)
|
|
4
|
+
|
|
5
|
+
const utils = require('../utils');
|
|
6
|
+
|
|
7
|
+
function formatPackList(data) {
|
|
8
|
+
const trayPacks = data?.data?.picker_plugins?.sticker_picker?.sticker_store?.tray_packs;
|
|
9
|
+
const storePacks = data?.data?.viewer?.sticker_store?.available_packs;
|
|
10
|
+
const packData = storePacks || trayPacks;
|
|
11
|
+
if (!packData?.edges) return { packs: [], page_info: { has_next_page: false } };
|
|
12
|
+
return {
|
|
13
|
+
packs: packData.edges.map(e => e.node ? ({ id: e.node.id, name: e.node.name, thumbnail: e.node.thumbnail_image?.uri }) : null).filter(Boolean),
|
|
14
|
+
page_info : packData.page_info,
|
|
15
|
+
store_id : data?.data?.viewer?.sticker_store?.id,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function formatStickerList(stickers) {
|
|
20
|
+
if (!stickers) return [];
|
|
21
|
+
return stickers.map(e => e.node ? ({
|
|
22
|
+
type : "sticker",
|
|
23
|
+
stickerID : e.node.id,
|
|
24
|
+
ID : e.node.id,
|
|
25
|
+
url : e.node.image?.uri,
|
|
26
|
+
animatedUrl : e.node.animated_image?.uri,
|
|
27
|
+
packID : e.node.pack?.id,
|
|
28
|
+
label : e.node.label || e.node.accessibility_label,
|
|
29
|
+
}) : null).filter(Boolean);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
|
33
|
+
async function gql(form) {
|
|
34
|
+
const res = await defaultFuncs.post("https://www.facebook.com/api/graphql/", ctx.jar, form)
|
|
35
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs));
|
|
36
|
+
if (!res) throw new Error("GraphQL returned no data.");
|
|
37
|
+
if (res.errors) throw new Error(res.errors[0].message);
|
|
38
|
+
return res;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
/**
|
|
43
|
+
* Search stickers by keyword.
|
|
44
|
+
* @param {string} query — Search term (e.g. "love", "happy")
|
|
45
|
+
* @returns {Promise<Array>}
|
|
46
|
+
*/
|
|
47
|
+
search: async (query) => {
|
|
48
|
+
const res = await gql({
|
|
49
|
+
fb_api_caller_class : 'RelayModern',
|
|
50
|
+
fb_api_req_friendly_name : 'CometStickerPickerSearchResultsRootQuery',
|
|
51
|
+
variables : JSON.stringify({ scale: 3, search_query: query, sticker_height: 128, sticker_width: 128, stickerInterface: "MESSAGES" }),
|
|
52
|
+
doc_id : '24004987559125954',
|
|
53
|
+
});
|
|
54
|
+
return formatStickerList(res?.data?.sticker_search?.sticker_results?.edges);
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* List your sticker packs.
|
|
59
|
+
* @returns {Promise<Array>}
|
|
60
|
+
*/
|
|
61
|
+
listPacks: async () => {
|
|
62
|
+
const res = await gql({
|
|
63
|
+
fb_api_caller_class : 'RelayModern',
|
|
64
|
+
fb_api_req_friendly_name : 'CometStickerPickerCardQuery',
|
|
65
|
+
variables : JSON.stringify({ scale: 3, stickerInterface: "MESSAGES" }),
|
|
66
|
+
doc_id : '10095807770482952',
|
|
67
|
+
});
|
|
68
|
+
return formatPackList(res).packs;
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Get all stickers in a pack by packID.
|
|
73
|
+
* @param {string} packID
|
|
74
|
+
* @returns {Promise<Array>}
|
|
75
|
+
*/
|
|
76
|
+
getStickersInPack: async (packID) => {
|
|
77
|
+
const res = await gql({
|
|
78
|
+
fb_api_caller_class : 'RelayModern',
|
|
79
|
+
fb_api_req_friendly_name : 'CometStickerPickerPackContentRootQuery',
|
|
80
|
+
variables : JSON.stringify({ packID, stickerWidth: 128, stickerHeight: 128, scale: 3 }),
|
|
81
|
+
doc_id : '23982341384707469',
|
|
82
|
+
});
|
|
83
|
+
return formatStickerList(res?.data?.sticker_pack?.stickers?.edges);
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Add a sticker pack to your collection.
|
|
88
|
+
* @param {string} packID
|
|
89
|
+
* @returns {Promise<object>}
|
|
90
|
+
*/
|
|
91
|
+
addPack: async (packID) => {
|
|
92
|
+
const res = await gql({
|
|
93
|
+
fb_api_caller_class : 'RelayModern',
|
|
94
|
+
fb_api_req_friendly_name : 'CometStickersStorePackMutationAddMutation',
|
|
95
|
+
variables : JSON.stringify({ input: { pack_id: packID, actor_id: ctx.userID, client_mutation_id: Math.round(Math.random() * 10).toString() } }),
|
|
96
|
+
doc_id : '9877489362345320',
|
|
97
|
+
});
|
|
98
|
+
return res.data.sticker_pack_add.sticker_pack;
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Get trending AI-generated stickers.
|
|
103
|
+
* @param {number} [limit=10]
|
|
104
|
+
* @returns {Promise<Array>}
|
|
105
|
+
*/
|
|
106
|
+
getAiStickers: async ({ limit = 10 } = {}) => {
|
|
107
|
+
const res = await gql({
|
|
108
|
+
fb_api_caller_class : 'RelayModern',
|
|
109
|
+
fb_api_req_friendly_name : 'CometStickerPickerStickerGeneratedCardQuery',
|
|
110
|
+
variables : JSON.stringify({ limit }),
|
|
111
|
+
doc_id : '24151467751156443',
|
|
112
|
+
});
|
|
113
|
+
const nodes = res?.data?.xfb_trending_generated_ai_stickers?.nodes || [];
|
|
114
|
+
return nodes.map(n => ({ type: "sticker", stickerID: n.id, ID: n.id, url: n.url, label: n.label }));
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
};
|
package/src/story.js
ADDED
|
@@ -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 S4hiilAns4ri, S4hiilAns4ri
|
|
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
|
+
};
|
package/src/theme.js
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require('../utils');
|
|
4
|
+
|
|
5
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
6
|
+
/**
|
|
7
|
+
* Author: S4hiilAns4ri (github.com/S4hiilAns4ri)
|
|
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
|
+
};
|