@badzz88/baileys 8.5.2 → 8.5.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/README.md +1 -1
- package/WAProto/WAProto.proto +1256 -75
- package/WAProto/index.d.ts +36042 -19649
- package/WAProto/index.js +181990 -135645
- package/engine-requirements.js +7 -15
- package/lib/Defaults/index.js +22 -17
- package/lib/Signal/Group/group_cipher.js +5 -5
- package/lib/Signal/Group/keyhelper.js +4 -4
- package/lib/Signal/Group/sender-chain-key.js +2 -2
- package/lib/Signal/Group/sender-key-distribution-message.js +1 -1
- package/lib/Signal/Group/sender-key-message.js +3 -3
- package/lib/Signal/Group/sender-key-record.js +1 -1
- package/lib/Signal/Group/sender-message-key.js +5 -5
- package/lib/Signal/libsignal.js +39 -59
- package/lib/Signal/lid-mapping.js +28 -10
- package/lib/Socket/aigroups.js +5 -5
- package/lib/Socket/business.js +3 -11
- package/lib/Socket/chats.js +668 -319
- package/lib/Socket/communities.js +85 -89
- package/lib/Socket/graphql.js +435 -228
- package/lib/Socket/groups.js +132 -211
- package/lib/Socket/index.js +9 -7
- package/lib/Socket/interactive-handler.js +117 -60
- package/lib/Socket/interop.js +56 -175
- package/lib/Socket/managed-account.js +79 -48
- package/lib/Socket/messages-recv.js +898 -340
- package/lib/Socket/messages-send.js +462 -160
- package/lib/Socket/mex.js +40 -53
- package/lib/Socket/newsletter.js +291 -291
- package/lib/Socket/privacy.js +77 -265
- package/lib/Socket/registration.js +164 -157
- package/lib/Socket/socket.js +181 -199
- package/lib/Socket/username.js +144 -227
- package/lib/Store/make-cache-manager-store.js +2 -2
- package/lib/Store/make-in-memory-store.js +25 -141
- package/lib/Types/Auth.js +3 -3
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Newsletter.js +96 -65
- package/lib/Types/State.js +4 -4
- package/lib/Types/index.js +1 -1
- package/lib/Utils/auth-utils.js +52 -57
- package/lib/Utils/browser-utils.js +1 -1
- package/lib/Utils/business.js +2 -6
- package/lib/Utils/chat-utils.js +102 -38
- package/lib/Utils/crypto.js +54 -84
- package/lib/Utils/decode-wa-message.js +316 -83
- package/lib/Utils/event-buffer.js +37 -61
- package/lib/Utils/generics.js +157 -103
- package/lib/Utils/group-history.js +3 -12
- package/lib/Utils/history.js +15 -15
- package/lib/Utils/index.js +1 -5
- package/lib/Utils/link-preview.js +3 -8
- package/lib/Utils/lt-hash.js +2 -35
- package/lib/Utils/make-mutex.js +1 -1
- package/lib/Utils/message-inspect.js +393 -0
- package/lib/Utils/message-retry-manager.js +27 -92
- package/lib/Utils/messages-media.js +159 -130
- package/lib/Utils/messages.js +144 -566
- package/lib/Utils/meta-ai-msmsg.js +62 -202
- package/lib/Utils/noise-handler.js +19 -21
- package/lib/Utils/offline-node-processor.js +3 -8
- package/lib/Utils/pre-key-manager.js +13 -23
- package/lib/Utils/process-message.js +197 -106
- package/lib/Utils/reporting-utils.js +2 -2
- package/lib/Utils/signal.js +28 -63
- package/lib/Utils/stanza-ack.js +39 -12
- package/lib/Utils/sync-action-utils.js +4 -7
- package/lib/Utils/tc-token-utils.js +20 -25
- package/lib/Utils/use-multi-file-auth-state.js +30 -14
- package/lib/Utils/validate-connection.js +59 -19
- package/lib/WABinary/decode.js +50 -16
- package/lib/WABinary/encode.js +54 -224
- package/lib/WABinary/generic-utils.js +7 -97
- package/lib/WABinary/jid-utils.js +27 -14
- package/lib/WAM/encode.js +7 -7
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +58 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +7 -1
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +13 -5
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -4
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +20 -7
- package/lib/WAUSync/Protocols/USyncNewsletterProtocol.js +865 -0
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +1 -1
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -2
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +1 -1
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +2 -1
- package/lib/WAUSync/Protocols/index.js +1 -0
- package/lib/WAUSync/USyncBackoff.js +26 -0
- package/lib/WAUSync/USyncQuery.js +77 -6
- package/lib/WAUSync/USyncUser.js +16 -8
- package/lib/WAUSync/index.js +1 -0
- package/lib/antiban.js +608 -854
- package/lib/index.js +3 -3
- package/package.json +16 -19
- package/lib/Socket/luxu.js +0 -387
- package/lib/Socket/text-router.js +0 -83
- package/lib/Store/keyed-db.js +0 -108
- package/lib/Types/Mex.js +0 -112
- package/lib/Utils/command-loader.d.ts +0 -31
- package/lib/Utils/command-loader.js +0 -100
- package/lib/Utils/companion-reg-client-utils.js +0 -42
- package/lib/Utils/curve25519-js.js +0 -275
- 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/sticker.js +0 -145
- package/lib/Utils/view-once-cache.d.ts +0 -9
- package/lib/Utils/view-once-cache.js +0 -79
package/lib/WABinary/encode.js
CHANGED
|
@@ -1,228 +1,58 @@
|
|
|
1
1
|
'use strict'
|
|
2
|
+
var __createBinding =
|
|
3
|
+
(this && this.__createBinding) ||
|
|
4
|
+
(Object.create
|
|
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 __setModuleDefault =
|
|
23
|
+
(this && this.__setModuleDefault) ||
|
|
24
|
+
(Object.create
|
|
25
|
+
? function (o, v) {
|
|
26
|
+
Object.defineProperty(o, 'default', { enumerable: true, value: v })
|
|
27
|
+
}
|
|
28
|
+
: function (o, v) {
|
|
29
|
+
o['default'] = v
|
|
30
|
+
})
|
|
31
|
+
var __importStar =
|
|
32
|
+
(this && this.__importStar) ||
|
|
33
|
+
(function () {
|
|
34
|
+
var ownKeys = function (o) {
|
|
35
|
+
ownKeys =
|
|
36
|
+
Object.getOwnPropertyNames ||
|
|
37
|
+
function (o) {
|
|
38
|
+
var ar = []
|
|
39
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k
|
|
40
|
+
return ar
|
|
41
|
+
}
|
|
42
|
+
return ownKeys(o)
|
|
43
|
+
}
|
|
44
|
+
return function (mod) {
|
|
45
|
+
if (mod && mod.__esModule) return mod
|
|
46
|
+
var result = {}
|
|
47
|
+
if (mod != null)
|
|
48
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== 'default') __createBinding(result, mod, k[i])
|
|
49
|
+
__setModuleDefault(result, mod)
|
|
50
|
+
return result
|
|
51
|
+
}
|
|
52
|
+
})()
|
|
2
53
|
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
54
|
exports.encodeBinaryNode = void 0
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const encodeBinaryNodeJS = (node, opts = constants, buffer = [0]) => {
|
|
8
|
-
const encoded = encodeBinaryNodeInner(node, opts, buffer);
|
|
9
|
-
return Buffer.from(encoded);
|
|
10
|
-
};
|
|
11
|
-
const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
12
|
-
const { TAGS, TOKEN_MAP } = opts;
|
|
13
|
-
const pushByte = (value) => buffer.push(value & 0xff);
|
|
14
|
-
const pushInt = (value, n, littleEndian = false) => {
|
|
15
|
-
for (let i = 0; i < n; i++) {
|
|
16
|
-
const curShift = littleEndian ? i : n - 1 - i;
|
|
17
|
-
buffer.push((value >> (curShift * 8)) & 0xff);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
const pushBytes = (bytes) => {
|
|
21
|
-
for (const b of bytes) {
|
|
22
|
-
buffer.push(b);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
const pushInt16 = (value) => {
|
|
26
|
-
pushBytes([(value >> 8) & 0xff, value & 0xff]);
|
|
27
|
-
};
|
|
28
|
-
const pushInt20 = (value) => pushBytes([(value >> 16) & 0x0f, (value >> 8) & 0xff, value & 0xff]);
|
|
29
|
-
const writeByteLength = (length) => {
|
|
30
|
-
if (length >= 4294967296) {
|
|
31
|
-
throw new Error('string too large to encode: ' + length);
|
|
32
|
-
}
|
|
33
|
-
if (length >= 1 << 20) {
|
|
34
|
-
pushByte(TAGS.BINARY_32);
|
|
35
|
-
pushInt(length, 4); // 32 bit integer
|
|
36
|
-
}
|
|
37
|
-
else if (length >= 256) {
|
|
38
|
-
pushByte(TAGS.BINARY_20);
|
|
39
|
-
pushInt20(length);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
pushByte(TAGS.BINARY_8);
|
|
43
|
-
pushByte(length);
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
const writeStringRaw = (str) => {
|
|
47
|
-
const bytes = Buffer.from(str, 'utf-8');
|
|
48
|
-
writeByteLength(bytes.length);
|
|
49
|
-
pushBytes(bytes);
|
|
50
|
-
};
|
|
51
|
-
const writeJid = ({ domainType, device, user, server }) => {
|
|
52
|
-
if (typeof device !== 'undefined') {
|
|
53
|
-
pushByte(TAGS.AD_JID);
|
|
54
|
-
pushByte(domainType || 0);
|
|
55
|
-
pushByte(device || 0);
|
|
56
|
-
writeString(user);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
pushByte(TAGS.JID_PAIR);
|
|
60
|
-
if (user.length) {
|
|
61
|
-
writeString(user);
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
pushByte(TAGS.LIST_EMPTY);
|
|
65
|
-
}
|
|
66
|
-
writeString(server);
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
const packNibble = (char) => {
|
|
70
|
-
switch (char) {
|
|
71
|
-
case '-':
|
|
72
|
-
return 10;
|
|
73
|
-
case '.':
|
|
74
|
-
return 11;
|
|
75
|
-
case '\0':
|
|
76
|
-
return 15;
|
|
77
|
-
default:
|
|
78
|
-
if (char >= '0' && char <= '9') {
|
|
79
|
-
return char.charCodeAt(0) - '0'.charCodeAt(0);
|
|
80
|
-
}
|
|
81
|
-
throw new Error(`invalid byte for nibble "${char}"`);
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
const packHex = (char) => {
|
|
85
|
-
if (char >= '0' && char <= '9') {
|
|
86
|
-
return char.charCodeAt(0) - '0'.charCodeAt(0);
|
|
87
|
-
}
|
|
88
|
-
if (char >= 'A' && char <= 'F') {
|
|
89
|
-
return 10 + char.charCodeAt(0) - 'A'.charCodeAt(0);
|
|
90
|
-
}
|
|
91
|
-
if (char >= 'a' && char <= 'f') {
|
|
92
|
-
return 10 + char.charCodeAt(0) - 'a'.charCodeAt(0);
|
|
93
|
-
}
|
|
94
|
-
if (char === '\0') {
|
|
95
|
-
return 15;
|
|
96
|
-
}
|
|
97
|
-
throw new Error(`Invalid hex char "${char}"`);
|
|
98
|
-
};
|
|
99
|
-
const writePackedBytes = (str, type) => {
|
|
100
|
-
if (str.length > TAGS.PACKED_MAX) {
|
|
101
|
-
throw new Error('Too many bytes to pack');
|
|
102
|
-
}
|
|
103
|
-
pushByte(type === 'nibble' ? TAGS.NIBBLE_8 : TAGS.HEX_8);
|
|
104
|
-
let roundedLength = Math.ceil(str.length / 2.0);
|
|
105
|
-
if (str.length % 2 !== 0) {
|
|
106
|
-
roundedLength |= 128;
|
|
107
|
-
}
|
|
108
|
-
pushByte(roundedLength);
|
|
109
|
-
const packFunction = type === 'nibble' ? packNibble : packHex;
|
|
110
|
-
const packBytePair = (v1, v2) => {
|
|
111
|
-
const result = (packFunction(v1) << 4) | packFunction(v2);
|
|
112
|
-
return result;
|
|
113
|
-
};
|
|
114
|
-
const strLengthHalf = Math.floor(str.length / 2);
|
|
115
|
-
for (let i = 0; i < strLengthHalf; i++) {
|
|
116
|
-
pushByte(packBytePair(str[2 * i], str[2 * i + 1]));
|
|
117
|
-
}
|
|
118
|
-
if (str.length % 2 !== 0) {
|
|
119
|
-
pushByte(packBytePair(str[str.length - 1], '\x00'));
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
const isNibble = (str) => {
|
|
123
|
-
if (!str || str.length > TAGS.PACKED_MAX) {
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
for (const char of str) {
|
|
127
|
-
const isInNibbleRange = char >= '0' && char <= '9';
|
|
128
|
-
if (!isInNibbleRange && char !== '-' && char !== '.') {
|
|
129
|
-
return false;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
return true;
|
|
133
|
-
};
|
|
134
|
-
const isHex = (str) => {
|
|
135
|
-
if (!str || str.length > TAGS.PACKED_MAX) {
|
|
136
|
-
return false;
|
|
137
|
-
}
|
|
138
|
-
for (const char of str) {
|
|
139
|
-
const isInNibbleRange = char >= '0' && char <= '9';
|
|
140
|
-
if (!isInNibbleRange && !(char >= 'A' && char <= 'F')) {
|
|
141
|
-
return false;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
return true;
|
|
145
|
-
};
|
|
146
|
-
const writeString = (str) => {
|
|
147
|
-
if (str === undefined || str === null) {
|
|
148
|
-
pushByte(TAGS.LIST_EMPTY);
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
if (str === '') {
|
|
152
|
-
writeStringRaw(str);
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
const tokenIndex = TOKEN_MAP[str];
|
|
156
|
-
if (tokenIndex) {
|
|
157
|
-
if (typeof tokenIndex.dict === 'number') {
|
|
158
|
-
pushByte(TAGS.DICTIONARY_0 + tokenIndex.dict);
|
|
159
|
-
}
|
|
160
|
-
pushByte(tokenIndex.index);
|
|
161
|
-
}
|
|
162
|
-
else if (isNibble(str)) {
|
|
163
|
-
writePackedBytes(str, 'nibble');
|
|
164
|
-
}
|
|
165
|
-
else if (isHex(str)) {
|
|
166
|
-
writePackedBytes(str, 'hex');
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
const decodedJid = jidDecode(str);
|
|
170
|
-
if (decodedJid) {
|
|
171
|
-
writeJid(decodedJid);
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
writeStringRaw(str);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
const writeListStart = (listSize) => {
|
|
179
|
-
if (listSize === 0) {
|
|
180
|
-
pushByte(TAGS.LIST_EMPTY);
|
|
181
|
-
}
|
|
182
|
-
else if (listSize < 256) {
|
|
183
|
-
pushBytes([TAGS.LIST_8, listSize]);
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
186
|
-
pushByte(TAGS.LIST_16);
|
|
187
|
-
pushInt16(listSize);
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
if (!tag) {
|
|
191
|
-
throw new Error('Invalid node: tag cannot be undefined');
|
|
192
|
-
}
|
|
193
|
-
const validAttributes = Object.keys(attrs || {}).filter(k => typeof attrs[k] !== 'undefined' && attrs[k] !== null);
|
|
194
|
-
writeListStart(2 * validAttributes.length + 1 + (typeof content !== 'undefined' ? 1 : 0));
|
|
195
|
-
writeString(tag);
|
|
196
|
-
for (const key of validAttributes) {
|
|
197
|
-
if (typeof attrs[key] === 'string') {
|
|
198
|
-
writeString(key);
|
|
199
|
-
writeString(attrs[key]);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
if (typeof content === 'string') {
|
|
203
|
-
writeString(content);
|
|
204
|
-
}
|
|
205
|
-
else if (Buffer.isBuffer(content) || content instanceof Uint8Array) {
|
|
206
|
-
writeByteLength(content.length);
|
|
207
|
-
pushBytes(content);
|
|
208
|
-
}
|
|
209
|
-
else if (Array.isArray(content)) {
|
|
210
|
-
const validContent = content.filter(item => item && (item.tag || Buffer.isBuffer(item) || item instanceof Uint8Array || typeof item === 'string'));
|
|
211
|
-
writeListStart(validContent.length);
|
|
212
|
-
for (const item of validContent) {
|
|
213
|
-
encodeBinaryNodeInner(item, opts, buffer);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
else if (typeof content === 'undefined') {
|
|
217
|
-
// do nothing
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`);
|
|
221
|
-
}
|
|
222
|
-
return buffer;
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
const encodeBinaryNode = (node, opts, buffer) => {
|
|
226
|
-
return encodeBinaryNodeJS(node, opts || constants, buffer || [0])
|
|
227
|
-
}
|
|
55
|
+
const rb = require('whatsapp-rust-bridge')
|
|
56
|
+
const encodeBinaryNode = node => Buffer.from(rb.encodeNode(node))
|
|
228
57
|
exports.encodeBinaryNode = encodeBinaryNode
|
|
58
|
+
|
|
@@ -13,12 +13,12 @@ exports.getBinaryNodeMessages =
|
|
|
13
13
|
exports.binaryNodeToString = binaryNodeToString
|
|
14
14
|
const boom_1 = require('@hapi/boom')
|
|
15
15
|
const index_js_1 = require('../../WAProto/index.js')
|
|
16
|
-
|
|
16
|
+
|
|
17
17
|
const indexCache = new WeakMap()
|
|
18
18
|
const getBinaryNodeChildren = (node, childTag) => {
|
|
19
19
|
if (!node || !Array.isArray(node.content)) return []
|
|
20
20
|
let index = indexCache.get(node)
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
if (!index) {
|
|
23
23
|
index = new Map()
|
|
24
24
|
for (const child of node.content) {
|
|
@@ -28,7 +28,7 @@ const getBinaryNodeChildren = (node, childTag) => {
|
|
|
28
28
|
}
|
|
29
29
|
indexCache.set(node, index)
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
return index.get(childTag) || []
|
|
33
33
|
}
|
|
34
34
|
exports.getBinaryNodeChildren = getBinaryNodeChildren
|
|
@@ -53,7 +53,7 @@ exports.getBinaryNodeChildBuffer = getBinaryNodeChildBuffer
|
|
|
53
53
|
const getBinaryNodeChildString = (node, childTag) => {
|
|
54
54
|
const child = (0, exports.getBinaryNodeChild)(node, childTag)?.content
|
|
55
55
|
if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
|
|
56
|
-
return Buffer.from(child).toString('
|
|
56
|
+
return Buffer.from(child).toString('utf8')
|
|
57
57
|
} else if (typeof child === 'string') {
|
|
58
58
|
return child
|
|
59
59
|
}
|
|
@@ -61,7 +61,9 @@ const getBinaryNodeChildString = (node, childTag) => {
|
|
|
61
61
|
exports.getBinaryNodeChildString = getBinaryNodeChildString
|
|
62
62
|
const getBinaryNodeChildUInt = (node, childTag, length) => {
|
|
63
63
|
const buff = (0, exports.getBinaryNodeChildBuffer)(node, childTag)
|
|
64
|
-
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
if (buff && buff.length >= length) {
|
|
65
67
|
return bufferToUInt(buff, length)
|
|
66
68
|
}
|
|
67
69
|
}
|
|
@@ -117,98 +119,6 @@ const getBinaryFilteredBizBot = nodeContent => {
|
|
|
117
119
|
}
|
|
118
120
|
exports.getBinaryFilteredBizBot = getBinaryFilteredBizBot
|
|
119
121
|
|
|
120
|
-
const getAdditionalNode = name => {
|
|
121
|
-
if (name) name = name.toLowerCase()
|
|
122
|
-
const ts = Math.floor(Date.now() / 1000) - 77980457
|
|
123
|
-
const order_response_name = {
|
|
124
|
-
review_and_pay: 'order_details',
|
|
125
|
-
review_order: 'order_status',
|
|
126
|
-
order_status: 'order_status',
|
|
127
|
-
payment_info: 'payment_info',
|
|
128
|
-
payment_status: 'payment_status',
|
|
129
|
-
payment_method: 'payment_method',
|
|
130
|
-
catalog_message: 'catalog_message'
|
|
131
|
-
}
|
|
132
|
-
const flow_name = {
|
|
133
|
-
cta_catalog: 'cta_catalog',
|
|
134
|
-
mpm: 'mpm',
|
|
135
|
-
call_request: 'call_permission_request',
|
|
136
|
-
view_catalog: 'automated_greeting_message_view_catalog',
|
|
137
|
-
wa_pay_detail: 'wa_payment_transaction_details',
|
|
138
|
-
send_location: 'send_location',
|
|
139
|
-
payment_key_info: 'payment_key_info'
|
|
140
|
-
}
|
|
141
|
-
if (order_response_name[name]) {
|
|
142
|
-
return [
|
|
143
|
-
{
|
|
144
|
-
tag: 'biz',
|
|
145
|
-
attrs: {
|
|
146
|
-
native_flow_name: order_response_name[name]
|
|
147
|
-
},
|
|
148
|
-
content: []
|
|
149
|
-
}
|
|
150
|
-
]
|
|
151
|
-
} else if (flow_name[name] || name === 'interactive' || name === 'buttons') {
|
|
152
|
-
return [
|
|
153
|
-
{
|
|
154
|
-
tag: 'biz',
|
|
155
|
-
attrs: {
|
|
156
|
-
actual_actors: '2',
|
|
157
|
-
host_storage: '2',
|
|
158
|
-
privacy_mode_ts: `${ts}`
|
|
159
|
-
},
|
|
160
|
-
content: [
|
|
161
|
-
{
|
|
162
|
-
tag: 'engagement',
|
|
163
|
-
attrs: {
|
|
164
|
-
customer_service_state: 'open',
|
|
165
|
-
conversation_state: 'open'
|
|
166
|
-
}
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
tag: 'interactive',
|
|
170
|
-
attrs: {
|
|
171
|
-
type: 'native_flow',
|
|
172
|
-
v: '1'
|
|
173
|
-
},
|
|
174
|
-
content: [
|
|
175
|
-
{
|
|
176
|
-
tag: 'native_flow',
|
|
177
|
-
attrs: {
|
|
178
|
-
v: '9',
|
|
179
|
-
name: flow_name[name] ?? 'mixed'
|
|
180
|
-
},
|
|
181
|
-
content: []
|
|
182
|
-
}
|
|
183
|
-
]
|
|
184
|
-
}
|
|
185
|
-
]
|
|
186
|
-
}
|
|
187
|
-
]
|
|
188
|
-
} else {
|
|
189
|
-
return [
|
|
190
|
-
{
|
|
191
|
-
tag: 'biz',
|
|
192
|
-
attrs: {
|
|
193
|
-
actual_actors: '2',
|
|
194
|
-
host_storage: '2',
|
|
195
|
-
privacy_mode_ts: `${ts}`
|
|
196
|
-
},
|
|
197
|
-
content: [
|
|
198
|
-
{
|
|
199
|
-
tag: 'engagement',
|
|
200
|
-
attrs: {
|
|
201
|
-
customer_service_state: 'open',
|
|
202
|
-
conversation_state: 'open'
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
]
|
|
206
|
-
}
|
|
207
|
-
]
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
exports.getAdditionalNode = getAdditionalNode
|
|
211
|
-
|
|
212
122
|
function bufferToUInt(e, t) {
|
|
213
123
|
let a = 0
|
|
214
124
|
for (let i = 0; i < t; i++) {
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
3
|
exports.transferDevice =
|
|
4
4
|
exports.jidNormalizedUser =
|
|
5
|
+
exports.isJidLid =
|
|
5
6
|
exports.isJidBot =
|
|
6
7
|
exports.isHostedLidUser =
|
|
7
8
|
exports.isHostedPnUser =
|
|
@@ -23,9 +24,13 @@ exports.transferDevice =
|
|
|
23
24
|
exports.PSA_WID =
|
|
24
25
|
exports.SERVER_JID =
|
|
25
26
|
exports.OFFICIAL_BIZ_JID =
|
|
27
|
+
exports.BOT_WHATSAPP_NET =
|
|
28
|
+
exports.BOT_SERVER =
|
|
26
29
|
exports.S_WHATSAPP_NET =
|
|
27
30
|
void 0
|
|
28
31
|
exports.S_WHATSAPP_NET = '@s.whatsapp.net'
|
|
32
|
+
exports.BOT_WHATSAPP_NET = '@bot.whatsapp.net'
|
|
33
|
+
exports.BOT_SERVER = '@bot'
|
|
29
34
|
exports.OFFICIAL_BIZ_JID = '16505361212@c.us'
|
|
30
35
|
exports.SERVER_JID = 'server@c.us'
|
|
31
36
|
exports.PSA_WID = '0@c.us'
|
|
@@ -35,6 +40,7 @@ var WAJIDDomains
|
|
|
35
40
|
;(function (WAJIDDomains) {
|
|
36
41
|
WAJIDDomains[(WAJIDDomains['WHATSAPP'] = 0)] = 'WHATSAPP'
|
|
37
42
|
WAJIDDomains[(WAJIDDomains['LID'] = 1)] = 'LID'
|
|
43
|
+
WAJIDDomains[(WAJIDDomains['BOT'] = 2)] = 'BOT'
|
|
38
44
|
WAJIDDomains[(WAJIDDomains['HOSTED'] = 128)] = 'HOSTED'
|
|
39
45
|
WAJIDDomains[(WAJIDDomains['HOSTED_LID'] = 129)] = 'HOSTED_LID'
|
|
40
46
|
})(WAJIDDomains || (exports.WAJIDDomains = WAJIDDomains = {}))
|
|
@@ -42,6 +48,8 @@ const getServerFromDomainType = (initialServer, domainType) => {
|
|
|
42
48
|
switch (domainType) {
|
|
43
49
|
case WAJIDDomains.LID:
|
|
44
50
|
return 'lid'
|
|
51
|
+
case WAJIDDomains.BOT:
|
|
52
|
+
return 'bot'
|
|
45
53
|
case WAJIDDomains.HOSTED:
|
|
46
54
|
return 'hosted'
|
|
47
55
|
case WAJIDDomains.HOSTED_LID:
|
|
@@ -280,7 +288,6 @@ const jidEncode = (user, server, device, agent) => {
|
|
|
280
288
|
}
|
|
281
289
|
exports.jidEncode = jidEncode
|
|
282
290
|
const jidDecode = jid => {
|
|
283
|
-
// todo: investigate how to implement hosted ids in this case
|
|
284
291
|
const sepIdx = typeof jid === 'string' ? jid.indexOf('@') : -1
|
|
285
292
|
if (sepIdx < 0) {
|
|
286
293
|
return undefined
|
|
@@ -292,12 +299,14 @@ const jidDecode = jid => {
|
|
|
292
299
|
let domainType = WAJIDDomains.WHATSAPP
|
|
293
300
|
if (server === 'lid') {
|
|
294
301
|
domainType = WAJIDDomains.LID
|
|
302
|
+
} else if (server === 'bot') {
|
|
303
|
+
domainType = WAJIDDomains.BOT
|
|
295
304
|
} else if (server === 'hosted') {
|
|
296
305
|
domainType = WAJIDDomains.HOSTED
|
|
297
306
|
} else if (server === 'hosted.lid') {
|
|
298
307
|
domainType = WAJIDDomains.HOSTED_LID
|
|
299
308
|
} else if (agent) {
|
|
300
|
-
domainType = parseInt(agent)
|
|
309
|
+
domainType = parseInt(agent, 10)
|
|
301
310
|
}
|
|
302
311
|
return {
|
|
303
312
|
server: server,
|
|
@@ -307,41 +316,45 @@ const jidDecode = jid => {
|
|
|
307
316
|
}
|
|
308
317
|
}
|
|
309
318
|
exports.jidDecode = jidDecode
|
|
310
|
-
|
|
319
|
+
|
|
311
320
|
const areJidsSameUser = (jid1, jid2) => (0, exports.jidDecode)(jid1)?.user === (0, exports.jidDecode)(jid2)?.user
|
|
312
321
|
exports.areJidsSameUser = areJidsSameUser
|
|
313
|
-
|
|
322
|
+
|
|
314
323
|
const isJidMetaAI = jid => jid?.endsWith('@bot')
|
|
315
324
|
exports.isJidMetaAI = isJidMetaAI
|
|
316
|
-
|
|
325
|
+
|
|
317
326
|
const isPnUser = jid => jid?.endsWith('@s.whatsapp.net')
|
|
318
327
|
exports.isPnUser = isPnUser
|
|
319
|
-
|
|
328
|
+
|
|
320
329
|
const isInteropUser = jid => jid?.endsWith('@interop')
|
|
321
330
|
exports.isInteropUser = isInteropUser
|
|
322
|
-
|
|
331
|
+
|
|
323
332
|
const isLidUser = jid => jid?.endsWith('@lid')
|
|
324
333
|
exports.isLidUser = isLidUser
|
|
325
|
-
|
|
334
|
+
|
|
335
|
+
const isJidLid = jid => jid?.endsWith('@lid')
|
|
336
|
+
exports.isJidLid = isJidLid
|
|
337
|
+
|
|
326
338
|
const isJidBroadcast = jid => jid?.endsWith('@broadcast')
|
|
327
339
|
exports.isJidBroadcast = isJidBroadcast
|
|
328
|
-
|
|
340
|
+
|
|
329
341
|
const isJidGroup = jid => jid?.endsWith('@g.us')
|
|
330
342
|
exports.isJidGroup = isJidGroup
|
|
331
|
-
|
|
343
|
+
|
|
332
344
|
const isJidStatusBroadcast = jid => jid === 'status@broadcast'
|
|
333
345
|
exports.isJidStatusBroadcast = isJidStatusBroadcast
|
|
334
|
-
|
|
346
|
+
|
|
335
347
|
const isJidNewsletter = jid => jid?.endsWith('@newsletter')
|
|
336
348
|
exports.isJidNewsletter = isJidNewsletter
|
|
337
|
-
|
|
349
|
+
|
|
338
350
|
const isHostedPnUser = jid => jid?.endsWith('@hosted')
|
|
339
351
|
exports.isHostedPnUser = isHostedPnUser
|
|
340
|
-
|
|
352
|
+
|
|
341
353
|
const isHostedLidUser = jid => jid?.endsWith('@hosted.lid')
|
|
342
354
|
exports.isHostedLidUser = isHostedLidUser
|
|
343
355
|
const botRegexp = /^1313555\d{4}$|^131655500\d{2}$/
|
|
344
|
-
|
|
356
|
+
|
|
357
|
+
const isJidBot = jid => jid && ((botRegexp.test(jid.split('@')[0]) && jid.endsWith('@c.us')) || jid.endsWith('@bot'))
|
|
345
358
|
exports.isJidBot = isJidBot
|
|
346
359
|
const jidNormalizedUser = jid => {
|
|
347
360
|
const result = (0, exports.jidDecode)(jid)
|
package/lib/WAM/encode.js
CHANGED
|
@@ -18,12 +18,12 @@ const encodeWAM = binaryInfo => {
|
|
|
18
18
|
}
|
|
19
19
|
exports.encodeWAM = encodeWAM
|
|
20
20
|
function encodeWAMHeader(binaryInfo) {
|
|
21
|
-
const headerBuffer = Buffer.alloc(8)
|
|
21
|
+
const headerBuffer = Buffer.alloc(8)
|
|
22
22
|
headerBuffer.write('WAM', 0, 'utf8')
|
|
23
23
|
headerBuffer.writeUInt8(binaryInfo.protocolVersion, 3)
|
|
24
|
-
headerBuffer.writeUInt8(1, 4)
|
|
24
|
+
headerBuffer.writeUInt8(1, 4)
|
|
25
25
|
headerBuffer.writeUInt16BE(binaryInfo.sequence, 5)
|
|
26
|
-
headerBuffer.writeUInt8(0, 7)
|
|
26
|
+
headerBuffer.writeUInt8(0, 7)
|
|
27
27
|
binaryInfo.buffer.push(headerBuffer)
|
|
28
28
|
}
|
|
29
29
|
function encodeGlobalAttributes(binaryInfo, globals) {
|
|
@@ -71,7 +71,7 @@ function serializeData(key, value, flag) {
|
|
|
71
71
|
return buffer
|
|
72
72
|
}
|
|
73
73
|
} else if (typeof value === 'number' && Number.isInteger(value)) {
|
|
74
|
-
|
|
74
|
+
|
|
75
75
|
if (value === 0 || value === 1) {
|
|
76
76
|
buffer = Buffer.alloc(bufferLength)
|
|
77
77
|
offset = serializeHeader(buffer, offset, key, flag | ((value + 1) << 4))
|
|
@@ -98,13 +98,13 @@ function serializeData(key, value, flag) {
|
|
|
98
98
|
return buffer
|
|
99
99
|
}
|
|
100
100
|
} else if (typeof value === 'number') {
|
|
101
|
-
|
|
101
|
+
|
|
102
102
|
buffer = Buffer.alloc(bufferLength + 8)
|
|
103
103
|
offset = serializeHeader(buffer, offset, key, flag | (7 << 4))
|
|
104
104
|
buffer.writeDoubleLE(value, offset)
|
|
105
105
|
return buffer
|
|
106
106
|
} else if (typeof value === 'string') {
|
|
107
|
-
|
|
107
|
+
|
|
108
108
|
const utf8Bytes = Buffer.byteLength(value, 'utf8')
|
|
109
109
|
if (utf8Bytes < 256) {
|
|
110
110
|
buffer = Buffer.alloc(bufferLength + 1 + utf8Bytes)
|
|
@@ -124,7 +124,7 @@ function serializeData(key, value, flag) {
|
|
|
124
124
|
buffer.write(value, offset, 'utf8')
|
|
125
125
|
return buffer
|
|
126
126
|
}
|
|
127
|
-
throw
|
|
127
|
+
throw new Error(`WAM serializeData: unsupported value type ${typeof value} for key ${key}`)
|
|
128
128
|
}
|
|
129
129
|
function serializeHeader(buffer, offset, key, flag) {
|
|
130
130
|
if (key < 256) {
|
|
@@ -32,11 +32,68 @@ class USyncBusinessProtocol {
|
|
|
32
32
|
;(0, WABinary_1.assertNodeErrorFree)(node)
|
|
33
33
|
const verifiedNameNode = (0, WABinary_1.getBinaryNodeChild)(node, 'verified_name')
|
|
34
34
|
const profileNode = (0, WABinary_1.getBinaryNodeChild)(node, 'profile')
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
let businessHours = undefined
|
|
38
|
+
if (profileNode) {
|
|
39
|
+
const businessHoursNode = (0, WABinary_1.getBinaryNodeChild)(profileNode, 'business_hours')
|
|
40
|
+
if (businessHoursNode) {
|
|
41
|
+
const configs = (0, WABinary_1.getBinaryNodeChildren)(businessHoursNode, 'business_hours_config')
|
|
42
|
+
businessHours = {
|
|
43
|
+
timezone: businessHoursNode.attrs?.timezone ?? null,
|
|
44
|
+
config: configs.map(({ attrs }) => ({
|
|
45
|
+
dayOfWeek: attrs?.day_of_week ?? null,
|
|
46
|
+
openTime: attrs?.open_time ?? null,
|
|
47
|
+
closeTime: attrs?.close_time ?? null,
|
|
48
|
+
mode: attrs?.mode ?? null
|
|
49
|
+
}))
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
const addressNode = profileNode ? (0, WABinary_1.getBinaryNodeChild)(profileNode, 'address') : null
|
|
56
|
+
const businessAddress = addressNode?.content
|
|
57
|
+
? Buffer.isBuffer(addressNode.content)
|
|
58
|
+
? addressNode.content.toString()
|
|
59
|
+
: String(addressNode.content)
|
|
60
|
+
: (profileNode?.attrs?.address ?? null)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
const catalogStatus = profileNode
|
|
64
|
+
? {
|
|
65
|
+
exists: profileNode.attrs?.catalog_exists === 'true' || profileNode.attrs?.catalog_exists === true,
|
|
66
|
+
sendAll: profileNode.attrs?.catalog_send_all === 'true' || profileNode.attrs?.catalog_send_all === true
|
|
67
|
+
}
|
|
68
|
+
: null
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
const cartEnabled =
|
|
72
|
+
profileNode?.attrs?.cart_enabled !== undefined
|
|
73
|
+
? profileNode.attrs.cart_enabled === 'true' || profileNode.attrs.cart_enabled === true
|
|
74
|
+
: null
|
|
75
|
+
const webCartEnabled =
|
|
76
|
+
profileNode?.attrs?.web_cart_enabled !== undefined
|
|
77
|
+
? profileNode.attrs.web_cart_enabled === 'true' || profileNode.attrs.web_cart_enabled === true
|
|
78
|
+
: null
|
|
79
|
+
const webCartOnOff = profileNode?.attrs?.web_cart_on_off ?? null
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
const commerceExperience = profileNode?.attrs?.commerce_experience ?? null
|
|
83
|
+
|
|
35
84
|
return {
|
|
36
85
|
verifiedName: verifiedNameNode?.content ?? null,
|
|
37
86
|
verifiedLevel: verifiedNameNode?.attrs?.verified_level ?? null,
|
|
87
|
+
verifiedNameLevel: verifiedNameNode?.attrs?.verified_level ?? null,
|
|
38
88
|
profileTag: profileNode?.attrs?.tag ?? null,
|
|
39
|
-
pnJid: node.attrs?.pn_jid ?? null
|
|
89
|
+
pnJid: node.attrs?.pn_jid ?? null,
|
|
90
|
+
businessHours: businessHours ?? null,
|
|
91
|
+
businessAddress,
|
|
92
|
+
catalogStatus,
|
|
93
|
+
cartEnabled,
|
|
94
|
+
webCartEnabled,
|
|
95
|
+
webCartOnOff,
|
|
96
|
+
commerceExperience
|
|
40
97
|
}
|
|
41
98
|
}
|
|
42
99
|
}
|
|
@@ -46,7 +46,13 @@ class USyncContactProtocol {
|
|
|
46
46
|
parser(node) {
|
|
47
47
|
if (node.tag === 'contact') {
|
|
48
48
|
;(0, WABinary_1.assertNodeErrorFree)(node)
|
|
49
|
-
|
|
49
|
+
const inWA = node?.attrs?.type === 'in'
|
|
50
|
+
const restrictionType = node?.attrs?.stella_addressbook_restriction_type
|
|
51
|
+
if (restrictionType !== undefined) {
|
|
52
|
+
|
|
53
|
+
return { inWA, stellaAddressbookRestrictionType: restrictionType }
|
|
54
|
+
}
|
|
55
|
+
return inWA
|
|
50
56
|
}
|
|
51
57
|
return false
|
|
52
58
|
}
|