nexus-fca 3.0.1 β 3.0.3
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/README.md +1 -0
- package/docs/README.md +3 -0
- package/docs/advanced-configuration.md +101 -0
- package/docs/configuration-reference.md +195 -0
- package/docs/cookie-management.md +87 -0
- package/docs/deployment-config.md +178 -0
- package/index.js +198 -33
- package/lib/logger.js +0 -1
- package/lib/safety/CookieManager.js +168 -0
- package/lib/safety/CookieRefresher.js +277 -0
- package/lib/safety/DeviceManager.js +161 -0
- package/lib/safety/SessionLock.js +3 -0
- package/lib/safety/SingleSessionGuard.js +99 -0
- package/lib/safety/sessionStability.js +3 -0
- package/package.json +1 -1
- package/src/listenMqtt.js +12 -5
- package/lib/login.js +0 -0
package/README.md
CHANGED
|
@@ -147,6 +147,7 @@ const login = require('nexus-fca');
|
|
|
147
147
|
|----------|----------|
|
|
148
148
|
| Full API Reference | `DOCS.md` |
|
|
149
149
|
| Feature Guides | `docs/*.md` |
|
|
150
|
+
| Configuration Reference | `docs/configuration-reference.md` |
|
|
150
151
|
| Safety Details | `docs/account-safety.md` |
|
|
151
152
|
| Examples | `examples/` |
|
|
152
153
|
|
package/docs/README.md
CHANGED
|
@@ -22,6 +22,9 @@ This folder contains comprehensive documentation for all features of Nexus-FCA,
|
|
|
22
22
|
### π§ Core API Documentation
|
|
23
23
|
Each `.md` file documents a single core API feature with usage examples, parameters, and safety notes.
|
|
24
24
|
|
|
25
|
+
Additional references:
|
|
26
|
+
- [Configuration Reference](./configuration-reference.md) β all env vars, programmatic options, and config file keys
|
|
27
|
+
|
|
25
28
|
### π Migration Guides
|
|
26
29
|
- **[Migration-fca-unofficial.md](./Migration-fca-unofficial.md)** - Migrate from fca-unofficial
|
|
27
30
|
- **[Migration-ws3-fca.md](./Migration-ws3-fca.md)** - Migrate from ws3-fca
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# Advanced Configuration Options for Nexus-FCA
|
|
2
|
+
|
|
3
|
+
This document outlines additional configuration options available to optimize your Nexus-FCA experience.
|
|
4
|
+
|
|
5
|
+
## Environment Variables
|
|
6
|
+
|
|
7
|
+
Nexus-FCA supports various environment variables to fine-tune its behavior:
|
|
8
|
+
|
|
9
|
+
### Session Management
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
# Device persistence
|
|
13
|
+
NEXUS_PERSISTENT_DEVICE=true # Enable consistent device fingerprinting (default)
|
|
14
|
+
NEXUS_DEVICE_FILE=./device.json # Custom path to device profile file
|
|
15
|
+
|
|
16
|
+
# Single-session guard (built-in)
|
|
17
|
+
# Uses SingleSessionGuard with NEXUS_SESSION_LOCK_PATH and NEXUS_FORCE_LOCK
|
|
18
|
+
NEXUS_SESSION_LOCK_PATH=./lock # Path to session lock file used by SingleSessionGuard
|
|
19
|
+
NEXUS_FORCE_LOCK=false # Force acquire lock even if lock exists
|
|
20
|
+
|
|
21
|
+
# Region control
|
|
22
|
+
NEXUS_REGION=NA # Set fixed region (NA, EU, AS)
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Cookie Management
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
# Cookie refresher settings
|
|
29
|
+
NEXUS_COOKIE_REFRESH_INTERVAL=1800000 # Refresh interval in ms (default: 30 minutes)
|
|
30
|
+
NEXUS_COOKIE_EXPIRY_DAYS=90 # Days to extend cookie expiry
|
|
31
|
+
NEXUS_COOKIE_BACKUP_PATH=./backups # Path to store cookie backups
|
|
32
|
+
NEXUS_COOKIE_MAX_BACKUPS=5 # Maximum number of cookie backups to keep
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Connection Settings
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
# Connection resilience
|
|
39
|
+
NEXUS_MAX_RETRIES=5 # Maximum connection retry attempts
|
|
40
|
+
NEXUS_RETRY_DELAY=5000 # Base delay between retries (ms)
|
|
41
|
+
NEXUS_KEEPALIVE_INTERVAL=300000 # Keepalive interval (ms)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Safety Features
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
# Safety controls
|
|
48
|
+
NEXUS_FCA_SAFE_MODE=1 # Enable basic safety measures
|
|
49
|
+
NEXUS_FCA_ULTRA_SAFE_MODE=1 # Enable maximum safety for stability
|
|
50
|
+
NEXUS_DELIVERY_TIMEOUT=60000 # Message delivery timeout (ms)
|
|
51
|
+
NEXUS_AUTO_MARK_READ=false # Automatically mark messages as read
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## API Configuration Options
|
|
55
|
+
|
|
56
|
+
When initializing the API, you can pass additional options:
|
|
57
|
+
|
|
58
|
+
```javascript
|
|
59
|
+
const api = await login({
|
|
60
|
+
appState: require('./appstate.json'),
|
|
61
|
+
|
|
62
|
+
// Session stability options
|
|
63
|
+
persistentDevice: true, // Use consistent device fingerprinting
|
|
64
|
+
deviceFilePath: './device.json', // Custom device profile path
|
|
65
|
+
// Single-session guard is enabled by default internally
|
|
66
|
+
// Configure via env: NEXUS_SESSION_LOCK_PATH, NEXUS_FORCE_LOCK
|
|
67
|
+
|
|
68
|
+
// Connection options
|
|
69
|
+
region: 'NA', // Set fixed region
|
|
70
|
+
userAgent: 'custom-user-agent', // Override user agent
|
|
71
|
+
|
|
72
|
+
// Cookie management
|
|
73
|
+
cookieRefreshInterval: 1800000, // Cookie refresh interval (ms)
|
|
74
|
+
cookieExpiryDays: 90, // Days to extend cookie expiry
|
|
75
|
+
cookieBackupEnabled: true, // Enable cookie backups
|
|
76
|
+
cookieMaxBackups: 5, // Maximum cookie backups
|
|
77
|
+
|
|
78
|
+
// Safety options
|
|
79
|
+
forceLogout: true, // Force logout any other sessions
|
|
80
|
+
safetyLevel: 2 // Safety level (0-2)
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Best Practices
|
|
85
|
+
|
|
86
|
+
For the most stable experience:
|
|
87
|
+
|
|
88
|
+
1. **Always enable persistent device**: Use the same device fingerprint across restarts
|
|
89
|
+
2. **Enable session locking**: Prevent multiple instances from using the same account
|
|
90
|
+
3. **Set a fixed region**: Use the `NEXUS_REGION` environment variable
|
|
91
|
+
4. **Use a modern user agent**: Let the system select an appropriate one
|
|
92
|
+
5. **Keep cookie refreshing enabled**: Maintains fresh cookies
|
|
93
|
+
6. **Back up working appstate files**: Keep copies of working sessions
|
|
94
|
+
|
|
95
|
+
## Security Considerations
|
|
96
|
+
|
|
97
|
+
- Store sensitive information like appstate files securely
|
|
98
|
+
- Use environment variables for credentials instead of hardcoding
|
|
99
|
+
- Use `.env` files in development (gitignored)
|
|
100
|
+
- Consider using a dedicated account for automation
|
|
101
|
+
- Respect Facebook's terms of service and rate limits
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# Configuration Reference (Nexus-FCA 3.0)
|
|
2
|
+
|
|
3
|
+
This document lists every supported configuration surface across the project: programmatic options, config file keys, and environment variables. Use this as a single source of truth when deploying locally or to PaaS.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
## 1) Programmatic options (api.setOptions / login options)
|
|
7
|
+
|
|
8
|
+
These map to `globalOptions` and are available via `api.setOptions({ ... })` or by passing as the second argument to `login(credentials, options)`.
|
|
9
|
+
|
|
10
|
+
- Booleans
|
|
11
|
+
- `online` (default: true) β Advertise chat availability when connected
|
|
12
|
+
- `selfListen` β Receive your own sent messages
|
|
13
|
+
- `listenEvents` β Emit non-message events (nicknames, pins, joins, etc.)
|
|
14
|
+
- `listenTyping` β Emit typing events
|
|
15
|
+
- `updatePresence` β Enable presence updates processing
|
|
16
|
+
- `forceLogin` β Force legacy login behavior where applicable
|
|
17
|
+
- `autoMarkDelivery` β Auto mark delivery for inbound messages
|
|
18
|
+
- `autoMarkRead` β Auto mark read for inbound messages
|
|
19
|
+
- `autoReconnect` (default: true) β Reconnect MQTT after disconnect
|
|
20
|
+
- `emitReady` β Emit a synthetic `ready` event after connect
|
|
21
|
+
|
|
22
|
+
- Strings
|
|
23
|
+
- `logLevel`: 'silent' | 'error' | 'warn' | 'info' | 'verbose'
|
|
24
|
+
- `pageID`: string β Page scope for actions
|
|
25
|
+
- `userAgent`: string β Overrides UA for outbound requests
|
|
26
|
+
- `proxy`: string β HTTP(S) proxy URL
|
|
27
|
+
- `acceptLanguage`: string β Accept-Language header for MQTT/Web requests
|
|
28
|
+
|
|
29
|
+
- Numbers
|
|
30
|
+
- `logRecordSize` β npmlog ring buffer size
|
|
31
|
+
|
|
32
|
+
- Advanced (set via helper methods)
|
|
33
|
+
- `api.setBackoffOptions({ base, factor, max, jitter })` β Adaptive MQTT reconnect backoff tuning
|
|
34
|
+
- `api.setEditOptions({ maxPendingEdits, editTTLms, ackTimeoutMs, maxResendAttempts })` β Message edit safety controls
|
|
35
|
+
- `api.enableLazyPreflight(enable=true)` β When true, preflight is lighter/skipped if recent successful connect
|
|
36
|
+
- Group queue controls for large group threads:
|
|
37
|
+
- `api.enableGroupQueue(enable=true)`
|
|
38
|
+
- `api.setGroupQueueCapacity(n)`
|
|
39
|
+
- Internals: `groupQueueIdleMs` (default 30m) β idle purge window
|
|
40
|
+
|
|
41
|
+
Notes:
|
|
42
|
+
- Unknown keys passed to `setOptions` are warned and ignored.
|
|
43
|
+
- `api.listen` is an alias of `api.listenMqtt`.
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
## 2) Config file: fca-config.json
|
|
47
|
+
|
|
48
|
+
Auto-created in project root on first run and merged with defaults. Good for project-wide non-secret settings.
|
|
49
|
+
|
|
50
|
+
Example keys (merge-safe):
|
|
51
|
+
|
|
52
|
+
```json
|
|
53
|
+
{
|
|
54
|
+
"autoUpdate": true,
|
|
55
|
+
"mqtt": { "enabled": true, "reconnectInterval": 3600 },
|
|
56
|
+
"logLevel": "warn",
|
|
57
|
+
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) ...",
|
|
58
|
+
"proxy": "http://user:pass@host:port"
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
For secrets and per-deploy toggles, prefer environment variables.
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
## 3) Environment variables
|
|
66
|
+
|
|
67
|
+
Environment variables are the primary way to configure behavior in production. They override defaults and complement programmatic options.
|
|
68
|
+
|
|
69
|
+
### 3.1 Storage & persistence
|
|
70
|
+
- `NEXUS_DATA_DIR` β Base directory for persistent files (fallback: `RENDER_DATA_DIR` or CWD)
|
|
71
|
+
- `NEXUS_APPSTATE_PATH` β Path to appstate.json
|
|
72
|
+
- `NEXUS_CREDENTIALS_PATH` β Path to credentials.json (integrated login)
|
|
73
|
+
- `NEXUS_BACKUP_PATH` β Directory for appstate backups
|
|
74
|
+
- `NEXUS_DEVICE_FILE` β Path to persistent-device.json
|
|
75
|
+
- `NEXUS_PERSISTENT_DEVICE` = true|false β Keep stable device fingerprint
|
|
76
|
+
|
|
77
|
+
### 3.2 Networking & headers
|
|
78
|
+
- `NEXUS_PROXY` β HTTP(S) proxy URL (also respects `HTTPS_PROXY` / `HTTP_PROXY`)
|
|
79
|
+
- `NEXUS_ACCEPT_LANGUAGE` β Example: `en-US,en;q=0.9`
|
|
80
|
+
- `NEXUS_UA` β Override User-Agent
|
|
81
|
+
- `NEXUS_REGION` β Force MQTT region (e.g., `HIL`)
|
|
82
|
+
|
|
83
|
+
### 3.3 Stability & preflight
|
|
84
|
+
- `NEXUS_DISABLE_PREFLIGHT` = true|false β Skip heavy preflight validation
|
|
85
|
+
- `NEXUS_ONLINE` = true|false β Override chat availability flag
|
|
86
|
+
- `NEXUS_VERBOSE_MQTT` = true|false β Extra MQTT diagnostics logging
|
|
87
|
+
|
|
88
|
+
### 3.4 Single-session guard (prevents concurrent runs)
|
|
89
|
+
- `NEXUS_SESSION_LOCK_PATH` β Path for session lock file (default: `<DATA_DIR>/session.lock`)
|
|
90
|
+
- `NEXUS_SESSION_TTL_MS` β Lock stale timeout (default: 900000 = 15m)
|
|
91
|
+
- `NEXUS_FORCE_LOCK` = true|false β Force takeover if lock present
|
|
92
|
+
|
|
93
|
+
### 3.5 Safety layer & allow/block lists
|
|
94
|
+
- `NEXUS_FCA_ULTRA_SAFE_MODE` = '1' β Maximum protection presets
|
|
95
|
+
- `NEXUS_FCA_SAFE_MODE` = '1' β Safe mode presets
|
|
96
|
+
- `NEXUS_FCA_ALLOW_LIST` β Comma-separated userIDs allowed
|
|
97
|
+
- `NEXUS_FCA_BLOCK_LIST` β Comma-separated userIDs blocked
|
|
98
|
+
|
|
99
|
+
### 3.6 Example-only envs (for quick scripts)
|
|
100
|
+
Used in example snippets and README demos; not used by the core library itself:
|
|
101
|
+
- `FB_EMAIL` β Facebook username/email
|
|
102
|
+
- `FB_PASS` / `FB_PASSWORD` β Facebook password
|
|
103
|
+
- `FB_2FA_SECRET` β TOTP secret for 2FA (if used)
|
|
104
|
+
- `EMAIL` / `PASSWORD` β Alternative names used in example scripts
|
|
105
|
+
- `DEBUG` β e.g. `nexus-fca:*` to enable debug output in certain examples
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
## 4) Integrated Nexus Login System options
|
|
109
|
+
|
|
110
|
+
Used internally for credential-based login; also exported for direct use via `IntegratedNexusLoginSystem`. Options can be provided in code or via the env overrides above.
|
|
111
|
+
|
|
112
|
+
- Paths & persistence
|
|
113
|
+
- `appstatePath` (env: `NEXUS_APPSTATE_PATH`)
|
|
114
|
+
- `credentialsPath` (env: `NEXUS_CREDENTIALS_PATH`)
|
|
115
|
+
- `backupPath` (env: `NEXUS_BACKUP_PATH`)
|
|
116
|
+
- `persistentDevice` (env: `NEXUS_PERSISTENT_DEVICE`)
|
|
117
|
+
- `persistentDeviceFile` (env: `NEXUS_DEVICE_FILE`)
|
|
118
|
+
|
|
119
|
+
- Behavior
|
|
120
|
+
- `autoLogin` (default: true)
|
|
121
|
+
- `autoSave` (default: true)
|
|
122
|
+
- `safeMode` (default: true)
|
|
123
|
+
- `maxRetries` (default: 3)
|
|
124
|
+
- `retryDelay` (default: 5000 ms)
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
## 5) MQTT & connection behavior
|
|
128
|
+
|
|
129
|
+
Controlled via programmatic options and envs:
|
|
130
|
+
|
|
131
|
+
- `autoReconnect` (default true) β Reconnect on close/error
|
|
132
|
+
- Backoff: `api.setBackoffOptions({ base, factor, max, jitter })`
|
|
133
|
+
- Keepalives & diagnostics: `NEXUS_VERBOSE_MQTT` for extra logs
|
|
134
|
+
- Headers: `acceptLanguage`, `userAgent`, `proxy`
|
|
135
|
+
- Region override: `NEXUS_REGION`
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
## 6) Delivery & read behavior
|
|
139
|
+
|
|
140
|
+
- `autoMarkDelivery` β Calls `markAsDelivered` for inbound messages
|
|
141
|
+
- `autoMarkRead` β Optional follow-up read marking
|
|
142
|
+
- Adaptive suppression & retries are built-in; metrics accessible via `api.getHealthMetrics()`
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
## 7) Health and memory metrics
|
|
146
|
+
|
|
147
|
+
- `api.getHealthMetrics()` β ACKs, reconnect counts, delivery stats, last connect timestamps, etc.
|
|
148
|
+
- `api.getMemoryMetrics()` β Pending edits, outbound queue depth, group queue prunes, memory guard actions
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
## 8) Logging
|
|
152
|
+
|
|
153
|
+
- `logLevel`: 'silent' | 'error' | 'warn' | 'info' | 'verbose'
|
|
154
|
+
- `logRecordSize`: ring buffer size
|
|
155
|
+
- Temporarily increase MQTT verbosity with `NEXUS_VERBOSE_MQTT=true` when debugging
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
## 9) Quick matrix (where to set)
|
|
159
|
+
|
|
160
|
+
| Setting | setOptions | login options | fca-config.json | ENV |
|
|
161
|
+
|--------------------------------|------------|---------------|-----------------|-----|
|
|
162
|
+
| online | β
| β
| | β
(`NEXUS_ONLINE`) |
|
|
163
|
+
| selfListen / listenEvents | β
| β
| | |
|
|
164
|
+
| updatePresence | β
| β
| | |
|
|
165
|
+
| autoMarkDelivery / autoMarkRead| β
| β
| | |
|
|
166
|
+
| autoReconnect | β
| β
| | |
|
|
167
|
+
| userAgent | β
| β
| β
| β
(`NEXUS_UA`) |
|
|
168
|
+
| proxy | β
| β
| β
| β
(`NEXUS_PROXY`/`HTTPS_PROXY`/`HTTP_PROXY`) |
|
|
169
|
+
| acceptLanguage | β
| β
| | β
(`NEXUS_ACCEPT_LANGUAGE`) |
|
|
170
|
+
| disablePreflight | via `enableLazyPreflight(false)` | β
| | β
(`NEXUS_DISABLE_PREFLIGHT`) |
|
|
171
|
+
| pageID | β
| β
| | |
|
|
172
|
+
| backoff/edit settings | helper fns | | | |
|
|
173
|
+
| data/appstate/backup/device | | via Integrated Login | | β
(`NEXUS_*` paths) |
|
|
174
|
+
| session guard (lock/ttl/force) | | | | β
|
|
|
175
|
+
| safety modes / lists | | | | β
|
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
## 10) Recommended PaaS baseline
|
|
179
|
+
|
|
180
|
+
Set at minimum:
|
|
181
|
+
|
|
182
|
+
```
|
|
183
|
+
NEXUS_DATA_DIR=/var/data/nexus-fca
|
|
184
|
+
NEXUS_APPSTATE_PATH=/var/data/nexus-fca/appstate.json
|
|
185
|
+
NEXUS_DEVICE_FILE=/var/data/nexus-fca/persistent-device.json
|
|
186
|
+
NEXUS_PERSISTENT_DEVICE=true
|
|
187
|
+
NEXUS_ACCEPT_LANGUAGE=en-US,en;q=0.9
|
|
188
|
+
# Optional hardening
|
|
189
|
+
NEXUS_DISABLE_PREFLIGHT=true
|
|
190
|
+
# Optional proxy/region
|
|
191
|
+
# NEXUS_PROXY=http://user:pass@host:port
|
|
192
|
+
# NEXUS_REGION=HIL
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
See also: `docs/deployment-config.md` for end-to-end deployment steps.
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Cookie Expiry and Session Management Guide
|
|
2
|
+
|
|
3
|
+
This document explains how Nexus-FCA handles cookie management to prevent rapid session expiry and improve overall stability.
|
|
4
|
+
|
|
5
|
+
## Understanding the Issue
|
|
6
|
+
|
|
7
|
+
Facebook cookies may expire rapidly (within hours) due to several reasons:
|
|
8
|
+
|
|
9
|
+
1. **Missing Expiry Dates**: Some cookies don't have proper expiry timestamps
|
|
10
|
+
2. **Short-lived Sessions**: Facebook may issue cookies with short expiry times
|
|
11
|
+
3. **Device Inconsistency**: Using different device profiles between sessions
|
|
12
|
+
4. **Multiple Sessions**: Running multiple bots with the same account
|
|
13
|
+
5. **Security Triggers**: Suspicious activities triggering Facebook safety mechanisms
|
|
14
|
+
|
|
15
|
+
## Nexus-FCA Solution
|
|
16
|
+
|
|
17
|
+
Nexus-FCA implements a robust multi-layered approach to maintain session stability:
|
|
18
|
+
|
|
19
|
+
### 1. Cookie Expiry Extension
|
|
20
|
+
|
|
21
|
+
The system automatically extends cookie expiry dates:
|
|
22
|
+
|
|
23
|
+
- Critical cookies (`c_user`, `xs`, `fr`, `datr`, `sb`) are extended to 90 days
|
|
24
|
+
- All cookies are validated at startup and fixed if needed
|
|
25
|
+
- Proper expiry format is enforced using the standard RFC format
|
|
26
|
+
|
|
27
|
+
### 2. Persistent Device Profile
|
|
28
|
+
|
|
29
|
+
To maintain consistency across restarts:
|
|
30
|
+
|
|
31
|
+
- Device fingerprints (device ID, user agent, family device ID) are preserved
|
|
32
|
+
- The same device profile is used for all requests
|
|
33
|
+
- Configuration option: `persistentDevice: true` (enabled by default)
|
|
34
|
+
|
|
35
|
+
### 3. Cookie Refresher
|
|
36
|
+
|
|
37
|
+
An active background service keeps your session fresh:
|
|
38
|
+
|
|
39
|
+
- Periodically refreshes cookies (every 30 minutes)
|
|
40
|
+
- Makes lightweight requests to maintain session activity
|
|
41
|
+
- Extends cookie expiry dates automatically
|
|
42
|
+
- Creates backups of working sessions
|
|
43
|
+
|
|
44
|
+
### 4. Single Session Guard
|
|
45
|
+
|
|
46
|
+
Prevents multiple instances from using the same account:
|
|
47
|
+
|
|
48
|
+
- File-based locking mechanism prevents duplicate sessions
|
|
49
|
+
- Ensures Facebook sees consistent device information
|
|
50
|
+
- Configuration via `NEXUS_SESSION_LOCK_PATH` and `NEXUS_FORCE_LOCK`
|
|
51
|
+
|
|
52
|
+
## Best Practices
|
|
53
|
+
|
|
54
|
+
For maximum session stability:
|
|
55
|
+
|
|
56
|
+
1. **Use Persistent Device**: Always enable persistentDevice (default)
|
|
57
|
+
2. **Keep Proxy Consistent**: Use the same proxy for extended periods
|
|
58
|
+
3. **Set Region**: Use `NEXUS_REGION` to maintain a consistent region
|
|
59
|
+
4. **Avoid Multiple Instances**: Never run multiple bots with the same account
|
|
60
|
+
5. **Regular Backups**: Keep backups of working appstate files
|
|
61
|
+
|
|
62
|
+
## Configuration
|
|
63
|
+
|
|
64
|
+
Key environment variables for session stability:
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
# Session stability
|
|
68
|
+
NEXUS_PERSISTENT_DEVICE=true # Keep device fingerprint consistent (default)
|
|
69
|
+
NEXUS_DEVICE_FILE=./device.json # Custom device profile path
|
|
70
|
+
NEXUS_SESSION_LOCK_PATH=./lock # Single session lock file location
|
|
71
|
+
NEXUS_REGION=NA # Fixed region (NA, EU, AS, etc.)
|
|
72
|
+
|
|
73
|
+
# Safety settings
|
|
74
|
+
NEXUS_FCA_ULTRA_SAFE_MODE=1 # Maximum safety for stability
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Troubleshooting
|
|
78
|
+
|
|
79
|
+
If you still experience session expiry:
|
|
80
|
+
|
|
81
|
+
1. **Check Logs**: Look for warnings about cookie expiry or checkpoint
|
|
82
|
+
2. **Monitor Activity**: High message volume can trigger Facebook limits
|
|
83
|
+
3. **Fresh Login**: Generate a completely new appstate if needed
|
|
84
|
+
4. **API Limits**: Respect Facebook rate limits with delay between actions
|
|
85
|
+
5. **Secure Network**: Use residential IPs rather than datacenter IPs
|
|
86
|
+
|
|
87
|
+
The new cookie management system should significantly improve stability and prevent the rapid expiry issues previously encountered.
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# Deployment & Configuration Guide (Nexus-FCA 3.0)
|
|
2
|
+
|
|
3
|
+
This guide shows how to use Nexus-FCA as an npm package, configure it via file and environment variables, deploy safely on platforms like Render, and avoid the βyou couldn't create multiple sessionsβ warning.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
## 1) Using as an npm package
|
|
7
|
+
|
|
8
|
+
Install:
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install nexus-fca
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Basic appstate usage:
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
const login = require('nexus-fca');
|
|
18
|
+
|
|
19
|
+
(async () => {
|
|
20
|
+
const api = await login({ appState: require('./appstate.json') });
|
|
21
|
+
api.listen((err, evt) => {
|
|
22
|
+
if (err) return console.error(err);
|
|
23
|
+
if (evt.body) api.sendMessage('Echo: ' + evt.body, evt.threadID);
|
|
24
|
+
});
|
|
25
|
+
})();
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
## 2) Configuration options
|
|
30
|
+
|
|
31
|
+
You can control behavior via:
|
|
32
|
+
- Programmatic options: `api.setOptions({ ... })`
|
|
33
|
+
- Config file: `fca-config.json` (auto-created on first run)
|
|
34
|
+
- Environment variables (recommended for hosting)
|
|
35
|
+
|
|
36
|
+
### 2.1 Programmatic options (common)
|
|
37
|
+
```js
|
|
38
|
+
api.setOptions({
|
|
39
|
+
autoReconnect: true,
|
|
40
|
+
updatePresence: false,
|
|
41
|
+
selfListen: false,
|
|
42
|
+
logLevel: 'warn', // npmlog level: silly|verbose|info|warn|error
|
|
43
|
+
userAgent: '...Chrome/...',
|
|
44
|
+
proxy: 'http://user:pass@host:port',
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### 2.2 Config file: `fca-config.json`
|
|
49
|
+
A default file is stored at project root and merged with internal defaults. You can keep project-wide settings here:
|
|
50
|
+
|
|
51
|
+
```json
|
|
52
|
+
{
|
|
53
|
+
"autoUpdate": true,
|
|
54
|
+
"mqtt": { "enabled": true, "reconnectInterval": 3600 },
|
|
55
|
+
"logLevel": "warn",
|
|
56
|
+
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)...",
|
|
57
|
+
"proxy": "http://user:pass@host:port"
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Note: For secrets and deployment toggles, prefer environment variables below.
|
|
62
|
+
|
|
63
|
+
### 2.3 Environment variables (hosting-friendly)
|
|
64
|
+
These are read at runtime and override defaults:
|
|
65
|
+
|
|
66
|
+
- Storage & persistence
|
|
67
|
+
- `NEXUS_DATA_DIR` β base directory for persistent files
|
|
68
|
+
- `NEXUS_APPSTATE_PATH` β path to `appstate.json`
|
|
69
|
+
- `NEXUS_DEVICE_FILE` β path to `persistent-device.json`
|
|
70
|
+
- `NEXUS_BACKUP_PATH` β directory for appstate backups
|
|
71
|
+
- `NEXUS_PERSISTENT_DEVICE` β `true|false` (keep same device fingerprint)
|
|
72
|
+
|
|
73
|
+
- Networking & headers
|
|
74
|
+
- `NEXUS_PROXY` (or `HTTPS_PROXY` / `HTTP_PROXY`) β Proxy URL
|
|
75
|
+
- `NEXUS_ACCEPT_LANGUAGE` β e.g. `en-US,en;q=0.9`
|
|
76
|
+
- `NEXUS_UA` β override User-Agent
|
|
77
|
+
- `NEXUS_REGION` β force MQTT region (e.g., `HIL`)
|
|
78
|
+
|
|
79
|
+
- Stability & preflight
|
|
80
|
+
- `NEXUS_DISABLE_PREFLIGHT` β `true|false` (skip heavy session preflight)
|
|
81
|
+
- `NEXUS_ONLINE` β `true|false`
|
|
82
|
+
- `NEXUS_VERBOSE_MQTT` β `true|false` (extra MQTT logs only when needed)
|
|
83
|
+
|
|
84
|
+
Example (Render):
|
|
85
|
+
```
|
|
86
|
+
NEXUS_DATA_DIR=/var/data/nexus-fca
|
|
87
|
+
NEXUS_APPSTATE_PATH=/var/data/nexus-fca/appstate.json
|
|
88
|
+
NEXUS_DEVICE_FILE=/var/data/nexus-fca/persistent-device.json
|
|
89
|
+
NEXUS_BACKUP_PATH=/var/data/nexus-fca/backups
|
|
90
|
+
NEXUS_PERSISTENT_DEVICE=true
|
|
91
|
+
|
|
92
|
+
NEXUS_ACCEPT_LANGUAGE=en-US,en;q=0.9
|
|
93
|
+
NEXUS_UA=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
|
|
94
|
+
NEXUS_DISABLE_PREFLIGHT=true
|
|
95
|
+
NEXUS_ONLINE=false
|
|
96
|
+
# Optional region & proxy
|
|
97
|
+
# NEXUS_REGION=HIL
|
|
98
|
+
# NEXUS_PROXY=http://user:pass@host:port
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
## 3) Deploying on Render (or other PaaS)
|
|
103
|
+
|
|
104
|
+
1) Persistent disk
|
|
105
|
+
- Mount a disk and point `NEXUS_DATA_DIR` to it.
|
|
106
|
+
- Ensure `appstate.json` and `persistent-device.json` live on this disk.
|
|
107
|
+
|
|
108
|
+
2) Single instance per account
|
|
109
|
+
- Run only one service instance for a given account.
|
|
110
|
+
- Disable autoscaling/replicas for this worker.
|
|
111
|
+
|
|
112
|
+
3) Environment hardening
|
|
113
|
+
- Set `NEXUS_PERSISTENT_DEVICE=true` to anchor device fingerprint.
|
|
114
|
+
- Set `NEXUS_DISABLE_PREFLIGHT=true` to reduce heavy checks.
|
|
115
|
+
- Optionally use a reputable residential/mobile proxy via `NEXUS_PROXY`.
|
|
116
|
+
|
|
117
|
+
4) Keep your appstate fresh
|
|
118
|
+
- Generate appstate locally on a trusted network, then deploy it.
|
|
119
|
+
- Avoid frequent credential logins from the server itself.
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
## 4) "You couldn't create multiple sessions" β what it means and fixes
|
|
123
|
+
|
|
124
|
+
This warning typically appears when Facebook detects concurrent or rapidly rotating logins for the same account, often from:
|
|
125
|
+
- Multiple bots/instances using the same account at the same time
|
|
126
|
+
- Different IPs or device fingerprints in quick succession
|
|
127
|
+
- Frequent logouts/re-logins (or unstable appstate)
|
|
128
|
+
|
|
129
|
+
How to avoid:
|
|
130
|
+
- Run exactly one bot instance per account.
|
|
131
|
+
- Reuse the same `appstate.json` and `persistent-device.json` (set `NEXUS_PERSISTENT_DEVICE=true`).
|
|
132
|
+
- Avoid logging in with username/password from multiple placesβgenerate appstate once and reuse it.
|
|
133
|
+
- Use a stable IP. If your PaaS IPs rotate or look like a datacenter bot, use a reputable residential/mobile proxy.
|
|
134
|
+
- Keep preflight light on PaaS (`NEXUS_DISABLE_PREFLIGHT=true`).
|
|
135
|
+
|
|
136
|
+
Recovery steps when you see the warning:
|
|
137
|
+
- Stop all other running instances for the same account.
|
|
138
|
+
- Log in manually in a browser, pass any checkpoint, verify recent logins.
|
|
139
|
+
- Regenerate a fresh appstate (locally), deploy, and keep it persistent.
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
## 5) Minimal config-first example
|
|
143
|
+
|
|
144
|
+
`fca-config.json` (project root):
|
|
145
|
+
```json
|
|
146
|
+
{
|
|
147
|
+
"logLevel": "warn",
|
|
148
|
+
"mqtt": { "enabled": true, "reconnectInterval": 3600 },
|
|
149
|
+
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/121.0.0.0 Safari/537.36"
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Bot code:
|
|
154
|
+
```js
|
|
155
|
+
const login = require('nexus-fca');
|
|
156
|
+
(async () => {
|
|
157
|
+
const api = await login({ appState: require(process.env.NEXUS_APPSTATE_PATH || './appstate.json') });
|
|
158
|
+
// Optional fine-tuning
|
|
159
|
+
api.setOptions({
|
|
160
|
+
autoReconnect: true,
|
|
161
|
+
updatePresence: false,
|
|
162
|
+
proxy: process.env.NEXUS_PROXY,
|
|
163
|
+
});
|
|
164
|
+
api.listen((err, evt) => {
|
|
165
|
+
if (err) return console.error(err);
|
|
166
|
+
if (evt.body) api.sendMessage('Echo: ' + evt.body, evt.threadID);
|
|
167
|
+
});
|
|
168
|
+
})();
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
## 6) Troubleshooting quick tips
|
|
173
|
+
- Rapid cookie expiry: ensure persistence paths are on mounted disk; set `NEXUS_PERSISTENT_DEVICE=true`.
|
|
174
|
+
- Frequent reconnect warnings: let adaptive backoff work; keep `autoReconnect=true`.
|
|
175
|
+
- No replies sent: check proxy/network egress; use delivery metrics via `api.getHealthMetrics()`.
|
|
176
|
+
- Noisy logs: avoid `NEXUS_VERBOSE_MQTT` unless debugging; prefer `logLevel=warn`.
|
|
177
|
+
|
|
178
|
+
For full API details, see `DOCS.md` and other files in `docs/`.
|