@vanzxy/baileys 1.4.0 → 1.4.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/cjs/WAProto/index.js +106053 -0
- package/cjs/lib/Defaults/index.js +168 -0
- package/cjs/lib/Signal/Group/ciphertext-message.js +16 -0
- package/cjs/lib/Signal/Group/group-session-builder.js +67 -0
- package/cjs/lib/Signal/Group/group_cipher.js +86 -0
- package/cjs/lib/Signal/Group/index.js +58 -0
- package/cjs/lib/Signal/Group/keyhelper.js +56 -0
- package/cjs/lib/Signal/Group/sender-chain-key.js +30 -0
- package/cjs/lib/Signal/Group/sender-key-distribution-message.js +67 -0
- package/cjs/lib/Signal/Group/sender-key-message.js +70 -0
- package/cjs/lib/Signal/Group/sender-key-name.js +52 -0
- package/cjs/lib/Signal/Group/sender-key-record.js +45 -0
- package/cjs/lib/Signal/Group/sender-key-state.js +88 -0
- package/cjs/lib/Signal/Group/sender-message-key.js +30 -0
- package/cjs/lib/Signal/libsignal.js +467 -0
- package/cjs/lib/Signal/lid-mapping.js +281 -0
- package/cjs/lib/Socket/Client/index.js +19 -0
- package/cjs/lib/Socket/Client/types.js +15 -0
- package/cjs/lib/Socket/Client/websocket.js +61 -0
- package/cjs/lib/Socket/business.js +384 -0
- package/cjs/lib/Socket/chats.js +1257 -0
- package/cjs/lib/Socket/communities.js +442 -0
- package/cjs/lib/Socket/dugong.js +753 -0
- package/cjs/lib/Socket/groups.js +360 -0
- package/cjs/lib/Socket/index.js +19 -0
- package/cjs/lib/Socket/messages-recv.js +1790 -0
- package/cjs/lib/Socket/messages-send.js +1390 -0
- package/cjs/lib/Socket/mex.js +46 -0
- package/cjs/lib/Socket/newsletter.js +340 -0
- package/cjs/lib/Socket/socket.js +1007 -0
- package/cjs/lib/Store/index.js +20 -0
- package/cjs/lib/Store/make-in-memory-store.js +438 -0
- package/cjs/lib/Store/make-ordered-dictionary.js +82 -0
- package/cjs/lib/Store/object-repository.js +28 -0
- package/cjs/lib/Types/Auth.js +3 -0
- package/cjs/lib/Types/Bussines.js +3 -0
- package/cjs/lib/Types/Call.js +3 -0
- package/cjs/lib/Types/Chat.js +11 -0
- package/cjs/lib/Types/Contact.js +3 -0
- package/cjs/lib/Types/Events.js +4 -0
- package/cjs/lib/Types/GroupMetadata.js +3 -0
- package/cjs/lib/Types/Label.js +26 -0
- package/cjs/lib/Types/LabelAssociation.js +8 -0
- package/cjs/lib/Types/Message.js +19 -0
- package/cjs/lib/Types/Mex.js +40 -0
- package/cjs/lib/Types/Product.js +3 -0
- package/cjs/lib/Types/RichType.js +24 -0
- package/cjs/lib/Types/Signal.js +4 -0
- package/cjs/lib/Types/Socket.js +4 -0
- package/cjs/lib/Types/State.js +54 -0
- package/cjs/lib/Types/USync.js +4 -0
- package/cjs/lib/Types/index.js +42 -0
- package/cjs/lib/Utils/MessageBuilder.js +2164 -0
- package/cjs/lib/Utils/auth-utils.js +312 -0
- package/cjs/lib/Utils/browser-utils.js +32 -0
- package/cjs/lib/Utils/business.js +245 -0
- package/cjs/lib/Utils/chat-utils.js +937 -0
- package/cjs/lib/Utils/companion-reg-client-utils.js +45 -0
- package/cjs/lib/Utils/crypto.js +196 -0
- package/cjs/lib/Utils/decode-wa-message.js +324 -0
- package/cjs/lib/Utils/event-buffer.js +643 -0
- package/cjs/lib/Utils/generics.js +429 -0
- package/cjs/lib/Utils/history.js +151 -0
- package/cjs/lib/Utils/identity-change-handler.js +56 -0
- package/cjs/lib/Utils/index.js +42 -0
- package/cjs/lib/Utils/link-preview.js +122 -0
- package/cjs/lib/Utils/logger.js +8 -0
- package/cjs/lib/Utils/lt-hash.js +62 -0
- package/cjs/lib/Utils/make-mutex.js +38 -0
- package/cjs/lib/Utils/message-retry-manager.js +267 -0
- package/cjs/lib/Utils/messages-media.js +933 -0
- package/cjs/lib/Utils/messages.js +2175 -0
- package/cjs/lib/Utils/noise-handler.js +205 -0
- package/cjs/lib/Utils/offline-node-processor.js +43 -0
- package/cjs/lib/Utils/pre-key-manager.js +113 -0
- package/cjs/lib/Utils/process-message.js +772 -0
- package/cjs/lib/Utils/reporting-utils.js +263 -0
- package/cjs/lib/Utils/rich-message-utils.js +439 -0
- package/cjs/lib/Utils/signal.js +214 -0
- package/cjs/lib/Utils/stanza-ack.js +41 -0
- package/cjs/lib/Utils/sync-action-utils.js +54 -0
- package/cjs/lib/Utils/tc-token-utils.js +174 -0
- package/cjs/lib/Utils/use-multi-file-auth-state.js +125 -0
- package/cjs/lib/Utils/use-single-file-auth-state.js +121 -0
- package/cjs/lib/Utils/use-sqlite-auth-state.js +182 -0
- package/cjs/lib/Utils/validate-connection.js +210 -0
- package/cjs/lib/WABinary/constants.js +1470 -0
- package/cjs/lib/WABinary/decode.js +301 -0
- package/cjs/lib/WABinary/encode.js +257 -0
- package/cjs/lib/WABinary/generic-utils.js +274 -0
- package/cjs/lib/WABinary/index.js +22 -0
- package/cjs/lib/WABinary/jid-utils.js +114 -0
- package/cjs/lib/WABinary/types.js +37 -0
- package/cjs/lib/WAM/BinaryInfo.js +14 -0
- package/cjs/lib/WAM/constants.js +22856 -0
- package/cjs/lib/WAM/encode.js +154 -0
- package/cjs/lib/WAM/index.js +20 -0
- package/cjs/lib/WAUSync/Protocols/USyncContactProtocol.js +56 -0
- package/cjs/lib/WAUSync/Protocols/USyncDeviceProtocol.js +67 -0
- package/cjs/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +31 -0
- package/cjs/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
- package/cjs/lib/WAUSync/Protocols/USyncUsernameProtocol.js +29 -0
- package/cjs/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +55 -0
- package/cjs/lib/WAUSync/Protocols/UsyncLIDProtocol.js +33 -0
- package/cjs/lib/WAUSync/Protocols/index.js +24 -0
- package/cjs/lib/WAUSync/USyncQuery.js +126 -0
- package/cjs/lib/WAUSync/USyncUser.js +35 -0
- package/cjs/lib/WAUSync/index.js +20 -0
- package/cjs/lib/index.js +34 -0
- package/cjs/package.json +1 -0
- package/lib/Socket/messages-send.js +4 -3
- package/lib/Utils/messages.js +4 -1
- package/package.json +16 -5
- package/postinstall-banner.js +3 -2
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getBizBinaryNode = exports.getBinaryNodeMessages = exports.reduceBinaryNodeToDictionary = exports.assertNodeErrorFree = exports.getBinaryNodeChildUInt = exports.getBinaryNodeChildString = exports.getBinaryNodeChildBuffer = exports.getAllBinaryNodeChildren = exports.getBinaryNodeChild = exports.getBinaryNodeChildren = void 0;
|
|
4
|
+
exports.binaryNodeToString = binaryNodeToString;
|
|
5
|
+
const boom_1 = require("@hapi/boom");
|
|
6
|
+
const crypto_1 = require("crypto");
|
|
7
|
+
const index_js_1 = require("../../WAProto/index.js");
|
|
8
|
+
// some extra useful utilities
|
|
9
|
+
const indexCache = new WeakMap();
|
|
10
|
+
const getBinaryNodeChildren = (node, childTag) => {
|
|
11
|
+
if (!node || !Array.isArray(node.content))
|
|
12
|
+
return [];
|
|
13
|
+
let index = indexCache.get(node);
|
|
14
|
+
// Build the index once per node
|
|
15
|
+
if (!index) {
|
|
16
|
+
index = new Map();
|
|
17
|
+
for (const child of node.content) {
|
|
18
|
+
let arr = index.get(child.tag);
|
|
19
|
+
if (!arr)
|
|
20
|
+
index.set(child.tag, (arr = []));
|
|
21
|
+
arr.push(child);
|
|
22
|
+
}
|
|
23
|
+
indexCache.set(node, index);
|
|
24
|
+
}
|
|
25
|
+
// Return first matching child
|
|
26
|
+
return index.get(childTag) || [];
|
|
27
|
+
};
|
|
28
|
+
exports.getBinaryNodeChildren = getBinaryNodeChildren;
|
|
29
|
+
const getBinaryNodeChild = (node, childTag) => {
|
|
30
|
+
return (0, exports.getBinaryNodeChildren)(node, childTag)[0];
|
|
31
|
+
};
|
|
32
|
+
exports.getBinaryNodeChild = getBinaryNodeChild;
|
|
33
|
+
const getAllBinaryNodeChildren = ({ content }) => {
|
|
34
|
+
if (Array.isArray(content)) {
|
|
35
|
+
return content;
|
|
36
|
+
}
|
|
37
|
+
return [];
|
|
38
|
+
};
|
|
39
|
+
exports.getAllBinaryNodeChildren = getAllBinaryNodeChildren;
|
|
40
|
+
const getBinaryNodeChildBuffer = (node, childTag) => {
|
|
41
|
+
const child = (0, exports.getBinaryNodeChild)(node, childTag)?.content;
|
|
42
|
+
if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
|
|
43
|
+
return child;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
exports.getBinaryNodeChildBuffer = getBinaryNodeChildBuffer;
|
|
47
|
+
const getBinaryNodeChildString = (node, childTag) => {
|
|
48
|
+
const child = (0, exports.getBinaryNodeChild)(node, childTag)?.content;
|
|
49
|
+
if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
|
|
50
|
+
return Buffer.from(child).toString('utf-8');
|
|
51
|
+
}
|
|
52
|
+
else if (typeof child === 'string') {
|
|
53
|
+
return child;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
exports.getBinaryNodeChildString = getBinaryNodeChildString;
|
|
57
|
+
const getBinaryNodeChildUInt = (node, childTag, length) => {
|
|
58
|
+
const buff = (0, exports.getBinaryNodeChildBuffer)(node, childTag);
|
|
59
|
+
if (buff) {
|
|
60
|
+
return bufferToUInt(buff, length);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
exports.getBinaryNodeChildUInt = getBinaryNodeChildUInt;
|
|
64
|
+
const assertNodeErrorFree = (node) => {
|
|
65
|
+
const errNode = (0, exports.getBinaryNodeChild)(node, 'error');
|
|
66
|
+
if (errNode) {
|
|
67
|
+
throw new boom_1.Boom(errNode.attrs.text || 'Unknown error', { data: +errNode.attrs.code });
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
exports.assertNodeErrorFree = assertNodeErrorFree;
|
|
71
|
+
const reduceBinaryNodeToDictionary = (node, tag) => {
|
|
72
|
+
const nodes = (0, exports.getBinaryNodeChildren)(node, tag);
|
|
73
|
+
const dict = nodes.reduce((dict, { attrs }) => {
|
|
74
|
+
if (typeof attrs.name === 'string') {
|
|
75
|
+
dict[attrs.name] = attrs.value || attrs.config_value;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
dict[attrs.config_code] = attrs.value || attrs.config_value;
|
|
79
|
+
}
|
|
80
|
+
return dict;
|
|
81
|
+
}, {});
|
|
82
|
+
return dict;
|
|
83
|
+
};
|
|
84
|
+
exports.reduceBinaryNodeToDictionary = reduceBinaryNodeToDictionary;
|
|
85
|
+
const getBinaryNodeMessages = ({ content }) => {
|
|
86
|
+
const msgs = [];
|
|
87
|
+
if (Array.isArray(content)) {
|
|
88
|
+
for (const item of content) {
|
|
89
|
+
if (item.tag === 'message') {
|
|
90
|
+
msgs.push(index_js_1.proto.WebMessageInfo.decode(item.content).toJSON());
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return msgs;
|
|
95
|
+
};
|
|
96
|
+
exports.getBinaryNodeMessages = getBinaryNodeMessages;
|
|
97
|
+
function bufferToUInt(e, t) {
|
|
98
|
+
let a = 0;
|
|
99
|
+
for (let i = 0; i < t; i++) {
|
|
100
|
+
a = 256 * a + e[i];
|
|
101
|
+
}
|
|
102
|
+
return a;
|
|
103
|
+
}
|
|
104
|
+
const tabs = (n) => '\t'.repeat(n);
|
|
105
|
+
function binaryNodeToString(node, i = 0) {
|
|
106
|
+
if (!node) {
|
|
107
|
+
return node;
|
|
108
|
+
}
|
|
109
|
+
if (typeof node === 'string') {
|
|
110
|
+
return tabs(i) + node;
|
|
111
|
+
}
|
|
112
|
+
if (node instanceof Uint8Array) {
|
|
113
|
+
return tabs(i) + Buffer.from(node).toString('hex');
|
|
114
|
+
}
|
|
115
|
+
if (Array.isArray(node)) {
|
|
116
|
+
return node.map(x => tabs(i + 1) + binaryNodeToString(x, i + 1)).join('\n');
|
|
117
|
+
}
|
|
118
|
+
const children = binaryNodeToString(node.content, i + 1);
|
|
119
|
+
const tag = `<${node.tag} ${Object.entries(node.attrs || {})
|
|
120
|
+
.filter(([, v]) => v !== undefined)
|
|
121
|
+
.map(([k, v]) => `${k}='${v}'`)
|
|
122
|
+
.join(' ')}`;
|
|
123
|
+
const content = children ? `>\n${children}\n${tabs(i)}</${node.tag}>` : '/>';
|
|
124
|
+
return tag + content;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Lia@Changes 30-01-26
|
|
128
|
+
* ---
|
|
129
|
+
* Produce the binary node (WABinary-like JSON shape) required for the specific
|
|
130
|
+
* interactive button / list type.
|
|
131
|
+
* compatible with observed official client traffic.
|
|
132
|
+
*
|
|
133
|
+
* NOTE: Returning different "v" (version) and "name" values influences how
|
|
134
|
+
* WhatsApp renders & validates flows. The constants here are empirically derived.
|
|
135
|
+
*
|
|
136
|
+
* @param {object} message Normalized message content (after Baileys normalization).
|
|
137
|
+
* @returns {object} A node with shape { tag, attrs, [content] } to inject into additionalNodes.
|
|
138
|
+
*/
|
|
139
|
+
const FLOWS_MAP = {
|
|
140
|
+
// Original flow types
|
|
141
|
+
mpm: true,
|
|
142
|
+
// Vanz@Fix (bug 44): the "catalog" nativeFlow shortcut generates a button
|
|
143
|
+
// named 'catalog_message' (see prepareNativeFlowButtons in messages.js),
|
|
144
|
+
// never 'cta_catalog' — the old key here never matched anything, so
|
|
145
|
+
// catalog_message always fell through to the generic mixed-flow node
|
|
146
|
+
// instead of getting its dedicated native_flow node.
|
|
147
|
+
catalog_message: true,
|
|
148
|
+
send_location: true,
|
|
149
|
+
call_permission_request: true,
|
|
150
|
+
wa_payment_transaction_details: true,
|
|
151
|
+
automated_greeting_message_view_catalog: true,
|
|
152
|
+
// Vanzxy extended button types
|
|
153
|
+
card_message: true,
|
|
154
|
+
order_status: true,
|
|
155
|
+
track_order: true,
|
|
156
|
+
reorder: true,
|
|
157
|
+
cancel_order: true,
|
|
158
|
+
clear_chat: true,
|
|
159
|
+
navigateToScreen: true,
|
|
160
|
+
payment_status: true,
|
|
161
|
+
payment_method: true,
|
|
162
|
+
flow_action: true,
|
|
163
|
+
voice_call: true,
|
|
164
|
+
video_call_button: true,
|
|
165
|
+
otp_button: true,
|
|
166
|
+
authentication_button: true,
|
|
167
|
+
cta_reminder: true,
|
|
168
|
+
cta_cancel_reminder: true,
|
|
169
|
+
single_select: true,
|
|
170
|
+
};
|
|
171
|
+
const DECISION_SOURCE_CONTENT = [
|
|
172
|
+
{
|
|
173
|
+
tag: 'decision_source',
|
|
174
|
+
attrs: { value: 'df' }
|
|
175
|
+
}
|
|
176
|
+
];
|
|
177
|
+
const LIST_TYPE_CONTENT = {
|
|
178
|
+
tag: 'list',
|
|
179
|
+
attrs: { v: '2', type: 'product_list' }
|
|
180
|
+
};
|
|
181
|
+
const NATIVE_FLOW_ATTRIBUTE = { type: 'native_flow', v: '1' };
|
|
182
|
+
const MIXED_NATIVE_FLOW = {
|
|
183
|
+
tag: 'interactive',
|
|
184
|
+
attrs: NATIVE_FLOW_ATTRIBUTE,
|
|
185
|
+
content: [
|
|
186
|
+
{
|
|
187
|
+
tag: 'native_flow',
|
|
188
|
+
attrs: { v: '9', name: 'mixed' }
|
|
189
|
+
}
|
|
190
|
+
]
|
|
191
|
+
};
|
|
192
|
+
const getBizBinaryNode = (message) => {
|
|
193
|
+
const flowMsg = message.interactiveMessage?.nativeFlowMessage;
|
|
194
|
+
const firstButtonName = flowMsg?.buttons?.[0]?.name;
|
|
195
|
+
const qualityContent = {
|
|
196
|
+
tag: 'quality_control',
|
|
197
|
+
attrs: {
|
|
198
|
+
decision_id: (0, crypto_1.randomBytes)(20).toString('hex'),
|
|
199
|
+
source_type: 'third_party'
|
|
200
|
+
},
|
|
201
|
+
content: DECISION_SOURCE_CONTENT
|
|
202
|
+
};
|
|
203
|
+
const bizAttributes = {
|
|
204
|
+
actual_actors: '2',
|
|
205
|
+
host_storage: '2',
|
|
206
|
+
privacy_mode_ts: `${Date.now() / 1_000 | 0}`
|
|
207
|
+
};
|
|
208
|
+
const ORDER_RESPONSE_ALIAS = {
|
|
209
|
+
review_and_pay: 'order_details',
|
|
210
|
+
review_order: 'order_status',
|
|
211
|
+
payment_info: 'payment_info',
|
|
212
|
+
payment_status: 'payment_status',
|
|
213
|
+
payment_method: 'payment_method',
|
|
214
|
+
order_details: 'order_details',
|
|
215
|
+
order_status: 'order_status',
|
|
216
|
+
track_order: 'track_order',
|
|
217
|
+
reorder: 'reorder',
|
|
218
|
+
cancel_order: 'cancel_order',
|
|
219
|
+
};
|
|
220
|
+
if (firstButtonName && ORDER_RESPONSE_ALIAS[firstButtonName]) {
|
|
221
|
+
bizAttributes.native_flow_name = ORDER_RESPONSE_ALIAS[firstButtonName];
|
|
222
|
+
return {
|
|
223
|
+
tag: 'biz',
|
|
224
|
+
attrs: bizAttributes,
|
|
225
|
+
content: [qualityContent]
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
if (firstButtonName && FLOWS_MAP[firstButtonName]) {
|
|
229
|
+
return {
|
|
230
|
+
tag: 'biz',
|
|
231
|
+
attrs: bizAttributes,
|
|
232
|
+
content: [
|
|
233
|
+
{
|
|
234
|
+
tag: 'interactive',
|
|
235
|
+
attrs: NATIVE_FLOW_ATTRIBUTE,
|
|
236
|
+
content: [
|
|
237
|
+
{
|
|
238
|
+
tag: 'native_flow',
|
|
239
|
+
attrs: { v: '2', name: firstButtonName }
|
|
240
|
+
}
|
|
241
|
+
]
|
|
242
|
+
},
|
|
243
|
+
qualityContent
|
|
244
|
+
]
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
if (flowMsg || message.buttonsMessage || message.templateMessage) {
|
|
248
|
+
return {
|
|
249
|
+
tag: 'biz',
|
|
250
|
+
attrs: bizAttributes,
|
|
251
|
+
content: [
|
|
252
|
+
MIXED_NATIVE_FLOW,
|
|
253
|
+
qualityContent
|
|
254
|
+
]
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
if (message.listMessage) {
|
|
258
|
+
return {
|
|
259
|
+
tag: 'biz',
|
|
260
|
+
attrs: bizAttributes,
|
|
261
|
+
content: [
|
|
262
|
+
LIST_TYPE_CONTENT,
|
|
263
|
+
qualityContent
|
|
264
|
+
]
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
return {
|
|
268
|
+
tag: 'biz',
|
|
269
|
+
attrs: bizAttributes,
|
|
270
|
+
content: [qualityContent]
|
|
271
|
+
};
|
|
272
|
+
};
|
|
273
|
+
exports.getBizBinaryNode = getBizBinaryNode;
|
|
274
|
+
//# sourceMappingURL=generic-utils.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./encode.js"), exports);
|
|
18
|
+
__exportStar(require("./decode.js"), exports);
|
|
19
|
+
__exportStar(require("./generic-utils.js"), exports);
|
|
20
|
+
__exportStar(require("./jid-utils.js"), exports);
|
|
21
|
+
__exportStar(require("./types.js"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transferDevice = exports.jidNormalizedUser = exports.isJidBot = exports.isHostedLidUser = exports.isHostedPnUser = exports.isJidNewsletter = exports.isJidStatusBroadcast = exports.isJidGroup = exports.isJidBroadcast = exports.isLidUser = exports.isPnUser = exports.isJidMetaAI = exports.areJidsSameUser = exports.jidDecode = exports.jidEncode = exports.getServerFromDomainType = exports.WAJIDDomains = exports.META_AI_JID = exports.STORIES_JID = exports.PSA_WID = exports.SERVER_JID = exports.OFFICIAL_BIZ_JID = exports.S_WHATSAPP_NET = void 0;
|
|
4
|
+
exports.S_WHATSAPP_NET = '@s.whatsapp.net';
|
|
5
|
+
exports.OFFICIAL_BIZ_JID = '16505361212@c.us';
|
|
6
|
+
exports.SERVER_JID = 'server@c.us';
|
|
7
|
+
exports.PSA_WID = '0@c.us';
|
|
8
|
+
exports.STORIES_JID = 'status@broadcast';
|
|
9
|
+
exports.META_AI_JID = '13135550002@c.us';
|
|
10
|
+
(function (WAJIDDomains) {
|
|
11
|
+
WAJIDDomains[WAJIDDomains["WHATSAPP"] = 0] = "WHATSAPP";
|
|
12
|
+
WAJIDDomains[WAJIDDomains["LID"] = 1] = "LID";
|
|
13
|
+
WAJIDDomains[WAJIDDomains["HOSTED"] = 128] = "HOSTED";
|
|
14
|
+
WAJIDDomains[WAJIDDomains["HOSTED_LID"] = 129] = "HOSTED_LID";
|
|
15
|
+
})(exports.WAJIDDomains || (exports.WAJIDDomains = {}));
|
|
16
|
+
const getServerFromDomainType = (initialServer, domainType) => {
|
|
17
|
+
switch (domainType) {
|
|
18
|
+
case exports.WAJIDDomains.LID:
|
|
19
|
+
return 'lid';
|
|
20
|
+
case exports.WAJIDDomains.HOSTED:
|
|
21
|
+
return 'hosted';
|
|
22
|
+
case exports.WAJIDDomains.HOSTED_LID:
|
|
23
|
+
return 'hosted.lid';
|
|
24
|
+
case exports.WAJIDDomains.WHATSAPP:
|
|
25
|
+
default:
|
|
26
|
+
return initialServer;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
exports.getServerFromDomainType = getServerFromDomainType;
|
|
30
|
+
const jidEncode = (user, server, device, agent) => {
|
|
31
|
+
return `${user || ''}${!!agent ? `_${agent}` : ''}${!!device ? `:${device}` : ''}@${server || 'lid'}`;
|
|
32
|
+
};
|
|
33
|
+
exports.jidEncode = jidEncode;
|
|
34
|
+
const jidDecode = (jid) => {
|
|
35
|
+
// todo: investigate how to implement hosted ids in this case
|
|
36
|
+
const sepIdx = typeof jid === 'string' ? jid.indexOf('@') : -1;
|
|
37
|
+
if (sepIdx < 0) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
const server = jid.slice(sepIdx + 1);
|
|
41
|
+
const userCombined = jid.slice(0, sepIdx);
|
|
42
|
+
const [userAgent, device] = userCombined.split(':');
|
|
43
|
+
const [user, agent] = userAgent.split('_');
|
|
44
|
+
let domainType = exports.WAJIDDomains.WHATSAPP;
|
|
45
|
+
if (server === 'lid') {
|
|
46
|
+
domainType = exports.WAJIDDomains.LID;
|
|
47
|
+
}
|
|
48
|
+
else if (server === 'hosted') {
|
|
49
|
+
domainType = exports.WAJIDDomains.HOSTED;
|
|
50
|
+
}
|
|
51
|
+
else if (server === 'hosted.lid') {
|
|
52
|
+
domainType = exports.WAJIDDomains.HOSTED_LID;
|
|
53
|
+
}
|
|
54
|
+
else if (agent) {
|
|
55
|
+
domainType = parseInt(agent);
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
server: server,
|
|
59
|
+
user: user,
|
|
60
|
+
domainType,
|
|
61
|
+
device: device ? +device : undefined
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
exports.jidDecode = jidDecode;
|
|
65
|
+
/** is the jid a user */
|
|
66
|
+
const areJidsSameUser = (jid1, jid2) => (0, exports.jidDecode)(jid1)?.user === (0, exports.jidDecode)(jid2)?.user;
|
|
67
|
+
exports.areJidsSameUser = areJidsSameUser;
|
|
68
|
+
/** is the jid Meta AI */
|
|
69
|
+
const isJidMetaAI = (jid) => jid?.endsWith('@bot');
|
|
70
|
+
exports.isJidMetaAI = isJidMetaAI;
|
|
71
|
+
/** is the jid a PN user */
|
|
72
|
+
const isPnUser = (jid) => jid?.endsWith('@s.whatsapp.net');
|
|
73
|
+
exports.isPnUser = isPnUser;
|
|
74
|
+
/** is the jid a LID */
|
|
75
|
+
const isLidUser = (jid) => jid?.endsWith('@lid');
|
|
76
|
+
exports.isLidUser = isLidUser;
|
|
77
|
+
/** is the jid a broadcast */
|
|
78
|
+
const isJidBroadcast = (jid) => jid?.endsWith('@broadcast');
|
|
79
|
+
exports.isJidBroadcast = isJidBroadcast;
|
|
80
|
+
/** is the jid a group */
|
|
81
|
+
const isJidGroup = (jid) => jid?.endsWith('@g.us');
|
|
82
|
+
exports.isJidGroup = isJidGroup;
|
|
83
|
+
/** is the jid the status broadcast */
|
|
84
|
+
const isJidStatusBroadcast = (jid) => jid === 'status@broadcast';
|
|
85
|
+
exports.isJidStatusBroadcast = isJidStatusBroadcast;
|
|
86
|
+
/** is the jid a newsletter */
|
|
87
|
+
const isJidNewsletter = (jid) => jid?.endsWith('@newsletter');
|
|
88
|
+
exports.isJidNewsletter = isJidNewsletter;
|
|
89
|
+
/** is the jid a hosted PN */
|
|
90
|
+
const isHostedPnUser = (jid) => jid?.endsWith('@hosted');
|
|
91
|
+
exports.isHostedPnUser = isHostedPnUser;
|
|
92
|
+
/** is the jid a hosted LID */
|
|
93
|
+
const isHostedLidUser = (jid) => jid?.endsWith('@hosted.lid');
|
|
94
|
+
exports.isHostedLidUser = isHostedLidUser;
|
|
95
|
+
const botRegexp = /^1313555\d{4}$|^131655500\d{2}$/;
|
|
96
|
+
const isJidBot = (jid) => jid && botRegexp.test(jid.split('@')[0]) && jid.endsWith('@c.us');
|
|
97
|
+
exports.isJidBot = isJidBot;
|
|
98
|
+
const jidNormalizedUser = (jid) => {
|
|
99
|
+
const result = (0, exports.jidDecode)(jid);
|
|
100
|
+
if (!result) {
|
|
101
|
+
return '';
|
|
102
|
+
}
|
|
103
|
+
const { user, server } = result;
|
|
104
|
+
return (0, exports.jidEncode)(user, server === 'c.us' ? 's.whatsapp.net' : server);
|
|
105
|
+
};
|
|
106
|
+
exports.jidNormalizedUser = jidNormalizedUser;
|
|
107
|
+
const transferDevice = (fromJid, toJid) => {
|
|
108
|
+
const fromDecoded = (0, exports.jidDecode)(fromJid);
|
|
109
|
+
const deviceId = fromDecoded?.device || 0;
|
|
110
|
+
const { server, user } = (0, exports.jidDecode)(toJid);
|
|
111
|
+
return (0, exports.jidEncode)(user, server, deviceId);
|
|
112
|
+
};
|
|
113
|
+
exports.transferDevice = transferDevice;
|
|
114
|
+
//# sourceMappingURL=jid-utils.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const constants = __importStar(require("./constants.js"));
|
|
37
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BinaryInfo = void 0;
|
|
4
|
+
class BinaryInfo {
|
|
5
|
+
constructor(options = {}) {
|
|
6
|
+
this.protocolVersion = 5;
|
|
7
|
+
this.sequence = 0;
|
|
8
|
+
this.events = [];
|
|
9
|
+
this.buffer = [];
|
|
10
|
+
Object.assign(this, options);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.BinaryInfo = BinaryInfo;
|
|
14
|
+
//# sourceMappingURL=BinaryInfo.js.map
|