@cexi/hoonfca 0.0.0-stage → 1.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/LICENSE +191 -0
- package/README.md +363 -2
- package/dist/cjs.cjs +9 -0
- package/dist/global-types.d.ts +2 -0
- package/dist/index.d.mts +1254 -0
- package/dist/index.d.ts +1254 -0
- package/dist/index.js +17481 -0
- package/dist/index.mjs +17435 -0
- package/docs/ARCHITECTURE.md +467 -0
- package/docs/DOCS.md +709 -0
- package/docs/sqlite-cache-recovery.md +49 -0
- package/fca-config.example.json +33 -0
- package/npm-shrinkwrap.json +4859 -0
- package/package.json +111 -4
- package/scripts/check-package-exports.cjs +84 -0
- package/scripts/recover-sqlite-cache.cjs +504 -0
- package/scripts/sqlite-cache-dump.py +123 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding any notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
Copyright 2026 Pham Minh Dong (DongDev/Donix)
|
|
180
|
+
|
|
181
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
182
|
+
you may not use this file except in compliance with the License.
|
|
183
|
+
You may obtain a copy of the License at
|
|
184
|
+
|
|
185
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
186
|
+
|
|
187
|
+
Unless required by applicable law or agreed to in writing, software
|
|
188
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
189
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
190
|
+
See the License for the specific language governing permissions and
|
|
191
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,364 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @cexi/hoonfca
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An **unofficial** Node.js library for interacting with **Facebook Messenger** through user-session emulation. It speaks the same HTTP/GraphQL and MQTT protocols the browser client uses, giving you programmatic access to messages, threads, reactions, typing indicators, and more — all in TypeScript with full type definitions.
|
|
4
|
+
|
|
5
|
+
> **Disclaimer:** This library operates by emulating a logged-in browser session. Using it may violate Facebook / Meta's Terms of Service and could result in account restrictions or bans. The author assumes **no responsibility** for how you use this software. Use it only for lawful purposes and at your own risk.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Table of Contents
|
|
10
|
+
|
|
11
|
+
- [Installation](#installation)
|
|
12
|
+
- [Quick Start](#quick-start)
|
|
13
|
+
- [Authentication](#authentication)
|
|
14
|
+
- [API Styles](#api-styles)
|
|
15
|
+
- [MessengerBot (Event-Driven)](#messengerbot-event-driven)
|
|
16
|
+
- [Configuration](#configuration)
|
|
17
|
+
- [Features Overview](#features-overview)
|
|
18
|
+
- [Project Documentation](#project-documentation)
|
|
19
|
+
- [Requirements](#requirements)
|
|
20
|
+
- [License](#license)
|
|
21
|
+
- [Links](#links)
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install @cexi/hoonfca
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
If you clone the repository and want to work with the source directly:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
git clone https://github.com/bdrakib123/hoon-fca.git
|
|
35
|
+
cd hoon-fca
|
|
36
|
+
npm install
|
|
37
|
+
npm run build
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The build produces these artifacts in `dist/`:
|
|
41
|
+
|
|
42
|
+
| File | Format / role |
|
|
43
|
+
|-------------------|----------------------------------------------------|
|
|
44
|
+
| `dist/cjs.cjs` | **CommonJS entry** — `require()` resolves here; the export **is** the `login` function (Mirai / classic FCA). |
|
|
45
|
+
| `dist/index.js` | Internal CJS bundle (required by `cjs.cjs`) |
|
|
46
|
+
| `dist/index.mjs` | ES Modules (ESM) |
|
|
47
|
+
| `dist/index.d.ts` | TypeScript typings |
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Quick Start
|
|
52
|
+
|
|
53
|
+
### Event-driven bot (recommended)
|
|
54
|
+
|
|
55
|
+
```javascript
|
|
56
|
+
const { createMessengerBot } = require("@cexi/hoonfca");
|
|
57
|
+
|
|
58
|
+
async function main() {
|
|
59
|
+
const bot = await createMessengerBot(
|
|
60
|
+
{ appState: require("./appstate.json") },
|
|
61
|
+
{
|
|
62
|
+
listenEvents: true,
|
|
63
|
+
stopOnSignals: true,
|
|
64
|
+
commandPrefix: "/"
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
bot.on("error", (err) => console.error("Bot error:", err));
|
|
69
|
+
|
|
70
|
+
bot.on("messageCreate", (event) => {
|
|
71
|
+
if (event.body) {
|
|
72
|
+
console.log(`[${event.threadID}] ${event.body}`);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
bot.command("ping", async (ctx) => {
|
|
77
|
+
await ctx.replyAsync("pong");
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
main();
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Classic `require` (default export = `login`)
|
|
85
|
+
|
|
86
|
+
Same pattern as older FCA forks: the required module **is** `login`. Callback gets **`api`**, not `ctx`.
|
|
87
|
+
|
|
88
|
+
```javascript
|
|
89
|
+
const login = require("@cexi/hoonfca");
|
|
90
|
+
|
|
91
|
+
login({ appState: require("./appstate.json") }, (err, api) => {
|
|
92
|
+
if (err) return console.error(err);
|
|
93
|
+
api.setOptions({ listenEvents: true });
|
|
94
|
+
api.listenMqtt((e, ev) => {
|
|
95
|
+
if (e) return console.error(e);
|
|
96
|
+
if (ev.type === "message") api.sendMessage(ev.body, ev.threadID);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Optional FCA options before the callback: `login(credentials, { listenEvents: true }, (err, api) => { ... })`.
|
|
102
|
+
|
|
103
|
+
### Async / Promise style
|
|
104
|
+
|
|
105
|
+
```javascript
|
|
106
|
+
const { login } = require("@cexi/hoonfca");
|
|
107
|
+
|
|
108
|
+
async function main() {
|
|
109
|
+
const ctx = await login({ appState: require("./appstate.json") });
|
|
110
|
+
const api = ctx.api;
|
|
111
|
+
|
|
112
|
+
api.listenMqtt((err, event) => {
|
|
113
|
+
if (err) return console.error(err);
|
|
114
|
+
if (event.type === "message") {
|
|
115
|
+
api.sendMessage(`Echo: ${event.body}`, event.threadID);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
main();
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## Authentication
|
|
126
|
+
|
|
127
|
+
With **`require("@cexi/hoonfca")`**, you get the **`login`** function directly (see [Quick Start](#quick-start)). With **named** imports / ESM, use `import { login } from "..."` or `import login from "..."`.
|
|
128
|
+
|
|
129
|
+
The library supports multiple credential strategies. Pass **one** of the following to `login()` or `createMessengerBot()`:
|
|
130
|
+
|
|
131
|
+
| Credential | Description |
|
|
132
|
+
|----------------|-------------------------------------------------------------------------------------------------------------|
|
|
133
|
+
| `appState` | An array of cookie objects (`{ key, value, domain, path, ... }`) exported from a browser extension or tool. **Recommended for bots.** |
|
|
134
|
+
| `Cookie` | A raw cookie header string, e.g. `"c_user=...; xs=...; ..."`. |
|
|
135
|
+
| `email` + `password` | Web login credentials. Prone to checkpoints and CAPTCHAs; **not recommended** for long-running bots. |
|
|
136
|
+
|
|
137
|
+
Optional `loginViaAPI` / `tokensViaAPI` support is disabled unless you explicitly configure a trusted HTTPS `apiServer` in your private `fca-config.json`. No third-party login server is used by default. Prefer `appState` or `Cookie` authentication for long-running bots.
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## API Styles
|
|
142
|
+
|
|
143
|
+
After authentication, you get an `FcaContext` object. The library offers two ways to call Messenger functions:
|
|
144
|
+
|
|
145
|
+
### 1. Flat API (legacy-compatible)
|
|
146
|
+
|
|
147
|
+
Every method lives directly on `ctx.api`:
|
|
148
|
+
|
|
149
|
+
```javascript
|
|
150
|
+
api.sendMessage("Hello!", threadID);
|
|
151
|
+
api.getThreadInfo(threadID, (err, info) => { ... });
|
|
152
|
+
api.setMessageReaction(":heart:", messageID);
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### 2. Namespaced client facade
|
|
156
|
+
|
|
157
|
+
Group related methods under domain namespaces for cleaner code:
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
import { createFcaClient } from "@cexi/hoonfca";
|
|
161
|
+
|
|
162
|
+
const client = createFcaClient(ctx.api);
|
|
163
|
+
|
|
164
|
+
await client.messages.send("Hello!", threadID);
|
|
165
|
+
await client.threads.getInfo(threadID);
|
|
166
|
+
await client.users.getInfo(userID);
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Available namespaces: `messages`, `threads`, `users`, `account`, `realtime`, `http`, `scheduler`.
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## MessengerBot (Event-Driven)
|
|
174
|
+
|
|
175
|
+
`MessengerBot` provides a high-level, event-driven interface inspired by Discord.js and Telegraf.
|
|
176
|
+
|
|
177
|
+
### Creating a bot
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
import { createMessengerBot } from "@cexi/hoonfca";
|
|
181
|
+
|
|
182
|
+
const bot = await createMessengerBot(
|
|
183
|
+
{ appState: require("./appstate.json") },
|
|
184
|
+
{
|
|
185
|
+
listenEvents: true,
|
|
186
|
+
stopOnSignals: true,
|
|
187
|
+
commandPrefix: "/",
|
|
188
|
+
maxEventListeners: 64,
|
|
189
|
+
enableComposer: true
|
|
190
|
+
}
|
|
191
|
+
);
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Events
|
|
195
|
+
|
|
196
|
+
| Event | Trigger |
|
|
197
|
+
|----------------------|----------------------------------------------|
|
|
198
|
+
| `message` | Any incoming message (including replies) |
|
|
199
|
+
| `messageCreate` | Alias for `message` |
|
|
200
|
+
| `message_reply` | A reply to an existing message |
|
|
201
|
+
| `messageReactionAdd` | A reaction is added to a message |
|
|
202
|
+
| `messageDelete` | A message is unsent/deleted |
|
|
203
|
+
| `typingStart` | A user starts typing |
|
|
204
|
+
| `typingStop` | A user stops typing |
|
|
205
|
+
| `threadUpdate` | Thread metadata changes (title, participants) |
|
|
206
|
+
| `ready` | MQTT connection established |
|
|
207
|
+
| `raw` / `update` | Every MQTT delta (unfiltered) |
|
|
208
|
+
| `error` | Any error during listening |
|
|
209
|
+
|
|
210
|
+
### Composer middleware
|
|
211
|
+
|
|
212
|
+
The composer pipeline processes `message` and `message_reply` events through a chain of middleware functions:
|
|
213
|
+
|
|
214
|
+
```javascript
|
|
215
|
+
// Global middleware
|
|
216
|
+
bot.use(async (ctx, next) => {
|
|
217
|
+
console.log(`[${ctx.threadID}] ${ctx.text}`);
|
|
218
|
+
await next();
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
// Command handler — matches "/ping" at the start of a message
|
|
222
|
+
bot.command("ping", async (ctx) => {
|
|
223
|
+
await ctx.replyAsync("pong");
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
// Pattern matching — regex or substring
|
|
227
|
+
bot.hears(/hello/i, async (ctx) => {
|
|
228
|
+
await ctx.replyAsync("Hi there!");
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
bot.hears("goodbye", async (ctx) => {
|
|
232
|
+
ctx.reply("See you later!");
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
// Error handler for the composer chain
|
|
236
|
+
bot.catch((err, ctx) => {
|
|
237
|
+
console.error("Composer error:", err);
|
|
238
|
+
});
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### MessengerContext
|
|
242
|
+
|
|
243
|
+
Each composer handler receives a `MessengerContext` with:
|
|
244
|
+
|
|
245
|
+
| Property / Method | Description |
|
|
246
|
+
|-----------------------|-----------------------------------------------|
|
|
247
|
+
| `ctx.text` | Trimmed message body |
|
|
248
|
+
| `ctx.body` | Raw message body |
|
|
249
|
+
| `ctx.threadID` | Thread the message belongs to |
|
|
250
|
+
| `ctx.senderID` | User who sent the message |
|
|
251
|
+
| `ctx.messageID` | Unique message identifier |
|
|
252
|
+
| `ctx.event` | Full `MessageEvent` object |
|
|
253
|
+
| `ctx.reply(payload)` | Send a reply (callback-style) |
|
|
254
|
+
| `ctx.replyAsync(payload)` | Send a reply (returns a `Promise`) |
|
|
255
|
+
|
|
256
|
+
### Lifecycle
|
|
257
|
+
|
|
258
|
+
```javascript
|
|
259
|
+
await bot.launch({ stopOnSignals: true });
|
|
260
|
+
|
|
261
|
+
// Graceful shutdown
|
|
262
|
+
await bot.stop();
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
When `stopOnSignals` is `true`, the bot automatically calls `stop()` on `SIGINT` / `SIGTERM`.
|
|
266
|
+
|
|
267
|
+
---
|
|
268
|
+
|
|
269
|
+
## Configuration
|
|
270
|
+
|
|
271
|
+
Copy the example config and edit it:
|
|
272
|
+
|
|
273
|
+
```bash
|
|
274
|
+
cp fca-config.example.json fca-config.json
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### Configuration blocks
|
|
278
|
+
|
|
279
|
+
| Block | Purpose |
|
|
280
|
+
|-----------------|-------------------------------------------------------------------------------|
|
|
281
|
+
| `checkUpdate` | Automatic npm version check on startup |
|
|
282
|
+
| `mqtt` | MQTT reconnect interval, enable/disable realtime |
|
|
283
|
+
| `autoLogin` | Re-authenticate automatically when the session expires |
|
|
284
|
+
| `credentials` | Email / password / 2FA secret for auto-login |
|
|
285
|
+
| `antiGetInfo` | Toggle SQLite-backed caching for `getThreadInfo` / `getUserInfo` |
|
|
286
|
+
| `remoteControl` | WebSocket-based remote control for external dashboards |
|
|
287
|
+
| `apiServer` | External API server URL for token-based login |
|
|
288
|
+
|
|
289
|
+
### Login options (`FcaOptions`)
|
|
290
|
+
|
|
291
|
+
| Option | Type | Default | Description |
|
|
292
|
+
|-------------------|-----------|-----------|--------------------------------------------------|
|
|
293
|
+
| `listenEvents` | `boolean` | `false` | Receive thread events (not just messages) |
|
|
294
|
+
| `selfListen` | `boolean` | `false` | Receive your own messages |
|
|
295
|
+
| `selfListenEvent` | `boolean` | `false` | Receive your own thread events |
|
|
296
|
+
| `listenTyping` | `boolean` | `false` | Receive typing indicators |
|
|
297
|
+
| `updatePresence` | `boolean` | `false` | Receive presence/online status updates |
|
|
298
|
+
| `forceLogin` | `boolean` | `false` | Force login even if already logged in |
|
|
299
|
+
| `autoMarkRead` | `boolean` | `false` | Automatically mark messages as read |
|
|
300
|
+
| `autoReconnect` | `boolean` | `false` | Reconnect MQTT automatically on disconnect |
|
|
301
|
+
| `online` | `boolean` | `false` | Appear online to other users |
|
|
302
|
+
| `emitReady` | `boolean` | `false` | Emit a `ready` event when MQTT connects |
|
|
303
|
+
| `userAgent` | `string` | Chrome UA | Custom User-Agent header |
|
|
304
|
+
| `proxy` | `string` | — | HTTP/SOCKS proxy URL |
|
|
305
|
+
| `pageID` | `string` | — | Act as a Facebook Page instead of a user |
|
|
306
|
+
| `logLevel` | `string` | `"info"` | Logging verbosity (`silly`, `info`, `warn`, `error`, `silent`) |
|
|
307
|
+
|
|
308
|
+
---
|
|
309
|
+
|
|
310
|
+
## Features Overview
|
|
311
|
+
|
|
312
|
+
### Messaging
|
|
313
|
+
Send text, attachments, stickers; edit, unsend, delete messages; forward attachments; upload files; set reactions; share contacts; send typing indicators; mark as read/delivered/seen.
|
|
314
|
+
|
|
315
|
+
### Threads
|
|
316
|
+
Get thread info and history; list threads; search threads; create groups; add/remove participants; change admin status; change group name, image, color, emoji; create polls; archive/mute/delete threads; handle message requests.
|
|
317
|
+
|
|
318
|
+
### Users
|
|
319
|
+
Look up user info (single and batch); resolve user IDs from vanity URLs; get friends list.
|
|
320
|
+
|
|
321
|
+
### Account
|
|
322
|
+
Change avatar, bio, blocked status; handle friend requests; unfriend; set post reactions; refresh `fb_dtsg`; logout; manage external modules; auto-save app state.
|
|
323
|
+
|
|
324
|
+
### Realtime (MQTT)
|
|
325
|
+
Persistent WebSocket connection to Facebook's MQTT broker. Receives messages, reactions, typing indicators, presence, thread events, read receipts, and more in real time. Automatic reconnection with debounce and jitter.
|
|
326
|
+
|
|
327
|
+
### Database (optional)
|
|
328
|
+
SQLite-backed caching via Sequelize. Thread and user data are cached locally to reduce API calls. Thread cache is kept in sync with realtime events through `attachThreadInfoRealtimeSync`.
|
|
329
|
+
|
|
330
|
+
### Scheduler
|
|
331
|
+
Built-in scheduling domain for deferred or periodic tasks.
|
|
332
|
+
|
|
333
|
+
---
|
|
334
|
+
|
|
335
|
+
## Project Documentation
|
|
336
|
+
|
|
337
|
+
| Document | Contents |
|
|
338
|
+
|------------------------------------------------|---------------------------------------------------------|
|
|
339
|
+
| [docs/DOCS.md](./docs/DOCS.md) | Full API reference: login, facade, MessengerBot, MQTT, caching |
|
|
340
|
+
| [docs/ARCHITECTURE.md](./docs/ARCHITECTURE.md) | Source tree layout, bootstrap flow, module design |
|
|
341
|
+
| [CHANGELOG](https://github.com/bdrakib123/hoon-fca/blob/main/CHANGELOG.md) | Version history (repository only; not in the npm package) |
|
|
342
|
+
| [fca-config.example.json](./fca-config.example.json) | Sample configuration file |
|
|
343
|
+
|
|
344
|
+
---
|
|
345
|
+
|
|
346
|
+
## Requirements
|
|
347
|
+
|
|
348
|
+
- **Node.js** >= 20.18.1
|
|
349
|
+
- **npm** or any compatible package manager
|
|
350
|
+
|
|
351
|
+
---
|
|
352
|
+
|
|
353
|
+
## License
|
|
354
|
+
|
|
355
|
+
This project is licensed under the **Apache License, Version 2.0**. See the [LICENSE](./LICENSE) file for the full text.
|
|
356
|
+
|
|
357
|
+
---
|
|
358
|
+
|
|
359
|
+
## Links
|
|
360
|
+
|
|
361
|
+
- **npm:** [@cexi/hoonfca](https://www.npmjs.com/package/@cexi/hoonfca)
|
|
362
|
+
- **GitHub:** [bdrakib123/hoon-fca](https://github.com/bdrakib123/hoon-fca)
|
|
363
|
+
- **Issues:** [GitHub Issues](https://github.com/bdrakib123/hoon-fca/issues)
|
|
364
|
+
- **Author:** Rakib — [GitHub](https://github.com/bdrakib123)
|
package/dist/cjs.cjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const m = require("./index.js");
|
|
3
|
+
const core = typeof m.login === "function" ? m.login : m.default;
|
|
4
|
+
if (typeof core !== "function") {
|
|
5
|
+
throw new Error("@cexi/hoonfca: expected login to be a function (check dist/index.js exports).");
|
|
6
|
+
}
|
|
7
|
+
Object.assign(core, m);
|
|
8
|
+
core.default = core;
|
|
9
|
+
module.exports = core;
|