@baileys-md/baileys 11.0.0 → 11.0.2
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 +2 -1303
- package/lib/Defaults/index.js +3 -1
- package/lib/Defaults/phonenumber-mcc.js +223 -0
- package/lib/Utils/messages-media.js +9 -6
- package/lib/Utils/use-multi-file-auth-state.js +70 -116
- package/package.json +1 -18
package/lib/Defaults/index.js
CHANGED
|
@@ -3,7 +3,9 @@ import { makeLibSignalRepository } from '../Signal/libsignal.js';
|
|
|
3
3
|
import { Browsers } from '../Utils/index.js';
|
|
4
4
|
import logger from '../Utils/logger.js';
|
|
5
5
|
import * as defaultVersion from '../Defaults/baileys-version.js'
|
|
6
|
+
import number from './phonenumber-mcc.js'
|
|
6
7
|
const { version } = defaultVersion;
|
|
8
|
+
export const PHONENUMBER_MCC = number;
|
|
7
9
|
export const UNAUTHORIZED_CODES = [401, 403, 419];
|
|
8
10
|
export const DEFAULT_ORIGIN = 'https://web.whatsapp.com';
|
|
9
11
|
export const DEF_CALLBACK_PREFIX = 'CB:';
|
|
@@ -31,7 +33,7 @@ export const DEFAULT_CONNECTION_CONFIG = {
|
|
|
31
33
|
browser: Browsers.ubuntu('Chrome'),
|
|
32
34
|
waWebSocketUrl: 'https://web.whatsapp.com/ws/chat',
|
|
33
35
|
connectTimeoutMs: 20000,
|
|
34
|
-
keepAliveIntervalMs:
|
|
36
|
+
keepAliveIntervalMs: 1000,
|
|
35
37
|
logger: logger.child({ class: 'baileys' }),
|
|
36
38
|
emitOwnEvents: true,
|
|
37
39
|
defaultQueryTimeoutMs: 60000,
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
"93": 412,
|
|
3
|
+
"355": 276,
|
|
4
|
+
"213": 603,
|
|
5
|
+
"1-684": 544,
|
|
6
|
+
"376": 213,
|
|
7
|
+
"244": 631,
|
|
8
|
+
"1-264": 365,
|
|
9
|
+
"1-268": 344,
|
|
10
|
+
"54": 722,
|
|
11
|
+
"374": 283,
|
|
12
|
+
"297": 363,
|
|
13
|
+
"61": 505,
|
|
14
|
+
"43": 232,
|
|
15
|
+
"994": 400,
|
|
16
|
+
"1-242": 364,
|
|
17
|
+
"973": 426,
|
|
18
|
+
"880": 470,
|
|
19
|
+
"1-246": 342,
|
|
20
|
+
"375": 257,
|
|
21
|
+
"32": 206,
|
|
22
|
+
"501": 702,
|
|
23
|
+
"229": 616,
|
|
24
|
+
"1-441": 350,
|
|
25
|
+
"975": 402,
|
|
26
|
+
"591": 736,
|
|
27
|
+
"387": 218,
|
|
28
|
+
"267": 652,
|
|
29
|
+
"55": 724,
|
|
30
|
+
"1-284": 348,
|
|
31
|
+
"673": 528,
|
|
32
|
+
"359": 284,
|
|
33
|
+
"226": 613,
|
|
34
|
+
"257": 642,
|
|
35
|
+
"855": 456,
|
|
36
|
+
"237": 624,
|
|
37
|
+
"238": 625,
|
|
38
|
+
"1-345": 346,
|
|
39
|
+
"236": 623,
|
|
40
|
+
"235": 622,
|
|
41
|
+
"56": 730,
|
|
42
|
+
"86": 454,
|
|
43
|
+
"57": 732,
|
|
44
|
+
"269": 654,
|
|
45
|
+
"682": 548,
|
|
46
|
+
"506": 712,
|
|
47
|
+
"385": 219,
|
|
48
|
+
"53": 368,
|
|
49
|
+
"357": 280,
|
|
50
|
+
"420": 230,
|
|
51
|
+
"243": 630,
|
|
52
|
+
"45": 238,
|
|
53
|
+
"253": 638,
|
|
54
|
+
"1-767": 366,
|
|
55
|
+
"1-809": 370,
|
|
56
|
+
"1-849": 370,
|
|
57
|
+
"1-829": 370,
|
|
58
|
+
"593": 740,
|
|
59
|
+
"20": 602,
|
|
60
|
+
"503": 706,
|
|
61
|
+
"240": 627,
|
|
62
|
+
"291": 657,
|
|
63
|
+
"372": 248,
|
|
64
|
+
"251": 636,
|
|
65
|
+
"500": 750,
|
|
66
|
+
"298": 288,
|
|
67
|
+
"679": 542,
|
|
68
|
+
"358": 244,
|
|
69
|
+
"33": 208,
|
|
70
|
+
"689": 547,
|
|
71
|
+
"241": 628,
|
|
72
|
+
"220": 607,
|
|
73
|
+
"995": 282,
|
|
74
|
+
"49": 262,
|
|
75
|
+
"233": 620,
|
|
76
|
+
"350": 266,
|
|
77
|
+
"30": 202,
|
|
78
|
+
"299": 290,
|
|
79
|
+
"1-473": 352,
|
|
80
|
+
"1-671": 535,
|
|
81
|
+
"502": 704,
|
|
82
|
+
"224": 537,
|
|
83
|
+
"592": 738,
|
|
84
|
+
"509": 372,
|
|
85
|
+
"504": 708,
|
|
86
|
+
"852": 454,
|
|
87
|
+
"36": 216,
|
|
88
|
+
"354": 274,
|
|
89
|
+
"91": 404,
|
|
90
|
+
"62": 510,
|
|
91
|
+
"98": 432,
|
|
92
|
+
"964": 418,
|
|
93
|
+
"353": 234,
|
|
94
|
+
"972": 425,
|
|
95
|
+
"39": 222,
|
|
96
|
+
"225": 612,
|
|
97
|
+
"1-876": 338,
|
|
98
|
+
"81": 440,
|
|
99
|
+
"962": 416,
|
|
100
|
+
"254": 639,
|
|
101
|
+
"686": 545,
|
|
102
|
+
"383": 221,
|
|
103
|
+
"965": 419,
|
|
104
|
+
"371": 247,
|
|
105
|
+
"961": 415,
|
|
106
|
+
"266": 651,
|
|
107
|
+
"231": 618,
|
|
108
|
+
"218": 606,
|
|
109
|
+
"423": 295,
|
|
110
|
+
"370": 246,
|
|
111
|
+
"352": 270,
|
|
112
|
+
"389": 294,
|
|
113
|
+
"261": 646,
|
|
114
|
+
"265": 650,
|
|
115
|
+
"60": 502,
|
|
116
|
+
"960": 472,
|
|
117
|
+
"223": 610,
|
|
118
|
+
"356": 278,
|
|
119
|
+
"692": 551,
|
|
120
|
+
"222": 609,
|
|
121
|
+
"230": 617,
|
|
122
|
+
"52": 334,
|
|
123
|
+
"691": 550,
|
|
124
|
+
"373": 259,
|
|
125
|
+
"377": 212,
|
|
126
|
+
"976": 428,
|
|
127
|
+
"382": 297,
|
|
128
|
+
"1-664": 354,
|
|
129
|
+
"212": 604,
|
|
130
|
+
"258": 643,
|
|
131
|
+
"95": 414,
|
|
132
|
+
"264": 649,
|
|
133
|
+
"674": 536,
|
|
134
|
+
"977": 429,
|
|
135
|
+
"31": 204,
|
|
136
|
+
"687": 546,
|
|
137
|
+
"64": 530,
|
|
138
|
+
"505": 710,
|
|
139
|
+
"227": 614,
|
|
140
|
+
"234": 621,
|
|
141
|
+
"683": 555,
|
|
142
|
+
"1-670": 534,
|
|
143
|
+
"47": 242,
|
|
144
|
+
"968": 226,
|
|
145
|
+
"92": 410,
|
|
146
|
+
"680": 552,
|
|
147
|
+
"970": 423,
|
|
148
|
+
"507": 714,
|
|
149
|
+
"675": 537,
|
|
150
|
+
"595": 744,
|
|
151
|
+
"51": 716,
|
|
152
|
+
"63": 515,
|
|
153
|
+
"48": 260,
|
|
154
|
+
"351": 268,
|
|
155
|
+
"1-787, 1-939": 330,
|
|
156
|
+
"974": 427,
|
|
157
|
+
"242": 630,
|
|
158
|
+
"40": 226,
|
|
159
|
+
"7": 250,
|
|
160
|
+
"250": 635,
|
|
161
|
+
"290": 658,
|
|
162
|
+
"1-869": 356,
|
|
163
|
+
"1-758": 358,
|
|
164
|
+
"508": 308,
|
|
165
|
+
"1-784": 360,
|
|
166
|
+
"685": 544,
|
|
167
|
+
"378": 292,
|
|
168
|
+
"239": 626,
|
|
169
|
+
"966": 420,
|
|
170
|
+
"221": 608,
|
|
171
|
+
"381": 220,
|
|
172
|
+
"248": 633,
|
|
173
|
+
"232": 619,
|
|
174
|
+
"65": 525,
|
|
175
|
+
"386": 293,
|
|
176
|
+
"677": 540,
|
|
177
|
+
"27": 655,
|
|
178
|
+
"211": 659,
|
|
179
|
+
"34": 214,
|
|
180
|
+
"94": 413,
|
|
181
|
+
"249": 634,
|
|
182
|
+
"597": 746,
|
|
183
|
+
"268": 653,
|
|
184
|
+
"46": 240,
|
|
185
|
+
"41": 228,
|
|
186
|
+
"963": 417,
|
|
187
|
+
"886": 466,
|
|
188
|
+
"992": 436,
|
|
189
|
+
"255": 640,
|
|
190
|
+
"66": 520,
|
|
191
|
+
"228": 615,
|
|
192
|
+
"690": 554,
|
|
193
|
+
"676": 539,
|
|
194
|
+
"1-868": 374,
|
|
195
|
+
"216": 605,
|
|
196
|
+
"90": 286,
|
|
197
|
+
"993": 438,
|
|
198
|
+
"1-649": 376,
|
|
199
|
+
"688": 553,
|
|
200
|
+
"1-340": 332,
|
|
201
|
+
"256": 641,
|
|
202
|
+
"380": 255,
|
|
203
|
+
"971": 424,
|
|
204
|
+
"44": 234,
|
|
205
|
+
"1": 310,
|
|
206
|
+
"598": 748,
|
|
207
|
+
"998": 434,
|
|
208
|
+
"678": 541,
|
|
209
|
+
"379": 225,
|
|
210
|
+
"58": 734,
|
|
211
|
+
"681": 543,
|
|
212
|
+
"967": 421,
|
|
213
|
+
"260": 645,
|
|
214
|
+
"263": 648,
|
|
215
|
+
"670": 514,
|
|
216
|
+
"245": 632,
|
|
217
|
+
"856": 457,
|
|
218
|
+
"599": 362,
|
|
219
|
+
"850": 467,
|
|
220
|
+
"262": 647,
|
|
221
|
+
"82": 450,
|
|
222
|
+
"84": 452
|
|
223
|
+
}
|
|
@@ -89,21 +89,24 @@ export const extractImageThumb = async (bufferOrFilePath, width = 32) => {
|
|
|
89
89
|
// This will have positive speed and performance impacts as well as minimizing RAM usage.
|
|
90
90
|
if (bufferOrFilePath instanceof Readable) {
|
|
91
91
|
bufferOrFilePath = await toBuffer(bufferOrFilePath);
|
|
92
|
-
}
|
|
92
|
+
}
|
|
93
93
|
const Jimp = await (await import('jimp')).default
|
|
94
|
-
const
|
|
94
|
+
const { read, MIME_JPEG, RESIZE_BILINEAR, AUTO } = Jimp
|
|
95
|
+
const jimp = await read(bufferOrFilePath);
|
|
95
96
|
const dimensions = {
|
|
96
|
-
width: jimp.
|
|
97
|
-
height: jimp.
|
|
97
|
+
width: jimp.getWidth(),
|
|
98
|
+
height: jimp.getHeight()
|
|
98
99
|
};
|
|
99
100
|
const buffer = await jimp
|
|
100
|
-
.
|
|
101
|
-
.
|
|
101
|
+
.quality(50)
|
|
102
|
+
.resize(width, AUTO, RESIZE_BILINEAR)
|
|
103
|
+
.getBufferAsync(MIME_JPEG);
|
|
102
104
|
return {
|
|
103
105
|
buffer,
|
|
104
106
|
original: dimensions
|
|
105
107
|
};
|
|
106
108
|
};
|
|
109
|
+
/**/
|
|
107
110
|
export const encodeBase64EncodedStringForUpload = (b64) => encodeURIComponent(b64.replace(/\+/g, '-').replace(/\//g, '_').replace(/\=+$/, ''));
|
|
108
111
|
export const generateProfilePicture = async (mediaUpload) => {
|
|
109
112
|
let buffer;
|
|
@@ -1,121 +1,75 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { mkdir, readFile, stat, unlink, writeFile } from 'fs/promises';
|
|
1
|
+
import fs from 'fs';
|
|
3
2
|
import { join } from 'path';
|
|
4
3
|
import { proto } from '../../WAProto/index.js';
|
|
5
4
|
import { initAuthCreds } from './auth-utils.js';
|
|
6
5
|
import { BufferJSON } from './generics.js';
|
|
7
|
-
// We need to lock files due to the fact that we are using async functions to read and write files
|
|
8
|
-
// https://github.com/WhiskeySockets/Baileys/issues/794
|
|
9
|
-
// https://github.com/nodejs/node/issues/26338
|
|
10
|
-
// Use a Map to store mutexes for each file path
|
|
11
|
-
const fileLocks = new Map();
|
|
12
|
-
// Get or create a mutex for a specific file path
|
|
13
|
-
const getFileLock = (path) => {
|
|
14
|
-
let mutex = fileLocks.get(path);
|
|
15
|
-
if (!mutex) {
|
|
16
|
-
mutex = new Mutex();
|
|
17
|
-
fileLocks.set(path, mutex);
|
|
18
|
-
}
|
|
19
|
-
return mutex;
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* stores the full authentication state in a single folder.
|
|
23
|
-
* Far more efficient than singlefileauthstate
|
|
24
|
-
*
|
|
25
|
-
* Again, I wouldn't endorse this for any production level use other than perhaps a bot.
|
|
26
|
-
* Would recommend writing an auth state for use with a proper SQL or No-SQL DB
|
|
27
|
-
* */
|
|
28
6
|
export const useMultiFileAuthState = async (folder) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
data[id] = value;
|
|
100
|
-
}));
|
|
101
|
-
return data;
|
|
102
|
-
},
|
|
103
|
-
set: async (data) => {
|
|
104
|
-
const tasks = [];
|
|
105
|
-
for (const category in data) {
|
|
106
|
-
for (const id in data[category]) {
|
|
107
|
-
const value = data[category][id];
|
|
108
|
-
const file = `${category}-${id}.json`;
|
|
109
|
-
tasks.push(value ? await writeData(value, file) : await removeData(file));
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
await Promise.all(tasks);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
saveCreds: async () => {
|
|
117
|
-
return await writeData(creds, 'creds.json');
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
};
|
|
121
|
-
//# sourceMappingURL=use-multi-file-auth-state.js.map
|
|
7
|
+
const writeData = async (data, file) => {
|
|
8
|
+
const filePath = await (0, join)(folder, fixFileName(file));
|
|
9
|
+
return (0, fs.writeFileSync)((0, join)(filePath), JSON.stringify(data, BufferJSON.replacer));
|
|
10
|
+
};
|
|
11
|
+
const readData = async (file) => {
|
|
12
|
+
try {
|
|
13
|
+
const filePath = await (0, join)(folder, fixFileName(file));
|
|
14
|
+
const data = (0, fs.readFileSync)(filePath, {
|
|
15
|
+
encoding: 'utf-8'
|
|
16
|
+
});
|
|
17
|
+
return JSON.parse(data, BufferJSON.reviver);
|
|
18
|
+
} catch (e) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const removeData = async (file) => {
|
|
23
|
+
try {
|
|
24
|
+
const filePath = await (0, join)(folder, fixFileName(file));
|
|
25
|
+
(0, fs.unlinkSync)(filePath);
|
|
26
|
+
} catch (_a) {}
|
|
27
|
+
};
|
|
28
|
+
try {
|
|
29
|
+
const stats = fs.statSync(folder);
|
|
30
|
+
if (!stats.isDirectory()) {
|
|
31
|
+
throw new Error(`found something that is not a directory at ${folder}, either delete it or specify a different location`);
|
|
32
|
+
}
|
|
33
|
+
} catch (error) {
|
|
34
|
+
fs.mkdirSync(folder, {
|
|
35
|
+
recursive: true
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
const fixFileName = (file) => {
|
|
39
|
+
var _a;
|
|
40
|
+
return (_a = file === null || file === void 0 ? void 0 : file.replace(/\//g, '__')) === null || _a === void 0 ? void 0 : _a.replace(/:/g, '-');
|
|
41
|
+
};
|
|
42
|
+
const creds = await readData('creds.json') || await (0, await initAuthCreds)();
|
|
43
|
+
return {
|
|
44
|
+
state: {
|
|
45
|
+
creds,
|
|
46
|
+
keys: {
|
|
47
|
+
get: async (type, ids) => {
|
|
48
|
+
const data = {};
|
|
49
|
+
await Promise.all(ids.map(async (id) => {
|
|
50
|
+
let value = await readData(`${type}-${id}.json`);
|
|
51
|
+
if (type === 'app-state-sync-key' && value) {
|
|
52
|
+
value = proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
53
|
+
}
|
|
54
|
+
data[id] = value;
|
|
55
|
+
}));
|
|
56
|
+
return data;
|
|
57
|
+
},
|
|
58
|
+
set: async (data) => {
|
|
59
|
+
const tasks = [];
|
|
60
|
+
for (const category in data) {
|
|
61
|
+
for (const id in data[category]) {
|
|
62
|
+
const value = data[category][id];
|
|
63
|
+
const file = `${category}-${id}.json`;
|
|
64
|
+
tasks.push(value ? await writeData(value, file) : await removeData(file));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
await Promise.all(tasks);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
saveCreds: () => {
|
|
72
|
+
return writeData(creds, 'creds.json');
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@baileys-md/baileys",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "11.0.
|
|
4
|
+
"version": "11.0.2",
|
|
5
5
|
"description": "A WebSockets library for interacting with WhatsApp Web",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"whatsapp",
|
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
"@cacheable/node-cache": "^1.4.0",
|
|
24
24
|
"@baileys-md/keyed-db": "^0.2.5",
|
|
25
25
|
"@hapi/boom": "^9.1.3",
|
|
26
|
-
"async-mutex": "^0.5.0",
|
|
27
26
|
"axios": "1.3.2",
|
|
28
27
|
"jimp": "0.16.2",
|
|
29
28
|
"libsignal": "npm:@baileys-md/libsignal",
|
|
@@ -31,22 +30,6 @@
|
|
|
31
30
|
"pino": "^9.6",
|
|
32
31
|
"protobufjs": "^7.2.4",
|
|
33
32
|
"ws": "npm:@baileys-md/ws"
|
|
34
|
-
},
|
|
35
|
-
"peerDependencies": {
|
|
36
|
-
"audio-decode": "^2.1.3",
|
|
37
|
-
"jimp": "0.16.2",
|
|
38
|
-
"link-preview-js": "^3.0.0"
|
|
39
|
-
},
|
|
40
|
-
"peerDependenciesMeta": {
|
|
41
|
-
"audio-decode": {
|
|
42
|
-
"optional": true
|
|
43
|
-
},
|
|
44
|
-
"jimp": {
|
|
45
|
-
"optional": true
|
|
46
|
-
},
|
|
47
|
-
"link-preview-js": {
|
|
48
|
-
"optional": true
|
|
49
|
-
}
|
|
50
33
|
},
|
|
51
34
|
"packageManager": "yarn@4.9.2",
|
|
52
35
|
"engines": {
|