@badzz88/baileys 8.5.7 → 8.5.8
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 +337 -1055
- package/WAProto/WAProto.proto +284 -264
- package/WAProto/index.js +5 -5
- package/engine-requirements.js +7 -15
- package/lib/Defaults/index.js +130 -187
- package/lib/Signal/Group/ciphertext-message.js +11 -14
- package/lib/Signal/Group/group-session-builder.js +29 -91
- package/lib/Signal/Group/group_cipher.js +81 -88
- package/lib/Signal/Group/index.js +12 -136
- package/lib/Signal/Group/keyhelper.js +15 -70
- package/lib/Signal/Group/sender-chain-key.js +25 -31
- package/lib/Signal/Group/sender-key-distribution-message.js +62 -65
- package/lib/Signal/Group/sender-key-message.js +65 -68
- package/lib/Signal/Group/sender-key-name.js +41 -43
- package/lib/Signal/Group/sender-key-record.js +40 -43
- package/lib/Signal/Group/sender-key-state.js +83 -96
- package/lib/Signal/Group/sender-message-key.js +25 -29
- package/lib/Signal/libsignal.js +425 -453
- package/lib/Signal/lid-mapping.js +276 -259
- package/lib/Socket/Client/index.js +3 -30
- package/lib/Socket/Client/types.js +10 -12
- package/lib/Socket/Client/websocket.js +53 -61
- package/lib/Socket/business.js +379 -422
- package/lib/Socket/chats.js +1193 -1816
- package/lib/Socket/communities.js +431 -549
- package/lib/Socket/graphql.js +672 -612
- package/lib/Socket/groups.js +374 -764
- package/lib/Socket/index.js +17 -38
- package/lib/Socket/interop.js +417 -503
- package/lib/Socket/messages-recv.js +1915 -2441
- package/lib/Socket/messages-send.js +1213 -1630
- package/lib/Socket/mex.js +9 -15
- package/lib/Socket/newsletter.js +747 -808
- package/lib/Socket/privacy.js +310 -441
- package/lib/Socket/socket.js +1025 -1022
- package/lib/Socket/username.js +8 -15
- package/lib/Store/index.js +10 -36
- package/lib/Store/make-cache-manager-store.js +80 -85
- package/lib/Store/make-in-memory-store.js +231 -591
- package/lib/Store/make-ordered-dictionary.js +72 -78
- package/lib/Store/object-repository.js +28 -25
- package/lib/Types/Auth.js +2 -38
- package/lib/Types/Bussines.js +2 -2
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.js +8 -4
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.js +24 -26
- package/lib/Types/LabelAssociation.js +6 -8
- package/lib/Types/Message.js +11 -95
- package/lib/Types/Mex.js +111 -112
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.js +3 -2
- package/lib/Types/State.js +56 -70
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.js +26 -55
- package/lib/Utils/auth-utils.js +288 -292
- package/lib/Utils/browser-utils.js +47 -113
- package/lib/Utils/business.js +224 -240
- package/lib/Utils/chat-utils.js +869 -1205
- package/lib/Utils/companion-reg-client-utils.js +34 -41
- package/lib/Utils/crypto.js +107 -144
- package/lib/Utils/decode-wa-message.js +308 -518
- package/lib/Utils/event-buffer.js +611 -596
- package/lib/Utils/generics.js +355 -515
- package/lib/Utils/history.js +134 -244
- package/lib/Utils/identity-change-handler.js +49 -51
- package/lib/Utils/index.js +23 -57
- package/lib/Utils/link-preview.js +77 -135
- package/lib/Utils/logger.js +3 -9
- package/lib/Utils/lt-hash.js +6 -37
- package/lib/Utils/make-mutex.js +33 -36
- package/lib/Utils/message-composer.js +233 -439
- package/lib/Utils/message-retry-manager.js +260 -265
- package/lib/Utils/messages-media.js +829 -855
- package/lib/Utils/messages.js +961 -2528
- package/lib/Utils/noise-handler.js +200 -195
- package/lib/Utils/offline-node-processor.js +33 -35
- package/lib/Utils/pre-key-manager.js +102 -103
- package/lib/Utils/process-message.js +560 -978
- package/lib/Utils/reporting-utils.js +253 -257
- package/lib/Utils/signal.js +195 -218
- package/lib/Utils/stanza-ack.js +29 -31
- package/lib/Utils/sticker.js +109 -144
- package/lib/Utils/sync-action-utils.js +45 -50
- package/lib/Utils/tc-token-utils.js +139 -137
- package/lib/Utils/use-multi-file-auth-state.js +109 -109
- package/lib/Utils/validate-connection.js +202 -218
- package/lib/WABinary/constants.js +1299 -1302
- package/lib/WABinary/decode.js +262 -343
- package/lib/WABinary/encode.js +4 -12
- package/lib/WABinary/generic-utils.js +187 -223
- package/lib/WABinary/index.js +6 -33
- package/lib/WABinary/jid-utils.js +88 -351
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +9 -12
- package/lib/WAM/constants.js +22853 -39486
- package/lib/WAM/encode.js +140 -132
- package/lib/WAM/index.js +4 -31
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +21 -23
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +9 -9
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +7 -7
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +10 -10
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +7 -7
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +11 -12
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +4 -5
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +7 -7
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +7 -8
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -7
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +8 -8
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +7 -7
- package/lib/WAUSync/Protocols/index.js +12 -39
- package/lib/WAUSync/USyncQuery.js +67 -49
- package/lib/WAUSync/USyncUser.js +11 -5
- package/lib/WAUSync/index.js +3 -31
- package/lib/index.js +15 -48
- package/package.json +129 -99
- package/LICENSE +0 -21
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Socket/aigroups.js +0 -240
- package/lib/Socket/interactive-handler.js +0 -522
- package/lib/Socket/managed-account.js +0 -183
- package/lib/Socket/registration.js +0 -427
- package/lib/Socket/text-router.js +0 -83
- package/lib/Types/Newsletter.js +0 -121
- package/lib/Utils/command-loader.d.ts +0 -31
- package/lib/Utils/command-loader.js +0 -100
- package/lib/Utils/consumer-application.js +0 -107
- package/lib/Utils/curve25519-js.js +0 -275
- package/lib/Utils/group-history.js +0 -60
- package/lib/Utils/jid-display-normalization.js +0 -218
- package/lib/Utils/meta-ai-msmsg.js +0 -262
- package/lib/Utils/native-bridge.js +0 -82
- package/lib/Utils/session-pool.d.ts +0 -16
- package/lib/Utils/session-pool.js +0 -94
- package/lib/Utils/sticker.d.ts +0 -17
- package/lib/Utils/view-once-cache.d.ts +0 -9
- package/lib/Utils/view-once-cache.js +0 -79
- package/lib/Utils/voip-rekey.js +0 -22
- package/lib/antiban.js +0 -4637
package/lib/WAM/encode.js
CHANGED
|
@@ -1,142 +1,150 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return buffer
|
|
18
|
-
}
|
|
19
|
-
exports.encodeWAM = encodeWAM
|
|
1
|
+
import { BinaryInfo } from './BinaryInfo.js';
|
|
2
|
+
import { FLAG_BYTE, FLAG_EVENT, FLAG_EXTENDED, FLAG_FIELD, FLAG_GLOBAL, WEB_EVENTS, WEB_GLOBALS } from './constants.js';
|
|
3
|
+
const getHeaderBitLength = (key) => (key < 256 ? 2 : 3);
|
|
4
|
+
export const encodeWAM = (binaryInfo) => {
|
|
5
|
+
binaryInfo.buffer = [];
|
|
6
|
+
encodeWAMHeader(binaryInfo);
|
|
7
|
+
encodeEvents(binaryInfo);
|
|
8
|
+
const totalSize = binaryInfo.buffer.map(a => a.length).reduce((a, b) => a + b);
|
|
9
|
+
const buffer = Buffer.alloc(totalSize);
|
|
10
|
+
let offset = 0;
|
|
11
|
+
for (const buffer_ of binaryInfo.buffer) {
|
|
12
|
+
buffer_.copy(buffer, offset);
|
|
13
|
+
offset += buffer_.length;
|
|
14
|
+
}
|
|
15
|
+
return buffer;
|
|
16
|
+
};
|
|
20
17
|
function encodeWAMHeader(binaryInfo) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
const headerBuffer = Buffer.alloc(8); // starting buffer
|
|
19
|
+
headerBuffer.write('WAM', 0, 'utf8');
|
|
20
|
+
headerBuffer.writeUInt8(binaryInfo.protocolVersion, 3);
|
|
21
|
+
headerBuffer.writeUInt8(1, 4); //random flag
|
|
22
|
+
headerBuffer.writeUInt16BE(binaryInfo.sequence, 5);
|
|
23
|
+
headerBuffer.writeUInt8(0, 7); // regular channel
|
|
24
|
+
binaryInfo.buffer.push(headerBuffer);
|
|
28
25
|
}
|
|
29
26
|
function encodeGlobalAttributes(binaryInfo, globals) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
27
|
+
for (const [key, _value] of Object.entries(globals)) {
|
|
28
|
+
const id = WEB_GLOBALS.find(a => a?.name === key).id;
|
|
29
|
+
let value = _value;
|
|
30
|
+
if (typeof value === 'boolean') {
|
|
31
|
+
value = value ? 1 : 0;
|
|
32
|
+
}
|
|
33
|
+
binaryInfo.buffer.push(serializeData(id, value, FLAG_GLOBAL));
|
|
34
|
+
}
|
|
38
35
|
}
|
|
39
36
|
function encodeEvents(binaryInfo) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
37
|
+
for (const [name, { props, globals }] of binaryInfo.events.map(a => Object.entries(a)[0])) {
|
|
38
|
+
encodeGlobalAttributes(binaryInfo, globals);
|
|
39
|
+
const event = WEB_EVENTS.find(a => a.name === name);
|
|
40
|
+
const props_ = Object.entries(props);
|
|
41
|
+
let extended = false;
|
|
42
|
+
for (const [, value] of props_) {
|
|
43
|
+
extended || (extended = value !== null);
|
|
44
|
+
}
|
|
45
|
+
const eventFlag = extended ? FLAG_EVENT : FLAG_EVENT | FLAG_EXTENDED;
|
|
46
|
+
binaryInfo.buffer.push(serializeData(event.id, -event.weight, eventFlag));
|
|
47
|
+
for (let i = 0; i < props_.length; i++) {
|
|
48
|
+
const [key, _value] = props_[i];
|
|
49
|
+
const id = event.props[key]?.[0];
|
|
50
|
+
extended = i < props_.length - 1;
|
|
51
|
+
let value = _value;
|
|
52
|
+
if (typeof value === 'boolean') {
|
|
53
|
+
value = value ? 1 : 0;
|
|
54
|
+
}
|
|
55
|
+
const fieldFlag = extended ? FLAG_EVENT : FLAG_FIELD | FLAG_EXTENDED;
|
|
56
|
+
binaryInfo.buffer.push(serializeData(id, value, fieldFlag));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
62
59
|
}
|
|
63
60
|
function serializeData(key, value, flag) {
|
|
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
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
61
|
+
const bufferLength = getHeaderBitLength(key);
|
|
62
|
+
let buffer;
|
|
63
|
+
let offset = 0;
|
|
64
|
+
if (value === null) {
|
|
65
|
+
if (flag === FLAG_GLOBAL) {
|
|
66
|
+
buffer = Buffer.alloc(bufferLength);
|
|
67
|
+
offset = serializeHeader(buffer, offset, key, flag);
|
|
68
|
+
return buffer;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else if (typeof value === 'number' && Number.isInteger(value)) {
|
|
72
|
+
// is number
|
|
73
|
+
if (value === 0 || value === 1) {
|
|
74
|
+
buffer = Buffer.alloc(bufferLength);
|
|
75
|
+
offset = serializeHeader(buffer, offset, key, flag | ((value + 1) << 4));
|
|
76
|
+
return buffer;
|
|
77
|
+
}
|
|
78
|
+
else if (-128 <= value && value < 128) {
|
|
79
|
+
buffer = Buffer.alloc(bufferLength + 1);
|
|
80
|
+
offset = serializeHeader(buffer, offset, key, flag | (3 << 4));
|
|
81
|
+
buffer.writeInt8(value, offset);
|
|
82
|
+
return buffer;
|
|
83
|
+
}
|
|
84
|
+
else if (-32768 <= value && value < 32768) {
|
|
85
|
+
buffer = Buffer.alloc(bufferLength + 2);
|
|
86
|
+
offset = serializeHeader(buffer, offset, key, flag | (4 << 4));
|
|
87
|
+
buffer.writeInt16LE(value, offset);
|
|
88
|
+
return buffer;
|
|
89
|
+
}
|
|
90
|
+
else if (-2147483648 <= value && value < 2147483648) {
|
|
91
|
+
buffer = Buffer.alloc(bufferLength + 4);
|
|
92
|
+
offset = serializeHeader(buffer, offset, key, flag | (5 << 4));
|
|
93
|
+
buffer.writeInt32LE(value, offset);
|
|
94
|
+
return buffer;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
buffer = Buffer.alloc(bufferLength + 8);
|
|
98
|
+
offset = serializeHeader(buffer, offset, key, flag | (7 << 4));
|
|
99
|
+
buffer.writeDoubleLE(value, offset);
|
|
100
|
+
return buffer;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else if (typeof value === 'number') {
|
|
104
|
+
// is float
|
|
105
|
+
buffer = Buffer.alloc(bufferLength + 8);
|
|
106
|
+
offset = serializeHeader(buffer, offset, key, flag | (7 << 4));
|
|
107
|
+
buffer.writeDoubleLE(value, offset);
|
|
108
|
+
return buffer;
|
|
109
|
+
}
|
|
110
|
+
else if (typeof value === 'string') {
|
|
111
|
+
// is string
|
|
112
|
+
const utf8Bytes = Buffer.byteLength(value, 'utf8');
|
|
113
|
+
if (utf8Bytes < 256) {
|
|
114
|
+
buffer = Buffer.alloc(bufferLength + 1 + utf8Bytes);
|
|
115
|
+
offset = serializeHeader(buffer, offset, key, flag | (8 << 4));
|
|
116
|
+
buffer.writeUint8(utf8Bytes, offset++);
|
|
117
|
+
}
|
|
118
|
+
else if (utf8Bytes < 65536) {
|
|
119
|
+
buffer = Buffer.alloc(bufferLength + 2 + utf8Bytes);
|
|
120
|
+
offset = serializeHeader(buffer, offset, key, flag | (9 << 4));
|
|
121
|
+
buffer.writeUInt16LE(utf8Bytes, offset);
|
|
122
|
+
offset += 2;
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
buffer = Buffer.alloc(bufferLength + 4 + utf8Bytes);
|
|
126
|
+
offset = serializeHeader(buffer, offset, key, flag | (10 << 4));
|
|
127
|
+
buffer.writeUInt32LE(utf8Bytes, offset);
|
|
128
|
+
offset += 4;
|
|
129
|
+
}
|
|
130
|
+
buffer.write(value, offset, 'utf8');
|
|
131
|
+
return buffer;
|
|
132
|
+
}
|
|
133
|
+
throw 'missing';
|
|
128
134
|
}
|
|
129
135
|
function serializeHeader(buffer, offset, key, flag) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
136
|
+
if (key < 256) {
|
|
137
|
+
buffer.writeUInt8(flag, offset);
|
|
138
|
+
offset += 1;
|
|
139
|
+
buffer.writeUInt8(key, offset);
|
|
140
|
+
offset += 1;
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
buffer.writeUInt8(flag | FLAG_BYTE, offset);
|
|
144
|
+
offset += 1;
|
|
145
|
+
buffer.writeUInt16LE(key, offset);
|
|
146
|
+
offset += 2;
|
|
147
|
+
}
|
|
148
|
+
return offset;
|
|
142
149
|
}
|
|
150
|
+
//# sourceMappingURL=encode.js.map
|
package/lib/WAM/index.js
CHANGED
|
@@ -1,31 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
? function (o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k
|
|
7
|
-
var desc = Object.getOwnPropertyDescriptor(m, k)
|
|
8
|
-
if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
-
desc = {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
get: function () {
|
|
12
|
-
return m[k]
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
Object.defineProperty(o, k2, desc)
|
|
17
|
-
}
|
|
18
|
-
: function (o, m, k, k2) {
|
|
19
|
-
if (k2 === undefined) k2 = k
|
|
20
|
-
o[k2] = m[k]
|
|
21
|
-
})
|
|
22
|
-
var __exportStar =
|
|
23
|
-
(this && this.__exportStar) ||
|
|
24
|
-
function (m, exports) {
|
|
25
|
-
for (var p in m)
|
|
26
|
-
if (p !== 'default' && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p)
|
|
27
|
-
}
|
|
28
|
-
Object.defineProperty(exports, '__esModule', { value: true })
|
|
29
|
-
__exportStar(require('./constants'), exports)
|
|
30
|
-
__exportStar(require('./encode'), exports)
|
|
31
|
-
__exportStar(require('./BinaryInfo'), exports)
|
|
1
|
+
export * from './constants.js';
|
|
2
|
+
export * from './encode.js';
|
|
3
|
+
export * from './BinaryInfo.js';
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const WABinary_1 = require('../../WABinary')
|
|
5
|
-
class USyncBotProfileProtocol {
|
|
1
|
+
import { getBinaryNodeChild, getBinaryNodeChildren, getBinaryNodeChildString } from '../../WABinary/index.js'
|
|
2
|
+
|
|
3
|
+
export class USyncBotProfileProtocol {
|
|
6
4
|
constructor() {
|
|
7
5
|
this.name = 'bot'
|
|
8
6
|
}
|
|
7
|
+
|
|
9
8
|
getQueryElement() {
|
|
10
9
|
return {
|
|
11
10
|
tag: 'bot',
|
|
@@ -13,6 +12,7 @@ class USyncBotProfileProtocol {
|
|
|
13
12
|
content: [{ tag: 'profile', attrs: { v: '1' } }]
|
|
14
13
|
}
|
|
15
14
|
}
|
|
15
|
+
|
|
16
16
|
getUserElement(user) {
|
|
17
17
|
return {
|
|
18
18
|
tag: 'bot',
|
|
@@ -20,36 +20,34 @@ class USyncBotProfileProtocol {
|
|
|
20
20
|
content: [{ tag: 'profile', attrs: { persona_id: user.personaId } }]
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
+
|
|
23
24
|
parser(node) {
|
|
24
|
-
const botNode =
|
|
25
|
-
const profile =
|
|
26
|
-
const commandsNode =
|
|
27
|
-
const promptsNode =
|
|
25
|
+
const botNode = getBinaryNodeChild(node, 'bot')
|
|
26
|
+
const profile = getBinaryNodeChild(botNode, 'profile')
|
|
27
|
+
const commandsNode = getBinaryNodeChild(profile, 'commands')
|
|
28
|
+
const promptsNode = getBinaryNodeChild(profile, 'prompts')
|
|
28
29
|
const commands = []
|
|
29
30
|
const prompts = []
|
|
30
|
-
for (const command of
|
|
31
|
+
for (const command of getBinaryNodeChildren(commandsNode, 'command')) {
|
|
31
32
|
commands.push({
|
|
32
|
-
name:
|
|
33
|
-
description:
|
|
33
|
+
name: getBinaryNodeChildString(command, 'name'),
|
|
34
|
+
description: getBinaryNodeChildString(command, 'description')
|
|
34
35
|
})
|
|
35
36
|
}
|
|
36
|
-
for (const prompt of
|
|
37
|
-
prompts.push(
|
|
38
|
-
`${(0, WABinary_1.getBinaryNodeChildString)(prompt, 'emoji')} ${(0, WABinary_1.getBinaryNodeChildString)(prompt, 'text')}`
|
|
39
|
-
)
|
|
37
|
+
for (const prompt of getBinaryNodeChildren(promptsNode, 'prompt')) {
|
|
38
|
+
prompts.push(`${getBinaryNodeChildString(prompt, 'emoji')} ${getBinaryNodeChildString(prompt, 'text')}`)
|
|
40
39
|
}
|
|
41
40
|
return {
|
|
42
|
-
isDefault: !!
|
|
41
|
+
isDefault: !!getBinaryNodeChild(profile, 'default'),
|
|
43
42
|
jid: node.attrs.jid,
|
|
44
|
-
name:
|
|
45
|
-
attributes:
|
|
46
|
-
description:
|
|
47
|
-
category:
|
|
43
|
+
name: getBinaryNodeChildString(profile, 'name'),
|
|
44
|
+
attributes: getBinaryNodeChildString(profile, 'attributes'),
|
|
45
|
+
description: getBinaryNodeChildString(profile, 'description'),
|
|
46
|
+
category: getBinaryNodeChildString(profile, 'category'),
|
|
48
47
|
personaId: profile.attrs['persona_id'],
|
|
49
|
-
commandsDescription:
|
|
48
|
+
commandsDescription: getBinaryNodeChildString(commandsNode, 'description'),
|
|
50
49
|
commands,
|
|
51
50
|
prompts
|
|
52
51
|
}
|
|
53
52
|
}
|
|
54
53
|
}
|
|
55
|
-
exports.USyncBotProfileProtocol = USyncBotProfileProtocol
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const WABinary_1 = require('../../WABinary')
|
|
5
|
-
class USyncBusinessProtocol {
|
|
1
|
+
import { assertNodeErrorFree, getBinaryNodeChild } from '../../WABinary/index.js'
|
|
2
|
+
|
|
3
|
+
export class USyncBusinessProtocol {
|
|
6
4
|
constructor(profileVersion = '2') {
|
|
7
5
|
this.name = 'business'
|
|
8
6
|
this.profileVersion = profileVersion
|
|
9
7
|
}
|
|
8
|
+
|
|
10
9
|
getQueryElement() {
|
|
11
10
|
return {
|
|
12
11
|
tag: 'business',
|
|
@@ -17,6 +16,7 @@ class USyncBusinessProtocol {
|
|
|
17
16
|
]
|
|
18
17
|
}
|
|
19
18
|
}
|
|
19
|
+
|
|
20
20
|
getUserElement(user) {
|
|
21
21
|
const children = []
|
|
22
22
|
if (user.verifiedNameSerial) {
|
|
@@ -27,11 +27,12 @@ class USyncBusinessProtocol {
|
|
|
27
27
|
}
|
|
28
28
|
return children.length > 0 ? { tag: 'business', attrs: {}, content: children } : null
|
|
29
29
|
}
|
|
30
|
+
|
|
30
31
|
parser(node) {
|
|
31
32
|
if (node.tag !== 'business') return null
|
|
32
|
-
|
|
33
|
-
const verifiedNameNode =
|
|
34
|
-
const profileNode =
|
|
33
|
+
assertNodeErrorFree(node)
|
|
34
|
+
const verifiedNameNode = getBinaryNodeChild(node, 'verified_name')
|
|
35
|
+
const profileNode = getBinaryNodeChild(node, 'profile')
|
|
35
36
|
return {
|
|
36
37
|
verifiedName: verifiedNameNode?.content ?? null,
|
|
37
38
|
verifiedLevel: verifiedNameNode?.attrs?.verified_level ?? null,
|
|
@@ -40,4 +41,3 @@ class USyncBusinessProtocol {
|
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
|
-
exports.USyncBusinessProtocol = USyncBusinessProtocol
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const WABinary_1 = require('../../WABinary')
|
|
5
|
-
class USyncContactProtocol {
|
|
1
|
+
import { assertNodeErrorFree } from '../../WABinary/index.js'
|
|
2
|
+
|
|
3
|
+
export class USyncContactProtocol {
|
|
6
4
|
constructor() {
|
|
7
5
|
this.name = 'contact'
|
|
8
6
|
}
|
|
7
|
+
|
|
9
8
|
getQueryElement() {
|
|
10
9
|
return {
|
|
11
10
|
tag: 'contact',
|
|
12
11
|
attrs: {}
|
|
13
12
|
}
|
|
14
13
|
}
|
|
14
|
+
|
|
15
15
|
getUserElement(user) {
|
|
16
16
|
if (user.phone) {
|
|
17
17
|
return {
|
|
@@ -43,12 +43,12 @@ class USyncContactProtocol {
|
|
|
43
43
|
attrs: {}
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
+
|
|
46
47
|
parser(node) {
|
|
47
48
|
if (node.tag === 'contact') {
|
|
48
|
-
|
|
49
|
+
assertNodeErrorFree(node)
|
|
49
50
|
return node?.attrs?.type === 'in'
|
|
50
51
|
}
|
|
51
52
|
return false
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
|
-
exports.USyncContactProtocol = USyncContactProtocol
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const WABinary_1 = require('../../WABinary')
|
|
5
|
-
class USyncDeviceProtocol {
|
|
1
|
+
import { assertNodeErrorFree, getBinaryNodeChild } from '../../WABinary/index.js'
|
|
2
|
+
|
|
3
|
+
export class USyncDeviceProtocol {
|
|
6
4
|
constructor() {
|
|
7
5
|
this.name = 'devices'
|
|
8
6
|
}
|
|
7
|
+
|
|
9
8
|
getQueryElement() {
|
|
10
9
|
return {
|
|
11
10
|
tag: 'devices',
|
|
@@ -14,19 +13,21 @@ class USyncDeviceProtocol {
|
|
|
14
13
|
}
|
|
15
14
|
}
|
|
16
15
|
}
|
|
17
|
-
|
|
16
|
+
|
|
17
|
+
getUserElement(/* user */) {
|
|
18
18
|
//TODO: Implement device phashing, ts and expectedTs
|
|
19
19
|
//TODO: if all are not present, return null <- current behavior
|
|
20
20
|
//TODO: otherwise return a node w tag 'devices' w those as attrs
|
|
21
21
|
return null
|
|
22
22
|
}
|
|
23
|
+
|
|
23
24
|
parser(node) {
|
|
24
25
|
const deviceList = []
|
|
25
26
|
let keyIndex = undefined
|
|
26
27
|
if (node.tag === 'devices') {
|
|
27
|
-
|
|
28
|
-
const deviceListNode =
|
|
29
|
-
const keyIndexNode =
|
|
28
|
+
assertNodeErrorFree(node)
|
|
29
|
+
const deviceListNode = getBinaryNodeChild(node, 'device-list')
|
|
30
|
+
const keyIndexNode = getBinaryNodeChild(node, 'key-index-list')
|
|
30
31
|
if (Array.isArray(deviceListNode?.content)) {
|
|
31
32
|
for (const { tag, attrs } of deviceListNode.content) {
|
|
32
33
|
const id = +attrs.id
|
|
@@ -54,4 +55,3 @@ class USyncDeviceProtocol {
|
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
|
-
exports.USyncDeviceProtocol = USyncDeviceProtocol
|
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const WABinary_1 = require('../../WABinary')
|
|
5
|
-
class USyncDisappearingModeProtocol {
|
|
1
|
+
import { assertNodeErrorFree } from '../../WABinary/index.js'
|
|
2
|
+
|
|
3
|
+
export class USyncDisappearingModeProtocol {
|
|
6
4
|
constructor() {
|
|
7
5
|
this.name = 'disappearing_mode'
|
|
8
6
|
}
|
|
7
|
+
|
|
9
8
|
getQueryElement() {
|
|
10
9
|
return {
|
|
11
10
|
tag: 'disappearing_mode',
|
|
12
11
|
attrs: {}
|
|
13
12
|
}
|
|
14
13
|
}
|
|
14
|
+
|
|
15
15
|
getUserElement() {
|
|
16
16
|
return null
|
|
17
17
|
}
|
|
18
|
+
|
|
18
19
|
parser(node) {
|
|
19
20
|
if (node.tag === 'disappearing_mode') {
|
|
20
|
-
|
|
21
|
+
assertNodeErrorFree(node)
|
|
21
22
|
const duration = +node?.attrs.duration
|
|
22
23
|
const setAt = new Date(+(node?.attrs.t || 0) * 1000)
|
|
23
24
|
return {
|
|
@@ -27,4 +28,3 @@ class USyncDisappearingModeProtocol {
|
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
|
-
exports.USyncDisappearingModeProtocol = USyncDisappearingModeProtocol
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.USyncFeatureProtocol = exports.USYNC_FEATURES = void 0
|
|
4
|
-
const WABinary_1 = require('../../WABinary')
|
|
1
|
+
import { getBinaryNodeChild } from '../../WABinary/index.js'
|
|
2
|
+
|
|
5
3
|
// Device feature flags that can be queried, ported from WhatsApp Web's
|
|
6
4
|
// WAWebUsyncFeature module.
|
|
7
|
-
|
|
5
|
+
export const USYNC_FEATURES = [
|
|
8
6
|
'document',
|
|
9
7
|
'encrypt',
|
|
10
8
|
'encrypt_blist',
|
|
@@ -17,14 +15,16 @@ exports.USYNC_FEATURES = [
|
|
|
17
15
|
'voip',
|
|
18
16
|
'multi_agent'
|
|
19
17
|
]
|
|
20
|
-
|
|
18
|
+
|
|
19
|
+
export class USyncFeatureProtocol {
|
|
21
20
|
/**
|
|
22
21
|
* @param {string[]} [features] feature names to query (defaults to all known)
|
|
23
22
|
*/
|
|
24
23
|
constructor(features) {
|
|
25
24
|
this.name = 'feature'
|
|
26
|
-
this.features = features && features.length ? features :
|
|
25
|
+
this.features = features && features.length ? features : USYNC_FEATURES
|
|
27
26
|
}
|
|
27
|
+
|
|
28
28
|
getQueryElement() {
|
|
29
29
|
return {
|
|
30
30
|
tag: 'feature',
|
|
@@ -32,14 +32,14 @@ class USyncFeatureProtocol {
|
|
|
32
32
|
content: this.features.map(feature => ({ tag: feature, attrs: {} }))
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
+
|
|
35
36
|
getUserElement() {
|
|
36
37
|
return null
|
|
37
38
|
}
|
|
39
|
+
|
|
38
40
|
parser(node) {
|
|
39
|
-
if (node.tag !== 'feature')
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
const errorNode = (0, WABinary_1.getBinaryNodeChild)(node, 'error')
|
|
41
|
+
if (node.tag !== 'feature') return null
|
|
42
|
+
const errorNode = getBinaryNodeChild(node, 'error')
|
|
43
43
|
if (errorNode) {
|
|
44
44
|
return {
|
|
45
45
|
errorCode: errorNode.attrs?.code ? +errorNode.attrs.code : undefined,
|
|
@@ -56,4 +56,3 @@ class USyncFeatureProtocol {
|
|
|
56
56
|
return features
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
exports.USyncFeatureProtocol = USyncFeatureProtocol
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
-
exports.USyncLIDProtocol = void 0
|
|
4
|
-
class USyncLIDProtocol {
|
|
1
|
+
export class USyncLIDProtocol {
|
|
5
2
|
constructor() {
|
|
6
3
|
this.name = 'lid'
|
|
7
4
|
}
|
|
5
|
+
|
|
8
6
|
getQueryElement() {
|
|
9
7
|
return {
|
|
10
8
|
tag: 'lid',
|
|
11
9
|
attrs: {}
|
|
12
10
|
}
|
|
13
11
|
}
|
|
12
|
+
|
|
14
13
|
getUserElement(user) {
|
|
15
14
|
if (user.lid) {
|
|
16
15
|
return {
|
|
@@ -21,6 +20,7 @@ class USyncLIDProtocol {
|
|
|
21
20
|
return null
|
|
22
21
|
}
|
|
23
22
|
}
|
|
23
|
+
|
|
24
24
|
parser(node) {
|
|
25
25
|
if (node.tag === 'lid') {
|
|
26
26
|
return node.attrs.val
|
|
@@ -28,4 +28,3 @@ class USyncLIDProtocol {
|
|
|
28
28
|
return null
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
exports.USyncLIDProtocol = USyncLIDProtocol
|