stfca 1.0.2 → 1.0.4
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 +32 -0
- package/README.md +45 -2
- package/checkUpdate.js +109 -0
- package/index.js +460 -1
- package/package.json +22 -46
- package/src/OldMessage.js +234 -0
- package/src/{api/action/addExternalModule.js → addExternalModule.js} +25 -25
- package/src/addUserToGroup.js +115 -0
- package/src/changeAdminStatus.js +103 -0
- package/src/changeArchivedStatus.js +55 -0
- package/src/{api/action/changeAvatar.js → changeAvatar.js} +136 -137
- package/src/changeAvatarV2.js +86 -0
- package/src/changeAvt.js +85 -0
- package/src/{api/action/changeBio.js → changeBio.js} +76 -75
- package/src/{api/messaging/changeBlockedStatus.js → changeBlockedStatus.js} +49 -48
- package/src/changeBlockedStatusMqtt.js +80 -0
- package/src/changeCover.js +72 -0
- package/src/changeGroupImage.js +135 -0
- package/src/changeName.js +79 -0
- package/src/changeNickname.js +59 -0
- package/src/changeThreadColor.js +65 -0
- package/src/changeThreadEmoji.js +55 -0
- package/src/changeUsername.js +59 -0
- package/src/createCommentPost.js +230 -0
- package/src/{api/messaging/createNewGroup.js → createNewGroup.js} +88 -88
- package/src/createPoll.js +71 -0
- package/src/createPost.js +276 -0
- package/src/{api/messaging/deleteMessage.js → deleteMessage.js} +56 -56
- package/src/{api/messaging/deleteThread.js → deleteThread.js} +56 -56
- package/src/editMessage.js +68 -0
- package/src/editMessageOld.js +67 -0
- package/src/follow.js +74 -0
- package/src/forwardAttachment.js +60 -0
- package/src/getAccess.js +112 -0
- package/src/getAvatarUser.js +78 -0
- package/src/{api/action/getCurrentUserID.js → getCurrentUserID.js} +7 -7
- package/src/{api/messaging/getEmojiUrl.js → getEmojiUrl.js} +2 -2
- package/src/{api/messaging/getFriendsList.js → getFriendsList.js} +83 -82
- package/src/{api/messaging/getMessage.js → getMessage.js} +847 -829
- package/src/getRegion.js +7 -0
- package/src/{api/threads/getThreadHistory.js → getThreadHistory.js} +680 -664
- package/src/getThreadHistoryDeprecated.js +71 -0
- package/src/getThreadInfo.js +232 -0
- package/src/getThreadInfoDeprecated.js +56 -0
- package/src/getThreadList.js +213 -0
- package/src/getThreadListDeprecated.js +46 -0
- package/src/getThreadPictures.js +59 -0
- package/src/getUID.js +119 -0
- package/src/{api/users/getUserID.js → getUserID.js} +61 -65
- package/src/getUserInfo.js +66 -0
- package/src/handleFriendRequest.js +46 -0
- package/src/handleMessageRequest.js +47 -0
- package/src/httpGet.js +49 -0
- package/src/httpPost.js +48 -0
- package/src/listenMqtt.js +864 -0
- package/src/logout.js +75 -0
- package/src/markAsDelivered.js +47 -0
- package/src/markAsRead.js +70 -0
- package/src/markAsReadAll.js +40 -0
- package/src/markAsSeen.js +48 -0
- package/src/muteThread.js +45 -0
- package/src/refreshFb_dtsg.js +89 -0
- package/src/removeUserFromGroup.js +79 -0
- package/src/{api/messaging/resolvePhotoUrl.js → resolvePhotoUrl.js} +45 -43
- package/src/{api/messaging/searchForThread.js → searchForThread.js} +53 -52
- package/src/searchStickers.js +53 -0
- package/src/sendMessage.js +234 -0
- package/src/{api/messaging/sendMessageMqtt.js → sendMessageMqtt.js} +322 -323
- package/src/sendTypingIndicator.js +101 -0
- package/src/sendTypingIndicatorV2.js +28 -0
- package/src/setMessageReaction.js +122 -0
- package/src/setMessageReactionMqtt.js +62 -0
- package/src/{api/action/setPostReaction.js → setPostReaction.js} +112 -106
- package/src/setStoryReaction.js +64 -0
- package/src/setTitle.js +90 -0
- package/src/shareContact.js +110 -0
- package/src/shareLink.js +59 -0
- package/src/stopListenMqtt.js +23 -0
- package/src/{api/messaging/threadColors.js → threadColors.js} +131 -128
- package/src/{api/action/unfriend.js → unfriend.js} +52 -54
- package/src/unsendMessage.js +45 -0
- package/src/{api/messaging/uploadAttachment.js → uploadAttachment.js} +93 -95
- package/utils.js +2876 -0
- package/LICENSE-MIT +0 -4
- package/index.d.ts +0 -615
- package/module/config.js +0 -33
- package/module/login.js +0 -48
- package/module/loginHelper.js +0 -722
- package/module/options.js +0 -44
- package/src/api/action/handleFriendRequest.js +0 -57
- package/src/api/action/logout.js +0 -76
- package/src/api/action/refreshFb_dtsg.js +0 -71
- package/src/api/http/httpGet.js +0 -46
- package/src/api/http/httpPost.js +0 -52
- package/src/api/http/postFormData.js +0 -47
- package/src/api/messaging/addUserToGroup.js +0 -68
- package/src/api/messaging/changeAdminStatus.js +0 -122
- package/src/api/messaging/changeArchivedStatus.js +0 -55
- package/src/api/messaging/changeGroupImage.js +0 -90
- package/src/api/messaging/changeNickname.js +0 -70
- package/src/api/messaging/changeThreadColor.js +0 -79
- package/src/api/messaging/changeThreadEmoji.js +0 -106
- package/src/api/messaging/createPoll.js +0 -43
- package/src/api/messaging/editMessage.js +0 -68
- package/src/api/messaging/forwardAttachment.js +0 -51
- package/src/api/messaging/handleMessageRequest.js +0 -65
- package/src/api/messaging/markAsDelivered.js +0 -57
- package/src/api/messaging/markAsRead.js +0 -88
- package/src/api/messaging/markAsReadAll.js +0 -49
- package/src/api/messaging/markAsSeen.js +0 -61
- package/src/api/messaging/muteThread.js +0 -50
- package/src/api/messaging/removeUserFromGroup.js +0 -105
- package/src/api/messaging/sendMessage.js +0 -379
- package/src/api/messaging/sendTypingIndicator.js +0 -67
- package/src/api/messaging/setMessageReaction.js +0 -75
- package/src/api/messaging/setTitle.js +0 -119
- package/src/api/messaging/shareContact.js +0 -49
- package/src/api/messaging/unsendMessage.js +0 -81
- package/src/api/socket/core/connectMqtt.js +0 -179
- package/src/api/socket/core/getSeqID.js +0 -25
- package/src/api/socket/core/getTaskResponseData.js +0 -22
- package/src/api/socket/core/markDelivery.js +0 -12
- package/src/api/socket/core/parseDelta.js +0 -351
- package/src/api/socket/detail/buildStream.js +0 -208
- package/src/api/socket/detail/constants.js +0 -24
- package/src/api/socket/listenMqtt.js +0 -133
- package/src/api/threads/getThreadInfo.js +0 -358
- package/src/api/threads/getThreadList.js +0 -248
- package/src/api/threads/getThreadPictures.js +0 -78
- package/src/api/users/getUserInfo.js +0 -319
- package/src/api/users/getUserInfoV2.js +0 -133
- package/src/core/sendReqMqtt.js +0 -63
- package/src/database/models/index.js +0 -49
- package/src/database/models/thread.js +0 -31
- package/src/database/models/user.js +0 -32
- package/src/database/threadData.js +0 -98
- package/src/database/userData.js +0 -89
- package/src/utils/client.js +0 -214
- package/src/utils/constants.js +0 -23
- package/src/utils/format.js +0 -1111
- package/src/utils/headers.js +0 -41
- package/src/utils/request.js +0 -215
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
|
|
2
|
+
# Changelog
|
|
3
|
+
|
|
4
|
+
All notable changes to ST-FCA will be documented in this file.
|
|
5
|
+
|
|
6
|
+
## [1.0.3] - 2025-01-13
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
- 🎨 Enhanced MQTT connection logging with visual indicators
|
|
10
|
+
- 🔄 Auto-reconnect status display
|
|
11
|
+
- 📊 Connection region display
|
|
12
|
+
- ⚡ Automatic update checking and installation
|
|
13
|
+
- 💾 Automatic backup creation before updates
|
|
14
|
+
- 🎯 Better error messages and debugging
|
|
15
|
+
- 📋 Changelog tracking
|
|
16
|
+
- 🌟 Branding: "Maintained & Enhanced by ST | Sheikh Tamim"
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
- Improved console output with colors and formatting
|
|
20
|
+
- Better connection status messages
|
|
21
|
+
- Enhanced stability and error handling
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
- MQTT reconnection reliability
|
|
25
|
+
- Connection timeout handling
|
|
26
|
+
- Error message clarity
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
**Maintained & Enhanced by ST | Sheikh Tamim**
|
|
31
|
+
GitHub: https://github.com/sheikhtamimlover/ST-FCA
|
|
32
|
+
NPM: https://www.npmjs.com/package/stfca
|
package/README.md
CHANGED
|
@@ -1,9 +1,52 @@
|
|
|
1
|
-
# stfca
|
|
1
|
+
# ST-FCA (stfca)
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/stfca)
|
|
4
4
|
[](https://www.npmjs.com/package/stfca)
|
|
5
|
+
[](https://github.com/sheikhtamimlover/ST-FCA)
|
|
5
6
|
|
|
6
|
-
> **Unofficial Facebook Chat API for Node.js** - Interact with Facebook Messenger programmatically
|
|
7
|
+
> **Unofficial Facebook Chat API for Node.js** - Interact with Facebook Messenger programmatically for ST-BOT
|
|
8
|
+
>
|
|
9
|
+
> **Enhanced & Maintained by ST | Sheikh Tamim**
|
|
10
|
+
|
|
11
|
+
## 🌟 What's New in ST-FCA
|
|
12
|
+
|
|
13
|
+
- ✨ Enhanced MQTT connection logging
|
|
14
|
+
- 🔄 Auto-reconnect with configurable intervals
|
|
15
|
+
- 📊 Better connection status indicators
|
|
16
|
+
- 🎨 Improved console output with colors
|
|
17
|
+
- 🔐 Enhanced security and stability
|
|
18
|
+
- 🚀 Automatic update checking and installation
|
|
19
|
+
- 💡 Better error handling and debugging
|
|
20
|
+
|
|
21
|
+
## 📦 Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install stfca
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Or with yarn:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
yarn add stfca
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## 🔄 Auto-Update Feature
|
|
34
|
+
|
|
35
|
+
ST-FCA includes an automatic update checker that runs when your bot starts. When a new version is available:
|
|
36
|
+
|
|
37
|
+
1. 📋 Shows recent changes
|
|
38
|
+
2. 💾 Creates automatic backups
|
|
39
|
+
3. 📦 Downloads and installs updates
|
|
40
|
+
4. 🔄 Restarts automatically to apply changes
|
|
41
|
+
|
|
42
|
+
### Manual Update Check
|
|
43
|
+
|
|
44
|
+
You can also check for updates manually:
|
|
45
|
+
|
|
46
|
+
```javascript
|
|
47
|
+
const { checkForFCAUpdate } = require('stfca/checkUpdate.js');
|
|
48
|
+
await checkForFCAUpdate();
|
|
49
|
+
```
|
|
7
50
|
|
|
8
51
|
## ⚠️ Important Disclaimer
|
|
9
52
|
|
package/checkUpdate.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
|
|
2
|
+
const axios = require('axios');
|
|
3
|
+
const { execSync } = require('child_process');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
|
|
7
|
+
async function checkForFCAUpdate() {
|
|
8
|
+
try {
|
|
9
|
+
console.log('\x1b[33m%s\x1b[0m', '🔍 Checking for ST-FCA updates...');
|
|
10
|
+
|
|
11
|
+
// Get latest version from GitHub
|
|
12
|
+
const { data: packageData } = await axios.get(
|
|
13
|
+
'https://raw.githubusercontent.com/sheikhtamimlover/ST-FCA/main/package.json'
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
const latestVersion = packageData.version;
|
|
17
|
+
const currentPackagePath = path.join(__dirname, 'package.json');
|
|
18
|
+
|
|
19
|
+
// Check if package.json exists in fb-chat-api folder
|
|
20
|
+
let currentVersion = '1.0.3';
|
|
21
|
+
if (fs.existsSync(currentPackagePath)) {
|
|
22
|
+
const currentPackage = JSON.parse(fs.readFileSync(currentPackagePath, 'utf-8'));
|
|
23
|
+
currentVersion = currentPackage.version;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (latestVersion !== currentVersion) {
|
|
27
|
+
console.log('\x1b[32m%s\x1b[0m', `✨ New ST-FCA version available: ${latestVersion} (current: ${currentVersion})`);
|
|
28
|
+
console.log('\x1b[33m%s\x1b[0m', '📦 Updating ST-FCA...');
|
|
29
|
+
|
|
30
|
+
// Get changes info
|
|
31
|
+
try {
|
|
32
|
+
const { data: changesData } = await axios.get(
|
|
33
|
+
'https://raw.githubusercontent.com/sheikhtamimlover/ST-FCA/main/CHANGELOG.md'
|
|
34
|
+
);
|
|
35
|
+
console.log('\x1b[36m%s\x1b[0m', '📋 Recent Changes:');
|
|
36
|
+
const latestChanges = changesData.split('##')[1]?.split('\n').slice(0, 5).join('\n');
|
|
37
|
+
if (latestChanges) {
|
|
38
|
+
console.log(latestChanges);
|
|
39
|
+
}
|
|
40
|
+
} catch (err) {
|
|
41
|
+
// Silently ignore changelog fetch errors
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Update FCA files
|
|
45
|
+
await updateFCAFiles();
|
|
46
|
+
|
|
47
|
+
console.log('\x1b[32m%s\x1b[0m', '✅ ST-FCA updated successfully!');
|
|
48
|
+
return true;
|
|
49
|
+
} else {
|
|
50
|
+
console.log('\x1b[32m%s\x1b[0m', `✅ ST-FCA is up to date (v${currentVersion})`);
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
} catch (error) {
|
|
54
|
+
console.log('\x1b[31m%s\x1b[0m', '❌ Failed to check for ST-FCA updates:', error.message);
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function updateFCAFiles() {
|
|
60
|
+
const filesToUpdate = [
|
|
61
|
+
'index.js',
|
|
62
|
+
'utils.js',
|
|
63
|
+
'src/listenMqtt.js',
|
|
64
|
+
'package.json',
|
|
65
|
+
'README.md'
|
|
66
|
+
];
|
|
67
|
+
|
|
68
|
+
const backupDir = path.join(__dirname, 'backup_' + Date.now());
|
|
69
|
+
if (!fs.existsSync(backupDir)) {
|
|
70
|
+
fs.mkdirSync(backupDir, { recursive: true });
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
for (const file of filesToUpdate) {
|
|
74
|
+
try {
|
|
75
|
+
const targetPath = path.join(__dirname, file);
|
|
76
|
+
|
|
77
|
+
// Backup existing file
|
|
78
|
+
if (fs.existsSync(targetPath)) {
|
|
79
|
+
const backupPath = path.join(backupDir, file);
|
|
80
|
+
const backupFileDir = path.dirname(backupPath);
|
|
81
|
+
if (!fs.existsSync(backupFileDir)) {
|
|
82
|
+
fs.mkdirSync(backupFileDir, { recursive: true });
|
|
83
|
+
}
|
|
84
|
+
fs.copyFileSync(targetPath, backupPath);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Download new file
|
|
88
|
+
const { data } = await axios.get(
|
|
89
|
+
`https://raw.githubusercontent.com/sheikhtamimlover/ST-FCA/main/${file}`,
|
|
90
|
+
{ responseType: 'arraybuffer' }
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
// Ensure directory exists
|
|
94
|
+
const fileDir = path.dirname(targetPath);
|
|
95
|
+
if (!fs.existsSync(fileDir)) {
|
|
96
|
+
fs.mkdirSync(fileDir, { recursive: true });
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
fs.writeFileSync(targetPath, Buffer.from(data));
|
|
100
|
+
console.log('\x1b[32m%s\x1b[0m', ` ✓ Updated: ${file}`);
|
|
101
|
+
} catch (error) {
|
|
102
|
+
console.log('\x1b[31m%s\x1b[0m', ` ✗ Failed to update: ${file}`, error.message);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
console.log('\x1b[33m%s\x1b[0m', `💾 Backup saved to: ${backupDir}`);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
module.exports = { checkForFCAUpdate, updateFCAFiles };
|
package/index.js
CHANGED
|
@@ -1 +1,460 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var utils = require("./utils");
|
|
4
|
+
var cheerio = require("cheerio");
|
|
5
|
+
var log = require("npmlog");
|
|
6
|
+
/*var { getThemeColors } = require("../../func/utils/log.js");
|
|
7
|
+
var logger = require("../../func/utils/log.js");
|
|
8
|
+
var { cra, cv, cb, co } = getThemeColors();*/
|
|
9
|
+
log.maxRecordSize = 100;
|
|
10
|
+
var checkVerified = null;
|
|
11
|
+
const Boolean_Option = ['online', 'selfListen', 'listenEvents', 'updatePresence', 'forceLogin', 'autoMarkDelivery', 'autoMarkRead', 'listenTyping', 'autoReconnect', 'emitReady'];
|
|
12
|
+
global.ditconmemay = false;
|
|
13
|
+
|
|
14
|
+
function setOptions(globalOptions, options) {
|
|
15
|
+
Object.keys(options).map(function (key) {
|
|
16
|
+
switch (Boolean_Option.includes(key)) {
|
|
17
|
+
case true: {
|
|
18
|
+
globalOptions[key] = Boolean(options[key]);
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
case false: {
|
|
22
|
+
switch (key) {
|
|
23
|
+
case 'pauseLog': {
|
|
24
|
+
if (options.pauseLog) log.pause();
|
|
25
|
+
else log.resume();
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
case 'logLevel': {
|
|
29
|
+
log.level = options.logLevel;
|
|
30
|
+
globalOptions.logLevel = options.logLevel;
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
case 'logRecordSize': {
|
|
34
|
+
log.maxRecordSize = options.logRecordSize;
|
|
35
|
+
globalOptions.logRecordSize = options.logRecordSize;
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
case 'pageID': {
|
|
39
|
+
globalOptions.pageID = options.pageID.toString();
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
case 'userAgent': {
|
|
43
|
+
globalOptions.userAgent = (options.userAgent || 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36');
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
case 'proxy': {
|
|
47
|
+
if (typeof options.proxy != "string") {
|
|
48
|
+
delete globalOptions.proxy;
|
|
49
|
+
utils.setProxy();
|
|
50
|
+
} else {
|
|
51
|
+
globalOptions.proxy = options.proxy;
|
|
52
|
+
utils.setProxy(globalOptions.proxy);
|
|
53
|
+
}
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
default: {
|
|
57
|
+
log.warn("setOptions", "Unrecognized option given to setOptions: " + key);
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function buildAPI(globalOptions, html, jar) {
|
|
68
|
+
let fb_dtsg = null;
|
|
69
|
+
let irisSeqID = null;
|
|
70
|
+
function extractFromHTML() {
|
|
71
|
+
try {
|
|
72
|
+
const $ = cheerio.load(html);
|
|
73
|
+
$('script').each((i, script) => {
|
|
74
|
+
if (!fb_dtsg) {
|
|
75
|
+
const scriptText = $(script).html() || '';
|
|
76
|
+
const patterns = [
|
|
77
|
+
/\["DTSGInitialData",\[\],{"token":"([^"]+)"}]/,
|
|
78
|
+
/\["DTSGInitData",\[\],{"token":"([^"]+)"/,
|
|
79
|
+
/"token":"([^"]+)"/,
|
|
80
|
+
/{\\"token\\":\\"([^\\]+)\\"/,
|
|
81
|
+
/,\{"token":"([^"]+)"\},\d+\]/,
|
|
82
|
+
/"async_get_token":"([^"]+)"/,
|
|
83
|
+
/"dtsg":\{"token":"([^"]+)"/,
|
|
84
|
+
/DTSGInitialData[^>]+>([^<]+)/
|
|
85
|
+
];
|
|
86
|
+
for (const pattern of patterns) {
|
|
87
|
+
const match = scriptText.match(pattern);
|
|
88
|
+
if (match && match[1]) {
|
|
89
|
+
try {
|
|
90
|
+
const possibleJson = match[1].replace(/\\"/g, '"');
|
|
91
|
+
const parsed = JSON.parse(possibleJson);
|
|
92
|
+
fb_dtsg = parsed.token || parsed;
|
|
93
|
+
} catch {
|
|
94
|
+
fb_dtsg = match[1];
|
|
95
|
+
}
|
|
96
|
+
if (fb_dtsg) break;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
if (!fb_dtsg) {
|
|
102
|
+
const dtsgInput = $('input[name="fb_dtsg"]').val();
|
|
103
|
+
if (dtsgInput) fb_dtsg = dtsgInput;
|
|
104
|
+
}
|
|
105
|
+
const seqMatches = html.match(/irisSeqID":"([^"]+)"/);
|
|
106
|
+
if (seqMatches && seqMatches[1]) {
|
|
107
|
+
irisSeqID = seqMatches[1];
|
|
108
|
+
}
|
|
109
|
+
try {
|
|
110
|
+
const jsonMatches = html.match(/\{"dtsg":({[^}]+})/);
|
|
111
|
+
if (jsonMatches && jsonMatches[1]) {
|
|
112
|
+
const dtsgData = JSON.parse(jsonMatches[1]);
|
|
113
|
+
if (dtsgData.token) fb_dtsg = dtsgData.token;
|
|
114
|
+
}
|
|
115
|
+
} catch { }
|
|
116
|
+
if (fb_dtsg) {
|
|
117
|
+
console.log("Found fb_dtsg!");
|
|
118
|
+
}
|
|
119
|
+
} catch (e) {
|
|
120
|
+
console.log("Error finding fb_dtsg:", e);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
extractFromHTML();
|
|
124
|
+
var userID;
|
|
125
|
+
var cookies = jar.getCookies("https://www.facebook.com");
|
|
126
|
+
var userCookie = cookies.find(cookie => cookie.cookieString().startsWith("c_user="));
|
|
127
|
+
var tiktikCookie = cookies.find(cookie => cookie.cookieString().startsWith("i_user="));
|
|
128
|
+
if (!userCookie && !tiktikCookie) {
|
|
129
|
+
return log.error("Error! Your cookiestate is not valid!");
|
|
130
|
+
}
|
|
131
|
+
if (html.includes("/checkpoint/block/?next")) {
|
|
132
|
+
return log.error('error', "Appstate is dead rechange it!", 'error');
|
|
133
|
+
}
|
|
134
|
+
userID = (tiktikCookie || userCookie).cookieString().split("=")[1];
|
|
135
|
+
//logger.log(`${cra(`[ CONNECT ]`)} Logged in as ${userID}`, "DATABASE");
|
|
136
|
+
try { clearInterval(checkVerified); } catch (_) { }
|
|
137
|
+
const clientID = (Math.random() * 2147483648 | 0).toString(16);
|
|
138
|
+
let mqttEndpoint = `wss://edge-chat.facebook.com/chat?region=pnb&sid=${userID}`;
|
|
139
|
+
let region = "PNB";
|
|
140
|
+
|
|
141
|
+
try {
|
|
142
|
+
const endpointMatch = html.match(/"endpoint":"([^"]+)"/);
|
|
143
|
+
if (endpointMatch.input.includes("601051028565049")) {
|
|
144
|
+
console.log(`login error.`);
|
|
145
|
+
ditconmemay = true;
|
|
146
|
+
}
|
|
147
|
+
if (endpointMatch) {
|
|
148
|
+
mqttEndpoint = endpointMatch[1].replace(/\\\//g, '/');
|
|
149
|
+
const url = new URL(mqttEndpoint);
|
|
150
|
+
region = url.searchParams.get('region')?.toUpperCase() || "PNB";
|
|
151
|
+
}
|
|
152
|
+
} catch (e) {
|
|
153
|
+
console.log('Using default MQTT endpoint');
|
|
154
|
+
}
|
|
155
|
+
log.info('Logging in...');
|
|
156
|
+
var ctx = {
|
|
157
|
+
userID: userID,
|
|
158
|
+
jar: jar,
|
|
159
|
+
clientID: clientID,
|
|
160
|
+
globalOptions: globalOptions,
|
|
161
|
+
loggedIn: true,
|
|
162
|
+
access_token: 'NONE',
|
|
163
|
+
clientMutationId: 0,
|
|
164
|
+
mqttClient: undefined,
|
|
165
|
+
lastSeqId: irisSeqID,
|
|
166
|
+
syncToken: undefined,
|
|
167
|
+
mqttEndpoint: mqttEndpoint,
|
|
168
|
+
region: region,
|
|
169
|
+
firstListen: true,
|
|
170
|
+
fb_dtsg: fb_dtsg,
|
|
171
|
+
req_ID: 0,
|
|
172
|
+
callback_Task: {},
|
|
173
|
+
wsReqNumber: 0,
|
|
174
|
+
wsTaskNumber: 0,
|
|
175
|
+
reqCallbacks: {}
|
|
176
|
+
};
|
|
177
|
+
var api = {
|
|
178
|
+
setOptions: setOptions.bind(null, globalOptions),
|
|
179
|
+
getAppState: () => utils.getAppState(jar),
|
|
180
|
+
postFormData: (url, body) => utils.makeDefaults(html, userID, ctx).postFormData(url, ctx.jar, body)
|
|
181
|
+
};
|
|
182
|
+
var defaultFuncs = utils.makeDefaults(html, userID, ctx);
|
|
183
|
+
api.postFormData = function (url, body) {
|
|
184
|
+
return defaultFuncs.postFormData(url, ctx.jar, body);
|
|
185
|
+
};
|
|
186
|
+
api.getFreshDtsg = async function () {
|
|
187
|
+
try {
|
|
188
|
+
const res = await defaultFuncs.get('https://www.facebook.com/', jar, null, globalOptions);
|
|
189
|
+
const $ = cheerio.load(res.body);
|
|
190
|
+
let newDtsg;
|
|
191
|
+
const patterns = [
|
|
192
|
+
/\["DTSGInitialData",\[\],{"token":"([^"]+)"}]/,
|
|
193
|
+
/\["DTSGInitData",\[\],{"token":"([^"]+)"/,
|
|
194
|
+
/"token":"([^"]+)"/,
|
|
195
|
+
/name="fb_dtsg" value="([^"]+)"/
|
|
196
|
+
];
|
|
197
|
+
|
|
198
|
+
$('script').each((i, script) => {
|
|
199
|
+
if (!newDtsg) {
|
|
200
|
+
const scriptText = $(script).html() || '';
|
|
201
|
+
for (const pattern of patterns) {
|
|
202
|
+
const match = scriptText.match(pattern);
|
|
203
|
+
if (match && match[1]) {
|
|
204
|
+
newDtsg = match[1];
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
if (!newDtsg) {
|
|
212
|
+
newDtsg = $('input[name="fb_dtsg"]').val();
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return newDtsg;
|
|
216
|
+
} catch (e) {
|
|
217
|
+
console.log("Error getting fresh dtsg:", e);
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
//if (noMqttData) api.htmlData = noMqttData;
|
|
222
|
+
require('fs').readdirSync(__dirname + '/src/').filter(v => v.endsWith('.js')).forEach(v => { api[v.replace('.js', '')] = require(`./src/${v}`)(utils.makeDefaults(html, userID, ctx), api, ctx); });
|
|
223
|
+
api.listen = api.listenMqtt;
|
|
224
|
+
return {
|
|
225
|
+
ctx,
|
|
226
|
+
defaultFuncs,
|
|
227
|
+
api
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
|
|
232
|
+
return async function (res) {
|
|
233
|
+
try {
|
|
234
|
+
const html = res.body;
|
|
235
|
+
const $ = cheerio.load(html);
|
|
236
|
+
let arr = [];
|
|
237
|
+
$("#login_form input").each((i, v) => arr.push({ val: $(v).val(), name: $(v).attr("name") }));
|
|
238
|
+
arr = arr.filter(v => v.val && v.val.length);
|
|
239
|
+
let form = utils.arrToForm(arr);
|
|
240
|
+
form.lsd = utils.getFrom(html, "[\"LSD\",[],{\"token\":\"", "\"}");
|
|
241
|
+
form.lgndim = Buffer.from(JSON.stringify({ w: 1440, h: 900, aw: 1440, ah: 834, c: 24 })).toString('base64');
|
|
242
|
+
form.email = email;
|
|
243
|
+
form.pass = password;
|
|
244
|
+
form.default_persistent = '0';
|
|
245
|
+
form.lgnrnd = utils.getFrom(html, "name=\"lgnrnd\" value=\"", "\"");
|
|
246
|
+
form.locale = 'en_US';
|
|
247
|
+
form.timezone = '240';
|
|
248
|
+
form.lgnjs = Math.floor(Date.now() / 1000);
|
|
249
|
+
const willBeCookies = html.split("\"_js_");
|
|
250
|
+
willBeCookies.slice(1).forEach(val => {
|
|
251
|
+
const cookieData = JSON.parse("[\"" + utils.getFrom(val, "", "]") + "]");
|
|
252
|
+
jar.setCookie(utils.formatCookie(cookieData, "facebook"), "https://www.facebook.com");
|
|
253
|
+
});
|
|
254
|
+
log.info("Logging in...");
|
|
255
|
+
const loginRes = await utils.post(
|
|
256
|
+
"https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110",
|
|
257
|
+
jar,
|
|
258
|
+
form,
|
|
259
|
+
loginOptions
|
|
260
|
+
);
|
|
261
|
+
await utils.saveCookies(jar)(loginRes);
|
|
262
|
+
const headers = loginRes.headers;
|
|
263
|
+
if (!headers.location) throw new Error("Wrong username/password.");
|
|
264
|
+
if (headers.location.includes('https://www.facebook.com/checkpoint/')) {
|
|
265
|
+
log.info("login", "You have login approvals turned on.");
|
|
266
|
+
const checkpointRes = await utils.get(headers.location, jar, null, loginOptions);
|
|
267
|
+
await utils.saveCookies(jar)(checkpointRes);
|
|
268
|
+
const checkpointHtml = checkpointRes.body;
|
|
269
|
+
const $ = cheerio.load(checkpointHtml);
|
|
270
|
+
let checkpointForm = [];
|
|
271
|
+
$("form input").each((i, v) => checkpointForm.push({ val: $(v).val(), name: $(v).attr("name") }));
|
|
272
|
+
checkpointForm = checkpointForm.filter(v => v.val && v.val.length);
|
|
273
|
+
const form = utils.arrToForm(checkpointForm);
|
|
274
|
+
if (checkpointHtml.includes("checkpoint/?next")) {
|
|
275
|
+
return new Promise((resolve, reject) => {
|
|
276
|
+
const submit2FA = async (code) => {
|
|
277
|
+
try {
|
|
278
|
+
form.approvals_code = code;
|
|
279
|
+
form['submit[Continue]'] = $("#checkpointSubmitButton").html();
|
|
280
|
+
const approvalRes = await utils.post(
|
|
281
|
+
"https://www.facebook.com/checkpoint/?next=https%3A%2F%2Fwww.facebook.com%2Fhome.php",
|
|
282
|
+
jar,
|
|
283
|
+
form,
|
|
284
|
+
loginOptions
|
|
285
|
+
);
|
|
286
|
+
await utils.saveCookies(jar)(approvalRes);
|
|
287
|
+
const approvalError = $("#approvals_code").parent().attr("data-xui-error");
|
|
288
|
+
if (approvalError) throw new Error("Invalid 2FA code.");
|
|
289
|
+
form.name_action_selected = 'dont_save';
|
|
290
|
+
const finalRes = await utils.post(
|
|
291
|
+
"https://www.facebook.com/checkpoint/?next=https%3A%2F%2Fwww.facebook.com%2Fhome.php",
|
|
292
|
+
jar,
|
|
293
|
+
form,
|
|
294
|
+
loginOptions
|
|
295
|
+
);
|
|
296
|
+
await utils.saveCookies(jar)(finalRes);
|
|
297
|
+
const appState = utils.getAppState(jar);
|
|
298
|
+
resolve(await loginHelper(appState, email, password, loginOptions, callback));
|
|
299
|
+
} catch (error) {
|
|
300
|
+
reject(error);
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
throw {
|
|
304
|
+
error: 'login-approval',
|
|
305
|
+
continue: submit2FA
|
|
306
|
+
};
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
if (!loginOptions.forceLogin) throw new Error("Couldn't login. Facebook might have blocked this account.");
|
|
310
|
+
form['submit[This was me]'] = checkpointHtml.includes("Suspicious Login Attempt") ? "This was me" : "This Is Okay";
|
|
311
|
+
await utils.post("https://www.facebook.com/checkpoint/?next=https%3A%2F%2Fwww.facebook.com%2Fhome.php", jar, form, loginOptions);
|
|
312
|
+
form.name_action_selected = 'save_device';
|
|
313
|
+
const reviewRes = await utils.post("https://www.facebook.com/checkpoint/?next=https%3A%2F%2Fwww.facebook.com%2Fhome.php", jar, form, loginOptions);
|
|
314
|
+
const appState = utils.getAppState(jar);
|
|
315
|
+
return await loginHelper(appState, email, password, loginOptions, callback);
|
|
316
|
+
}
|
|
317
|
+
await utils.get('https://www.facebook.com/', jar, null, loginOptions);
|
|
318
|
+
return await utils.saveCookies(jar);
|
|
319
|
+
} catch (error) {
|
|
320
|
+
callback(error);
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
function loginHelper(appState, email, password, globalOptions, callback, prCallback) {
|
|
327
|
+
let mainPromise = null;
|
|
328
|
+
const jar = utils.getJar();
|
|
329
|
+
if (appState) {
|
|
330
|
+
try {
|
|
331
|
+
appState = JSON.parse(appState);
|
|
332
|
+
} catch (e) {
|
|
333
|
+
try {
|
|
334
|
+
appState = appState;
|
|
335
|
+
} catch (e) {
|
|
336
|
+
return callback(new Error("Failed to parse appState"));
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
try {
|
|
341
|
+
appState.forEach(c => {
|
|
342
|
+
const str = `${c.key}=${c.value}; expires=${c.expires}; domain=${c.domain}; path=${c.path};`;
|
|
343
|
+
jar.setCookie(str, "http://" + c.domain);
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
mainPromise = utils.get('https://www.facebook.com/', jar, null, globalOptions, { noRef: true })
|
|
347
|
+
.then(utils.saveCookies(jar));
|
|
348
|
+
} catch (e) {
|
|
349
|
+
process.exit(0);
|
|
350
|
+
}
|
|
351
|
+
} else {
|
|
352
|
+
mainPromise = utils
|
|
353
|
+
.get("https://www.facebook.com/", null, null, globalOptions, { noRef: true })
|
|
354
|
+
.then(utils.saveCookies(jar))
|
|
355
|
+
.then(makeLogin(jar, email, password, globalOptions, callback, prCallback))
|
|
356
|
+
.then(() => utils.get('https://www.facebook.com/', jar, null, globalOptions).then(utils.saveCookies(jar)));
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function handleRedirect(res) {
|
|
360
|
+
const reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/;
|
|
361
|
+
const redirect = reg.exec(res.body);
|
|
362
|
+
if (redirect && redirect[1]) {
|
|
363
|
+
return utils.get(redirect[1], jar, null, globalOptions).then(utils.saveCookies(jar));
|
|
364
|
+
}
|
|
365
|
+
return res;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
let ctx, api;
|
|
369
|
+
mainPromise = mainPromise
|
|
370
|
+
.then(handleRedirect)
|
|
371
|
+
.then(res => {
|
|
372
|
+
const mobileAgentRegex = /MPageLoadClientMetrics/gs;
|
|
373
|
+
if (!mobileAgentRegex.test(res.body)) {
|
|
374
|
+
globalOptions.userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36";
|
|
375
|
+
return utils.get('https://www.facebook.com/', jar, null, globalOptions, { noRef: true }).then(utils.saveCookies(jar));
|
|
376
|
+
}
|
|
377
|
+
return res;
|
|
378
|
+
})
|
|
379
|
+
.then(handleRedirect)
|
|
380
|
+
.then(res => {
|
|
381
|
+
const html = res.body;
|
|
382
|
+
const Obj = buildAPI(globalOptions, html, jar);
|
|
383
|
+
ctx = Obj.ctx;
|
|
384
|
+
api = Obj.api;
|
|
385
|
+
return res;
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
if (globalOptions.pageID) {
|
|
389
|
+
mainPromise = mainPromise
|
|
390
|
+
.then(() => utils.get(`https://www.facebook.com/${globalOptions.pageID}/messages/?section=messages&subsection=inbox`, jar, null, globalOptions))
|
|
391
|
+
.then(resData => {
|
|
392
|
+
let url = utils.getFrom(resData.body, 'window.location.replace("https:\\/\\/www.facebook.com\\', '");').split('\\').join('');
|
|
393
|
+
url = url.substring(0, url.length - 1);
|
|
394
|
+
return utils.get('https://www.facebook.com' + url, jar, null, globalOptions);
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
mainPromise
|
|
399
|
+
.then(async () => {
|
|
400
|
+
log.info('Login successful');
|
|
401
|
+
callback(null, api);
|
|
402
|
+
})
|
|
403
|
+
.catch(e => {
|
|
404
|
+
callback(e);
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
function login(loginData, options, callback) {
|
|
410
|
+
if (utils.getType(options) === 'Function' || utils.getType(options) === 'AsyncFunction') {
|
|
411
|
+
callback = options;
|
|
412
|
+
options = {};
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
var globalOptions = {
|
|
416
|
+
selfListen: false,
|
|
417
|
+
listenEvents: true,
|
|
418
|
+
listenTyping: false,
|
|
419
|
+
updatePresence: false,
|
|
420
|
+
forceLogin: false,
|
|
421
|
+
autoMarkDelivery: false,
|
|
422
|
+
autoMarkRead: false,
|
|
423
|
+
autoReconnect: true,
|
|
424
|
+
logRecordSize: 100,
|
|
425
|
+
online: false,
|
|
426
|
+
emitReady: false,
|
|
427
|
+
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
var prCallback = null;
|
|
431
|
+
if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
|
|
432
|
+
var rejectFunc = null;
|
|
433
|
+
var resolveFunc = null;
|
|
434
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
|
435
|
+
resolveFunc = resolve;
|
|
436
|
+
rejectFunc = reject;
|
|
437
|
+
});
|
|
438
|
+
prCallback = function (error, api) {
|
|
439
|
+
if (error) return rejectFunc(error);
|
|
440
|
+
return resolveFunc(api);
|
|
441
|
+
};
|
|
442
|
+
callback = prCallback;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
if (loginData.email && loginData.password) {
|
|
446
|
+
setOptions(globalOptions, {
|
|
447
|
+
logLevel: "silent",
|
|
448
|
+
forceLogin: true,
|
|
449
|
+
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"
|
|
450
|
+
});
|
|
451
|
+
loginHelper(loginData.appState, loginData.email, loginData.password, globalOptions, callback, prCallback);
|
|
452
|
+
} else if (loginData.appState) {
|
|
453
|
+
setOptions(globalOptions, options);
|
|
454
|
+
return loginHelper(loginData.appState, loginData.email, loginData.password, globalOptions, callback, prCallback);
|
|
455
|
+
}
|
|
456
|
+
return returnPromise;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
module.exports = login;
|