@hoangquyet/fca
v0.1.5
Published
Remote private WebSocket FCA client wrapper.
Maintainers
Readme
@hoangquyet/fca
Remote private WebSocket FCA client wrapper for Messenger bot runtimes.
Install
npm install @hoangquyet/fcaUsage
const fca = require("@hoangquyet/fca");
async function main() {
const api = await fca.connect({
key: "YOUR_PRIVATE_API_KEY"
});
await api.sendMessage("hello", "THREAD_ID");
api.ws.on("*", (event) => {
console.log(event);
});
}
main().catch(console.error);require("@hoangquyet/fca") is callable and also exposes:
fca.connect(config)fca.initFCA(config)fca.FCAApifca.LocalBridgefca.PrivateWsClient
Config
Required:
config.cookie: raw Facebook cookie string, or providecookie.txt.- Or enable auto-login with
config.facebookAccount.emailandconfig.facebookAccount.password. config.api.key: private API key when your backend requires it.
Optional:
config.api.url: private FCA backend URL. Defaults tohttps://api.khotools.com.config.api.wsUrl/config.api.wsURL: explicit private WebSocket URL.config.reconnectMinutes: scheduled private WS reconnect interval.config.reconnectMs: reconnect interval in milliseconds.config.api.fca:Defaults tofcaPrime`.
Short form:
const api = await fca.connect({
key: "YOUR_PRIVATE_API_KEY"
});On first run, the package creates configFca.json in the current project root. Every next run reads that file automatically.
Custom cookie path:
const api = await fca.connect({
key: "YOUR_PRIVATE_API_KEY",
cookieFile: "C:/bots/account-a/cookie.txt"
});cookiePath is also accepted:
const api = await fca.connect({
key: "YOUR_PRIVATE_API_KEY",
cookiePath: "./sessions/main-cookie.txt"
});Direct raw cookie has the highest priority:
const api = await fca.connect({
key: "YOUR_PRIVATE_API_KEY",
cookie: "c_user=...; xs=..."
});Config passed to connect() overrides values loaded from configFca.json.
Auto-login form:
const api = await fca.connect({
key: "YOUR_PRIVATE_API_KEY",
cookieFile: "./cookie.txt",
autoLoginOnLogout: true,
facebookAccount: {
email: "facebook-email",
password: "facebook-password",
twofactor: "",
type: "ios"
}
});When auto-login succeeds, the package writes the new cookie to cookieFile and persists token/cookie back to configFca.json when config.__configPath or config.configPath is provided.
autoLoginOnLogout: false disables auto-login. Set it to true to allow auto-login when cookie is missing or the remote session reports logout.
E2EE
E2EE calls are proxied through the private backend when supported:
await api.sendMessage({
body: "hello e2ee",
forceE2EE: true,
chatJid: "USER_ID@msgr"
}, "USER_ID");Helpers include:
api.getE2EESession()api.unsendE2EEMessage(chatJid, messageID, options)api.downloadE2EEMedia(...)
FCA logs use ANSI gradient colors by default. Disable colors with:
NO_COLOR=1 node bot.js