@itsliaaa/baileys 0.1.32 → 0.2.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/README.md +328 -74
- package/WAProto/index.js +22 -18
- package/lib/Defaults/index.js +2 -0
- package/lib/Socket/chats.js +223 -57
- package/lib/Socket/groups.js +6 -0
- package/lib/Socket/messages-recv.js +230 -53
- package/lib/Socket/messages-send.js +78 -7
- package/lib/Utils/chat-utils.js +34 -7
- package/lib/Utils/decode-wa-message.js +14 -0
- package/lib/Utils/event-buffer.js +2 -0
- package/lib/Utils/generics.js +9 -0
- package/lib/Utils/history.js +11 -9
- package/lib/Utils/identity-change-handler.js +1 -0
- package/lib/Utils/messages-media.js +1 -1
- package/lib/Utils/messages.js +21 -6
- package/lib/Utils/process-message.js +53 -1
- package/lib/Utils/rich-message-utils.js +40 -35
- package/lib/Utils/sync-action-utils.js +1 -0
- package/lib/Utils/tc-token-utils.js +151 -5
- package/lib/Utils/use-single-file-auth-state.js +19 -26
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +26 -3
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +22 -0
- package/lib/WAUSync/Protocols/index.js +2 -1
- package/lib/WAUSync/USyncQuery.js +5 -1
- package/lib/WAUSync/USyncUser.js +8 -0
- package/package.json +2 -2
|
@@ -4,27 +4,26 @@ import { proto } from '../../WAProto/index.js';
|
|
|
4
4
|
import { initAuthCreds } from './auth-utils.js';
|
|
5
5
|
import { BufferJSON } from './generics.js';
|
|
6
6
|
import { LRUCache } from 'lru-cache';
|
|
7
|
+
import { Mutex } from 'async-mutex';
|
|
7
8
|
// Lia@Changes 25-03-26 --- Add useSingleFileAuthState with integrated cache
|
|
8
9
|
const FLUSH_TIMEOUT_MS = 3000;
|
|
9
10
|
// Lia@Changes 22-04-26 --- Enhanced useSingleFileAuthState with LRUCache
|
|
10
11
|
export const useSingleFileAuthState = async (fileName) => {
|
|
11
12
|
const cache = new LRUCache({
|
|
12
|
-
max:
|
|
13
|
+
max: 15000,
|
|
13
14
|
ttl: 1000 * DEFAULT_CACHE_TTLS.SIGNAL_STORE,
|
|
14
15
|
updateAgeOnGet: false,
|
|
15
16
|
updateAgeOnHas: false,
|
|
16
17
|
ttlAutopurge: true
|
|
17
18
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (loadPromise) return loadPromise;
|
|
27
|
-
loadPromise = (async () => {
|
|
19
|
+
// Lia@Changes 26-04-26 --- Add mutex for prevent race condition
|
|
20
|
+
const mutex = new Mutex();
|
|
21
|
+
let fileData = {};
|
|
22
|
+
let isLoaded = false;
|
|
23
|
+
let flushTimeout = null;
|
|
24
|
+
const loadKey = async () => {
|
|
25
|
+
return await mutex.runExclusive(async () => {
|
|
26
|
+
if (isLoaded) return;
|
|
28
27
|
try {
|
|
29
28
|
const data = JSON.parse(await readFile(fileName, 'utf-8'), BufferJSON.reviver);
|
|
30
29
|
fileData = data || {};
|
|
@@ -36,26 +35,20 @@ export const useSingleFileAuthState = async (fileName) => {
|
|
|
36
35
|
fileData = {};
|
|
37
36
|
}
|
|
38
37
|
isLoaded = true;
|
|
39
|
-
|
|
40
|
-
})();
|
|
41
|
-
return loadPromise;
|
|
38
|
+
});
|
|
42
39
|
};
|
|
43
40
|
const flushKey = () => {
|
|
44
41
|
if (flushTimeout) return;
|
|
45
42
|
flushTimeout = setTimeout(async () => {
|
|
46
43
|
flushTimeout = null;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
await writeFile(tempFile, JSON.stringify(fileData, BufferJSON.replacer));
|
|
56
|
-
await rename(tempFile, fileName);
|
|
57
|
-
} while (isNeedWrite);
|
|
58
|
-
isWriting = false;
|
|
44
|
+
await mutex.runExclusive(async () => {
|
|
45
|
+
try {
|
|
46
|
+
const tempFile = fileName + '.temp';
|
|
47
|
+
await writeFile(tempFile, JSON.stringify(fileData, BufferJSON.replacer));
|
|
48
|
+
await rename(tempFile, fileName);
|
|
49
|
+
}
|
|
50
|
+
catch { }
|
|
51
|
+
});
|
|
59
52
|
}, FLUSH_TIMEOUT_MS);
|
|
60
53
|
};
|
|
61
54
|
const writeKey = (keyName, value) => {
|
|
@@ -11,11 +11,34 @@ export class USyncContactProtocol {
|
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
getUserElement(user) {
|
|
14
|
-
|
|
14
|
+
if (user.phone) {
|
|
15
|
+
return {
|
|
16
|
+
tag: 'contact',
|
|
17
|
+
attrs: {},
|
|
18
|
+
content: user.phone
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
if (user.username) {
|
|
22
|
+
return {
|
|
23
|
+
tag: 'contact',
|
|
24
|
+
attrs: {
|
|
25
|
+
username: user.username,
|
|
26
|
+
...(user.usernameKey ? { pin: user.usernameKey } : {}),
|
|
27
|
+
...(user.lid ? { lid: user.lid } : {})
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
if (user.type) {
|
|
32
|
+
return {
|
|
33
|
+
tag: 'contact',
|
|
34
|
+
attrs: {
|
|
35
|
+
type: user.type
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
15
39
|
return {
|
|
16
40
|
tag: 'contact',
|
|
17
|
-
attrs: {}
|
|
18
|
-
content: user.phone
|
|
41
|
+
attrs: {}
|
|
19
42
|
};
|
|
20
43
|
}
|
|
21
44
|
parser(node) {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { assertNodeErrorFree } from '../../WABinary/index.js';
|
|
2
|
+
import { USyncUser } from '../USyncUser.js';
|
|
3
|
+
export class USyncUsernameProtocol {
|
|
4
|
+
name = 'username';
|
|
5
|
+
getQueryElement() {
|
|
6
|
+
return {
|
|
7
|
+
tag: 'username',
|
|
8
|
+
attrs: {}
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
getUserElement(user) {
|
|
12
|
+
void user;
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
parser(node) {
|
|
16
|
+
if (node.tag === 'username') {
|
|
17
|
+
assertNodeErrorFree(node);
|
|
18
|
+
return typeof node.content === 'string' ? node.content : null;
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './USyncDeviceProtocol.js';
|
|
2
2
|
export * from './USyncContactProtocol.js';
|
|
3
3
|
export * from './USyncStatusProtocol.js';
|
|
4
|
-
export * from './USyncDisappearingModeProtocol.js';
|
|
4
|
+
export * from './USyncDisappearingModeProtocol.js';
|
|
5
|
+
export * from './USyncUsernameProtocol.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getBinaryNodeChild } from '../WABinary/index.js';
|
|
2
2
|
import { USyncBotProfileProtocol } from './Protocols/UsyncBotProfileProtocol.js';
|
|
3
3
|
import { USyncLIDProtocol } from './Protocols/UsyncLIDProtocol.js';
|
|
4
|
-
import { USyncContactProtocol, USyncDeviceProtocol, USyncDisappearingModeProtocol, USyncStatusProtocol } from './Protocols/index.js';
|
|
4
|
+
import { USyncContactProtocol, USyncDeviceProtocol, USyncDisappearingModeProtocol, USyncStatusProtocol, USyncUsernameProtocol } from './Protocols/index.js';
|
|
5
5
|
import { USyncUser } from './USyncUser.js';
|
|
6
6
|
export class USyncQuery {
|
|
7
7
|
constructor() {
|
|
@@ -90,4 +90,8 @@ export class USyncQuery {
|
|
|
90
90
|
this.protocols.push(new USyncLIDProtocol());
|
|
91
91
|
return this;
|
|
92
92
|
}
|
|
93
|
+
withUsernameProtocol() {
|
|
94
|
+
this.protocols.push(new USyncUsernameProtocol());
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
93
97
|
}
|
package/lib/WAUSync/USyncUser.js
CHANGED
|
@@ -11,6 +11,14 @@ export class USyncUser {
|
|
|
11
11
|
this.phone = phone;
|
|
12
12
|
return this;
|
|
13
13
|
}
|
|
14
|
+
withUsername(username) {
|
|
15
|
+
this.username = username;
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
withUsernameKey(usernameKey) {
|
|
19
|
+
this.usernameKey = usernameKey;
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
14
22
|
withType(type) {
|
|
15
23
|
this.type = type;
|
|
16
24
|
return this;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itsliaaa/baileys",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Enhanced Baileys v7 with fixed newsletter media upload, plus support for interactive messages, albums, and more message types.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"fflate": "^0.8.2",
|
|
46
46
|
"libsignal": "github:WhiskeySockets/libsignal-wasm#master",
|
|
47
47
|
"lru-cache": "^11.2.6",
|
|
48
|
-
"music-metadata": "
|
|
48
|
+
"music-metadata": "11.12.1",
|
|
49
49
|
"p-queue": "^9.1.0",
|
|
50
50
|
"pino": "^9.6.0",
|
|
51
51
|
"protobufjs": "^7.5.4",
|