@dongdev/fca-unofficial 2.0.31 → 3.0.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/CHANGELOG.md +6 -0
- package/LICENSE-MIT +1 -1
- package/README.md +402 -95
- package/func/checkUpdate.js +0 -1
- package/index.d.ts +685 -607
- package/package.json +1 -1
- package/src/api/messaging/createThemeAI.js +98 -0
- package/src/api/messaging/sendMessage.js +234 -341
- package/src/api/socket/core/connectMqtt.js +58 -11
- package/src/api/socket/core/emitAuth.js +39 -9
- package/src/api/socket/core/parseDelta.js +13 -4
- package/src/api/socket/listenMqtt.js +79 -10
- package/src/utils/client.js +98 -25
- package/src/utils/request.js +30 -12
- package/src/api/messaging/sendMessageMqtt.js +0 -323
package/package.json
CHANGED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const log = require("npmlog");
|
|
4
|
+
const { getType } = require("../../utils/format");
|
|
5
|
+
const { parseAndCheckLogin } = require("../../utils/client");
|
|
6
|
+
|
|
7
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
8
|
+
return function createThemeAI(prompt, callback) {
|
|
9
|
+
let resolveFunc = function () { };
|
|
10
|
+
let rejectFunc = function () { };
|
|
11
|
+
const returnPromise = new Promise(function (resolve, reject) {
|
|
12
|
+
resolveFunc = resolve;
|
|
13
|
+
rejectFunc = reject;
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
if (!callback) {
|
|
17
|
+
callback = function (err, data) {
|
|
18
|
+
if (err) return rejectFunc(err);
|
|
19
|
+
resolveFunc(data);
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (getType(prompt) !== "String") {
|
|
24
|
+
return callback({ error: "Invalid prompt. Please provide a string." });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (!prompt || prompt.trim().length === 0) {
|
|
28
|
+
return callback({ error: "Prompt cannot be empty." });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const form = {
|
|
32
|
+
av: ctx.userID,
|
|
33
|
+
fb_api_caller_class: "RelayModern",
|
|
34
|
+
fb_api_req_friendly_name: "useGenerateAIThemeMutation",
|
|
35
|
+
doc_id: "23873748445608673",
|
|
36
|
+
variables: JSON.stringify({
|
|
37
|
+
input: {
|
|
38
|
+
client_mutation_id: Math.round(Math.random() * 19).toString(),
|
|
39
|
+
actor_id: ctx.userID,
|
|
40
|
+
bypass_cache: true,
|
|
41
|
+
caller: "MESSENGER",
|
|
42
|
+
num_themes: 1,
|
|
43
|
+
prompt: prompt.trim()
|
|
44
|
+
}
|
|
45
|
+
}),
|
|
46
|
+
server_timestamps: true
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
defaultFuncs
|
|
50
|
+
.post("https://www.facebook.com/api/graphql/", ctx.jar, form)
|
|
51
|
+
.then(parseAndCheckLogin(ctx, defaultFuncs))
|
|
52
|
+
.then(function (resData) {
|
|
53
|
+
if (resData.errors) {
|
|
54
|
+
throw resData;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (!resData.data || !resData.data.xfb_generate_ai_themes_from_prompt) {
|
|
58
|
+
throw {
|
|
59
|
+
error: "Invalid response from Facebook API",
|
|
60
|
+
res: resData
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const themes = resData.data.xfb_generate_ai_themes_from_prompt.themes;
|
|
65
|
+
if (!themes || !Array.isArray(themes) || themes.length === 0) {
|
|
66
|
+
throw {
|
|
67
|
+
error: "No themes generated",
|
|
68
|
+
res: resData
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const theme = themes[0];
|
|
73
|
+
if (!theme || !theme.id || !theme.background_asset) {
|
|
74
|
+
throw {
|
|
75
|
+
error: "Invalid theme data",
|
|
76
|
+
res: resData
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
callback(null, {
|
|
81
|
+
id: theme.id,
|
|
82
|
+
accessibility_label: theme.accessibility_label || null,
|
|
83
|
+
background_asset: {
|
|
84
|
+
id: theme.background_asset.id,
|
|
85
|
+
image: {
|
|
86
|
+
url: theme.background_asset.image?.uri || null
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
})
|
|
91
|
+
.catch(function (err) {
|
|
92
|
+
log.error("createThemeAI", err);
|
|
93
|
+
return callback(err);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
return returnPromise;
|
|
97
|
+
};
|
|
98
|
+
};
|