@vinzsocket/baileys 3.0.30 → 3.1.9
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 +115 -0
- package/lib/Socket/messages-send.js +6 -3
- package/lib/Utils/messages.d.ts +15 -0
- package/lib/Utils/messages.js +67 -7
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# Harps-Baileys
|
|
2
|
+
|
|
3
|
+
`Harps-Baileys` adalah package JavaScript/TypeScript berbasis ESM untuk berinteraksi dengan WhatsApp Web melalui WebSocket.
|
|
4
|
+
Dari isi zip ini, terlihat bahwa proyek ini adalah **hasil build/distribusi** dari library `@vinzsocket/baileys` versi `3.1.9`, bukan source mentahnya.
|
|
5
|
+
|
|
6
|
+
## Isi utama paket
|
|
7
|
+
|
|
8
|
+
Di dalam arsip ini ada beberapa bagian penting:
|
|
9
|
+
|
|
10
|
+
- `package.json` — metadata package, dependency, engine Node, dan script build.
|
|
11
|
+
- `engine-requirements.js` — pengecekan versi/runtime Node saat instalasi.
|
|
12
|
+
- `CHANGELOG.md` — riwayat perubahan versi.
|
|
13
|
+
- `WAProto/` — definisi protobuf WhatsApp dan file helper yang di-generate.
|
|
14
|
+
- `lib/` — inti library yang siap dipakai oleh aplikasi.
|
|
15
|
+
|
|
16
|
+
## Struktur folder
|
|
17
|
+
|
|
18
|
+
### `WAProto/`
|
|
19
|
+
Folder ini berisi komponen protobuf WhatsApp:
|
|
20
|
+
|
|
21
|
+
- `WAProto.proto` — definisi struktur data protobuf.
|
|
22
|
+
- `index.js` dan `index.d.ts` — entry point untuk ekspor protokol.
|
|
23
|
+
- `GenerateStatics.sh` — script untuk generate file statis protobuf.
|
|
24
|
+
- `fix-imports.js` — helper untuk merapikan import hasil generate.
|
|
25
|
+
|
|
26
|
+
### `lib/`
|
|
27
|
+
Ini adalah inti library yang sudah dikompilasi. Isinya didominasi file `.js`, `.d.ts`, dan `.map`.
|
|
28
|
+
|
|
29
|
+
#### `lib/Defaults/`
|
|
30
|
+
Berisi nilai default dan konfigurasi awal yang dipakai library.
|
|
31
|
+
|
|
32
|
+
#### `lib/Signal/`
|
|
33
|
+
Berisi implementasi mekanisme Signal / enkripsi, termasuk logika grup dan key management.
|
|
34
|
+
|
|
35
|
+
Subfolder penting di dalamnya:
|
|
36
|
+
|
|
37
|
+
- `Group/` — logic untuk pesan grup, sender key, dan distribusi key.
|
|
38
|
+
- file seperti `libsignal.d.ts` dan `lid-mapping.d.ts` — tipe dan helper terkait identitas/enkripsi.
|
|
39
|
+
|
|
40
|
+
#### `lib/Socket/`
|
|
41
|
+
Bagian socket adalah inti koneksi ke WhatsApp Web.
|
|
42
|
+
|
|
43
|
+
Isi yang terlihat mencakup:
|
|
44
|
+
|
|
45
|
+
- `Client/` — client layer dan tipe websocket.
|
|
46
|
+
- file bisnis dan socket utama untuk membangun koneksi, handle event, dan komunikasi real-time.
|
|
47
|
+
|
|
48
|
+
#### `lib/Types/`
|
|
49
|
+
Kumpulan type definitions untuk struktur data library, misalnya auth, chat, message, business, dan tipe internal lain.
|
|
50
|
+
|
|
51
|
+
#### `lib/Utils/`
|
|
52
|
+
Kumpulan helper/pemrosesan pendukung, misalnya:
|
|
53
|
+
|
|
54
|
+
- auth utils
|
|
55
|
+
- browser utils
|
|
56
|
+
- message utils
|
|
57
|
+
- file / media / link helper
|
|
58
|
+
- fungsi-fungsi kecil yang dipakai lintas modul
|
|
59
|
+
|
|
60
|
+
#### `lib/WABinary/`
|
|
61
|
+
Berisi encoder/decoder dan konstanta untuk format binary WhatsApp.
|
|
62
|
+
|
|
63
|
+
#### `lib/WAM/`
|
|
64
|
+
Berisi konstanta dan helper untuk model/protokol WhatsApp Message.
|
|
65
|
+
|
|
66
|
+
#### `lib/WAUSync/`
|
|
67
|
+
Berisi protokol sinkronisasi data WhatsApp, termasuk:
|
|
68
|
+
|
|
69
|
+
- contact sync
|
|
70
|
+
- device sync
|
|
71
|
+
- chat/message sync
|
|
72
|
+
- state synchronization
|
|
73
|
+
|
|
74
|
+
## Gambaran isi file di root package
|
|
75
|
+
|
|
76
|
+
File penting di root package:
|
|
77
|
+
|
|
78
|
+
- `lib/index.js` — entry point utama library.
|
|
79
|
+
- `lib/index.d.ts` — tipe TypeScript utama.
|
|
80
|
+
- `package.json` — informasi package dan entry point.
|
|
81
|
+
- `CHANGELOG.md` — catatan perubahan.
|
|
82
|
+
- `engine-requirements.js` — validasi lingkungan runtime.
|
|
83
|
+
|
|
84
|
+
## Cara memakai
|
|
85
|
+
|
|
86
|
+
Contoh dasar pemakaian:
|
|
87
|
+
|
|
88
|
+
```js
|
|
89
|
+
import makeWASocket from '@vinzsocket/baileys'
|
|
90
|
+
|
|
91
|
+
const conn = makeWASocket({
|
|
92
|
+
// konfigurasi koneksi
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
console.log('Socket siap dipakai')
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Catatan teknis
|
|
99
|
+
|
|
100
|
+
- Package ini memakai `"type": "module"`, jadi format utamanya **ESM**.
|
|
101
|
+
- Entry point utama ada di `lib/index.js`.
|
|
102
|
+
- Target Node di `package.json` adalah `>=20.0.0`.
|
|
103
|
+
- Isi arsip ini lebih cocok disebut **build output** daripada source project lengkap.
|
|
104
|
+
|
|
105
|
+
## Ringkasan singkat
|
|
106
|
+
|
|
107
|
+
Kalau disederhanakan, isi zip ini adalah:
|
|
108
|
+
|
|
109
|
+
1. metadata package,
|
|
110
|
+
2. definisi protobuf WhatsApp,
|
|
111
|
+
3. modul socket utama,
|
|
112
|
+
4. modul enkripsi dan binary protocol,
|
|
113
|
+
5. tipe data dan utility pendukung,
|
|
114
|
+
6. hasil build siap pakai untuk library WhatsApp Web socket.
|
|
115
|
+
|
|
@@ -2,7 +2,7 @@ import NodeCache from '@cacheable/node-cache';
|
|
|
2
2
|
import { Boom } from '@hapi/boom';
|
|
3
3
|
import { proto } from '../../WAProto/index.js';
|
|
4
4
|
import { DEFAULT_CACHE_TTLS, WA_DEFAULT_EPHEMERAL } from '../Defaults/index.js';
|
|
5
|
-
import { aggregateMessageKeysNotFromMe, assertMediaContent, assertMeId, bindWaitForEvent, decryptMediaRetryData, DEF_MEDIA_HOST, encodeNewsletterMessage, encodeSignedDeviceIdentity, encodeWAMessage, encryptMediaRetryRequest, extractDeviceJids, generateMessageID, generateMessageIDV2, generateParticipantHashV2, generateWAMessage, generateWAMessageContent, generateWAMessageFromContent, getStatusCodeForMediaRetry, getUrlFromDirectPath, getWAUploadToServer, MessageRetryManager, normalizeMessageContent, parseAndInjectE2ESessions, prepareWAMessageMedia, unixTimestampSeconds } from '../Utils/index.js';
|
|
5
|
+
import { aggregateMessageKeysNotFromMe, assertMediaContent, assertMeId, bindWaitForEvent, buildInteractiveAdditionalNodes, decryptMediaRetryData, DEF_MEDIA_HOST, encodeNewsletterMessage, encodeSignedDeviceIdentity, encodeWAMessage, encryptMediaRetryRequest, extractDeviceJids, generateMessageID, generateMessageIDV2, generateParticipantHashV2, generateWAMessage, generateWAMessageContent, generateWAMessageFromContent, getStatusCodeForMediaRetry, getUrlFromDirectPath, getWAUploadToServer, MessageRetryManager, normalizeMessageContent, parseAndInjectE2ESessions, prepareWAMessageMedia, unixTimestampSeconds } from '../Utils/index.js';
|
|
6
6
|
import { getUrlInfo } from '../Utils/link-preview.js';
|
|
7
7
|
import { makeKeyedMutex, makeMutex } from '../Utils/make-mutex.js';
|
|
8
8
|
import { getMessageReportingToken, shouldIncludeReportingToken } from '../Utils/reporting-utils.js';
|
|
@@ -1088,14 +1088,16 @@ export const makeMessagesSocket = (config) => {
|
|
|
1088
1088
|
const productContent = await extendedMessages.handleProduct(content, jid, quoted);
|
|
1089
1089
|
const productMsg = await generateWAMessageFromContent(jid, productContent, { quoted });
|
|
1090
1090
|
return await relayMessage(jid, productMsg.message, {
|
|
1091
|
-
messageId: productMsg.key.id
|
|
1091
|
+
messageId: productMsg.key.id,
|
|
1092
|
+
additionalNodes: buildInteractiveAdditionalNodes(jid, productMsg.message)
|
|
1092
1093
|
});
|
|
1093
1094
|
}
|
|
1094
1095
|
case 'INTERACTIVE': {
|
|
1095
1096
|
const interactiveContent = await extendedMessages.handleInteractive(content, jid, quoted, options);
|
|
1096
1097
|
const interactiveMsg = await generateWAMessageFromContent(jid, interactiveContent, { quoted });
|
|
1097
1098
|
return await relayMessage(jid, interactiveMsg.message, {
|
|
1098
|
-
messageId: interactiveMsg.key.id
|
|
1099
|
+
messageId: interactiveMsg.key.id,
|
|
1100
|
+
additionalNodes: buildInteractiveAdditionalNodes(jid, interactiveMsg.message)
|
|
1099
1101
|
});
|
|
1100
1102
|
}
|
|
1101
1103
|
case 'ALBUM':
|
|
@@ -1168,6 +1170,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
1168
1170
|
}
|
|
1169
1171
|
});
|
|
1170
1172
|
}
|
|
1173
|
+
additionalNodes.push(...buildInteractiveAdditionalNodes(jid, fullMsg.message));
|
|
1171
1174
|
await relayMessage(jid, fullMsg.message, {
|
|
1172
1175
|
messageId: fullMsg.key.id,
|
|
1173
1176
|
useCachedGroupMetadata: options.useCachedGroupMetadata,
|
package/lib/Utils/messages.d.ts
CHANGED
|
@@ -20,6 +20,21 @@ export declare const prepareDisappearingMessageSettingContent: (ephemeralExpirat
|
|
|
20
20
|
*/
|
|
21
21
|
export declare const generateForwardMessageContent: (message: WAMessage, forceForward?: boolean) => proto.IMessage;
|
|
22
22
|
export declare const hasNonNullishProperty: <K extends PropertyKey>(message: AnyMessageContent, key: K) => message is ExtractByKey<AnyMessageContent, K>;
|
|
23
|
+
/** Normalizes a community-style buttons/templateButtons/interactiveButtons array into
|
|
24
|
+
* WhatsApp's native flow button shape: `{ name, buttonParamsJson }`. */
|
|
25
|
+
export declare const normalizeToNativeFlowButtons: (buttons: import("../Types/Message.js").WAButtonShape[]) => proto.Message.InteractiveMessage.NativeFlowMessage.INativeFlowButton[];
|
|
26
|
+
/** Wraps interactive/button/list/product message content in a viewOnceMessage with
|
|
27
|
+
* deviceListMetadataVersion set. See buildInteractiveAdditionalNodes for the binary
|
|
28
|
+
* node hint that's also required for the message to actually render. */
|
|
29
|
+
export declare const patchInteractiveMessage: (m: proto.IMessage) => proto.IMessage;
|
|
30
|
+
/** Builds the `<biz><interactive/></biz>` / `<biz><list/></biz>` (+ `<bot biz_bot="1"/>`
|
|
31
|
+
* for 1:1 chats) binary nodes required for interactive/button/list messages to render.
|
|
32
|
+
* Pass the result as `additionalNodes` to relayMessage(). */
|
|
33
|
+
export declare const buildInteractiveAdditionalNodes: (jid: string, m: proto.IMessage) => Array<{
|
|
34
|
+
tag: string;
|
|
35
|
+
attrs: Record<string, string>;
|
|
36
|
+
content?: any[];
|
|
37
|
+
}>;
|
|
23
38
|
export declare const generateWAMessageContent: (message: AnyMessageContent, options: MessageContentGenerationOptions) => Promise<proto.Message>;
|
|
24
39
|
export declare const generateWAMessageFromContent: (jid: string, message: WAMessageContent, options: MessageGenerationOptionsFromContent) => WAMessage;
|
|
25
40
|
export declare const generateWAMessage: (jid: string, content: AnyMessageContent, options: MessageGenerationOptions) => Promise<WAMessage>;
|
package/lib/Utils/messages.js
CHANGED
|
@@ -331,14 +331,19 @@ export const normalizeToNativeFlowButtons = (buttons) => {
|
|
|
331
331
|
}).filter(Boolean);
|
|
332
332
|
};
|
|
333
333
|
/**
|
|
334
|
-
*
|
|
335
|
-
*
|
|
336
|
-
*
|
|
337
|
-
*
|
|
334
|
+
* Wraps interactive/button/list/product messages in a viewOnceMessage with
|
|
335
|
+
* deviceListMetadataVersion set. This matches the convention used by most community
|
|
336
|
+
* Baileys forks (baileys-pro, FizzxyDev, indraazy, etc) and by this bot's own `simple.js`
|
|
337
|
+
* helpers (sendBut/sendList).
|
|
338
338
|
*
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
*
|
|
339
|
+
* NOTE: this wrapper alone is NOT sufficient for buttons to render — WhatsApp's server
|
|
340
|
+
* also needs the `<biz><interactive/></biz>` binary node hint, which is NOT part of the
|
|
341
|
+
* message content and must be passed separately via `additionalNodes` to relayMessage().
|
|
342
|
+
* See `buildInteractiveAdditionalNodes()` below, which messages-send.js's sendMessage()
|
|
343
|
+
* and Socket/dugong.js both call for this exact reason.
|
|
344
|
+
*
|
|
345
|
+
* Safe to call on any message content object `m`. No-ops if `m` is already wrapped,
|
|
346
|
+
* or doesn't need wrapping.
|
|
342
347
|
*/
|
|
343
348
|
export const patchInteractiveMessage = (m) => {
|
|
344
349
|
if (!m || typeof m !== 'object') return m;
|
|
@@ -364,6 +369,61 @@ export const patchInteractiveMessage = (m) => {
|
|
|
364
369
|
}
|
|
365
370
|
};
|
|
366
371
|
};
|
|
372
|
+
/**
|
|
373
|
+
* Build the `additionalNodes` required for interactive/button/list messages to actually
|
|
374
|
+
* render on the recipient's client. WhatsApp's server uses these binary node hints
|
|
375
|
+
* (<biz><interactive .../></biz> or <biz><list .../></biz>, plus <bot biz_bot="1"/> for
|
|
376
|
+
* 1:1 chats) to decide whether to treat the message as an interactive flow — without them
|
|
377
|
+
* the message still delivers, but renders empty/invisible on most clients.
|
|
378
|
+
*
|
|
379
|
+
* @param {string} jid - destination jid (used to detect group vs 1:1)
|
|
380
|
+
* @param {object} m - the message content object, e.g. { interactiveMessage: {...} } or
|
|
381
|
+
* one already unwrapped from a viewOnceMessage (pass the inner message).
|
|
382
|
+
* @returns {Array<object>} additionalNodes to pass into relayMessage()
|
|
383
|
+
*/
|
|
384
|
+
export const buildInteractiveAdditionalNodes = (jid, m) => {
|
|
385
|
+
if (!m || typeof m !== 'object') return [];
|
|
386
|
+
const inner = m.viewOnceMessage?.message || m.viewOnceMessageV2?.message || m;
|
|
387
|
+
const nodes = [];
|
|
388
|
+
const group = isJidGroup(jid);
|
|
389
|
+
if (inner.listMessage) {
|
|
390
|
+
nodes.push({
|
|
391
|
+
tag: 'biz',
|
|
392
|
+
attrs: {},
|
|
393
|
+
content: [
|
|
394
|
+
{
|
|
395
|
+
tag: 'list',
|
|
396
|
+
attrs: { type: 'product_list', v: '2' }
|
|
397
|
+
}
|
|
398
|
+
]
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
else if (inner.interactiveMessage || inner.buttonsMessage || inner.templateMessage || inner.productMessage) {
|
|
402
|
+
nodes.push({
|
|
403
|
+
tag: 'biz',
|
|
404
|
+
attrs: {},
|
|
405
|
+
content: [
|
|
406
|
+
{
|
|
407
|
+
tag: 'interactive',
|
|
408
|
+
attrs: { type: 'native_flow', v: '1' },
|
|
409
|
+
content: [
|
|
410
|
+
{
|
|
411
|
+
tag: 'native_flow',
|
|
412
|
+
attrs: { name: 'mixed', v: '9' }
|
|
413
|
+
}
|
|
414
|
+
]
|
|
415
|
+
}
|
|
416
|
+
]
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
if (nodes.length > 0 && !group) {
|
|
420
|
+
nodes.push({
|
|
421
|
+
tag: 'bot',
|
|
422
|
+
attrs: { biz_bot: '1' }
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
return nodes;
|
|
426
|
+
};
|
|
367
427
|
export const hasNonNullishProperty = (message, key) => {
|
|
368
428
|
return (typeof message === 'object' &&
|
|
369
429
|
message !== null &&
|