kage-baileys 3.0.6 → 3.2.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/Example/connection.cjs +4 -0
- package/README.MD +4726 -48
- package/README.md +5941 -0
- package/WAProto/WAProto.proto +3395 -415
- package/WAProto/compat.cjs +12 -0
- package/WAProto/index.d.ts +47104 -19888
- package/WAProto/index.js +131979 -57361
- package/lib/Addon/http-error.js +43 -0
- package/lib/Addon/index.js +32 -0
- package/lib/Addon/keyed-db.js +250 -0
- package/lib/Addon/link-preview.js +82 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/connection.js +110 -0
- package/lib/Defaults/constants.js +156 -0
- package/lib/Defaults/history.js +46 -0
- package/lib/Defaults/index.js +230 -0
- package/lib/Defaults/media.js +104 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Defaults/prefix.js +44 -0
- package/lib/Extensions/business-advanced.js +382 -0
- package/lib/Extensions/business.js +159 -0
- package/lib/Extensions/chats-advanced.js +1106 -0
- package/lib/Extensions/chats.js +349 -0
- package/lib/Extensions/communities-advanced.js +430 -0
- package/lib/Extensions/community.js +94 -0
- package/lib/Extensions/groups-advanced.js +343 -0
- package/lib/Extensions/index.js +30 -0
- package/lib/Extensions/messages-recv-advanced.js +1690 -0
- package/lib/Extensions/messages-send-advanced.js +622 -0
- package/lib/Extensions/messages-send.js +1380 -0
- package/lib/Extensions/newsletter-advanced.js +228 -0
- package/lib/Extensions/newsletter.js +72 -0
- package/lib/Extensions/socket.js +389 -0
- package/lib/Modded/message_builder.js +2084 -4
- package/lib/Signal/Group/ciphertext-message.js +54 -0
- package/lib/Signal/Group/group-session-builder.js +124 -0
- package/lib/Signal/Group/group_cipher.js +216 -0
- package/lib/Signal/Group/index.js +124 -0
- package/lib/Signal/Group/keyhelper.js +108 -0
- package/lib/Signal/Group/sender-chain-key.js +83 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +157 -0
- package/lib/Signal/Group/sender-key-message.js +166 -0
- package/lib/Signal/Group/sender-key-name.js +130 -0
- package/lib/Signal/Group/sender-key-record.js +113 -0
- package/lib/Signal/Group/sender-key-state.js +208 -0
- package/lib/Signal/Group/sender-message-key.js +82 -0
- package/lib/Signal/libsignal.js +935 -0
- package/lib/Signal/lid-mapping.js +545 -1
- package/lib/Socket/Client/index.js +60 -0
- package/lib/Socket/Client/types.js +51 -0
- package/lib/Socket/Client/websocket.js +152 -0
- package/lib/Socket/business.js +831 -0
- package/lib/Socket/chats.js +2535 -49
- package/lib/Socket/communities.js +450 -1
- package/lib/Socket/community.js +1022 -0
- package/lib/Socket/dugong.js +1 -1
- package/lib/Socket/groups.js +747 -0
- package/lib/Socket/index.js +60 -2
- package/lib/Socket/messages-recv.js +3450 -5
- package/lib/Socket/messages-send.js +3123 -0
- package/lib/Socket/mex.js +126 -1
- package/lib/Socket/newsletter.js +465 -0
- package/lib/Socket/socket.js +2217 -1
- package/lib/Store/index.js +79 -0
- package/lib/Store/make-cache-manager-store.js +186 -0
- package/lib/Store/make-in-memory-store.js +878 -0
- package/lib/Store/make-ordered-dictionary.js +187 -0
- package/lib/Store/object-repository.js +78 -0
- package/lib/Types/Auth.js +25 -0
- package/lib/Types/Bussines.js +25 -1
- package/lib/Types/Call.js +25 -0
- package/lib/Types/Chat.js +39 -0
- package/lib/Types/Contact.js +25 -0
- package/lib/Types/Events.js +25 -0
- package/lib/Types/GroupMetadata.js +25 -0
- package/lib/Types/Label.js +76 -0
- package/lib/Types/LabelAssociation.js +40 -0
- package/lib/Types/Message.js +57 -0
- package/lib/Types/Mex.js +56 -1
- package/lib/Types/MexUpdates.js +46 -0
- package/lib/Types/Newsletter.js +56 -0
- package/lib/Types/Product.js +25 -0
- package/lib/Types/RichType.js +23 -0
- package/lib/Types/Signal.js +25 -0
- package/lib/Types/Socket.js +25 -0
- package/lib/Types/State.js +92 -0
- package/lib/Types/USync.js +25 -0
- package/lib/Types/index.js +133 -0
- package/lib/Utils/auth-utils.js +703 -0
- package/lib/Utils/automation-tools.js +51 -16
- package/lib/Utils/baileys-event-stream.js +146 -0
- package/lib/Utils/browser-utils.js +95 -0
- package/lib/Utils/business.js +525 -0
- package/lib/Utils/chat-utils.js +1861 -0
- package/lib/Utils/companion-reg-client-utils.js +55 -1
- package/lib/Utils/crypto.js +355 -0
- package/lib/Utils/decode-wa-message.js +709 -0
- package/lib/Utils/event-buffer.js +1323 -8
- package/lib/Utils/generics.js +945 -1
- package/lib/Utils/history.js +266 -0
- package/lib/Utils/identity-change-handler.js +62 -1
- package/lib/Utils/index.js +114 -0
- package/lib/Utils/link-preview.js +179 -0
- package/lib/Utils/logger.js +42 -0
- package/lib/Utils/lt-hash.js +73 -0
- package/lib/Utils/make-mutex.js +104 -0
- package/lib/Utils/message-inspector.js +110 -0
- package/lib/Utils/message-retry-manager.js +507 -2
- package/lib/Utils/messages-media.js +1931 -1
- package/lib/Utils/messages.js +3748 -0
- package/lib/Utils/noise-handler.js +423 -0
- package/lib/Utils/offline-node-processor.js +53 -1
- package/lib/Utils/pre-key-manager.js +255 -1
- package/lib/Utils/process-message.js +1592 -0
- package/lib/Utils/reporting-utils.js +272 -1
- package/lib/Utils/rich-message-utils.js +377 -0
- package/lib/Utils/rich-messages.js +1 -1
- package/lib/Utils/signal.js +437 -0
- package/lib/Utils/stanza-ack.js +51 -1
- package/lib/Utils/status-refresh.js +37 -0
- package/lib/Utils/status-tools.js +4 -2
- package/lib/Utils/sync-action-utils.js +63 -1
- package/lib/Utils/tc-token-utils.js +185 -1
- package/lib/Utils/terminal-banner.js +31 -0
- package/lib/Utils/use-multi-file-auth-state.js +271 -0
- package/lib/Utils/use-single-file-auth-state.js +108 -0
- package/lib/Utils/use-sqlite-auth-state.js +142 -0
- package/lib/Utils/validate-connection.js +497 -1
- package/lib/Utils/view-once-compat.js +13 -5
- package/lib/VoIP/audio-feeder.js +150 -0
- package/lib/VoIP/index.js +289 -0
- package/lib/VoIP/relay-transport.js +608 -0
- package/lib/VoIP/signaling.js +583 -0
- package/lib/VoIP/types.js +30 -0
- package/lib/VoIP/wasm-engine.js +1261 -2
- package/lib/VoIP/worker-bootstrap.js +1090 -2
- package/lib/WABinary/constants.js +2805 -0
- package/lib/WABinary/decode.js +649 -2
- package/lib/WABinary/encode.js +564 -2
- package/lib/WABinary/generic-utils.js +401 -0
- package/lib/WABinary/index.js +82 -0
- package/lib/WABinary/jid-utils.js +290 -0
- package/lib/WABinary/types.js +25 -0
- package/lib/WAM/BinaryInfo.js +50 -0
- package/lib/WAM/constants.js +45747 -0
- package/lib/WAM/encode.js +393 -0
- package/lib/WAM/index.js +78 -0
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +135 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +110 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +142 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +85 -0
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +69 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +107 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +38 -1
- package/lib/WAUSync/Protocols/index.js +83 -0
- package/lib/WAUSync/USyncQuery.js +241 -2
- package/lib/WAUSync/USyncUser.js +86 -0
- package/lib/WAUSync/index.js +78 -0
- package/lib/assets/wasm/loader.js +1875 -1
- package/lib/assets/wasm/worker-modules.js +11047 -1
- package/lib/index.d.ts +126 -0
- package/lib/index.js +53 -21
- package/lib/index.mjs +437 -0
- package/licenses/upstream-MIT.txt +22 -0
- package/maintenance/api-coverage.json +1642 -0
- package/maintenance/archivos-sha256.json +207 -0
- package/maintenance/consumer-validation.log +3 -0
- package/maintenance/dependency-audit.json +4 -4
- package/maintenance/extension-inventory.json +57 -0
- package/maintenance/protocol-update.json +1101 -0
- package/maintenance/protocol-wire-audit.json +4 -0
- package/maintenance/reference-socket-surface.json +209 -0
- package/maintenance/resumen-validacion.json +50 -0
- package/maintenance/validation.log +2725 -0
- package/maintenance/verification.json +566 -0
- package/package.json +107 -9
- package/scripts/check-imports.cjs +10 -0
- package/scripts/check-package.cjs +40 -0
- package/scripts/check-syntax.cjs +1 -1
- package/scripts/generate-protobuf.cjs +6 -1
- package/scripts/generate-public-types.cjs +9 -0
- package/scripts/kage-base64-fix.cjs +45 -0
- package/scripts/maintenance.cjs +10 -0
- package/test/advanced.test.cjs +24 -0
- package/test/base64-fix.test.cjs +49 -0
- package/test/maintenance.test.cjs +1 -1
- package/test/npm-publication.test.cjs +141 -0
- package/test/recepcion-reparada.test.cjs +98 -0
- package/test/resilience-binary.test.cjs +69 -0
- package/test/resilience-transport.test.cjs +34 -0
- package/test/types.test.ts +5 -0
- package/test/upgrade.test.cjs +104 -0
- package/tsconfig.json +20 -0
- package/WAProto/p.html +0 -1
- package/lib/KageExtra/Modded/message_builder.js +0 -2330
- package/lib/KageExtra/VoIP/audio-feeder.js +0 -136
- package/lib/KageExtra/VoIP/index.js +0 -282
- package/lib/KageExtra/VoIP/relay-transport.js +0 -559
- package/lib/KageExtra/VoIP/signaling.js +0 -603
- package/lib/KageExtra/VoIP/types.js +0 -17
- package/lib/KageExtra/VoIP/wasm-engine.js +0 -1214
- package/lib/KageExtra/VoIP/worker-bootstrap.js +0 -1042
- package/lib/KageExtra/assets/wasm/loader.js +0 -5
- package/lib/KageExtra/assets/wasm/whatsapp.wasm +0 -0
- package/lib/KageExtra/assets/wasm/worker-modules.js +0 -273
- package/lib/KageExtra/index.js +0 -3
- package/lib/KageExtra/package.json +0 -1
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -53
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -24
- package/maintenance/revision-full-check.txt +0 -1097
- package/maintenance/revision-library-tests.tap +0 -1088
- package/maintenance/revision-protobuf.txt +0 -5
- package/maintenance/revision-syntax.txt +0 -5
- package/maintenance/schema-coverage.json +0 -23
- package/maintenance/schema-merge.json +0 -30
- package/maintenance/validation-node20.txt +0 -191
- package/maintenance/validation-node22.txt +0 -237
|
@@ -108,3 +108,404 @@ function binaryNodeToString(node, i = 0) {
|
|
|
108
108
|
const content = children ? `>\n${children}\n${tabs(i)}</${node.tag}>` : '/>';
|
|
109
109
|
return tag + content;
|
|
110
110
|
}
|
|
111
|
+
|
|
112
|
+
// Kage: compatibilidad de API.
|
|
113
|
+
const __kageModule84 = (() => {
|
|
114
|
+
const module = { exports: {} }; const exports = module.exports;
|
|
115
|
+
"use strict"
|
|
116
|
+
|
|
117
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
118
|
+
|
|
119
|
+
const { Boom } = require("@hapi/boom")
|
|
120
|
+
const { proto } = require("../../WAProto")
|
|
121
|
+
|
|
122
|
+
// some extra useful utilities
|
|
123
|
+
const getBinaryNodeChildren = (node, childTag) => {
|
|
124
|
+
if (Array.isArray(node?.content)) {
|
|
125
|
+
return node.content.filter(item => item.tag === childTag)
|
|
126
|
+
}
|
|
127
|
+
return []
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const getAllBinaryNodeChildren = ({ content }) => {
|
|
131
|
+
if (Array.isArray(content)) {
|
|
132
|
+
return content
|
|
133
|
+
}
|
|
134
|
+
return []
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const getBinaryNodeChild = (node, childTag) => {
|
|
138
|
+
if (Array.isArray(node?.content)) {
|
|
139
|
+
return node?.content.find(item => item.tag === childTag)
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const getBinaryNodeChildBuffer = (node, childTag) => {
|
|
144
|
+
const child = getBinaryNodeChild(node, childTag)?.content
|
|
145
|
+
if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
|
|
146
|
+
return child
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const getBinaryNodeChildString = (node, childTag) => {
|
|
151
|
+
const child = getBinaryNodeChild(node, childTag)?.content
|
|
152
|
+
if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
|
|
153
|
+
return Buffer.from(child).toString('utf-8')
|
|
154
|
+
}
|
|
155
|
+
else if (typeof child === 'string') {
|
|
156
|
+
return child
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const getBinaryNodeChildUInt = (node, childTag, length) => {
|
|
161
|
+
const buff = getBinaryNodeChildBuffer(node, childTag)
|
|
162
|
+
if (buff) {
|
|
163
|
+
return bufferToUInt(buff, length)
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const assertNodeErrorFree = (node) => {
|
|
168
|
+
const errNode = getBinaryNodeChild(node, 'error')
|
|
169
|
+
if (errNode) {
|
|
170
|
+
throw new Boom(errNode.attrs.text || 'Unknown error', { data: +errNode.attrs.code })
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const reduceBinaryNodeToDictionary = (node, tag) => {
|
|
175
|
+
const nodes = getBinaryNodeChildren(node, tag)
|
|
176
|
+
const dict = nodes.reduce((dict, { attrs }) => {
|
|
177
|
+
dict[attrs.name || attrs.config_code] = attrs.value || attrs.config_value
|
|
178
|
+
return dict
|
|
179
|
+
}, {})
|
|
180
|
+
return dict
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const getBinaryNodeMessages = ({ content }) => {
|
|
184
|
+
const msgs = []
|
|
185
|
+
if (Array.isArray(content)) {
|
|
186
|
+
for (const item of content) {
|
|
187
|
+
if (item.tag === 'message') {
|
|
188
|
+
msgs.push(proto.WebMessageInfo.decode(item.content))
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return msgs
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const getBinaryFilteredButtons = (nodeContent) => {
|
|
196
|
+
if (!Array.isArray(nodeContent)) return false
|
|
197
|
+
|
|
198
|
+
return nodeContent.some(a =>
|
|
199
|
+
['native_flow'].includes(a?.content?.[0]?.content?.[0]?.tag) ||
|
|
200
|
+
['interactive', 'buttons', 'list'].includes(a?.content?.[0]?.tag) ||
|
|
201
|
+
['hsm', 'biz'].includes(a?.tag)
|
|
202
|
+
)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const getBinaryFilteredBizBot = (nodeContent) => {
|
|
206
|
+
if (!Array.isArray(nodeContent)) return false
|
|
207
|
+
|
|
208
|
+
return nodeContent.some(b =>
|
|
209
|
+
['bot'].includes(b?.tag) && b?.attrs?.biz_bot === '1'
|
|
210
|
+
)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function bufferToUInt(e, t) {
|
|
214
|
+
let a = 0
|
|
215
|
+
for (let i = 0; i < t; i++) {
|
|
216
|
+
a = 256 * a + e[i]
|
|
217
|
+
}
|
|
218
|
+
return a
|
|
219
|
+
}
|
|
220
|
+
const tabs = (n) => '\t'.repeat(n)
|
|
221
|
+
function binaryNodeToString(node, i = 0) {
|
|
222
|
+
if (!node) {
|
|
223
|
+
return node
|
|
224
|
+
}
|
|
225
|
+
if (typeof node === 'string') {
|
|
226
|
+
return tabs(i) + node
|
|
227
|
+
}
|
|
228
|
+
if (node instanceof Uint8Array) {
|
|
229
|
+
return tabs(i) + Buffer.from(node).toString('hex')
|
|
230
|
+
}
|
|
231
|
+
if (Array.isArray(node)) {
|
|
232
|
+
return node.map((x) => tabs(i + 1) + binaryNodeToString(x, i + 1)).join('\n')
|
|
233
|
+
}
|
|
234
|
+
const children = binaryNodeToString(node.content, i + 1)
|
|
235
|
+
const tag = `<${node.tag} ${Object.entries(node.attrs || {})
|
|
236
|
+
.filter(([, v]) => v !== undefined)
|
|
237
|
+
.map(([k, v]) => `${k}='${v}'`)
|
|
238
|
+
.join(' ')}`
|
|
239
|
+
const content = children ? `>\n${children}\n${tabs(i)}</${node.tag}>` : '/>'
|
|
240
|
+
return tag + content
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
module.exports = {
|
|
244
|
+
getBinaryNodeChildren,
|
|
245
|
+
getAllBinaryNodeChildren,
|
|
246
|
+
getBinaryNodeChild,
|
|
247
|
+
getBinaryNodeChildBuffer,
|
|
248
|
+
getBinaryNodeChildString,
|
|
249
|
+
getBinaryNodeChildUInt,
|
|
250
|
+
assertNodeErrorFree,
|
|
251
|
+
reduceBinaryNodeToDictionary,
|
|
252
|
+
getBinaryNodeMessages,
|
|
253
|
+
getBinaryFilteredButtons,
|
|
254
|
+
getBinaryFilteredBizBot,
|
|
255
|
+
binaryNodeToString
|
|
256
|
+
}
|
|
257
|
+
return module.exports;
|
|
258
|
+
})();
|
|
259
|
+
for (const key of Object.keys(__kageModule84)) {
|
|
260
|
+
if (key !== '__esModule' && !Object.prototype.hasOwnProperty.call(exports,key)) Object.defineProperty(exports,key,{enumerable:true,configurable:true,get:()=>__kageModule84[key]});
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// Kage: funciones avanzadas.
|
|
264
|
+
const __kageModule193 = (() => {
|
|
265
|
+
const module = { exports: {} }; const exports = module.exports;
|
|
266
|
+
"use strict";
|
|
267
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
268
|
+
exports.getBizBinaryNode = exports.getBinaryNodeMessages = exports.reduceBinaryNodeToDictionary = exports.assertNodeErrorFree = exports.getBinaryNodeChildUInt = exports.getBinaryNodeChildString = exports.getBinaryNodeChildBuffer = exports.getAllBinaryNodeChildren = exports.getBinaryNodeChild = exports.getBinaryNodeChildren = void 0;
|
|
269
|
+
exports.binaryNodeToString = binaryNodeToString;
|
|
270
|
+
const node_crypto_1 = require("node:crypto");
|
|
271
|
+
const index_js_1 = require("../Addon/index.js");
|
|
272
|
+
const index_js_2 = require("../../WAProto/index.js");
|
|
273
|
+
// some extra useful utilities
|
|
274
|
+
const indexCache = new WeakMap();
|
|
275
|
+
const getBinaryNodeChildren = (node, childTag) => {
|
|
276
|
+
if (!node || !Array.isArray(node.content))
|
|
277
|
+
return [];
|
|
278
|
+
let index = indexCache.get(node);
|
|
279
|
+
// Build the index once per node
|
|
280
|
+
if (!index) {
|
|
281
|
+
index = new Map();
|
|
282
|
+
for (const child of node.content) {
|
|
283
|
+
let arr = index.get(child.tag);
|
|
284
|
+
if (!arr)
|
|
285
|
+
index.set(child.tag, (arr = []));
|
|
286
|
+
arr.push(child);
|
|
287
|
+
}
|
|
288
|
+
indexCache.set(node, index);
|
|
289
|
+
}
|
|
290
|
+
// Return first matching child
|
|
291
|
+
return index.get(childTag) || [];
|
|
292
|
+
};
|
|
293
|
+
exports.getBinaryNodeChildren = getBinaryNodeChildren;
|
|
294
|
+
const getBinaryNodeChild = (node, childTag) => {
|
|
295
|
+
return (0, exports.getBinaryNodeChildren)(node, childTag)[0];
|
|
296
|
+
};
|
|
297
|
+
exports.getBinaryNodeChild = getBinaryNodeChild;
|
|
298
|
+
const getAllBinaryNodeChildren = ({ content }) => {
|
|
299
|
+
if (Array.isArray(content)) {
|
|
300
|
+
return content;
|
|
301
|
+
}
|
|
302
|
+
return [];
|
|
303
|
+
};
|
|
304
|
+
exports.getAllBinaryNodeChildren = getAllBinaryNodeChildren;
|
|
305
|
+
const getBinaryNodeChildBuffer = (node, childTag) => {
|
|
306
|
+
const child = (0, exports.getBinaryNodeChild)(node, childTag)?.content;
|
|
307
|
+
if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
|
|
308
|
+
return child;
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
exports.getBinaryNodeChildBuffer = getBinaryNodeChildBuffer;
|
|
312
|
+
const getBinaryNodeChildString = (node, childTag) => {
|
|
313
|
+
const child = (0, exports.getBinaryNodeChild)(node, childTag)?.content;
|
|
314
|
+
if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
|
|
315
|
+
return Buffer.from(child).toString('utf-8');
|
|
316
|
+
}
|
|
317
|
+
else if (typeof child === 'string') {
|
|
318
|
+
return child;
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
exports.getBinaryNodeChildString = getBinaryNodeChildString;
|
|
322
|
+
const getBinaryNodeChildUInt = (node, childTag, length) => {
|
|
323
|
+
const buff = (0, exports.getBinaryNodeChildBuffer)(node, childTag);
|
|
324
|
+
if (buff) {
|
|
325
|
+
return bufferToUInt(buff, length);
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
exports.getBinaryNodeChildUInt = getBinaryNodeChildUInt;
|
|
329
|
+
const assertNodeErrorFree = (node) => {
|
|
330
|
+
const errNode = (0, exports.getBinaryNodeChild)(node, 'error');
|
|
331
|
+
if (errNode) {
|
|
332
|
+
throw new index_js_1.HttpError(errNode.attrs.text || 'Unknown error', { data: +errNode.attrs.code });
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
exports.assertNodeErrorFree = assertNodeErrorFree;
|
|
336
|
+
const reduceBinaryNodeToDictionary = (node, tag) => {
|
|
337
|
+
const nodes = (0, exports.getBinaryNodeChildren)(node, tag);
|
|
338
|
+
const dict = nodes.reduce((dict, { attrs }) => {
|
|
339
|
+
if (typeof attrs.name === 'string') {
|
|
340
|
+
dict[attrs.name] = attrs.value || attrs.config_value;
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
dict[attrs.config_code] = attrs.value || attrs.config_value;
|
|
344
|
+
}
|
|
345
|
+
return dict;
|
|
346
|
+
}, {});
|
|
347
|
+
return dict;
|
|
348
|
+
};
|
|
349
|
+
exports.reduceBinaryNodeToDictionary = reduceBinaryNodeToDictionary;
|
|
350
|
+
const getBinaryNodeMessages = ({ content }) => {
|
|
351
|
+
const msgs = [];
|
|
352
|
+
if (Array.isArray(content)) {
|
|
353
|
+
for (const item of content) {
|
|
354
|
+
if (item.tag === 'message') {
|
|
355
|
+
msgs.push(index_js_2.proto.WebMessageInfo.decode(item.content).toJSON());
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
return msgs;
|
|
360
|
+
};
|
|
361
|
+
exports.getBinaryNodeMessages = getBinaryNodeMessages;
|
|
362
|
+
function bufferToUInt(e, t) {
|
|
363
|
+
let a = 0;
|
|
364
|
+
for (let i = 0; i < t; i++) {
|
|
365
|
+
a = 256 * a + e[i];
|
|
366
|
+
}
|
|
367
|
+
return a;
|
|
368
|
+
}
|
|
369
|
+
const tabs = (n) => '\t'.repeat(n);
|
|
370
|
+
function binaryNodeToString(node, i = 0) {
|
|
371
|
+
if (!node) {
|
|
372
|
+
return node;
|
|
373
|
+
}
|
|
374
|
+
if (typeof node === 'string') {
|
|
375
|
+
return tabs(i) + node;
|
|
376
|
+
}
|
|
377
|
+
if (node instanceof Uint8Array) {
|
|
378
|
+
return tabs(i) + Buffer.from(node).toString('hex');
|
|
379
|
+
}
|
|
380
|
+
if (Array.isArray(node)) {
|
|
381
|
+
return node.map(x => tabs(i + 1) + binaryNodeToString(x, i + 1)).join('\n');
|
|
382
|
+
}
|
|
383
|
+
const children = binaryNodeToString(node.content, i + 1);
|
|
384
|
+
const tag = `<${node.tag} ${Object.entries(node.attrs || {})
|
|
385
|
+
.filter(([, v]) => v !== undefined)
|
|
386
|
+
.map(([k, v]) => `${k}='${v}'`)
|
|
387
|
+
.join(' ')}`;
|
|
388
|
+
const content = children ? `>\n${children}\n${tabs(i)}</${node.tag}>` : '/>';
|
|
389
|
+
return tag + content;
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Kage: actualización de compatibilidad.
|
|
393
|
+
* ---
|
|
394
|
+
* Produce the binary node (WABinary-like JSON shape) required for the specific
|
|
395
|
+
* interactive button / list type.
|
|
396
|
+
* compatible with observed official client traffic.
|
|
397
|
+
*
|
|
398
|
+
* NOTE: Returning different "v" (version) and "name" values influences how
|
|
399
|
+
* WhatsApp renders & validates flows. The constants here are empirically derived.
|
|
400
|
+
*
|
|
401
|
+
* @param {object} message Normalized message content (after Baileys normalization).
|
|
402
|
+
* @returns {object} A node with shape { tag, attrs, [content] } to inject into additionalNodes.
|
|
403
|
+
*/
|
|
404
|
+
const FLOWS_MAP = {
|
|
405
|
+
mpm: true,
|
|
406
|
+
cta_catalog: true,
|
|
407
|
+
send_location: true,
|
|
408
|
+
call_permission_request: true,
|
|
409
|
+
wa_payment_transaction_details: true,
|
|
410
|
+
automated_greeting_message_view_catalog: true
|
|
411
|
+
};
|
|
412
|
+
const DECISION_SOURCE_CONTENT = [
|
|
413
|
+
{
|
|
414
|
+
tag: 'decision_source',
|
|
415
|
+
attrs: { value: 'df' }
|
|
416
|
+
}
|
|
417
|
+
];
|
|
418
|
+
const LIST_TYPE_CONTENT = {
|
|
419
|
+
tag: 'list',
|
|
420
|
+
attrs: { v: '2', type: 'product_list' }
|
|
421
|
+
};
|
|
422
|
+
const NATIVE_FLOW_ATTRIBUTE = { type: 'native_flow', v: '1' };
|
|
423
|
+
const MIXED_NATIVE_FLOW = {
|
|
424
|
+
tag: 'interactive',
|
|
425
|
+
attrs: NATIVE_FLOW_ATTRIBUTE,
|
|
426
|
+
content: [
|
|
427
|
+
{
|
|
428
|
+
tag: 'native_flow',
|
|
429
|
+
attrs: { v: '9', name: 'mixed' }
|
|
430
|
+
}
|
|
431
|
+
]
|
|
432
|
+
};
|
|
433
|
+
const getBizBinaryNode = (message) => {
|
|
434
|
+
const flowMsg = message.interactiveMessage?.nativeFlowMessage;
|
|
435
|
+
const firstButtonName = flowMsg?.buttons?.[0]?.name;
|
|
436
|
+
const qualityContent = {
|
|
437
|
+
tag: 'quality_control',
|
|
438
|
+
attrs: {
|
|
439
|
+
decision_id: (0, node_crypto_1.randomBytes)(20).toString('hex'),
|
|
440
|
+
source_type: 'third_party'
|
|
441
|
+
},
|
|
442
|
+
content: DECISION_SOURCE_CONTENT
|
|
443
|
+
};
|
|
444
|
+
const bizAttributes = {
|
|
445
|
+
actual_actors: '2',
|
|
446
|
+
host_storage: '2',
|
|
447
|
+
privacy_mode_ts: `${Date.now() / 1000 | 0}`
|
|
448
|
+
};
|
|
449
|
+
if (firstButtonName === 'review_and_pay' || firstButtonName === 'payment_info') {
|
|
450
|
+
bizAttributes.native_flow_name = firstButtonName === 'review_and_pay' ?
|
|
451
|
+
'order_details' :
|
|
452
|
+
firstButtonName;
|
|
453
|
+
return {
|
|
454
|
+
tag: 'biz',
|
|
455
|
+
attrs: bizAttributes,
|
|
456
|
+
content: [qualityContent]
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
if (firstButtonName && FLOWS_MAP[firstButtonName]) {
|
|
460
|
+
return {
|
|
461
|
+
tag: 'biz',
|
|
462
|
+
attrs: bizAttributes,
|
|
463
|
+
content: [
|
|
464
|
+
{
|
|
465
|
+
tag: 'interactive',
|
|
466
|
+
attrs: NATIVE_FLOW_ATTRIBUTE,
|
|
467
|
+
content: [
|
|
468
|
+
{
|
|
469
|
+
tag: 'native_flow',
|
|
470
|
+
attrs: { v: '2', name: firstButtonName }
|
|
471
|
+
}
|
|
472
|
+
]
|
|
473
|
+
},
|
|
474
|
+
qualityContent
|
|
475
|
+
]
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
if (flowMsg || message.buttonsMessage || message.templateMessage) {
|
|
479
|
+
return {
|
|
480
|
+
tag: 'biz',
|
|
481
|
+
attrs: bizAttributes,
|
|
482
|
+
content: [
|
|
483
|
+
MIXED_NATIVE_FLOW,
|
|
484
|
+
qualityContent
|
|
485
|
+
]
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
if (message.listMessage) {
|
|
489
|
+
return {
|
|
490
|
+
tag: 'biz',
|
|
491
|
+
attrs: bizAttributes,
|
|
492
|
+
content: [
|
|
493
|
+
LIST_TYPE_CONTENT,
|
|
494
|
+
qualityContent
|
|
495
|
+
]
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
return {
|
|
499
|
+
tag: 'biz',
|
|
500
|
+
attrs: bizAttributes,
|
|
501
|
+
content: [qualityContent]
|
|
502
|
+
};
|
|
503
|
+
};
|
|
504
|
+
exports.getBizBinaryNode = getBizBinaryNode;
|
|
505
|
+
|
|
506
|
+
return module.exports;
|
|
507
|
+
})();
|
|
508
|
+
for (const key of Object.keys(__kageModule193)) {
|
|
509
|
+
if (key !== '__esModule' && !Object.prototype.hasOwnProperty.call(exports,key)) Object.defineProperty(exports,key,{enumerable:true,configurable:true,get:()=>__kageModule193[key]});
|
|
510
|
+
}
|
|
511
|
+
Object.defineProperty(exports, Symbol.for('kage.advanced'), {value:__kageModule193, configurable:true});
|
package/lib/WABinary/index.js
CHANGED
|
@@ -19,3 +19,85 @@ __exportStar(require("./decode"), exports);
|
|
|
19
19
|
__exportStar(require("./generic-utils"), exports);
|
|
20
20
|
__exportStar(require("./jid-utils"), exports);
|
|
21
21
|
__exportStar(require("./types"), exports);
|
|
22
|
+
|
|
23
|
+
// Kage: compatibilidad de API.
|
|
24
|
+
const __kageModule85 = (() => {
|
|
25
|
+
const module = { exports: {} }; const exports = module.exports;
|
|
26
|
+
"use strict"
|
|
27
|
+
|
|
28
|
+
const __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
29
|
+
if (k2 === undefined) k2 = k
|
|
30
|
+
|
|
31
|
+
let desc = Object.getOwnPropertyDescriptor(m, k)
|
|
32
|
+
|
|
33
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
34
|
+
desc = {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
get: function() {
|
|
37
|
+
return m[k]
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
Object.defineProperty(o, k2, desc)
|
|
43
|
+
|
|
44
|
+
}) : (function(o, m, k, k2) {
|
|
45
|
+
if (k2 === undefined) k2 = k
|
|
46
|
+
o[k2] = m[k]
|
|
47
|
+
}
|
|
48
|
+
))
|
|
49
|
+
|
|
50
|
+
const __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
51
|
+
for (var p in m) {
|
|
52
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) {
|
|
53
|
+
__createBinding(exports, m, p)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
Object.defineProperty(exports, "__esModule", {
|
|
59
|
+
value: true
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
__exportStar(require("./encode"), exports)
|
|
63
|
+
__exportStar(require("./decode"), exports)
|
|
64
|
+
__exportStar(require("./generic-utils"), exports)
|
|
65
|
+
__exportStar(require("./jid-utils"), exports)
|
|
66
|
+
__exportStar(require("./types"), exports)
|
|
67
|
+
return module.exports;
|
|
68
|
+
})();
|
|
69
|
+
for (const key of Object.keys(__kageModule85)) {
|
|
70
|
+
if (key !== '__esModule' && !Object.prototype.hasOwnProperty.call(exports,key)) Object.defineProperty(exports,key,{enumerable:true,configurable:true,get:()=>__kageModule85[key]});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Kage: funciones avanzadas.
|
|
74
|
+
const __kageModule194 = (() => {
|
|
75
|
+
const module = { exports: {} }; const exports = module.exports;
|
|
76
|
+
"use strict";
|
|
77
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
78
|
+
if (k2 === undefined) k2 = k;
|
|
79
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
80
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
81
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
82
|
+
}
|
|
83
|
+
Object.defineProperty(o, k2, desc);
|
|
84
|
+
}) : (function(o, m, k, k2) {
|
|
85
|
+
if (k2 === undefined) k2 = k;
|
|
86
|
+
o[k2] = m[k];
|
|
87
|
+
}));
|
|
88
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
89
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
90
|
+
};
|
|
91
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
92
|
+
__exportStar(require("./encode.js"), exports);
|
|
93
|
+
__exportStar(require("./decode.js"), exports);
|
|
94
|
+
__exportStar(require("./generic-utils.js"), exports);
|
|
95
|
+
__exportStar(require("./jid-utils.js"), exports);
|
|
96
|
+
__exportStar(require("./types.js"), exports);
|
|
97
|
+
|
|
98
|
+
return module.exports;
|
|
99
|
+
})();
|
|
100
|
+
for (const key of Object.keys(__kageModule194)) {
|
|
101
|
+
if (key !== '__esModule' && !Object.prototype.hasOwnProperty.call(exports,key)) Object.defineProperty(exports,key,{enumerable:true,configurable:true,get:()=>__kageModule194[key]});
|
|
102
|
+
}
|
|
103
|
+
Object.defineProperty(exports, Symbol.for('kage.advanced'), {value:__kageModule194, configurable:true});
|