Mohammed Foud
commited on
Commit
·
7afc018
1
Parent(s):
044f5ef
first commit
Browse files- src/AccountManager.js +47 -14
src/AccountManager.js
CHANGED
@@ -5,7 +5,18 @@ const fs = require('fs');
|
|
5 |
const path = require('path');
|
6 |
const qrcode = require('qrcode');
|
7 |
const CONFIG = require('./config');
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
class WhatsAppAccountManager {
|
10 |
constructor(accountId) {
|
11 |
this.accountId = accountId;
|
@@ -17,19 +28,41 @@ class WhatsAppAccountManager {
|
|
17 |
fs.mkdirSync(this.sessionPath, { recursive: true });
|
18 |
}
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
'
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
this.csvWriter = createCsvWriter({
|
35 |
path: CONFIG.CSV_FILE,
|
|
|
5 |
const path = require('path');
|
6 |
const qrcode = require('qrcode');
|
7 |
const CONFIG = require('./config');
|
8 |
+
const axios = require('axios');
|
9 |
+
|
10 |
+
async function getFreeProxy() {
|
11 |
+
try {
|
12 |
+
const response = await axios.get('https://www.proxy-list.download/api/v1/get?type=http');
|
13 |
+
const proxyList = response.data.split('\n').filter(Boolean);
|
14 |
+
return proxyList[Math.floor(Math.random() * proxyList.length)]; // Select a random proxy
|
15 |
+
} catch (error) {
|
16 |
+
console.error('Error fetching proxy:', error);
|
17 |
+
return null;
|
18 |
+
}
|
19 |
+
}
|
20 |
class WhatsAppAccountManager {
|
21 |
constructor(accountId) {
|
22 |
this.accountId = accountId;
|
|
|
28 |
fs.mkdirSync(this.sessionPath, { recursive: true });
|
29 |
}
|
30 |
|
31 |
+
(async () => {
|
32 |
+
const proxy = await getFreeProxy();
|
33 |
+
console.log(`[${this.accountId}] Using proxy:`, proxy);
|
34 |
+
|
35 |
+
this.client = new Client({
|
36 |
+
authStrategy: new LocalAuth({ clientId: accountId }),
|
37 |
+
|
38 |
+
puppeteer: {
|
39 |
+
headless: true,
|
40 |
+
executablePath: '/usr/bin/google-chrome',
|
41 |
+
args: [
|
42 |
+
'--no-sandbox',
|
43 |
+
'--disable-setuid-sandbox',
|
44 |
+
`--user-data-dir=${this.sessionPath}`,
|
45 |
+
`--proxy-server=${proxy}`
|
46 |
+
],
|
47 |
+
}
|
48 |
+
});
|
49 |
+
|
50 |
+
|
51 |
+
})();
|
52 |
+
|
53 |
+
// this.client = new Client({
|
54 |
+
// authStrategy: new LocalAuth({ clientId: accountId }),
|
55 |
+
|
56 |
+
// puppeteer: {
|
57 |
+
// headless: true,
|
58 |
+
// executablePath: '/usr/bin/google-chrome',
|
59 |
+
// args: [
|
60 |
+
// '--no-sandbox',
|
61 |
+
// `--user-data-dir=${this.sessionPath}`,
|
62 |
+
// '--disable-setuid-sandbox'
|
63 |
+
// ],
|
64 |
+
// }
|
65 |
+
// });
|
66 |
|
67 |
this.csvWriter = createCsvWriter({
|
68 |
path: CONFIG.CSV_FILE,
|