@vinzsocket/baileys 3.3.1 → 3.3.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/README.md +2684 -1336
- package/WAProto/WAProto.proto +360 -916
- package/WAProto/fix-imports.js +22 -18
- package/WAProto/index.d.ts +14015 -0
- package/WAProto/index.js +47122 -81757
- package/engine-requirements.js +27 -0
- package/lib/Defaults/index.d.ts +15 -14
- package/lib/Defaults/index.d.ts.map +1 -1
- package/lib/Defaults/index.js +98 -109
- package/lib/Defaults/index.js.map +1 -1
- package/lib/Signal/Group/group_cipher.js.map +1 -1
- package/lib/Signal/Group/keyhelper.d.ts.map +1 -1
- package/lib/Signal/Group/keyhelper.js.map +1 -1
- package/lib/Signal/Group/sender-chain-key.js.map +1 -1
- package/lib/Signal/Group/sender-key-message.js.map +1 -1
- package/lib/Signal/Group/sender-message-key.js.map +1 -1
- package/lib/Signal/libsignal.d.ts.map +1 -1
- package/lib/Signal/libsignal.js +45 -17
- package/lib/Signal/libsignal.js.map +1 -1
- package/lib/Signal/lid-mapping.d.ts +4 -0
- package/lib/Signal/lid-mapping.d.ts.map +1 -1
- package/lib/Signal/lid-mapping.js +6 -0
- package/lib/Signal/lid-mapping.js.map +1 -1
- package/lib/Socket/business.d.ts +213 -532
- package/lib/Socket/business.d.ts.map +1 -1
- package/lib/Socket/business.js +358 -401
- package/lib/Socket/chats.d.ts +15 -2
- package/lib/Socket/chats.d.ts.map +1 -1
- package/lib/Socket/chats.js +247 -40
- package/lib/Socket/chats.js.map +1 -1
- package/lib/Socket/communities.d.ts +269 -641
- package/lib/Socket/communities.d.ts.map +1 -1
- package/lib/Socket/dugong.d.ts +315 -127
- package/lib/Socket/dugong.js +653 -749
- package/lib/Socket/groups.d.ts +13 -2
- package/lib/Socket/groups.d.ts.map +1 -1
- package/lib/Socket/groups.js +21 -1
- package/lib/Socket/groups.js.map +1 -1
- package/lib/Socket/index.d.ts +256 -631
- package/lib/Socket/index.d.ts.map +1 -1
- package/lib/Socket/index.js +9 -12
- package/lib/Socket/index.js.map +1 -1
- package/lib/Socket/messages-recv.d.ts +23 -58
- package/lib/Socket/messages-recv.d.ts.map +1 -1
- package/lib/Socket/messages-recv.js +645 -181
- package/lib/Socket/messages-recv.js.map +1 -1
- package/lib/Socket/messages-send.d.ts +201 -575
- package/lib/Socket/messages-send.d.ts.map +1 -1
- package/lib/Socket/messages-send.js +1185 -1552
- package/lib/Socket/messages-send.js.map +1 -1
- package/lib/Socket/mex.d.ts.map +1 -1
- package/lib/Socket/mex.js +2 -8
- package/lib/Socket/mex.js.map +1 -1
- package/lib/Socket/newsletter.d.ts +11 -18
- package/lib/Socket/newsletter.d.ts.map +1 -1
- package/lib/Socket/newsletter.js +165 -440
- package/lib/Socket/newsletter.js.map +1 -1
- package/lib/Socket/socket.d.ts +6 -2
- package/lib/Socket/socket.d.ts.map +1 -1
- package/lib/Socket/socket.js +59 -25
- package/lib/Socket/socket.js.map +1 -1
- package/lib/Types/Auth.d.ts +1 -0
- package/lib/Types/Auth.d.ts.map +1 -1
- package/lib/Types/Bussines.d.ts +22 -34
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Call.d.ts.map +1 -1
- package/lib/Types/Chat.d.ts +1 -0
- package/lib/Types/Chat.d.ts.map +1 -1
- package/lib/Types/Contact.d.ts +2 -0
- package/lib/Types/Contact.d.ts.map +1 -1
- package/lib/Types/Events.d.ts +20 -1
- package/lib/Types/Events.d.ts.map +1 -1
- package/lib/Types/GroupMetadata.d.ts +4 -1
- package/lib/Types/GroupMetadata.d.ts.map +1 -1
- package/lib/Types/Message.d.ts +294 -348
- package/lib/Types/Message.d.ts.map +1 -1
- package/lib/Types/Message.js.map +1 -1
- package/lib/Types/Mex.d.ts +141 -0
- package/lib/Types/Mex.d.ts.map +1 -0
- package/lib/Types/Mex.js +37 -0
- package/lib/Types/Mex.js.map +1 -0
- package/lib/Types/Signal.d.ts +12 -1
- package/lib/Types/Signal.d.ts.map +1 -1
- package/lib/Types/Socket.d.ts +126 -148
- package/lib/Types/Socket.d.ts.map +1 -1
- package/lib/Types/State.d.ts +58 -0
- package/lib/Types/State.d.ts.map +1 -1
- package/lib/Types/State.js +43 -0
- package/lib/Types/State.js.map +1 -1
- package/lib/Types/index.d.ts +52 -52
- package/lib/Types/index.d.ts.map +1 -1
- package/lib/Types/index.js +23 -30
- package/lib/Types/index.js.map +1 -1
- package/lib/Utils/auth-utils.d.ts +5 -0
- package/lib/Utils/auth-utils.d.ts.map +1 -1
- package/lib/Utils/auth-utils.js +12 -0
- package/lib/Utils/auth-utils.js.map +1 -1
- package/lib/Utils/browser-utils.js +1 -0
- package/lib/Utils/chat-utils.d.ts +34 -4
- package/lib/Utils/chat-utils.d.ts.map +1 -1
- package/lib/Utils/chat-utils.js +80 -20
- package/lib/Utils/chat-utils.js.map +1 -1
- package/lib/Utils/companion-reg-client-utils.d.ts +17 -0
- package/lib/Utils/companion-reg-client-utils.d.ts.map +1 -0
- package/lib/Utils/companion-reg-client-utils.js +35 -0
- package/lib/Utils/companion-reg-client-utils.js.map +1 -0
- package/lib/Utils/crypto.d.ts +12 -12
- package/lib/Utils/crypto.d.ts.map +1 -1
- package/lib/Utils/crypto.js.map +1 -1
- package/lib/Utils/decode-wa-message.d.ts +18 -0
- package/lib/Utils/decode-wa-message.d.ts.map +1 -1
- package/lib/Utils/decode-wa-message.js +34 -0
- package/lib/Utils/decode-wa-message.js.map +1 -1
- package/lib/Utils/event-buffer.d.ts +2 -0
- package/lib/Utils/event-buffer.d.ts.map +1 -1
- package/lib/Utils/event-buffer.js +49 -1
- package/lib/Utils/event-buffer.js.map +1 -1
- package/lib/Utils/generics.d.ts +2 -2
- package/lib/Utils/generics.d.ts.map +1 -1
- package/lib/Utils/generics.js +10 -1
- package/lib/Utils/generics.js.map +1 -1
- package/lib/Utils/history.d.ts +2 -0
- package/lib/Utils/history.d.ts.map +1 -1
- package/lib/Utils/history.js +12 -9
- package/lib/Utils/history.js.map +1 -1
- package/lib/Utils/identity-change-handler.d.ts +7 -0
- package/lib/Utils/identity-change-handler.d.ts.map +1 -1
- package/lib/Utils/identity-change-handler.js +1 -0
- package/lib/Utils/identity-change-handler.js.map +1 -1
- package/lib/Utils/index.d.ts +23 -23
- package/lib/Utils/index.d.ts.map +1 -1
- package/lib/Utils/index.js +4 -1
- package/lib/Utils/index.js.map +1 -1
- package/lib/Utils/link-preview.js +2 -2
- package/lib/Utils/link-preview.js.map +1 -1
- package/lib/Utils/logger.d.ts +1 -2
- package/lib/Utils/logger.d.ts.map +1 -1
- package/lib/Utils/mention.d.ts +14 -0
- package/lib/Utils/mention.js +138 -0
- package/lib/Utils/message-retry-manager.d.ts +5 -0
- package/lib/Utils/message-retry-manager.d.ts.map +1 -1
- package/lib/Utils/message-retry-manager.js +40 -0
- package/lib/Utils/message-retry-manager.js.map +1 -1
- package/lib/Utils/messages-media.d.ts +16 -13
- package/lib/Utils/messages-media.d.ts.map +1 -1
- package/lib/Utils/messages-media.js +85 -79
- package/lib/Utils/messages-media.js.map +1 -1
- package/lib/Utils/messages.d.ts +16 -1
- package/lib/Utils/messages.d.ts.map +1 -1
- package/lib/Utils/messages.js +1021 -1121
- package/lib/Utils/messages.js.map +1 -1
- package/lib/Utils/noise-handler.d.ts +1 -1
- package/lib/Utils/process-message.d.ts.map +1 -1
- package/lib/Utils/process-message.js +103 -1
- package/lib/Utils/process-message.js.map +1 -1
- package/lib/Utils/signal.d.ts +13 -0
- package/lib/Utils/signal.d.ts.map +1 -1
- package/lib/Utils/signal.js +42 -0
- package/lib/Utils/signal.js.map +1 -1
- package/lib/Utils/story-card.js +107 -0
- package/lib/Utils/sync-action-utils.d.ts.map +1 -1
- package/lib/Utils/sync-action-utils.js +1 -0
- package/lib/Utils/sync-action-utils.js.map +1 -1
- package/lib/Utils/tc-token-utils.d.ts +26 -1
- package/lib/Utils/tc-token-utils.d.ts.map +1 -1
- package/lib/Utils/tc-token-utils.js +151 -5
- package/lib/Utils/tc-token-utils.js.map +1 -1
- package/lib/Utils/validate-connection.d.ts.map +1 -1
- package/lib/Utils/validate-connection.js +12 -2
- package/lib/Utils/validate-connection.js.map +1 -1
- package/lib/WABinary/decode.d.ts +1 -1
- package/lib/WABinary/decode.d.ts.map +1 -1
- package/lib/WABinary/generic-utils.d.ts +1 -3
- package/lib/WABinary/generic-utils.d.ts.map +1 -1
- package/lib/WABinary/generic-utils.js +0 -78
- package/lib/WABinary/generic-utils.js.map +1 -1
- package/lib/WAM/encode.d.ts +1 -1
- package/lib/WAM/encode.d.ts.map +1 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +26 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -1
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/index.d.ts +1 -0
- package/lib/WAUSync/Protocols/index.d.ts.map +1 -1
- package/lib/WAUSync/Protocols/index.js +1 -0
- package/lib/WAUSync/Protocols/index.js.map +1 -1
- package/lib/WAUSync/USyncQuery.d.ts +1 -0
- package/lib/WAUSync/USyncQuery.d.ts.map +1 -1
- package/lib/WAUSync/USyncQuery.js +6 -2
- package/lib/WAUSync/USyncQuery.js.map +1 -1
- package/lib/WAUSync/USyncUser.d.ts +4 -0
- package/lib/WAUSync/USyncUser.d.ts.map +1 -1
- package/lib/WAUSync/USyncUser.js +8 -0
- package/lib/WAUSync/USyncUser.js.map +1 -1
- package/lib/index.d.ts +0 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +0 -1
- package/lib/index.js.map +1 -1
- package/package.json +91 -24
- package/LICENSE +0 -21
- package/lib/Socket/dugong.d.ts.map +0 -1
- package/lib/Socket/dugong.js.map +0 -1
- package/lib/Types/Newsletter.d.ts.map +0 -1
- package/lib/Types/Newsletter.js.map +0 -1
- package/lib/Utils/rich-messages.d.ts.map +0 -1
- package/lib/Utils/rich-messages.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,1658 +1,3006 @@
|
|
|
1
|
+
# 📱 Harps-Baileys
|
|
2
|
+
|
|
1
3
|
<div align="center">
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
**Fork WebSocket library WhatsApp Web Multi-Device — dasar dari ekosistem bot Harps-MD**
|
|
6
|
+
|
|
7
|
+
[](https://github.com/VinzSocket/Baileys)
|
|
8
|
+

|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
`npm install @vinzsocket/baileys`
|
|
14
|
+
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## 📚 Daftar Isi
|
|
20
|
+
|
|
21
|
+
1. [Tentang Harps-Baileys](#-tentang-harps-baileys)
|
|
22
|
+
2. [Kenapa Fork Ini Dibuat](#-kenapa-fork-ini-dibuat)
|
|
23
|
+
3. [Instalasi](#-instalasi)
|
|
24
|
+
4. [Requirements](#-requirements)
|
|
25
|
+
5. [Quick Start](#-quick-start)
|
|
26
|
+
6. [Autentikasi (Auth State)](#-autentikasi-auth-state)
|
|
27
|
+
7. [Konfigurasi Koneksi](#-konfigurasi-koneksi)
|
|
28
|
+
8. [Struktur Package](#-struktur-package)
|
|
29
|
+
9. [JID & Utilitas Dasar](#-jid--utilitas-dasar)
|
|
30
|
+
10. [Mengirim Pesan — Dasar](#-mengirim-pesan--dasar)
|
|
31
|
+
- [Teks & Link Preview](#teks--link-preview)
|
|
32
|
+
- [Media: Gambar, Video, Audio, Sticker, Dokumen](#media-gambar-video-audio-sticker-dokumen)
|
|
33
|
+
- [Kontak](#kontak)
|
|
34
|
+
- [Lokasi](#lokasi)
|
|
35
|
+
- [Reaksi (Reaction)](#reaksi-reaction)
|
|
36
|
+
- [Polling (Poll)](#polling-poll)
|
|
37
|
+
- [Event / Undangan Acara](#event--undangan-acara)
|
|
38
|
+
- [Hapus, Edit, Pin Pesan](#hapus-edit-pin-pesan)
|
|
39
|
+
- [View Once & PTV](#view-once--ptv)
|
|
40
|
+
- [Mention & Tag Semua](#mention--tag-semua)
|
|
41
|
+
- [Forward Pesan](#forward-pesan)
|
|
42
|
+
11. [Tombol & List — Native Flow](#-tombol--list--native-flow)
|
|
43
|
+
- [Shorthand `buttons` / `templateButtons` / `interactiveButtons`](#shorthand-buttons--templatebuttons--interactivebuttons)
|
|
44
|
+
- [Shorthand `sections` (List Message)](#shorthand-sections-list-message)
|
|
45
|
+
- [Shorthand `cards` (Carousel)](#shorthand-cards-carousel)
|
|
46
|
+
12. [Fitur Eksklusif Harps-Baileys (`dugong.js`)](#-fitur-eksklusif-harps-baileys-dugongjs)
|
|
47
|
+
- [NF V7 Button Builders](#nf-v7-button-builders)
|
|
48
|
+
- [Multi-Select Message](#multi-select-message)
|
|
49
|
+
- [Nested List Message](#nested-list-message)
|
|
50
|
+
- [Group Status V2 (Story Grup)](#group-status-v2-story-grup)
|
|
51
|
+
- [Story Card Generator (`renderStoryCard`)](#story-card-generator-renderstorycard)
|
|
52
|
+
- [Payment Request Message](#payment-request-message)
|
|
53
|
+
- [Product Message](#product-message)
|
|
54
|
+
- [Album Message](#album-message)
|
|
55
|
+
- [Poll Result Snapshot](#poll-result-snapshot)
|
|
56
|
+
- [`buildInteractiveAdditionalNodes` — Kenapa Wajib Ada](#buildinteractiveadditionalnodes--kenapa-wajib-ada)
|
|
57
|
+
13. [Mention Utilities (`mention.js`)](#-mention-utilities-mentionjs)
|
|
58
|
+
14. [Sistem Event](#-sistem-event)
|
|
59
|
+
15. [Grup (Groups API)](#-grup-groups-api)
|
|
60
|
+
16. [Komunitas (Communities API)](#-komunitas-communities-api)
|
|
61
|
+
17. [Business API](#-business-api)
|
|
62
|
+
18. [Newsletter / Channel API](#-newsletter--channel-api)
|
|
63
|
+
19. [Chats, Profil & Privasi](#-chats-profil--privasi)
|
|
64
|
+
20. [Mengunduh & Memperbarui Media](#-mengunduh--memperbarui-media)
|
|
65
|
+
21. [Penanganan Error](#-penanganan-error)
|
|
66
|
+
22. [Reliabilitas & Retry](#-reliabilitas--retry)
|
|
67
|
+
23. [Referensi Shorthand Field `sendMessage`](#-referensi-shorthand-field-sendmessage)
|
|
68
|
+
24. [Tipe Data (Types) Penting](#-tipe-data-types-penting)
|
|
69
|
+
24. [WAProto](#-waproto)
|
|
70
|
+
25. [Contoh Lengkap: Struktur Bot dengan Plugin](#-contoh-lengkap-struktur-bot-dengan-plugin)
|
|
71
|
+
26. [Migrasi dari Baileys Upstream / Fork Lain](#-migrasi-dari-baileys-upstream--fork-lain)
|
|
72
|
+
27. [Troubleshooting / FAQ](#-troubleshooting--faq)
|
|
73
|
+
28. [Referensi Cepat: Semua Method `sock`](#-referensi-cepat-semua-method-sock)
|
|
74
|
+
29. [Contoh Penerapan di Sistem RPG](#-contoh-penerapan-di-sistem-rpg)
|
|
75
|
+
30. [Tips Performa](#-tips-performa)
|
|
76
|
+
31. [Keamanan & Best Practices](#-keamanan--best-practices)
|
|
77
|
+
32. [Opsi Lengkap `sendMessage`](#-opsi-lengkap-sendmessagejid-content-options)
|
|
78
|
+
33. [Deployment](#-deployment)
|
|
79
|
+
34. [Perbandingan dengan Baileys Upstream](#-perbandingan-dengan-baileys-upstream)
|
|
80
|
+
35. [Glosarium Istilah](#-glosarium-istilah)
|
|
81
|
+
36. [Changelog Ringkas](#-changelog-ringkas)
|
|
82
|
+
37. [Ucapan Terima Kasih](#-ucapan-terima-kasih)
|
|
83
|
+
38. [Sumber Daya Tambahan](#-sumber-daya-tambahan)
|
|
84
|
+
39. [Kontribusi](#-kontribusi)
|
|
85
|
+
40. [Lisensi](#-lisensi)
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## 📖 Tentang Harps-Baileys
|
|
90
|
+
|
|
91
|
+
**Harps-Baileys** (dipublikasikan sebagai `@vinzsocket/baileys`) adalah fork dari library [Baileys](https://github.com/WhiskeySockets/Baileys) — WebSocket client untuk WhatsApp Web Multi-Device — yang dikembangkan dan dirawat oleh Alvin (VinzSocket) sebagai fondasi dari ekosistem bot **Harps-MD**.
|
|
92
|
+
|
|
93
|
+
Fork ini mempertahankan seluruh API inti Baileys (koneksi socket, autentikasi Signal Protocol, sinkronisasi riwayat chat, pengiriman & penerimaan pesan multi-device) sambil menambahkan sejumlah kapabilitas baru yang tidak tersedia di upstream, khususnya di area:
|
|
94
|
+
|
|
95
|
+
- **Native Flow interaktif generasi terbaru (NF V7)** — tombol URL, telepon, salin kode, reminder, alamat, lokasi, quick reply, dropdown tunggal/ganda, review pembayaran, review order, hingga multi-product message (MPM).
|
|
96
|
+
- **Group Status V2** — mengirim story/status langsung ke dalam grup, mendukung semua tipe media dengan caption.
|
|
97
|
+
- **Multi-Select Message** — satu pesan dengan beberapa dropdown independen sekaligus.
|
|
98
|
+
- **Nested List Message** — list legacy dengan auto-flatten section bersarang.
|
|
99
|
+
- **Story Card Generator** — membuat gambar status bergaya gradient (title/body/footer) secara programatik tanpa tools desain eksternal.
|
|
100
|
+
- **Shorthand pengiriman pesan** (`buttons`, `sections`, `cards`) yang menyederhanakan pembuatan payload interactive message modern.
|
|
101
|
+
- Perbaikan-perbaikan kompatibilitas & bug fix yang bersumber dari pengalaman menjalankan bot produksi (Harps-MD) sehari-hari.
|
|
102
|
+
|
|
103
|
+
Semua fitur tambahan ini dirancang agar **backward compatible** dengan pola-pola umum yang dipakai komunitas Baileys (mis. `buttonsMessage`, `templateButtons`, shape dari fork-fork populer lain) sehingga migrasi dari Baileys/fork lain ke Harps-Baileys seharusnya minim gesekan.
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## 🎯 Kenapa Fork Ini Dibuat
|
|
108
|
+
|
|
109
|
+
Baileys upstream berkembang cepat mengikuti perubahan protokol WhatsApp Web, tapi API interaktifnya (button, list, carousel) sering kali:
|
|
110
|
+
|
|
111
|
+
- Tidak konsisten antara versi (`buttonsMessage` legacy vs `interactiveMessage` modern).
|
|
112
|
+
- Tidak menyertakan binary node hint (`additionalNodes`) yang diperlukan supaya pesan interaktif benar-benar **tampil** di client penerima — banyak bot yang mengirim pesan sukses (tidak ada error) tapi pesannya kosong/tidak muncul di HP penerima.
|
|
113
|
+
- Tidak punya cara mudah untuk fitur-fitur yang cukup dibutuhkan komunitas bot Indonesia: kirim status ke grup, dropdown ganda dalam satu pesan, atau list bersarang.
|
|
114
|
+
|
|
115
|
+
Harps-Baileys mengisi celah tersebut dengan lapisan `dugong.js` (`ExtendedMessageBuilder`) dan util pendukungnya, sambil tetap 100% memakai jalur `relayMessage()` bawaan Baileys sehingga tidak menyimpang dari cara kerja protokol resminya.
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## 📦 Instalasi
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
npm install @vinzsocket/baileys
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Atau dengan Yarn:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
yarn add @vinzsocket/baileys
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Atau dengan pnpm:
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
pnpm add @vinzsocket/baileys
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Peer Dependencies Opsional
|
|
138
|
+
|
|
139
|
+
Beberapa fitur bersifat opsional dan baru aktif kalau peer dependency-nya terpasang:
|
|
140
|
+
|
|
141
|
+
| Package | Dibutuhkan Untuk | Wajib? |
|
|
142
|
+
|---|---|---|
|
|
143
|
+
| `jimp` | `renderStoryCard()`, decoding sticker/gambar tanpa native binding | Opsional |
|
|
144
|
+
| `sharp` | Konversi/optimasi gambar performa tinggi (alternatif `jimp`) | Opsional |
|
|
145
|
+
| `link-preview-js` | Link preview otomatis pada `extendedTextMessage` | Opsional |
|
|
146
|
+
| `audio-decode` | Decode metadata/durasi audio untuk voice note | Opsional |
|
|
147
|
+
|
|
148
|
+
Pasang sesuai kebutuhan, misalnya:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
npm install jimp sharp link-preview-js audio-decode
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Jika Anda memanggil fitur yang butuh salah satu package di atas tanpa menginstallnya, Harps-Baileys akan melempar error `Boom` yang jelas (bukan crash diam-diam), contohnya:
|
|
155
|
+
|
|
156
|
+
```
|
|
157
|
+
Error: renderStoryCard() requires the optional "jimp" peer dependency. Install it with: npm i jimp
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## ✅ Requirements
|
|
163
|
+
|
|
164
|
+
- **Node.js ≥ 20.0.0** (dicek otomatis lewat script `preinstall` → `engine-requirements.js`)
|
|
165
|
+
- Package ini adalah **ESM murni** (`"type": "module"` di `package.json`). Untuk import di proyek CommonJS:
|
|
166
|
+
|
|
167
|
+
```js
|
|
168
|
+
// CJS project — pakai dynamic import
|
|
169
|
+
const baileys = await import('@vinzsocket/baileys')
|
|
170
|
+
const makeWASocket = baileys.default
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Atau, jika Node.js Anda sudah ≥ 20.19.0 (atau ≥ 22.12.0 / ≥ 23.x), Anda bisa memakai `require()` langsung berkat dukungan `require(esm)` bawaan Node:
|
|
174
|
+
|
|
175
|
+
```js
|
|
176
|
+
const { default: makeWASocket } = require('@vinzsocket/baileys')
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Skrip `engine-requirements.js` akan:
|
|
180
|
+
|
|
181
|
+
- **Menghentikan instalasi** (`process.exit(1)`) jika Node.js Anda di bawah versi 20.
|
|
182
|
+
- Menampilkan **peringatan** (bukan error fatal) jika Node.js Anda di antara 20.0–20.18 / 22.0–22.11, karena `require(esm)` belum stabil di rentang tersebut — solusinya pakai `import()` dinamis seperti contoh di atas.
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## 🚀 Quick Start
|
|
187
|
+
|
|
188
|
+
Contoh paling sederhana: konek ke WhatsApp, tampilkan QR, dan balas pesan “ping” dengan “pong”.
|
|
189
|
+
|
|
190
|
+
```js
|
|
191
|
+
import makeWASocket, { useMultiFileAuthState, DisconnectReason } from '@vinzsocket/baileys'
|
|
192
|
+
import { Boom } from '@hapi/boom'
|
|
193
|
+
|
|
194
|
+
async function startBot() {
|
|
195
|
+
const { state, saveCreds } = await useMultiFileAuthState('sesi_auth')
|
|
196
|
+
|
|
197
|
+
const sock = makeWASocket({
|
|
198
|
+
auth: state,
|
|
199
|
+
printQRInTerminal: true // catatan: opsi ini deprecated di Baileys upstream terbaru,
|
|
200
|
+
// gunakan qrcode-terminal manual jika ingin QR di console modern
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
sock.ev.on('creds.update', saveCreds)
|
|
204
|
+
|
|
205
|
+
sock.ev.on('connection.update', (update) => {
|
|
206
|
+
const { connection, lastDisconnect } = update
|
|
207
|
+
if (connection === 'close') {
|
|
208
|
+
const shouldReconnect =
|
|
209
|
+
lastDisconnect?.error instanceof Boom &&
|
|
210
|
+
lastDisconnect.error.output?.statusCode !== DisconnectReason.loggedOut
|
|
211
|
+
console.log('Koneksi terputus, reconnect:', shouldReconnect)
|
|
212
|
+
if (shouldReconnect) startBot()
|
|
213
|
+
} else if (connection === 'open') {
|
|
214
|
+
console.log('✅ Terhubung ke WhatsApp!')
|
|
215
|
+
}
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
sock.ev.on('messages.upsert', async ({ messages, type }) => {
|
|
219
|
+
if (type !== 'notify') return
|
|
220
|
+
const msg = messages[0]
|
|
221
|
+
if (!msg.message || msg.key.fromMe) return
|
|
222
|
+
|
|
223
|
+
const text =
|
|
224
|
+
msg.message.conversation ||
|
|
225
|
+
msg.message.extendedTextMessage?.text ||
|
|
226
|
+
''
|
|
227
|
+
|
|
228
|
+
if (text.toLowerCase() === 'ping') {
|
|
229
|
+
await sock.sendMessage(msg.key.remoteJid, { text: 'pong 🏓' }, { quoted: msg })
|
|
230
|
+
}
|
|
231
|
+
})
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
startBot()
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
Jalankan:
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
node index.js
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
Scan QR yang muncul di terminal menggunakan WhatsApp di HP Anda (**Linked Devices → Link a Device**).
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## 🔐 Autentikasi (Auth State)
|
|
248
|
+
|
|
249
|
+
Harps-Baileys menyediakan helper `useMultiFileAuthState()` yang menyimpan kredensial sesi (`creds.json`) beserta seluruh key Signal Protocol (pre-key, sender key, session) sebagai file-file terpisah di sebuah folder — cocok untuk development maupun deployment sederhana berbasis filesystem.
|
|
250
|
+
|
|
251
|
+
```js
|
|
252
|
+
import { useMultiFileAuthState } from '@vinzsocket/baileys'
|
|
253
|
+
|
|
254
|
+
const { state, saveCreds } = await useMultiFileAuthState('./sesi_auth')
|
|
255
|
+
|
|
256
|
+
const sock = makeWASocket({ auth: state })
|
|
257
|
+
sock.ev.on('creds.update', saveCreds)
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
**Cara kerja:**
|
|
261
|
+
|
|
262
|
+
- Folder `./sesi_auth` akan otomatis dibuat jika belum ada.
|
|
263
|
+
- Setiap file di dalamnya merepresentasikan satu "kunci" (`creds.json`, `app-state-sync-key-*.json`, `pre-key-*.json`, `session-*.json`, `sender-key-*.json`, dst).
|
|
264
|
+
- `saveCreds()` dipanggil setiap kali event `creds.update` terpicu (biasanya setelah pairing awal, rotasi key, atau update signature akun).
|
|
265
|
+
- Untuk produksi berskala besar / multi-instance, disarankan mengganti implementasi ini dengan auth state custom yang menyimpan ke database (Redis, MongoDB, Postgres) — cukup implementasikan interface `AuthenticationState` yang sama (`creds` + `keys` dengan method `get`/`set`).
|
|
266
|
+
|
|
267
|
+
### Auth State Custom (Database)
|
|
268
|
+
|
|
269
|
+
Pola umum jika ingin menulis auth state sendiri:
|
|
270
|
+
|
|
271
|
+
```js
|
|
272
|
+
const authState = {
|
|
273
|
+
creds: /* objek AuthenticationCreds, load dari DB atau buat baru via initAuthCreds() */,
|
|
274
|
+
keys: {
|
|
275
|
+
get: async (type, ids) => {
|
|
276
|
+
// ambil banyak key sekaligus by id, kembalikan sebagai { [id]: value }
|
|
277
|
+
},
|
|
278
|
+
set: async (data) => {
|
|
279
|
+
// data: { [type]: { [id]: value | null } }
|
|
280
|
+
// null berarti key tsb harus dihapus
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
Lihat `Types/Auth.js` / `Types/Auth.d.ts` untuk bentuk lengkap `AuthenticationCreds` dan `SignalDataTypeMap` yang harus didukung oleh implementasi `keys.get` / `keys.set` Anda (pre-key, session, sender-key, app-state-sync-key, app-state-sync-version, sender-key-memory).
|
|
287
|
+
|
|
288
|
+
### Pairing dengan Nomor Telepon (tanpa scan QR)
|
|
289
|
+
|
|
290
|
+
```js
|
|
291
|
+
const sock = makeWASocket({ auth: state })
|
|
292
|
+
|
|
293
|
+
if (!sock.authState?.creds?.registered) {
|
|
294
|
+
const code = await sock.requestPairingCode('6281234567890') // nomor tanpa tanda +
|
|
295
|
+
console.log('Kode pairing Anda:', code)
|
|
296
|
+
}
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
Masukkan kode tersebut di WhatsApp: **Linked Devices → Link with phone number instead**.
|
|
300
|
+
|
|
301
|
+
---
|
|
302
|
+
|
|
303
|
+
## ⚙️ Konfigurasi Koneksi
|
|
304
|
+
|
|
305
|
+
`makeWASocket(config)` menerima objek konfigurasi yang di-*merge* di atas `DEFAULT_CONNECTION_CONFIG`. Berikut opsi-opsi yang tersedia beserta nilai default aktualnya (dari `Defaults/index.js`):
|
|
306
|
+
|
|
307
|
+
| Opsi | Default | Keterangan |
|
|
308
|
+
|---|---|---|
|
|
309
|
+
| `version` | `[2, 3000, 1035194821]` | Versi protokol WhatsApp Web yang disimulasikan. |
|
|
310
|
+
| `browser` | `Browsers.macOS('Chrome')` | Identitas browser yang dikirim saat pairing (memengaruhi tampilan "linked device" di HP). |
|
|
311
|
+
| `waWebSocketUrl` | `'wss://web.whatsapp.com/ws/chat'` | Endpoint WebSocket WhatsApp Web. |
|
|
312
|
+
| `connectTimeoutMs` | `20000` | Timeout koneksi awal (ms). |
|
|
313
|
+
| `keepAliveIntervalMs` | `30000` | Interval ping keep-alive (ms). |
|
|
314
|
+
| `logger` | `pino` child logger | Instance logger (pino-compatible). |
|
|
315
|
+
| `emitOwnEvents` | `true` | Jika `true`, pesan yang dikirim sendiri via `sendMessage` ikut memicu `messages.upsert`. |
|
|
316
|
+
| `defaultQueryTimeoutMs` | `60000` | Timeout default untuk query IQ ke server. |
|
|
317
|
+
| `customUploadHosts` | `[]` | Daftar host upload media custom (override host bawaan WA). |
|
|
318
|
+
| `retryRequestDelayMs` | `250` | Delay antar retry request yang gagal. |
|
|
319
|
+
| `maxMsgRetryCount` | `5` | Batas maksimum percobaan ulang pengiriman pesan gagal. |
|
|
320
|
+
| `fireInitQueries` | `true` | Jalankan query inisialisasi standar (privacy, blocklist, dll) saat konek. |
|
|
321
|
+
| `auth` | `undefined` | **Wajib diisi** — objek `AuthenticationState` (lihat bagian Auth State). |
|
|
322
|
+
| `markOnlineOnConnect` | `true` | Set status "online" otomatis saat tersambung. |
|
|
323
|
+
| `syncFullHistory` | `true` | Minta sinkronisasi riwayat chat penuh dari HP saat pairing pertama. |
|
|
324
|
+
| `patchMessageBeforeSending` | `msg => msg` | Hook untuk memodifikasi payload pesan mentah sebelum dikirim (lanjutan). |
|
|
325
|
+
| `shouldSyncHistoryMessage` | `({syncType}) => syncType !== FULL` | Filter jenis histori mana yang diproses. |
|
|
326
|
+
| `shouldIgnoreJid` | `() => false` | Hook untuk mengabaikan JID tertentu (mis. broadcast list, JID spam). |
|
|
327
|
+
| `linkPreviewImageThumbnailWidth` | `192` | Lebar thumbnail untuk link preview otomatis. |
|
|
328
|
+
| `transactionOpts` | `{ maxCommitRetries: 10, delayBetweenTriesMs: 3000 }` | Retry policy transaksi signal store. |
|
|
329
|
+
| `generateHighQualityLinkPreview` | `false` | Jika `true`, thumbnail link preview diunggah kualitas tinggi (butuh 1 request tambahan). |
|
|
330
|
+
| `enableAutoSessionRecreation` | `true` | Otomatis membuat ulang sesi Signal jika terdeteksi rusak/kadaluarsa. |
|
|
331
|
+
| `enableRecentMessageCache` | `true` | Cache pesan terbaru untuk mempercepat resolusi `getMessage` (retry, edit, delete). |
|
|
332
|
+
| `options` | `{}` | Opsi tambahan untuk `fetch` (mis. custom agent/dispatcher). |
|
|
333
|
+
| `appStateMacVerification` | `{ patch: false, snapshot: false }` | Verifikasi MAC saat sinkronisasi app-state (kontak, chat, dsb). |
|
|
334
|
+
| `countryCode` | `'US'` | Kode negara default untuk normalisasi nomor. |
|
|
335
|
+
| `getMessage` | `async () => undefined` | **Sangat disarankan diisi** — resolver pesan by key, dipakai untuk retry/decrypt ulang. |
|
|
336
|
+
| `cachedGroupMetadata` | `async () => undefined` | Resolver metadata grup dari cache Anda sendiri (mengurangi query `groupMetadata`). |
|
|
337
|
+
| `makeSignalRepository` | `makeLibSignalRepository` | Implementasi Signal repository (bisa diganti custom). |
|
|
338
|
+
|
|
339
|
+
### Contoh Konfigurasi Lengkap Produksi
|
|
340
|
+
|
|
341
|
+
```js
|
|
342
|
+
import makeWASocket, { useMultiFileAuthState, Browsers, makeCacheableSignalKeyStore } from '@vinzsocket/baileys'
|
|
343
|
+
import pino from 'pino'
|
|
344
|
+
import NodeCache from '@cacheable/node-cache'
|
|
345
|
+
|
|
346
|
+
const logger = pino({ level: 'silent' })
|
|
347
|
+
const msgRetryCounterCache = new NodeCache()
|
|
348
|
+
const groupCache = new NodeCache({ stdTTL: 5 * 60, useClones: false })
|
|
349
|
+
|
|
350
|
+
const { state, saveCreds } = await useMultiFileAuthState('sesi_auth')
|
|
351
|
+
|
|
352
|
+
const sock = makeWASocket({
|
|
353
|
+
auth: {
|
|
354
|
+
creds: state.creds,
|
|
355
|
+
keys: makeCacheableSignalKeyStore(state.keys, logger)
|
|
356
|
+
},
|
|
357
|
+
logger,
|
|
358
|
+
browser: Browsers.ubuntu('Chrome'),
|
|
359
|
+
syncFullHistory: false,
|
|
360
|
+
markOnlineOnConnect: false,
|
|
361
|
+
generateHighQualityLinkPreview: true,
|
|
362
|
+
msgRetryCounterCache,
|
|
363
|
+
cachedGroupMetadata: async (jid) => groupCache.get(jid),
|
|
364
|
+
getMessage: async (key) => {
|
|
365
|
+
// idealnya diarahkan ke store pesan Anda sendiri (DB/cache)
|
|
366
|
+
return undefined
|
|
367
|
+
}
|
|
368
|
+
})
|
|
369
|
+
|
|
370
|
+
sock.ev.on('groups.update', ([update]) => {
|
|
371
|
+
const cached = groupCache.get(update.id)
|
|
372
|
+
if (cached) groupCache.set(update.id, { ...cached, ...update })
|
|
373
|
+
})
|
|
374
|
+
|
|
375
|
+
sock.ev.on('group-participants.update', async ({ id }) => {
|
|
376
|
+
groupCache.del(id) // invalidate, biar di-fetch ulang saat dibutuhkan
|
|
377
|
+
})
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
`Browsers` menyediakan beberapa preset umum: `Browsers.ubuntu(name)`, `Browsers.macOS(name)`, `Browsers.windows(name)`, `Browsers.appropriate(name)` — masing-masing memengaruhi bagaimana perangkat ini tampil di daftar "Linked Devices" pengguna.
|
|
381
|
+
|
|
382
|
+
---
|
|
383
|
+
|
|
384
|
+
## 🗂️ Struktur Package
|
|
385
|
+
|
|
386
|
+
```
|
|
387
|
+
@vinzsocket/baileys
|
|
388
|
+
├── WAProto/ → definisi protobuf pesan WhatsApp (proto.Message, dll)
|
|
389
|
+
├── engine-requirements.js → cek versi Node.js saat preinstall
|
|
390
|
+
└── lib/
|
|
391
|
+
├── Defaults/ → konstanta & DEFAULT_CONNECTION_CONFIG
|
|
392
|
+
├── Signal/ → implementasi Signal Protocol (libsignal repository)
|
|
393
|
+
├── Socket/ → lapisan socket bertingkat (lihat di bawah) + dugong.js
|
|
394
|
+
│ └── Client/ → WebSocket transport & tipe client
|
|
395
|
+
├── Types/ → semua TypeScript type (Auth, Chat, Message, dll)
|
|
396
|
+
├── Utils/ → helper: pesan, media, mention, auth-state, story-card, dll
|
|
397
|
+
├── WABinary/ → encode/decode binary XML node WhatsApp + util JID
|
|
398
|
+
├── WAM/ → WhatsApp Analytics/Metrics binary encoder
|
|
399
|
+
└── WAUSync/ → USync protocol (query device/status massal)
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
Socket dibangun **bertingkat** (setiap layer membungkus layer sebelumnya), urutannya dari `Socket/index.js`:
|
|
403
|
+
|
|
404
|
+
```
|
|
405
|
+
makeCommunitiesSocket
|
|
406
|
+
└─ makeChatsSocket
|
|
407
|
+
└─ makeNewsletterSocket (dan seterusnya menurun ke)
|
|
408
|
+
└─ makeBusinessSocket
|
|
409
|
+
└─ makeGroupsSocket
|
|
410
|
+
└─ makeMessagesSocket (messages-send + messages-recv)
|
|
411
|
+
└─ socket dasar (Socket/socket.js — WebSocket, noise handshake, dsb)
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
Setiap layer menambahkan sekumpulan method ke objek `sock` yang dikembalikan `makeWASocket()`, sehingga API akhirnya terasa seperti satu objek datar (`sock.sendMessage`, `sock.groupCreate`, `sock.newsletterCreate`, dst) meskipun implementasinya berlapis.
|
|
415
|
+
|
|
416
|
+
---
|
|
417
|
+
|
|
418
|
+
## 🔎 JID & Utilitas Dasar
|
|
419
|
+
|
|
420
|
+
WhatsApp mengidentifikasi entitas (user, grup, channel, dst) lewat **JID** (Jabber ID). Harps-Baileys mengekspor beberapa helper dari `WABinary`:
|
|
421
|
+
|
|
422
|
+
```js
|
|
423
|
+
import {
|
|
424
|
+
jidEncode, jidDecode, areJidsSameUser,
|
|
425
|
+
isJidUser, isPnUser, isLidUser,
|
|
426
|
+
isJidGroup, isJidBroadcast, isJidStatusBroadcast,
|
|
427
|
+
isJidNewsletter, isJidMetaAI
|
|
428
|
+
} from '@vinzsocket/baileys'
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
| Fungsi | Kegunaan |
|
|
432
|
+
|---|---|
|
|
433
|
+
| `jidDecode(jid)` | Pecah JID jadi `{ user, server, device, agent }`. |
|
|
434
|
+
| `jidEncode(user, server, device?, agent?)` | Rakit ulang JID dari komponennya. |
|
|
435
|
+
| `areJidsSameUser(a, b)` | Bandingkan apakah dua JID merujuk user yang sama (mengabaikan device). |
|
|
436
|
+
| `isPnUser(jid)` | `true` jika JID berformat nomor telepon (`@s.whatsapp.net`). |
|
|
437
|
+
| `isLidUser(jid)` | `true` jika JID berformat LID (`@lid`) — identitas privasi baru WhatsApp. |
|
|
438
|
+
| `isJidGroup(jid)` | `true` jika JID adalah grup (`@g.us`). |
|
|
439
|
+
| `isJidBroadcast(jid)` | `true` jika JID adalah broadcast list. |
|
|
440
|
+
| `isJidStatusBroadcast(jid)` | `true` khusus untuk `status@broadcast`. |
|
|
441
|
+
|
|
442
|
+
### Konstanta JID Penting
|
|
443
|
+
|
|
444
|
+
```js
|
|
445
|
+
import { S_WHATSAPP_NET, STORIES_JID, OFFICIAL_BIZ_JID } from '@vinzsocket/baileys'
|
|
446
|
+
|
|
447
|
+
console.log(S_WHATSAPP_NET) // '@s.whatsapp.net'
|
|
448
|
+
console.log(STORIES_JID) // 'status@broadcast'
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
### Catatan Tentang LID (Linked Identity)
|
|
452
|
+
|
|
453
|
+
WhatsApp secara bertahap memigrasikan identitas pengguna dari nomor telepon (`@s.whatsapp.net`) ke identitas tersamar (`@lid`) demi privasi, terutama di dalam grup besar. Ini berarti:
|
|
454
|
+
|
|
455
|
+
- `msg.key.participant` di sebuah grup **bisa** berupa `@lid`, bukan nomor telepon asli.
|
|
456
|
+
- Jangan asumsikan Anda selalu bisa menampilkan nomor telepon dari sebuah JID — kadang WhatsApp memang tidak mengungkapkannya.
|
|
457
|
+
- Harps-Baileys menyediakan `buildTagAllText()` (lihat bagian [Mention Utilities](#-mention-utilities-mentionjs)) yang menangani kasus ini dengan aman, alih-alih menampilkan digit LID mentah yang membingungkan pengguna.
|
|
458
|
+
|
|
459
|
+
---
|
|
460
|
+
|
|
461
|
+
## ✉️ Mengirim Pesan — Dasar
|
|
462
|
+
|
|
463
|
+
Semua pengiriman pesan melewati satu pintu: `sock.sendMessage(jid, content, options?)`. Bentuk `content` menentukan tipe pesan apa yang dihasilkan — Harps-Baileys memakai pola *"shorthand key detection"*: Anda cukup memberi field yang relevan (`text`, `image`, `poll`, dst) dan library akan merakit payload protobuf yang benar secara otomatis lewat `generateWAMessageContent()`.
|
|
464
|
+
|
|
465
|
+
### Teks & Link Preview
|
|
466
|
+
|
|
467
|
+
```js
|
|
468
|
+
await sock.sendMessage(jid, { text: 'Halo dari Harps-Baileys!' })
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
Reply / quote pesan lain:
|
|
472
|
+
|
|
473
|
+
```js
|
|
474
|
+
await sock.sendMessage(jid, { text: 'Ini balasan' }, { quoted: msg })
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
Link preview otomatis terdeteksi dari URL di dalam teks (butuh `link-preview-js` terpasang):
|
|
478
|
+
|
|
479
|
+
```js
|
|
480
|
+
await sock.sendMessage(jid, {
|
|
481
|
+
text: 'Cek repo ini: https://github.com/VinzSocket/Baileys'
|
|
482
|
+
})
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
Kontrol manual link preview:
|
|
486
|
+
|
|
487
|
+
```js
|
|
488
|
+
await sock.sendMessage(jid, {
|
|
489
|
+
text: 'Lihat websitenya di bawah',
|
|
490
|
+
linkPreview: {
|
|
491
|
+
'matched-text': 'https://example.com',
|
|
492
|
+
title: 'Judul Custom',
|
|
493
|
+
description: 'Deskripsi custom',
|
|
494
|
+
jpegThumbnail: fs.readFileSync('./thumb.jpg')
|
|
495
|
+
}
|
|
496
|
+
})
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
Matikan link preview sama sekali:
|
|
500
|
+
|
|
501
|
+
```js
|
|
502
|
+
await sock.sendMessage(jid, { text: 'https://example.com tanpa preview', linkPreview: null })
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
Teks dengan warna latar (bubble style — umumnya tampil di beberapa versi client sebagai "status text style"):
|
|
506
|
+
|
|
507
|
+
```js
|
|
508
|
+
await sock.sendMessage(jid, {
|
|
509
|
+
text: 'Teks dengan gaya',
|
|
510
|
+
backgroundColor: '#FF5722', // atau nilai integer ARGB
|
|
511
|
+
font: 2 // 0-5, tergantung dukungan client
|
|
512
|
+
})
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
### Media: Gambar, Video, Audio, Sticker, Dokumen
|
|
516
|
+
|
|
517
|
+
**Gambar dengan caption:**
|
|
518
|
+
|
|
519
|
+
```js
|
|
520
|
+
await sock.sendMessage(jid, {
|
|
521
|
+
image: { url: 'https://example.com/foto.jpg' }, // atau Buffer / { stream }
|
|
522
|
+
caption: 'Ini captionnya'
|
|
523
|
+
})
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
**Video dengan caption + GIF playback:**
|
|
527
|
+
|
|
528
|
+
```js
|
|
529
|
+
await sock.sendMessage(jid, {
|
|
530
|
+
video: fs.readFileSync('./video.mp4'),
|
|
531
|
+
caption: 'Video kegiatan',
|
|
532
|
+
gifPlayback: false // true = tampil sebagai GIF loop
|
|
533
|
+
})
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
**Audio / Voice Note:**
|
|
537
|
+
|
|
538
|
+
```js
|
|
539
|
+
// Voice note (PTT)
|
|
540
|
+
await sock.sendMessage(jid, {
|
|
541
|
+
audio: { url: 'https://example.com/voice.ogg' },
|
|
542
|
+
ptt: true,
|
|
543
|
+
mimetype: 'audio/ogg; codecs=opus'
|
|
544
|
+
})
|
|
545
|
+
|
|
546
|
+
// Audio musik biasa
|
|
547
|
+
await sock.sendMessage(jid, {
|
|
548
|
+
audio: fs.readFileSync('./lagu.mp3'),
|
|
549
|
+
ptt: false,
|
|
550
|
+
mimetype: 'audio/mp4'
|
|
551
|
+
})
|
|
552
|
+
```
|
|
553
|
+
|
|
554
|
+
**Sticker:**
|
|
555
|
+
|
|
556
|
+
```js
|
|
557
|
+
await sock.sendMessage(jid, { sticker: { url: 'https://example.com/sticker.webp' } })
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
**Dokumen:**
|
|
561
|
+
|
|
562
|
+
```js
|
|
563
|
+
await sock.sendMessage(jid, {
|
|
564
|
+
document: { url: 'https://example.com/laporan.pdf' },
|
|
565
|
+
mimetype: 'application/pdf',
|
|
566
|
+
fileName: 'Laporan-Bulanan.pdf',
|
|
567
|
+
caption: 'Laporan bulan ini'
|
|
568
|
+
})
|
|
569
|
+
```
|
|
570
|
+
|
|
571
|
+
**Dokumen dengan thumbnail preview (patch fork ini):**
|
|
572
|
+
|
|
573
|
+
Harps-Baileys mendukung `jpegThumbnail` untuk dokumen (di-*monkey-patch* agar dokumen bisa menampilkan preview gambar seperti file PDF/gambar di WhatsApp Desktop):
|
|
574
|
+
|
|
575
|
+
```js
|
|
576
|
+
await sock.sendMessage(jid, {
|
|
577
|
+
document: fs.readFileSync('./brosur.pdf'),
|
|
578
|
+
mimetype: 'application/pdf',
|
|
579
|
+
fileName: 'Brosur.pdf',
|
|
580
|
+
jpegThumbnail: fs.readFileSync('./cover-brosur.jpg')
|
|
581
|
+
})
|
|
582
|
+
```
|
|
583
|
+
|
|
584
|
+
### Kontak
|
|
585
|
+
|
|
586
|
+
```js
|
|
587
|
+
await sock.sendMessage(jid, {
|
|
588
|
+
contacts: {
|
|
589
|
+
displayName: 'Nama Kontak',
|
|
590
|
+
contacts: [{
|
|
591
|
+
vcard:
|
|
592
|
+
'BEGIN:VCARD\nVERSION:3.0\nFN:Nama Kontak\nTEL;type=CELL;type=VOICE;waid=6281234567890:+62 812-3456-7890\nEND:VCARD'
|
|
593
|
+
}]
|
|
594
|
+
}
|
|
595
|
+
})
|
|
596
|
+
```
|
|
597
|
+
|
|
598
|
+
Untuk mengirim lebih dari satu kontak sekaligus, cukup tambahkan lebih banyak entri ke array `contacts.contacts` — Harps-Baileys otomatis memilih antara `contactMessage` (1 kontak) dan `contactsArrayMessage` (lebih dari 1).
|
|
599
|
+
|
|
600
|
+
### Lokasi
|
|
601
|
+
|
|
602
|
+
```js
|
|
603
|
+
await sock.sendMessage(jid, {
|
|
604
|
+
location: {
|
|
605
|
+
degreesLatitude: -6.200000,
|
|
606
|
+
degreesLongitude: 106.816666,
|
|
607
|
+
name: 'Monas',
|
|
608
|
+
address: 'Jakarta Pusat'
|
|
609
|
+
}
|
|
610
|
+
})
|
|
611
|
+
```
|
|
612
|
+
|
|
613
|
+
### Reaksi (Reaction)
|
|
614
|
+
|
|
615
|
+
```js
|
|
616
|
+
await sock.sendMessage(jid, {
|
|
617
|
+
react: {
|
|
618
|
+
text: '❤️', // kosongkan string ('') untuk menghapus reaksi
|
|
619
|
+
key: msg.key
|
|
620
|
+
}
|
|
621
|
+
})
|
|
622
|
+
```
|
|
623
|
+
|
|
624
|
+
### Polling (Poll)
|
|
625
|
+
|
|
626
|
+
```js
|
|
627
|
+
// Single-choice poll
|
|
628
|
+
await sock.sendMessage(jid, {
|
|
629
|
+
poll: {
|
|
630
|
+
name: 'Menu makan siang hari ini?',
|
|
631
|
+
values: ['Nasi Padang', 'Bakso', 'Mie Ayam', 'Soto'],
|
|
632
|
+
selectableCount: 1
|
|
633
|
+
}
|
|
634
|
+
})
|
|
635
|
+
|
|
636
|
+
// Multiple-choice poll
|
|
637
|
+
await sock.sendMessage(jid, {
|
|
638
|
+
poll: {
|
|
639
|
+
name: 'Pilih semua yang kamu suka',
|
|
640
|
+
values: ['Gunung', 'Pantai', 'Kota', 'Hutan'],
|
|
641
|
+
selectableCount: 2
|
|
642
|
+
}
|
|
643
|
+
})
|
|
644
|
+
|
|
645
|
+
// Poll khusus grup komunitas/announcement
|
|
646
|
+
await sock.sendMessage(jid, {
|
|
647
|
+
poll: {
|
|
648
|
+
name: 'Pengumuman: pilih jadwal rapat',
|
|
649
|
+
values: ['Senin', 'Rabu', 'Jumat'],
|
|
650
|
+
selectableCount: 1,
|
|
651
|
+
toAnnouncementGroup: true
|
|
652
|
+
}
|
|
653
|
+
})
|
|
654
|
+
```
|
|
655
|
+
|
|
656
|
+
> Catatan: `selectableCount: 1` otomatis menghasilkan `pollCreationMessageV3` (single-select), sedangkan `> 1` menghasilkan `pollCreationMessage` (multi-select). `toAnnouncementGroup: true` mengarah ke `pollCreationMessageV2` untuk grup komunitas.
|
|
657
|
+
|
|
658
|
+
Membaca hasil vote dari event `messages.update`:
|
|
659
|
+
|
|
660
|
+
```js
|
|
661
|
+
import { getAggregateVotesInPollMessage } from '@vinzsocket/baileys'
|
|
662
|
+
|
|
663
|
+
sock.ev.on('messages.update', (updates) => {
|
|
664
|
+
for (const { key, update } of updates) {
|
|
665
|
+
if (update.pollUpdates) {
|
|
666
|
+
const votes = getAggregateVotesInPollMessage({
|
|
667
|
+
message: originalPollMessage, // ambil dari store Anda via key
|
|
668
|
+
pollUpdates: update.pollUpdates
|
|
669
|
+
}, sock.user.id)
|
|
670
|
+
console.log(votes)
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
})
|
|
674
|
+
```
|
|
675
|
+
|
|
676
|
+
### Event / Undangan Acara
|
|
677
|
+
|
|
678
|
+
```js
|
|
679
|
+
await sock.sendMessage(jid, {
|
|
680
|
+
event: {
|
|
681
|
+
name: 'Rapat Koordinasi Bulanan',
|
|
682
|
+
description: 'Bahas roadmap fitur Q3',
|
|
683
|
+
startDate: new Date('2026-08-01T09:00:00+07:00'),
|
|
684
|
+
endDate: new Date('2026-08-01T11:00:00+07:00'),
|
|
685
|
+
location: { degreesLatitude: -6.2, degreesLongitude: 106.8, name: 'Kantor Pusat' },
|
|
686
|
+
extraGuestsAllowed: true
|
|
687
|
+
}
|
|
688
|
+
})
|
|
689
|
+
```
|
|
690
|
+
|
|
691
|
+
Event dengan tombol join-call otomatis (audio/video call link):
|
|
692
|
+
|
|
693
|
+
```js
|
|
694
|
+
await sock.sendMessage(jid, {
|
|
695
|
+
event: {
|
|
696
|
+
name: 'Sync Mingguan (Voice)',
|
|
697
|
+
description: 'Join lewat tombol di bawah',
|
|
698
|
+
startDate: new Date(),
|
|
699
|
+
call: 'audio' // atau 'video' — butuh getCallLink di config (createCallLink)
|
|
700
|
+
}
|
|
701
|
+
})
|
|
702
|
+
```
|
|
703
|
+
|
|
704
|
+
### Hapus, Edit, Pin Pesan
|
|
705
|
+
|
|
706
|
+
**Hapus (revoke) pesan:**
|
|
707
|
+
|
|
708
|
+
```js
|
|
709
|
+
await sock.sendMessage(jid, { delete: msg.key })
|
|
710
|
+
```
|
|
711
|
+
|
|
712
|
+
**Edit pesan:**
|
|
713
|
+
|
|
714
|
+
```js
|
|
715
|
+
await sock.sendMessage(jid, {
|
|
716
|
+
text: 'Teks yang sudah diperbarui',
|
|
717
|
+
edit: msg.key
|
|
718
|
+
})
|
|
719
|
+
```
|
|
720
|
+
|
|
721
|
+
**Pin pesan di chat (1 hari):**
|
|
722
|
+
|
|
723
|
+
```js
|
|
724
|
+
await sock.sendMessage(jid, {
|
|
725
|
+
pin: msg.key,
|
|
726
|
+
type: 1, // 1 = pin, 2 = unpin
|
|
727
|
+
time: 86400 // durasi pin dalam detik
|
|
728
|
+
})
|
|
729
|
+
```
|
|
730
|
+
|
|
731
|
+
### View Once & PTV
|
|
732
|
+
|
|
733
|
+
**View once (media sekali lihat):**
|
|
734
|
+
|
|
735
|
+
```js
|
|
736
|
+
await sock.sendMessage(jid, {
|
|
737
|
+
image: { url: 'https://example.com/rahasia.jpg' },
|
|
738
|
+
caption: 'Cuma bisa dilihat sekali',
|
|
739
|
+
viewOnce: true
|
|
740
|
+
})
|
|
741
|
+
```
|
|
742
|
+
|
|
743
|
+
**Video pesan bulat (PTV — Push To Video, seperti voice note tapi video):**
|
|
744
|
+
|
|
745
|
+
```js
|
|
746
|
+
await sock.sendMessage(jid, {
|
|
747
|
+
video: fs.readFileSync('./ptv.mp4'),
|
|
748
|
+
ptv: true
|
|
749
|
+
})
|
|
750
|
+
```
|
|
751
|
+
|
|
752
|
+
### Mention & Tag Semua
|
|
753
|
+
|
|
754
|
+
Mention manual di teks:
|
|
755
|
+
|
|
756
|
+
```js
|
|
757
|
+
await sock.sendMessage(jid, {
|
|
758
|
+
text: `Halo @${'6281234567890'}, cek pesan ini ya!`,
|
|
759
|
+
mentions: ['6281234567890@s.whatsapp.net']
|
|
760
|
+
})
|
|
761
|
+
```
|
|
762
|
+
|
|
763
|
+
Tag semua anggota grup (tanpa menuliskan satu per satu — non-JID mentions, muncul sebagai "@all" style di beberapa client):
|
|
764
|
+
|
|
765
|
+
```js
|
|
766
|
+
await sock.sendMessage(jid, {
|
|
767
|
+
text: 'Pengumuman penting untuk semua anggota!',
|
|
768
|
+
mentionAll: true
|
|
769
|
+
})
|
|
770
|
+
```
|
|
771
|
+
|
|
772
|
+
> Untuk tag-all yang menampilkan nama tiap anggota dengan aman (menangani kasus JID `@lid`), gunakan `buildTagAllText()` — lihat bagian [Mention Utilities](#-mention-utilities-mentionjs).
|
|
773
|
+
|
|
774
|
+
### Forward Pesan
|
|
775
|
+
|
|
776
|
+
```js
|
|
777
|
+
await sock.sendMessage(jid, {
|
|
778
|
+
forward: msg, // pesan WAMessage yang ingin diteruskan
|
|
779
|
+
force: false // true untuk memaksa status forwarded meski baru diteruskan 1x
|
|
780
|
+
})
|
|
781
|
+
```
|
|
782
|
+
|
|
783
|
+
---
|
|
784
|
+
|
|
785
|
+
## 🔘 Tombol & List — Native Flow
|
|
786
|
+
|
|
787
|
+
WhatsApp modern hanya mendukung **Native Flow** (`interactiveMessage.nativeFlowMessage`) untuk tombol interaktif. Bentuk lama (`buttonsMessage`, `templateMessage`/hydrated template) sudah **deprecated oleh WhatsApp** dan sempat menjadi subjek advisory keamanan (rawan spoofing) di komunitas Baileys — karena itu Harps-Baileys **tidak pernah** menghasilkan payload legacy tersebut, walaupun Anda menulis kode dengan gaya lama. Semua shorthand di bawah ini otomatis dikonversi ke Native Flow modern.
|
|
788
|
+
|
|
789
|
+
### Shorthand `buttons` / `templateButtons` / `interactiveButtons`
|
|
790
|
+
|
|
791
|
+
Ketiga nama field ini diperlakukan sama — pilih mana saja yang paling familiar untuk Anda (berguna saat migrasi dari fork lain).
|
|
792
|
+
|
|
793
|
+
```js
|
|
794
|
+
await sock.sendMessage(jid, {
|
|
795
|
+
text: 'Pilih salah satu opsi di bawah:',
|
|
796
|
+
footer: 'Harps-MD',
|
|
797
|
+
buttons: [
|
|
798
|
+
{ id: 'menu_1', text: '📋 Menu Utama' },
|
|
799
|
+
{ id: 'menu_2', text: '⚙️ Pengaturan' },
|
|
800
|
+
{ id: 'menu_3', text: '❓ Bantuan' }
|
|
801
|
+
]
|
|
802
|
+
}, { quoted: msg })
|
|
803
|
+
```
|
|
804
|
+
|
|
805
|
+
Dengan gambar/video sebagai header (otomatis dijadikan `interactiveMessage.header`):
|
|
806
|
+
|
|
807
|
+
```js
|
|
808
|
+
await sock.sendMessage(jid, {
|
|
809
|
+
image: { url: 'https://example.com/banner.jpg' },
|
|
810
|
+
caption: 'Selamat datang di Harps-MD!',
|
|
811
|
+
footer: 'Ketuk salah satu tombol',
|
|
812
|
+
buttons: [
|
|
813
|
+
{ id: 'start', text: '🚀 Mulai' },
|
|
814
|
+
{ id: 'info', text: 'ℹ️ Info Bot' }
|
|
815
|
+
]
|
|
816
|
+
})
|
|
817
|
+
```
|
|
818
|
+
|
|
819
|
+
Format button yang didukung `normalizeToNativeFlowButtons()` (semua di bawah ini valid & saling setara secara fungsi):
|
|
820
|
+
|
|
821
|
+
```js
|
|
822
|
+
// 1. Native flow langsung (paling eksplisit)
|
|
823
|
+
{ name: 'quick_reply', buttonParamsJson: JSON.stringify({ display_text: 'OK', id: 'ok' }) }
|
|
824
|
+
|
|
825
|
+
// 2. Legacy template wrapper
|
|
826
|
+
{ urlButton: { displayText: 'Website', url: 'https://example.com' } }
|
|
827
|
+
{ callButton: { displayText: 'Telepon', phoneNumber: '+6281234567890' } }
|
|
828
|
+
{ quickReplyButton: { displayText: 'Ya', id: 'yes' } }
|
|
829
|
+
|
|
830
|
+
// 3. Classic buttonsMessage shape
|
|
831
|
+
{ buttonId: 'yes', buttonText: { displayText: 'Ya' } }
|
|
832
|
+
|
|
833
|
+
// 4. Simple shape (paling ringkas, direkomendasikan)
|
|
834
|
+
{ id: 'yes', text: 'Ya' }
|
|
835
|
+
{ id: 'yes', displayText: 'Ya' }
|
|
836
|
+
```
|
|
837
|
+
|
|
838
|
+
### Shorthand `sections` (List Message)
|
|
839
|
+
|
|
840
|
+
```js
|
|
841
|
+
await sock.sendMessage(jid, {
|
|
842
|
+
text: 'Silakan pilih menu:',
|
|
843
|
+
title: '📋 Katalog Harps Shop',
|
|
844
|
+
buttonText: 'Buka Menu',
|
|
845
|
+
footer: 'Harps-MD',
|
|
846
|
+
sections: [
|
|
847
|
+
{
|
|
848
|
+
title: '⚔️ Senjata',
|
|
849
|
+
rows: [
|
|
850
|
+
{ rowId: 'sword', title: 'Pedang Besi', description: '40 ATK' },
|
|
851
|
+
{ rowId: 'bow', title: 'Busur', description: '30 ATK' }
|
|
852
|
+
]
|
|
853
|
+
},
|
|
854
|
+
{
|
|
855
|
+
title: '🛡️ Armor',
|
|
856
|
+
rows: [
|
|
857
|
+
{ rowId: 'shield', title: 'Perisai Kayu', description: '15 DEF' }
|
|
858
|
+
]
|
|
859
|
+
}
|
|
860
|
+
]
|
|
861
|
+
}, { quoted: msg })
|
|
862
|
+
```
|
|
863
|
+
|
|
864
|
+
### Shorthand `cards` (Carousel)
|
|
865
|
+
|
|
866
|
+
Carousel horizontal-scroll — cocok untuk katalog produk atau daftar item RPG dengan gambar:
|
|
867
|
+
|
|
868
|
+
```js
|
|
869
|
+
await sock.sendMessage(jid, {
|
|
870
|
+
text: 'Geser untuk lihat item lainnya:',
|
|
871
|
+
footer: 'Harps Shop',
|
|
872
|
+
cards: [
|
|
873
|
+
{
|
|
874
|
+
image: { url: 'https://example.com/sword.jpg' },
|
|
875
|
+
title: 'Pedang Legendaris',
|
|
876
|
+
body: 'ATK +100, harga 5000 gold',
|
|
877
|
+
buttons: [{ id: 'buy_sword', text: '💰 Beli' }]
|
|
878
|
+
},
|
|
879
|
+
{
|
|
880
|
+
image: { url: 'https://example.com/shield.jpg' },
|
|
881
|
+
title: 'Perisai Naga',
|
|
882
|
+
body: 'DEF +80, harga 3500 gold',
|
|
883
|
+
buttons: [{ id: 'buy_shield', text: '💰 Beli' }]
|
|
884
|
+
}
|
|
885
|
+
]
|
|
886
|
+
})
|
|
887
|
+
```
|
|
888
|
+
|
|
889
|
+
Setiap kartu (`card`) menerima field yang sama seperti pesan interaktif tunggal: `image`/`video`, `title`, `body` (atau `text`/`caption`), `footer`, dan `buttons` (format sama seperti shorthand `buttons` di atas).
|
|
890
|
+
|
|
891
|
+
---
|
|
892
|
+
|
|
893
|
+
## 🐉 Fitur Eksklusif Harps-Baileys (`dugong.js`)
|
|
894
|
+
|
|
895
|
+
`Socket/dugong.js` adalah jantung dari fitur-fitur khas Harps-Baileys — sebuah `ExtendedMessageBuilder` yang dipasang otomatis di dalam `sendMessage()`. Ia mendeteksi tipe pesan lanjutan berdasarkan field yang Anda kirim (`requestPaymentMessage`, `productMessage`, `interactiveMessage`, `albumMessage`, `eventMessage`, `pollResultMessage`, `groupStatusMessage`, `nestedListMessage`, `multiSelectMessage`) dan merakit payload protobuf yang sesuai — termasuk `additionalNodes` binary hint yang wajib ada supaya WhatsApp benar-benar merender pesan tersebut.
|
|
896
|
+
|
|
897
|
+
### NF V7 Button Builders
|
|
898
|
+
|
|
899
|
+
Semua builder ini bisa diimpor langsung untuk kontrol penuh atas payload (dipakai bersama `interactiveMessage.buttons` di level rendah, atau lewat shorthand `buttons` seperti dijelaskan sebelumnya):
|
|
900
|
+
|
|
901
|
+
```js
|
|
902
|
+
import {
|
|
903
|
+
nfButtonUrl, nfButtonCall, nfButtonCopy,
|
|
904
|
+
nfButtonReminder, nfButtonCancelReminder,
|
|
905
|
+
nfButtonAddress, nfButtonLocation,
|
|
906
|
+
nfButtonQuickReply, nfButtonSingleSelect,
|
|
907
|
+
nfButtonMultiSelect,
|
|
908
|
+
nfButtonReviewPay, nfButtonReviewOrder, nfButtonMPM
|
|
909
|
+
} from '@vinzsocket/baileys/lib/Socket/dugong.js'
|
|
910
|
+
```
|
|
911
|
+
|
|
912
|
+
| Builder | `name` Proto | Fungsi |
|
|
913
|
+
|---|---|---|
|
|
914
|
+
| `nfButtonUrl` | `cta_url` | Buka URL eksternal |
|
|
915
|
+
| `nfButtonCall` | `cta_call` | Panggil nomor telepon |
|
|
916
|
+
| `nfButtonCopy` | `cta_copy` | Salin kode/teks ke clipboard |
|
|
917
|
+
| `nfButtonReminder` | `cta_reminder` | Set reminder kalender |
|
|
918
|
+
| `nfButtonCancelReminder` | `cta_cancel_reminder` | Batalkan reminder yang sudah dibuat |
|
|
919
|
+
| `nfButtonAddress` | `address_message` | Minta pengguna isi & kirim alamat |
|
|
920
|
+
| `nfButtonLocation` | `send_location` | Minta pengguna kirim lokasi GPS |
|
|
921
|
+
| `nfButtonQuickReply` | `quick_reply` | Balasan cepat (mengirim id ke bot) |
|
|
922
|
+
| `nfButtonSingleSelect` | `single_select` | Satu tombol dropdown (list picker) |
|
|
923
|
+
| `nfButtonMultiSelect` | `single_select` × N | Beberapa tombol dropdown sekaligus |
|
|
924
|
+
| `nfButtonReviewPay` | `review_and_pay` | Alur pembayaran (review & pay) |
|
|
925
|
+
| `nfButtonReviewOrder` | `review_order` | Review status pesanan |
|
|
926
|
+
| `nfButtonMPM` | `mpm` | Multi-Product Message (katalog produk) |
|
|
927
|
+
|
|
928
|
+
Contoh penggunaan campuran beberapa builder dalam satu `interactiveMessage`:
|
|
929
|
+
|
|
930
|
+
```js
|
|
931
|
+
await conn.sendMessage(jid, {
|
|
932
|
+
interactiveMessage: {
|
|
933
|
+
title: '🎛️ Mixed Buttons',
|
|
934
|
+
footer: 'Harps-MD',
|
|
935
|
+
buttons: [
|
|
936
|
+
nfButtonQuickReply({ id: 'ok', displayText: '✅ OK' }),
|
|
937
|
+
nfButtonUrl({ displayText: '🌐 Website', url: 'https://example.com' }),
|
|
938
|
+
nfButtonCopy({ displayText: '📋 Salin', copyCode: 'KODE123' }),
|
|
939
|
+
nfButtonCall({ displayText: '📞 Hubungi Kami', phoneNumber: '+6281234567890' }),
|
|
940
|
+
nfButtonReminder({
|
|
941
|
+
displayText: '⏰ Ingatkan Saya',
|
|
942
|
+
title: 'Cek stok baru',
|
|
943
|
+
notes: 'Reminder dari Harps-MD',
|
|
944
|
+
startTime: Math.floor(Date.now() / 1000) + 3600,
|
|
945
|
+
endTime: Math.floor(Date.now() / 1000) + 7200
|
|
946
|
+
}),
|
|
947
|
+
nfButtonLocation({ displayText: '📍 Bagikan Lokasi' }),
|
|
948
|
+
nfButtonSingleSelect({
|
|
949
|
+
displayText: '📋 Pilih Kategori',
|
|
950
|
+
sections: [
|
|
951
|
+
{ title: 'Kategori', rows: [
|
|
952
|
+
{ id: 'a', title: 'Opsi A' },
|
|
953
|
+
{ id: 'b', title: 'Opsi B' }
|
|
954
|
+
]}
|
|
955
|
+
]
|
|
956
|
+
})
|
|
957
|
+
]
|
|
958
|
+
}
|
|
959
|
+
}, { quoted: msg })
|
|
960
|
+
```
|
|
961
|
+
|
|
962
|
+
Contoh `nfButtonReviewPay` (alur pembayaran):
|
|
963
|
+
|
|
964
|
+
```js
|
|
965
|
+
const paymentButton = nfButtonReviewPay({
|
|
966
|
+
currency: 'IDR',
|
|
967
|
+
totalAmount1000: 150000000, // Rp150.000 (dikalikan 1000 sesuai konvensi WA)
|
|
968
|
+
subtotal: 140000000,
|
|
969
|
+
tax: 10000000,
|
|
970
|
+
items: [{ name: 'Paket Premium Harps-MD', amount: { value: 140000000, offset: 1000 }, quantity: 1 }],
|
|
971
|
+
merchant: { displayName: 'Harps Store' }
|
|
972
|
+
})
|
|
973
|
+
```
|
|
974
|
+
|
|
975
|
+
Contoh `nfButtonMPM` (multi-product message):
|
|
976
|
+
|
|
977
|
+
```js
|
|
978
|
+
const mpmButton = nfButtonMPM({
|
|
979
|
+
sections: [
|
|
980
|
+
{ title: 'Produk Unggulan', productItems: [{ productId: 'prod_001' }, { productId: 'prod_002' }] }
|
|
981
|
+
]
|
|
982
|
+
})
|
|
983
|
+
```
|
|
984
|
+
|
|
985
|
+
### Multi-Select Message
|
|
986
|
+
|
|
987
|
+
Satu pesan dengan **beberapa** tombol dropdown independen — masing-masing tombol membuka bottom sheet-nya sendiri dengan section & row berbeda. Sangat berguna untuk form konfigurasi multi-langkah (mis. pilih senjata + armor sekaligus di RPG).
|
|
988
|
+
|
|
989
|
+
```js
|
|
990
|
+
await conn.sendMessage(jid, {
|
|
991
|
+
multiSelectMessage: {
|
|
992
|
+
title: '⚙️ Konfigurasi Karakter',
|
|
993
|
+
footer: 'Pilih semua opsi',
|
|
994
|
+
selectors: [
|
|
995
|
+
{
|
|
996
|
+
displayText: '⚔️ Pilih Senjata',
|
|
997
|
+
sections: [
|
|
998
|
+
{
|
|
999
|
+
title: '🗡️ Melee',
|
|
1000
|
+
rows: [
|
|
1001
|
+
{ id: 'sword', title: '⚔️ Iron Sword', description: '40 ATK' },
|
|
1002
|
+
{ id: 'axe', title: '🪓 Battle Axe', description: '60 ATK' }
|
|
1003
|
+
]
|
|
1004
|
+
},
|
|
1005
|
+
{
|
|
1006
|
+
title: '🏹 Ranged',
|
|
1007
|
+
rows: [
|
|
1008
|
+
{ id: 'bow', title: '🏹 Busur', description: '30 ATK' },
|
|
1009
|
+
{ id: 'xbow', title: '🔫 Crossbow', description: '55 ATK' }
|
|
1010
|
+
]
|
|
1011
|
+
}
|
|
1012
|
+
]
|
|
1013
|
+
},
|
|
1014
|
+
{
|
|
1015
|
+
displayText: '🛡️ Pilih Armor',
|
|
1016
|
+
sections: [
|
|
1017
|
+
{
|
|
1018
|
+
title: '🧥 Light',
|
|
1019
|
+
rows: [
|
|
1020
|
+
{ id: 'cloth', title: '👕 Cloth', description: '10 DEF' },
|
|
1021
|
+
{ id: 'leather', title: '🥼 Leather', description: '25 DEF' }
|
|
1022
|
+
]
|
|
1023
|
+
}
|
|
1024
|
+
]
|
|
1025
|
+
}
|
|
1026
|
+
],
|
|
1027
|
+
// Tombol tambahan opsional, digabung setelah semua dropdown selector
|
|
1028
|
+
extraButtons: [
|
|
1029
|
+
{ name: 'quick_reply', buttonParamsJson: JSON.stringify({ display_text: '✅ Konfirmasi', id: 'confirm' }) }
|
|
1030
|
+
]
|
|
1031
|
+
}
|
|
1032
|
+
}, { quoted: msg })
|
|
1033
|
+
```
|
|
1034
|
+
|
|
1035
|
+
Menangkap balasan dari selector di handler pesan masuk — setiap selector merespons sebagai `single_select` biasa, jadi Anda membaca `selectedRowId` dari respons native flow seperti biasa, dan gunakan konteks percakapan (state bot Anda) untuk tahu selector mana yang sedang dijawab.
|
|
1036
|
+
|
|
1037
|
+
### Nested List Message
|
|
1038
|
+
|
|
1039
|
+
`listMessage` legacy dengan **auto-flatten**: baris (`row`) yang memiliki `rows` miliknya sendiri otomatis dipecah menjadi *section* baru, bukan nested secara visual (karena WhatsApp tidak mendukung nesting sungguhan di list message).
|
|
1040
|
+
|
|
1041
|
+
```js
|
|
1042
|
+
await conn.sendMessage(jid, {
|
|
1043
|
+
nestedListMessage: {
|
|
1044
|
+
title: '🛒 Harps Shop',
|
|
1045
|
+
buttonText: '📋 Buka Katalog',
|
|
1046
|
+
footer: 'Pilih item',
|
|
1047
|
+
sections: [
|
|
1048
|
+
{
|
|
1049
|
+
title: '⚔️ Senjata',
|
|
1050
|
+
rows: [
|
|
1051
|
+
// Row biasa (flat), tetap ada di section "⚔️ Senjata"
|
|
1052
|
+
{ rowId: 'dagger', title: '🗡️ Dagger', description: '25 ATK' },
|
|
1053
|
+
// Row dengan `.rows` → otomatis jadi SECTION BARU "🏹 Jarak Jauh"
|
|
1054
|
+
{
|
|
1055
|
+
title: '🏹 Jarak Jauh',
|
|
1056
|
+
rows: [
|
|
1057
|
+
{ rowId: 'bow', title: '🏹 Busur', description: '30 ATK' },
|
|
1058
|
+
{ rowId: 'xbow', title: '🔫 Crossbow', description: '55 ATK' }
|
|
1059
|
+
]
|
|
1060
|
+
}
|
|
1061
|
+
]
|
|
1062
|
+
}
|
|
1063
|
+
]
|
|
1064
|
+
}
|
|
1065
|
+
}, { quoted: msg })
|
|
1066
|
+
```
|
|
1067
|
+
|
|
1068
|
+
Hasil setelah flatten (`buildNestedListMessage()`) akan berupa 2 section terpisah: `⚔️ Senjata` (berisi Dagger) dan `🏹 Jarak Jauh` (berisi Busur & Crossbow) — keduanya tetap tampil sebagai list picker WhatsApp standar.
|
|
1069
|
+
|
|
1070
|
+
`buildNestedListMessage()` juga bisa dipanggil langsung tanpa lewat `sendMessage` jika Anda hanya ingin objek payload-nya:
|
|
1071
|
+
|
|
1072
|
+
```js
|
|
1073
|
+
import { buildNestedListMessage } from '@vinzsocket/baileys/lib/Socket/dugong.js'
|
|
1074
|
+
|
|
1075
|
+
const payload = buildNestedListMessage({
|
|
1076
|
+
title: 'Menu',
|
|
1077
|
+
buttonText: 'Buka',
|
|
1078
|
+
sections: [ /* ... */ ]
|
|
1079
|
+
})
|
|
1080
|
+
// payload => { listMessage: { title, description, buttonText, listType: 1, sections: [...] } }
|
|
1081
|
+
```
|
|
1082
|
+
|
|
1083
|
+
### Group Status V2 (Story Grup)
|
|
1084
|
+
|
|
1085
|
+
Fitur untuk mengirim **story/status langsung ke sebuah grup** (bukan status pribadi Anda) — muncul sebagai ring status khusus untuk anggota grup tersebut. Mendukung semua tipe media dengan caption.
|
|
1086
|
+
|
|
1087
|
+
**Teks biasa:**
|
|
1088
|
+
|
|
1089
|
+
```js
|
|
1090
|
+
await conn.sendMessage(groupJid, {
|
|
1091
|
+
groupStatusMessage: { text: '📢 Pengumuman penting dari admin!' }
|
|
1092
|
+
})
|
|
1093
|
+
```
|
|
1094
|
+
|
|
1095
|
+
**Teks dengan gaya warna latar:**
|
|
1096
|
+
|
|
1097
|
+
```js
|
|
1098
|
+
await conn.sendMessage(groupJid, {
|
|
1099
|
+
groupStatusMessage: {
|
|
1100
|
+
text: 'Status dengan background merah',
|
|
1101
|
+
backgroundColor: 0xFFE53935, // ARGB
|
|
1102
|
+
textArgb: 0xFFFFFFFF,
|
|
1103
|
+
font: 1 // 0-5
|
|
1104
|
+
}
|
|
1105
|
+
})
|
|
1106
|
+
```
|
|
1107
|
+
|
|
1108
|
+
**Foto dengan caption:**
|
|
1109
|
+
|
|
1110
|
+
```js
|
|
1111
|
+
await conn.sendMessage(groupJid, {
|
|
1112
|
+
groupStatusMessage: {
|
|
1113
|
+
image: { url: 'https://example.com/photo.jpg' }, // atau Buffer
|
|
1114
|
+
caption: '📸 Foto kegiatan hari ini!'
|
|
1115
|
+
}
|
|
1116
|
+
})
|
|
1117
|
+
```
|
|
1118
|
+
|
|
1119
|
+
**Video dengan caption:**
|
|
1120
|
+
|
|
1121
|
+
```js
|
|
1122
|
+
await conn.sendMessage(groupJid, {
|
|
1123
|
+
groupStatusMessage: {
|
|
1124
|
+
video: { url: 'https://example.com/video.mp4' },
|
|
1125
|
+
caption: '🎬 Video kegiatan',
|
|
1126
|
+
seconds: 30 // opsional, durasi
|
|
1127
|
+
}
|
|
1128
|
+
})
|
|
1129
|
+
```
|
|
1130
|
+
|
|
1131
|
+
**GIF (video dengan `gifPlayback`):**
|
|
1132
|
+
|
|
1133
|
+
```js
|
|
1134
|
+
await conn.sendMessage(groupJid, {
|
|
1135
|
+
groupStatusMessage: {
|
|
1136
|
+
video: { url: 'https://example.com/anim.mp4' },
|
|
1137
|
+
gifPlayback: true
|
|
1138
|
+
}
|
|
1139
|
+
})
|
|
1140
|
+
```
|
|
1141
|
+
|
|
1142
|
+
**Audio voice note:**
|
|
1143
|
+
|
|
1144
|
+
```js
|
|
1145
|
+
await conn.sendMessage(groupJid, {
|
|
1146
|
+
groupStatusMessage: {
|
|
1147
|
+
audio: { url: 'https://example.com/voice.ogg' },
|
|
1148
|
+
ptt: true,
|
|
1149
|
+
seconds: 15
|
|
1150
|
+
}
|
|
1151
|
+
})
|
|
1152
|
+
```
|
|
1153
|
+
|
|
1154
|
+
**Audio musik:**
|
|
1155
|
+
|
|
1156
|
+
```js
|
|
1157
|
+
await conn.sendMessage(groupJid, {
|
|
1158
|
+
groupStatusMessage: {
|
|
1159
|
+
audio: { url: 'https://example.com/music.mp3' },
|
|
1160
|
+
ptt: false,
|
|
1161
|
+
mimetype: 'audio/mp4' // atau 'audio/mpeg'
|
|
1162
|
+
}
|
|
1163
|
+
})
|
|
1164
|
+
```
|
|
1165
|
+
|
|
1166
|
+
**Sticker:**
|
|
1167
|
+
|
|
1168
|
+
```js
|
|
1169
|
+
await conn.sendMessage(groupJid, {
|
|
1170
|
+
groupStatusMessage: { sticker: { url: 'https://example.com/sticker.webp' } }
|
|
1171
|
+
})
|
|
1172
|
+
```
|
|
1173
|
+
|
|
1174
|
+
**Dokumen dengan caption:**
|
|
1175
|
+
|
|
1176
|
+
```js
|
|
1177
|
+
await conn.sendMessage(groupJid, {
|
|
1178
|
+
groupStatusMessage: {
|
|
1179
|
+
document: { url: 'https://example.com/file.pdf' },
|
|
1180
|
+
mimetype: 'application/pdf',
|
|
1181
|
+
fileName: 'Laporan.pdf',
|
|
1182
|
+
caption: '📄 Laporan bulan ini'
|
|
1183
|
+
}
|
|
1184
|
+
})
|
|
1185
|
+
```
|
|
1186
|
+
|
|
1187
|
+
**Story card yang di-generate otomatis (lihat bagian berikutnya):**
|
|
1188
|
+
|
|
1189
|
+
```js
|
|
1190
|
+
await conn.sendMessage(groupJid, {
|
|
1191
|
+
groupStatusMessage: {
|
|
1192
|
+
card: {
|
|
1193
|
+
title: 'Level Up!',
|
|
1194
|
+
body: 'Karaktermu naik ke level 25',
|
|
1195
|
+
footer: 'Harps-MD RPG System',
|
|
1196
|
+
gradient: 'sunset'
|
|
1197
|
+
},
|
|
1198
|
+
caption: '🎉 Selamat!'
|
|
1199
|
+
}
|
|
1200
|
+
})
|
|
1201
|
+
```
|
|
1202
|
+
|
|
1203
|
+
**Pre-built WAMessage (advanced, kontrol penuh):**
|
|
1204
|
+
|
|
1205
|
+
```js
|
|
1206
|
+
await conn.sendMessage(groupJid, {
|
|
1207
|
+
groupStatusMessage: {
|
|
1208
|
+
message: { imageMessage: { /* ...payload imageMessage lengkap yang sudah jadi... */ } }
|
|
1209
|
+
}
|
|
1210
|
+
})
|
|
1211
|
+
```
|
|
1212
|
+
|
|
1213
|
+
**Raw relay (forward story apa adanya):**
|
|
1214
|
+
|
|
1215
|
+
```js
|
|
1216
|
+
await conn.sendMessage(groupJid, {
|
|
1217
|
+
groupStatusMessage: { raw: existingMessagePayload }
|
|
1218
|
+
})
|
|
1219
|
+
```
|
|
1220
|
+
|
|
1221
|
+
> ⚠️ **Penting:** sejak v3.3.0, setiap mode `handleGroupStory()` **wajib** menyertakan `additionalNodes` (node `<meta is_vsn2="1">`) di panggilan `relayMessage()`-nya. Tanpa ini, pesan tetap terkirim & ter-enkripsi normal (tidak ada error), tapi klien penerima tidak tahu payload tersebut harus dirender sebagai story grup — sehingga tidak pernah muncul sebagai ring status untuk anggota lain. Detail lengkap bug ini ada di [Changelog v3.3.0](#-changelog-ringkas). Jika Anda memakai versi ≥ 3.3.0, ini sudah otomatis tertangani.
|
|
1222
|
+
|
|
1223
|
+
### Story Card Generator (`renderStoryCard`)
|
|
1224
|
+
|
|
1225
|
+
`Utils/story-card.js` menyediakan generator gambar status bergaya gradient — **tanpa dependency native**, hanya memakai [Jimp](https://github.com/jimp-dev/jimp) (opsional peer dependency, di-*lazy import* sehingga tidak membebani konsumen yang tidak memakainya).
|
|
1226
|
+
|
|
1227
|
+
```js
|
|
1228
|
+
import { renderStoryCard, STORY_GRADIENTS } from '@vinzsocket/baileys'
|
|
1229
|
+
|
|
1230
|
+
const buffer = await renderStoryCard({
|
|
1231
|
+
title: 'Selamat Datang!',
|
|
1232
|
+
body: 'Bot Harps-MD sudah online 24 jam.',
|
|
1233
|
+
footer: 'harps-md.dev',
|
|
1234
|
+
gradient: 'ocean', // lihat daftar preset di bawah
|
|
1235
|
+
direction: 'vertical' // atau 'diagonal'
|
|
1236
|
+
})
|
|
1237
|
+
|
|
1238
|
+
await sock.sendMessage(jid, { image: buffer, caption: 'Story otomatis!' })
|
|
1239
|
+
```
|
|
1240
|
+
|
|
1241
|
+
**Opsi `renderStoryCard(opts)`:**
|
|
1242
|
+
|
|
1243
|
+
| Opsi | Default | Keterangan |
|
|
1244
|
+
|---|---|---|
|
|
1245
|
+
| `title` | — | Teks besar (headline) |
|
|
1246
|
+
| `body` | — | Teks subtitle di bawah title |
|
|
1247
|
+
| `footer` | — | Teks kecil branding, ditempel di bawah kanvas |
|
|
1248
|
+
| `gradient` | `'purple'` | Preset gradasi: lihat `STORY_GRADIENTS` |
|
|
1249
|
+
| `colors` | — | `[from, to]` ARGB hex eksplisit — mengalahkan `gradient` jika diisi |
|
|
1250
|
+
| `direction` | `'vertical'` | `'vertical'` atau `'diagonal'` |
|
|
1251
|
+
| `width` | `1080` | Lebar kanvas (rasio default status WA: 1080×1920) |
|
|
1252
|
+
| `height` | `1920` | Tinggi kanvas |
|
|
1253
|
+
|
|
1254
|
+
**Preset gradient (`STORY_GRADIENTS`):**
|
|
1255
|
+
|
|
1256
|
+
```js
|
|
1257
|
+
console.log(STORY_GRADIENTS)
|
|
1258
|
+
// ['sunset', 'purple', 'ocean', 'forest', 'midnight', 'fire']
|
|
1259
|
+
```
|
|
1260
|
+
|
|
1261
|
+
| Preset | Warna |
|
|
1262
|
+
|---|---|
|
|
1263
|
+
| `sunset` | Oranye → Peach |
|
|
1264
|
+
| `purple` | Ungu tua → Ungu terang |
|
|
1265
|
+
| `ocean` | Biru laut → Cyan muda |
|
|
1266
|
+
| `forest` | Hijau tua → Hijau muda |
|
|
1267
|
+
| `midnight` | Abu gelap → Abu lebih terang |
|
|
1268
|
+
| `fire` | Merah → Kuning |
|
|
1269
|
+
|
|
1270
|
+
Warna kustom (override total, mengabaikan preset):
|
|
1271
|
+
|
|
1272
|
+
```js
|
|
1273
|
+
const buffer = await renderStoryCard({
|
|
1274
|
+
title: 'Custom Color',
|
|
1275
|
+
colors: ['#FF0080', '#7928CA'],
|
|
1276
|
+
direction: 'diagonal'
|
|
1277
|
+
})
|
|
1278
|
+
```
|
|
1279
|
+
|
|
1280
|
+
Jika `jimp` tidak terpasang, pemanggilan ini akan melempar:
|
|
1281
|
+
|
|
1282
|
+
```
|
|
1283
|
+
Error: renderStoryCard() requires the optional "jimp" peer dependency. Install it with: npm i jimp
|
|
1284
|
+
```
|
|
1285
|
+
|
|
1286
|
+
### Payment Request Message
|
|
1287
|
+
|
|
1288
|
+
```js
|
|
1289
|
+
await conn.sendMessage(jid, {
|
|
1290
|
+
requestPaymentMessage: {
|
|
1291
|
+
amount: 5000000, // Rp50.000 (x1000)
|
|
1292
|
+
currency: 'IDR',
|
|
1293
|
+
from: '0@s.whatsapp.net',
|
|
1294
|
+
note: 'Pembayaran untuk item RPG',
|
|
1295
|
+
expiry: Math.floor(Date.now() / 1000) + 86400
|
|
1296
|
+
}
|
|
1297
|
+
})
|
|
1298
|
+
```
|
|
1299
|
+
|
|
1300
|
+
Dengan sticker sebagai catatan visual (opsional, menggantikan `note` teks):
|
|
1301
|
+
|
|
1302
|
+
```js
|
|
1303
|
+
await conn.sendMessage(jid, {
|
|
1304
|
+
requestPaymentMessage: {
|
|
1305
|
+
amount: 10000000,
|
|
1306
|
+
currency: 'IDR',
|
|
1307
|
+
sticker: { stickerMessage: preparedStickerMessage }
|
|
1308
|
+
}
|
|
1309
|
+
})
|
|
1310
|
+
```
|
|
1311
|
+
|
|
1312
|
+
### Product Message
|
|
1313
|
+
|
|
1314
|
+
```js
|
|
1315
|
+
await conn.sendMessage(jid, {
|
|
1316
|
+
productMessage: {
|
|
1317
|
+
title: 'Sword of Fire',
|
|
1318
|
+
description: 'Senjata legendaris dengan efek terbakar',
|
|
1319
|
+
thumbnail: { url: 'https://example.com/sword.jpg' },
|
|
1320
|
+
productId: 'sword_fire_001',
|
|
1321
|
+
retailerId: 'harps-shop',
|
|
1322
|
+
priceAmount1000: 500000000,
|
|
1323
|
+
currencyCode: 'IDR',
|
|
1324
|
+
body: 'Dapatkan sekarang di Harps Shop!',
|
|
1325
|
+
footer: 'Stok terbatas',
|
|
1326
|
+
buttons: [{ id: 'buy', text: '💰 Beli Sekarang' }]
|
|
1327
|
+
}
|
|
1328
|
+
})
|
|
1329
|
+
```
|
|
1330
|
+
|
|
1331
|
+
Product message dibungkus otomatis sebagai `viewOnceMessage` berisi `interactiveMessage` dengan header produk (`header.productMessage`) — konsisten dengan cara WhatsApp Business menampilkan katalog produk single-item.
|
|
1332
|
+
|
|
1333
|
+
### Album Message
|
|
1334
|
+
|
|
1335
|
+
Kirim beberapa foto/video sebagai satu **album** (dikelompokkan visual di client, mirip carousel foto Instagram):
|
|
1336
|
+
|
|
1337
|
+
```js
|
|
1338
|
+
await conn.sendMessage(jid, {
|
|
1339
|
+
albumMessage: [
|
|
1340
|
+
{ image: { url: 'https://example.com/1.jpg' } },
|
|
1341
|
+
{ image: { url: 'https://example.com/2.jpg' } },
|
|
1342
|
+
{ video: { url: 'https://example.com/clip.mp4' } }
|
|
1343
|
+
]
|
|
1344
|
+
})
|
|
1345
|
+
```
|
|
1346
|
+
|
|
1347
|
+
Di balik layar, `handleAlbum()`:
|
|
1348
|
+
|
|
1349
|
+
1. Mengirim pesan "container" album kosong (`albumMessage` dengan `expectedImageCount` / `expectedVideoCount`).
|
|
1350
|
+
2. Mengirim setiap item media satu per satu sebagai pesan terpisah yang di-*link* ke container lewat `messageContextInfo.messageAssociation` (`associationType: MEDIA_ALBUM`), sehingga client mengelompokkannya secara visual sebagai satu album.
|
|
1351
|
+
|
|
1352
|
+
### Poll Result Snapshot
|
|
1353
|
+
|
|
1354
|
+
Mengirim **snapshot hasil polling** (mis. untuk mengumumkan pemenang polling tanpa perlu vote lagi):
|
|
1355
|
+
|
|
1356
|
+
```js
|
|
1357
|
+
await conn.sendMessage(jid, {
|
|
1358
|
+
pollResultMessage: {
|
|
1359
|
+
name: 'Menu favorit bulan ini',
|
|
1360
|
+
pollVotes: [
|
|
1361
|
+
{ optionName: 'Nasi Padang', optionVoteCount: 42 },
|
|
1362
|
+
{ optionName: 'Bakso', optionVoteCount: 27 },
|
|
1363
|
+
{ optionName: 'Mie Ayam', optionVoteCount: 15 }
|
|
1364
|
+
]
|
|
1365
|
+
}
|
|
1366
|
+
})
|
|
1367
|
+
```
|
|
1368
|
+
|
|
1369
|
+
### `buildInteractiveAdditionalNodes` — Kenapa Wajib Ada
|
|
1370
|
+
|
|
1371
|
+
Ini adalah salah satu fitur paling penting (dan paling mudah terlewat) di seluruh keluarga fork Baileys. WhatsApp **tidak cukup** hanya menerima payload protobuf pesan interaktif — server juga butuh **binary node hint** terpisah yang dikirim bersamaan lewat parameter `additionalNodes` pada `relayMessage()`, di luar isi pesan itu sendiri. Tanpa hint ini:
|
|
1372
|
+
|
|
1373
|
+
- Pesan tetap **terkirim & ter-enkripsi dengan sukses** (tidak ada exception).
|
|
1374
|
+
- Tapi klien penerima **tidak tahu** bahwa payload tersebut harus dirender sebagai list/interactive/story — pesan bisa muncul kosong, sebagai pesan biasa, atau tidak muncul sama sekali.
|
|
1375
|
+
|
|
1376
|
+
`buildInteractiveAdditionalNodes(jid, message)` di `Utils/messages.js` menghasilkan node yang tepat berdasarkan isi pesan:
|
|
1377
|
+
|
|
1378
|
+
| Isi Pesan | Node yang Dihasilkan |
|
|
1379
|
+
|---|---|
|
|
1380
|
+
| `listMessage` | `<biz><list type="product_list" v="2"/></biz>` |
|
|
1381
|
+
| `interactiveMessage` / `buttonsMessage` / `templateMessage` / `productMessage` | `<biz><interactive type="native_flow" v="1"><native_flow name="mixed" v="9"/></interactive></biz>` |
|
|
1382
|
+
| `interactiveMessage.carouselMessage` | sama seperti di atas, tapi `name="carousel"` |
|
|
1383
|
+
| `groupStatusMessageV2` (khusus di dalam grup) | `<meta is_vsn2="1"/>` |
|
|
1384
|
+
| (tambahan, jika bukan grup & ada node interaktif) | `<bot biz_bot="1"/>` |
|
|
1385
|
+
|
|
1386
|
+
**Harps-Baileys sudah memanggil fungsi ini secara otomatis** di dalam `sendMessage()` dan seluruh handler `dugong.js` — Anda **tidak perlu** memanggilnya manual untuk penggunaan normal. Namun jika Anda melakukan `relayMessage()` secara manual (mis. dari plugin custom yang bypass `sendMessage`), pastikan menyertakannya:
|
|
1387
|
+
|
|
1388
|
+
```js
|
|
1389
|
+
import { buildInteractiveAdditionalNodes } from '@vinzsocket/baileys'
|
|
1390
|
+
|
|
1391
|
+
await sock.relayMessage(jid, msg.message, {
|
|
1392
|
+
messageId: msg.key.id,
|
|
1393
|
+
additionalNodes: buildInteractiveAdditionalNodes(jid, msg.message)
|
|
1394
|
+
})
|
|
1395
|
+
```
|
|
1396
|
+
|
|
1397
|
+
Fungsi pendukung terkait, `patchInteractiveMessage(m)`, membungkus payload interactive/button/list/product ke dalam `viewOnceMessage` dengan `messageContextInfo.deviceListMetadataVersion` — konvensi yang dipakai mayoritas fork komunitas (baileys-pro, dsb) agar kompatibel dengan cara WhatsApp memvalidasi pesan tersebut. Fungsi ini juga dipanggil otomatis oleh `generateWAMessageContent()`.
|
|
1398
|
+
|
|
1399
|
+
---
|
|
1400
|
+
|
|
1401
|
+
## 🏷️ Mention Utilities (`mention.js`)
|
|
1402
|
+
|
|
1403
|
+
`Utils/mention.js` diporting dari fork **baileys-lily** dan diadaptasi ke ESM untuk Harps-Baileys. Menyediakan tiga fungsi:
|
|
1404
|
+
|
|
1405
|
+
### `normalizeMentions(mentions)`
|
|
1406
|
+
|
|
1407
|
+
Menormalisasi input mention (string tunggal, array, atau campuran nomor mentah/JID) menjadi array JID valid. Hasilnya **di-cache** (maksimum 1000 entri, auto-clear jika penuh) untuk performa di bot dengan volume mention tinggi.
|
|
1408
|
+
|
|
1409
|
+
```js
|
|
1410
|
+
import { normalizeMentions } from '@vinzsocket/baileys/lib/Utils/mention.js'
|
|
1411
|
+
|
|
1412
|
+
normalizeMentions('6281234567890')
|
|
1413
|
+
// => ['6281234567890@s.whatsapp.net']
|
|
1414
|
+
|
|
1415
|
+
normalizeMentions(['6281234567890', '6289876543210@s.whatsapp.net', null, ''])
|
|
1416
|
+
// => ['6281234567890@s.whatsapp.net', '6289876543210@s.whatsapp.net']
|
|
1417
|
+
```
|
|
1418
|
+
|
|
1419
|
+
### `applyMentions(msg, mentions, contextInfo?)`
|
|
1420
|
+
|
|
1421
|
+
Menyisipkan daftar mention ke dalam sebuah objek pesan mentah — menangani tiga lokasi berbeda sekaligus (`messageContextInfo.mentionedJid`, `contextInfo.mentionedJid` yang diberikan, dan `interactiveMessage.contextInfo.mentionedJid` jika ada), tanpa duplikasi.
|
|
1422
|
+
|
|
1423
|
+
```js
|
|
1424
|
+
import { applyMentions } from '@vinzsocket/baileys/lib/Utils/mention.js'
|
|
1425
|
+
|
|
1426
|
+
const msg = { extendedTextMessage: { text: 'Halo semua' } }
|
|
1427
|
+
applyMentions(msg, ['6281234567890@s.whatsapp.net'])
|
|
1428
|
+
```
|
|
1429
|
+
|
|
1430
|
+
### `buildTagAllText(participants, options?)`
|
|
1431
|
+
|
|
1432
|
+
Membangun teks "tag semua anggota" beserta daftar `mentions`-nya dari `participants` hasil `groupMetadata(jid)` — **menangani kasus JID `@lid` dengan aman**: jika WhatsApp tidak mengungkapkan nomor telepon asli seorang anggota (mode privasi `addressingMode: 'lid'`), fungsi ini **tidak** menampilkan digit LID mentah sebagai `@206244447002720` (yang tidak berarti apa-apa bagi manusia), melainkan jatuh ke nama tampilan (jika Anda punya lookup) atau label generik `@Member`.
|
|
1433
|
+
|
|
1434
|
+
```js
|
|
1435
|
+
import { buildTagAllText } from '@vinzsocket/baileys/lib/Utils/mention.js'
|
|
1436
|
+
|
|
1437
|
+
const metadata = await sock.groupMetadata(groupJid)
|
|
1438
|
+
|
|
1439
|
+
const { text, mentions } = buildTagAllText(metadata.participants, {
|
|
1440
|
+
header: '📢 Pengumuman untuk semua anggota grup!',
|
|
1441
|
+
footer: 'Harap dibaca sampai selesai.',
|
|
1442
|
+
getDisplayName: (jid) => myContactStore[jid]?.notify // opsional, lookup nama dari store Anda
|
|
1443
|
+
})
|
|
1444
|
+
|
|
1445
|
+
await sock.sendMessage(groupJid, { text, mentions })
|
|
1446
|
+
```
|
|
1447
|
+
|
|
1448
|
+
**Perilaku penamaan per anggota:**
|
|
1449
|
+
|
|
1450
|
+
| Kondisi | Yang Ditampilkan |
|
|
1451
|
+
|---|---|
|
|
1452
|
+
| WhatsApp mengungkapkan nomor telepon asli | `@6281234567890` (nomor asli) |
|
|
1453
|
+
| Hanya LID + ada `getDisplayName` yang mengembalikan nama | `@NamaKontak` |
|
|
1454
|
+
| Hanya LID + tidak ada lookup nama | `@Member` (label generik, bukan digit LID) |
|
|
1455
|
+
|
|
1456
|
+
Ini penting karena menampilkan LID mentah bisa terlihat seperti nomor telepon acak/rusak dan membingungkan pengguna — dengan `buildTagAllText`, tampilan tetap rapi apa pun status privasi anggotanya.
|
|
1457
|
+
|
|
1458
|
+
---
|
|
1459
|
+
|
|
1460
|
+
## 📡 Sistem Event
|
|
1461
|
+
|
|
1462
|
+
Semua event WhatsApp diterima lewat `sock.ev` — sebuah `EventEmitter` (dari `@hapi/boom`-style bare event emitter, bukan dari library eksternal). Berikut daftar lengkap event yang dipancarkan oleh Harps-Baileys:
|
|
1463
|
+
|
|
1464
|
+
| Event | Kapan Dipancarkan |
|
|
1465
|
+
|---|---|
|
|
1466
|
+
| `connection.update` | Status koneksi berubah (`connecting`, `open`, `close`) atau QR baru tersedia. |
|
|
1467
|
+
| `creds.update` | Kredensial auth berubah — **wajib** disimpan via `saveCreds()`. |
|
|
1468
|
+
| `messages.upsert` | Pesan baru masuk (atau riwayat sedang sinkron, cek `type`). |
|
|
1469
|
+
| `messages.update` | Pesan yang sudah ada berubah (status baca, reaksi, poll vote, dst). |
|
|
1470
|
+
| `messages.delete` | Satu atau beberapa pesan dihapus. |
|
|
1471
|
+
| `messages.reaction` | Reaksi emoji baru pada sebuah pesan. |
|
|
1472
|
+
| `messages.media-update` | Hasil `updateMediaMessage()` — media berhasil/gagal di-refresh. |
|
|
1473
|
+
| `message-receipt.update` | Update tanda terima (delivered/read) per device. |
|
|
1474
|
+
| `message-capping.update` | Update terkait batasan tampilan pesan (mis. status kadaluarsa). |
|
|
1475
|
+
| `messaging-history.set` | Batch sinkronisasi riwayat chat/kontak/pesan diterima. |
|
|
1476
|
+
| `messaging-history.status` | Status progres sinkronisasi riwayat (mulai/selesai/timeout). |
|
|
1477
|
+
| `chats.upsert` | Chat baru ditambahkan ke daftar. |
|
|
1478
|
+
| `chats.update` | Metadata chat berubah (unread count, pin, mute, dst). |
|
|
1479
|
+
| `chats.delete` | Chat dihapus dari daftar. |
|
|
1480
|
+
| `chats.lock` | (internal) penguncian transaksi app-state untuk chat tertentu. |
|
|
1481
|
+
| `contacts.upsert` | Kontak baru ditambahkan/disinkronkan. |
|
|
1482
|
+
| `contacts.update` | Data kontak berubah (nama, status, dsb). |
|
|
1483
|
+
| `groups.upsert` | Grup baru ditemukan/dibuat. |
|
|
1484
|
+
| `groups.update` | Metadata grup berubah (subjek, deskripsi, setting). |
|
|
1485
|
+
| `group-participants.update` | Anggota ditambah/dikeluarkan/dipromosikan/diturunkan. |
|
|
1486
|
+
| `group.join-request` | Ada permintaan join grup baru (mode approval). |
|
|
1487
|
+
| `group.member-tag.update` | Update label/tag anggota grup. |
|
|
1488
|
+
| `blocklist.update` | Daftar kontak yang diblokir berubah. |
|
|
1489
|
+
| `call` | Ada panggilan masuk/status panggilan berubah. |
|
|
1490
|
+
| `presence.update` | Status online/typing/recording seseorang berubah. |
|
|
1491
|
+
| `labels.edit` | Label chat (fitur WhatsApp Business) diubah. |
|
|
1492
|
+
| `labels.association` | Label ditambahkan/dilepas dari chat/pesan tertentu. |
|
|
1493
|
+
| `newsletter.view` | Statistik view newsletter/channel berubah. |
|
|
1494
|
+
| `newsletter.reaction` | Reaksi baru pada post newsletter/channel. |
|
|
1495
|
+
| `newsletter-settings.update` | Pengaturan newsletter/channel berubah. |
|
|
1496
|
+
| `newsletter-participants.update` | Admin/follower newsletter berubah. |
|
|
1497
|
+
| `lid-mapping.update` | Pemetaan JID nomor telepon ↔ LID diperbarui. |
|
|
1498
|
+
| `settings.update` | Pengaturan akun WhatsApp berubah. |
|
|
1499
|
+
| `event` | Update terkait event/undangan (RSVP, dsb). |
|
|
1500
|
+
|
|
1501
|
+
### Contoh Pola Umum
|
|
4
1502
|
|
|
5
|
-
|
|
1503
|
+
```js
|
|
1504
|
+
sock.ev.on('messages.upsert', async ({ messages, type }) => {
|
|
1505
|
+
if (type !== 'notify') return // 'notify' = pesan baru real-time
|
|
1506
|
+
for (const msg of messages) {
|
|
1507
|
+
if (!msg.message) continue
|
|
1508
|
+
console.log('Pesan masuk dari:', msg.key.remoteJid)
|
|
1509
|
+
}
|
|
1510
|
+
})
|
|
6
1511
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1512
|
+
sock.ev.on('group-participants.update', async ({ id, participants, action }) => {
|
|
1513
|
+
if (action === 'add') {
|
|
1514
|
+
for (const p of participants) {
|
|
1515
|
+
await sock.sendMessage(id, { text: `Selamat datang @${p.split('@')[0]}!`, mentions: [p] })
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
})
|
|
12
1519
|
|
|
13
|
-
|
|
1520
|
+
sock.ev.on('call', async (calls) => {
|
|
1521
|
+
for (const call of calls) {
|
|
1522
|
+
if (call.status === 'offer') {
|
|
1523
|
+
console.log('Panggilan masuk dari', call.from)
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
})
|
|
1527
|
+
```
|
|
14
1528
|
|
|
15
|
-
|
|
16
|
-
with native support for interactive messages, album messages, unified rich responses, newsletter helpers, status mentions, and additional business/community utilities.
|
|
1529
|
+
### Menggabungkan Banyak Event (Event Buffering)
|
|
17
1530
|
|
|
18
|
-
|
|
19
|
-
It ships compiled runtime files in `lib/` and protobuf artifacts in `WAProto/`, and is intended to be consumed directly from npm or as a vendored dependency inside the **Ourin-MD** ecosystem.
|
|
1531
|
+
Untuk workload berat (sinkronisasi riwayat besar), Baileys menyediakan `makeEventBuffer` (via `Utils/event-buffer.js`) yang menggabungkan banyak event kecil menjadi satu batch — biasanya sudah dipakai secara internal oleh `sock.ev` (yang sebenarnya adalah `BaileysEventEmitter` dengan buffering opsional lewat `sock.ev.buffer()` / `sock.ev.flush()`):
|
|
20
1532
|
|
|
21
|
-
|
|
1533
|
+
```js
|
|
1534
|
+
sock.ev.buffer() // mulai buffering
|
|
1535
|
+
// ...lakukan banyak operasi...
|
|
1536
|
+
await sock.ev.flush() // proses semua event yang tertunda sekaligus
|
|
1537
|
+
```
|
|
22
1538
|
|
|
23
|
-
|
|
1539
|
+
Ini berguna saat Anda melakukan operasi berat (mis. restore banyak kontak) dan ingin event yang berhubungan digabung agar handler Anda tidak dipanggil ratusan kali secara terpisah.
|
|
24
1540
|
|
|
25
|
-
|
|
1541
|
+
---
|
|
26
1542
|
|
|
27
|
-
|
|
1543
|
+
## 👥 Grup (Groups API)
|
|
28
1544
|
|
|
29
|
-
|
|
1545
|
+
Semua method grup tersedia langsung di objek `sock` (dari layer `makeGroupsSocket`).
|
|
30
1546
|
|
|
31
|
-
|
|
1547
|
+
### Membuat & Mengelola Grup
|
|
32
1548
|
|
|
33
|
-
|
|
1549
|
+
```js
|
|
1550
|
+
// Buat grup baru
|
|
1551
|
+
const group = await sock.groupCreate('Nama Grup Baru', ['6281234567890@s.whatsapp.net', '6289876543210@s.whatsapp.net'])
|
|
1552
|
+
console.log(group.id) // JID grup baru
|
|
34
1553
|
|
|
35
|
-
|
|
1554
|
+
// Keluar dari grup
|
|
1555
|
+
await sock.groupLeave(groupJid)
|
|
36
1556
|
|
|
37
|
-
|
|
1557
|
+
// Ubah nama grup
|
|
1558
|
+
await sock.groupUpdateSubject(groupJid, 'Nama Grup yang Diperbarui')
|
|
38
1559
|
|
|
39
|
-
|
|
1560
|
+
// Ubah deskripsi grup
|
|
1561
|
+
await sock.groupUpdateDescription(groupJid, 'Deskripsi baru untuk grup ini')
|
|
1562
|
+
```
|
|
40
1563
|
|
|
41
|
-
|
|
42
|
-
- Browser parameter spoofing upgraded to MacOS to prevent Error 405 (Method Not Allowed) during pairing.
|
|
1564
|
+
### Mengelola Anggota
|
|
43
1565
|
|
|
44
|
-
|
|
1566
|
+
```js
|
|
1567
|
+
// Tambah anggota
|
|
1568
|
+
await sock.groupParticipantsUpdate(groupJid, ['6281234567890@s.whatsapp.net'], 'add')
|
|
45
1569
|
|
|
46
|
-
|
|
47
|
-
|
|
1570
|
+
// Keluarkan anggota
|
|
1571
|
+
await sock.groupParticipantsUpdate(groupJid, ['6281234567890@s.whatsapp.net'], 'remove')
|
|
48
1572
|
|
|
49
|
-
|
|
50
|
-
|
|
1573
|
+
// Jadikan admin
|
|
1574
|
+
await sock.groupParticipantsUpdate(groupJid, ['6281234567890@s.whatsapp.net'], 'promote')
|
|
51
1575
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
await ourin.send(jid);
|
|
57
|
-
```
|
|
1576
|
+
// Copot admin
|
|
1577
|
+
await sock.groupParticipantsUpdate(groupJid, ['6281234567890@s.whatsapp.net'], 'demote')
|
|
1578
|
+
```
|
|
58
1579
|
|
|
59
|
-
|
|
1580
|
+
`action` menerima salah satu dari: `'add'`, `'remove'`, `'promote'`, `'demote'`.
|
|
60
1581
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
- [ourin-baileys](#ourin-baileys)
|
|
64
|
-
- [Modded Baileys v7 — Interactive Messages, AI Rich Responses, Albums & More](#modded-baileys-v7--interactive-messages-ai-rich-responses-albums--more)
|
|
65
|
-
- [Table of Contents](#table-of-contents)
|
|
66
|
-
- [✨ Features](#-features)
|
|
67
|
-
- [✅ Requirements](#-requirements)
|
|
68
|
-
- [🗂️ What’s Inside This Repo](#-whats-inside-this-repo)
|
|
69
|
-
- [📦 Installation](#-installation)
|
|
70
|
-
- [From NPM](#from-npm)
|
|
71
|
-
- [Using Alias (Recommended for Ourin-MD Bots)](#using-alias-recommended-for-ourin-md-bots)
|
|
72
|
-
- [🛠️ Quick Start](#️-quick-start)
|
|
73
|
-
- [1. Project Setup](#1-project-setup)
|
|
74
|
-
- [2. Install Dependencies](#2-install-dependencies)
|
|
75
|
-
- [3. Create `index.js`](#3-create-indexjs)
|
|
76
|
-
- [4. Run](#4-run)
|
|
77
|
-
- [5. Pairing Code Example](#5-pairing-code-example)
|
|
78
|
-
- [🏗️ Architecture](#️-architecture)
|
|
79
|
-
- [Socket Layer Chain](#socket-layer-chain)
|
|
80
|
-
- [Key Modules](#key-modules)
|
|
81
|
-
- [Build Repo Layout](#build-repo-layout)
|
|
82
|
-
- [Connection Flow](#connection-flow)
|
|
83
|
-
- [📡 Socket API Reference](#-socket-api-reference)
|
|
84
|
-
- [Connection \& Authentication](#connection--authentication)
|
|
85
|
-
- [VoIP (Voice Calls)](#voip-voice-calls)
|
|
86
|
-
- [Message Sending](#message-sending)
|
|
87
|
-
- [Interactive Messages](#interactive-messages)
|
|
88
|
-
- [Album Messages](#album-messages)
|
|
89
|
-
- [AI Rich Response Messages](#ai-rich-response-messages)
|
|
90
|
-
- [Code Block V2 (Unified Response)](#code-block-v2-unified-response)
|
|
91
|
-
- [Other Message Types](#other-message-types)
|
|
92
|
-
- [Newsletter Methods](#newsletter-methods)
|
|
93
|
-
- [Group Methods](#group-methods)
|
|
94
|
-
- [Community Methods](#community-methods)
|
|
95
|
-
- [Business Methods](#business-methods)
|
|
96
|
-
- [Chat \& Profile Methods](#chat--profile-methods)
|
|
97
|
-
- [Privacy Settings](#privacy-settings)
|
|
98
|
-
- [📡 Event Reference](#-event-reference)
|
|
99
|
-
- [🔧 Utility Exports](#-utility-exports)
|
|
100
|
-
- [🏗️ Building This Package](#️-building-this-package)
|
|
101
|
-
- [🔀 Differences from Official Baileys](#-differences-from-official-baileys)
|
|
102
|
-
- [🤝 Contributing](#-contributing)
|
|
103
|
-
- [📄 License](#-license)
|
|
1582
|
+
### Mode Approval Join Request
|
|
104
1583
|
|
|
105
|
-
|
|
1584
|
+
Untuk grup dengan mode "admin harus menyetujui anggota baru":
|
|
106
1585
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
| --------------------------- | -------------------------------------------------------------------------------------- | ------ |
|
|
111
|
-
| **VoIP Voice Calls** | Native VoIP engine (WASM/WebRTC) via `VoipClient`, single shared socket | ✅ |
|
|
112
|
-
| **Interactive Messages** | Native flow buttons, list/select menus, button wrappers, carousel support via `Dugong` | ✅ |
|
|
113
|
-
| **Album Messages** | Multi-image/video album relay with count metadata and grouped delivery | ✅ |
|
|
114
|
-
| **Rich Response Helpers** | `sendTable`, `sendList`, `sendCodeBlock`, `sendRichMessage`, `sendUnifiedResponse` | ✅ |
|
|
115
|
-
| **Unified Response V2** | `sendTableV2`, `sendCodeBlockV2`, `sendLinkV2` with Meta-AI-style unified sections | ✅ |
|
|
116
|
-
| **Link Messages** | Rich inline links with citations, proofs, and forwarded bot context | ✅ |
|
|
117
|
-
| **Latex Rendering Hooks** | `sendLatex`, `sendLatexImage`, `sendLatexInlineImage` helper APIs | ✅ |
|
|
118
|
-
| **Payment Messages** | Request payment messages with note/sticker support | ✅ |
|
|
119
|
-
| **Product / Catalog** | Business product messages, catalog fetch/create/update/delete, cover photo helpers | ✅ |
|
|
120
|
-
| **Event / Poll Result** | Event message builders and poll result snapshots | ✅ |
|
|
121
|
-
| **Newsletter Extras** | URL resolve, metadata fetch, create/update, bulk follow, admin utilities, live updates | ✅ |
|
|
122
|
-
| **Communities & Groups** | Community CRUD, linked groups, invite workflows, join approval, labels | ✅ |
|
|
123
|
-
| **Status Mention** | `sendStatusMention()` helper to mention users/groups in status flows | ✅ |
|
|
124
|
-
| **LID & Session Handling** | LID↔PN mapping, session migration, retry/session recreation helpers | ✅ |
|
|
125
|
-
| **Build Output Ready** | Published runtime in `lib/` and protobuf artifacts in `WAProto/` | ✅ |
|
|
126
|
-
| **TypeScript Declarations** | Included `.d.ts` files for exported APIs and socket methods | ✅ |
|
|
1586
|
+
```js
|
|
1587
|
+
// Lihat daftar permintaan join yang pending
|
|
1588
|
+
const requests = await sock.groupRequestParticipantsList(groupJid)
|
|
127
1589
|
|
|
128
|
-
|
|
1590
|
+
// Setujui atau tolak
|
|
1591
|
+
await sock.groupRequestParticipantsUpdate(groupJid, ['6281234567890@s.whatsapp.net'], 'approve')
|
|
1592
|
+
await sock.groupRequestParticipantsUpdate(groupJid, ['6281234567890@s.whatsapp.net'], 'reject')
|
|
1593
|
+
```
|
|
129
1594
|
|
|
130
|
-
|
|
1595
|
+
### Undangan Grup
|
|
131
1596
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
- `pino` for logging
|
|
137
|
-
- `qrcode-terminal` if you want to render QR codes in the terminal yourself
|
|
138
|
-
- `sharp`, `jimp`, `audio-decode`, `link-preview-js` for optional media/rich utilities
|
|
1597
|
+
```js
|
|
1598
|
+
// Ambil kode undangan
|
|
1599
|
+
const code = await sock.groupInviteCode(groupJid)
|
|
1600
|
+
console.log(`https://chat.whatsapp.com/${code}`)
|
|
139
1601
|
|
|
140
|
-
|
|
141
|
-
|
|
1602
|
+
// Cabut & buat ulang kode undangan (kode lama jadi tidak valid)
|
|
1603
|
+
const newCode = await sock.groupRevokeInvite(groupJid)
|
|
142
1604
|
|
|
143
|
-
|
|
1605
|
+
// Terima undangan via kode
|
|
1606
|
+
const joinedGroupId = await sock.groupAcceptInvite(inviteCode)
|
|
144
1607
|
|
|
145
|
-
|
|
1608
|
+
// Lihat info grup dari kode undangan TANPA join
|
|
1609
|
+
const info = await sock.groupGetInviteInfo(inviteCode)
|
|
146
1610
|
|
|
147
|
-
|
|
1611
|
+
// Undang JID tertentu langsung (V4 invite — dikirim sebagai pesan groupInviteMessage)
|
|
1612
|
+
await sock.groupRevokeInviteV4(groupJid, targetJid)
|
|
1613
|
+
```
|
|
148
1614
|
|
|
149
|
-
|
|
150
|
-
| --------------------- | ------------------------------------------------------ |
|
|
151
|
-
| `lib/` | Main compiled runtime, types, socket layers, utilities |
|
|
152
|
-
| `WAProto/` | Generated protobuf runtime and typings |
|
|
153
|
-
| `package.json` | Published package metadata, dependencies, build script |
|
|
154
|
-
| `tsconfig.json` | TypeScript config used for authoring/build pipeline |
|
|
155
|
-
| `tsconfig.build.json` | Build-specific TS emit config targeting `lib/` |
|
|
156
|
-
| `proto-extract/` | Protobuf-related extraction/build assets |
|
|
1615
|
+
### Pengaturan Grup
|
|
157
1616
|
|
|
158
|
-
|
|
1617
|
+
```js
|
|
1618
|
+
// Hanya admin yang bisa kirim pesan ('announcement') atau semua anggota ('not_announcement')
|
|
1619
|
+
await sock.groupSettingUpdate(groupJid, 'announcement')
|
|
159
1620
|
|
|
160
|
-
|
|
1621
|
+
// Siapa yang boleh edit info grup: 'locked' (admin saja) / 'unlocked' (semua)
|
|
1622
|
+
await sock.groupSettingUpdate(groupJid, 'locked')
|
|
161
1623
|
|
|
162
|
-
|
|
1624
|
+
// Mode tambah anggota: 'all_member_add' / 'admin_add'
|
|
1625
|
+
await sock.groupMemberAddMode(groupJid, 'admin_add')
|
|
163
1626
|
|
|
164
|
-
|
|
1627
|
+
// Mode approval join: 'on' / 'off'
|
|
1628
|
+
await sock.groupJoinApprovalMode(groupJid, 'on')
|
|
165
1629
|
|
|
166
|
-
|
|
167
|
-
|
|
1630
|
+
// Pesan sekali lihat (disappearing messages) di grup
|
|
1631
|
+
await sock.groupToggleEphemeral(groupJid, 7 * 24 * 60 * 60) // 7 hari, dalam detik
|
|
1632
|
+
await sock.groupToggleEphemeral(groupJid, 0) // matikan
|
|
168
1633
|
```
|
|
169
1634
|
|
|
170
|
-
|
|
1635
|
+
### Membaca Metadata Grup
|
|
171
1636
|
|
|
172
|
-
```
|
|
173
|
-
|
|
1637
|
+
```js
|
|
1638
|
+
const metadata = await sock.groupMetadata(groupJid)
|
|
1639
|
+
console.log({
|
|
1640
|
+
subject: metadata.subject,
|
|
1641
|
+
desc: metadata.desc,
|
|
1642
|
+
owner: metadata.owner,
|
|
1643
|
+
participants: metadata.participants.length,
|
|
1644
|
+
memberAddMode: metadata.memberAddMode
|
|
1645
|
+
})
|
|
1646
|
+
|
|
1647
|
+
// Ambil semua grup yang diikuti akun ini
|
|
1648
|
+
const allGroups = await sock.groupFetchAllParticipating()
|
|
1649
|
+
console.log(Object.keys(allGroups).length, 'grup diikuti')
|
|
174
1650
|
```
|
|
175
1651
|
|
|
176
|
-
|
|
1652
|
+
**Field penting pada objek metadata grup:** `id`, `subject`, `subjectOwner`, `subjectTime`, `size`, `creation`, `owner`, `desc`, `descId`, `descOwner`, `descOwnerPn`, `descOwnerUsername`, `descTime`, `restrict`, `announce`, `isCommunity`, `isCommunityAnnounce`, `joinApprovalMode`, `memberAddMode`, `participants` (array `{ id, admin, jid?, phoneNumber? }`).
|
|
177
1653
|
|
|
178
|
-
|
|
1654
|
+
---
|
|
179
1655
|
|
|
180
|
-
|
|
181
|
-
{
|
|
182
|
-
"dependencies": {
|
|
183
|
-
"ourin": "npm:ourin-baileys@latest"
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
```
|
|
1656
|
+
## 🏘️ Komunitas (Communities API)
|
|
187
1657
|
|
|
188
|
-
|
|
1658
|
+
Struktur API-nya **sangat mirip Groups API**, karena komunitas WhatsApp pada dasarnya adalah "grup induk" yang menaungi beberapa grup anak.
|
|
189
1659
|
|
|
190
|
-
```
|
|
191
|
-
|
|
1660
|
+
```js
|
|
1661
|
+
// Buat komunitas baru
|
|
1662
|
+
const community = await sock.communityCreate('Nama Komunitas', 'Deskripsi komunitas')
|
|
1663
|
+
|
|
1664
|
+
// Buat grup baru langsung di dalam komunitas
|
|
1665
|
+
const subGroup = await sock.communityCreateGroup('Nama Grup', ['6281234567890@s.whatsapp.net'], community.id)
|
|
1666
|
+
|
|
1667
|
+
// Keluar dari komunitas
|
|
1668
|
+
await sock.communityLeave(communityJid)
|
|
1669
|
+
|
|
1670
|
+
// Ubah subjek/deskripsi
|
|
1671
|
+
await sock.communityUpdateSubject(communityJid, 'Nama Baru')
|
|
1672
|
+
await sock.communityUpdateDescription(communityJid, 'Deskripsi baru')
|
|
1673
|
+
|
|
1674
|
+
// Hubungkan / lepaskan grup yang sudah ada ke/dari komunitas
|
|
1675
|
+
await sock.communityLinkGroup(existingGroupJid, communityJid)
|
|
1676
|
+
await sock.communityUnlinkGroup(existingGroupJid, communityJid)
|
|
1677
|
+
|
|
1678
|
+
// Lihat semua grup yang terhubung ke komunitas ini
|
|
1679
|
+
const linkedGroups = await sock.communityFetchLinkedGroups(communityJid)
|
|
1680
|
+
|
|
1681
|
+
// Kelola anggota (sama seperti grup)
|
|
1682
|
+
await sock.communityParticipantsUpdate(communityJid, [jid], 'add')
|
|
1683
|
+
await sock.communityRequestParticipantsList(communityJid)
|
|
1684
|
+
await sock.communityRequestParticipantsUpdate(communityJid, [jid], 'approve')
|
|
1685
|
+
|
|
1686
|
+
// Undangan
|
|
1687
|
+
const code = await sock.communityInviteCode(communityJid)
|
|
1688
|
+
await sock.communityRevokeInvite(communityJid)
|
|
1689
|
+
await sock.communityAcceptInvite(code)
|
|
1690
|
+
await sock.communityRevokeInviteV4(communityJid, targetJid)
|
|
1691
|
+
const info = await sock.communityGetInviteInfo(code)
|
|
1692
|
+
|
|
1693
|
+
// Pengaturan
|
|
1694
|
+
await sock.communityToggleEphemeral(communityJid, 0)
|
|
1695
|
+
await sock.communitySettingUpdate(communityJid, 'announcement')
|
|
1696
|
+
await sock.communityMemberAddMode(communityJid, 'admin_add')
|
|
1697
|
+
await sock.communityJoinApprovalMode(communityJid, 'on')
|
|
1698
|
+
|
|
1699
|
+
// Metadata & daftar semua komunitas yang diikuti
|
|
1700
|
+
const metadata = await sock.communityMetadata(communityJid)
|
|
1701
|
+
const all = await sock.communityFetchAllParticipating()
|
|
192
1702
|
```
|
|
193
1703
|
|
|
194
|
-
|
|
195
|
-
> Using the alias `ourin` allows you to `import ourin from 'ourin'` without changing existing code.
|
|
196
|
-
|
|
197
|
-
> [!NOTE]
|
|
198
|
-
> Peer dependencies such as `sharp`, `jimp`, `audio-decode`, and `link-preview-js` are optional. Install only what your bot features need.
|
|
1704
|
+
Field metadata komunitas mencakup: `desc`, `descId`, `memberAddMode`, `isCommunity: true`, plus field umum grup lainnya (`subject`, `owner`, `participants`, dst).
|
|
199
1705
|
|
|
200
1706
|
---
|
|
201
1707
|
|
|
202
|
-
##
|
|
1708
|
+
## 💼 Business API
|
|
203
1709
|
|
|
204
|
-
|
|
1710
|
+
Untuk akun WhatsApp Business — mengelola katalog produk, koleksi, dan profil bisnis.
|
|
205
1711
|
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
```
|
|
1712
|
+
```js
|
|
1713
|
+
// Ambil detail order (mis. dari pesan review_order)
|
|
1714
|
+
const order = await sock.getOrderDetails(orderId, tokenBase64)
|
|
210
1715
|
|
|
211
|
-
|
|
1716
|
+
// Ambil katalog produk milik JID bisnis tertentu (atau diri sendiri jika tidak diisi)
|
|
1717
|
+
const catalog = await sock.getCatalog({ jid: businessJid, limit: 20 })
|
|
212
1718
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
"name": "my-bot",
|
|
216
|
-
"type": "module",
|
|
217
|
-
"dependencies": {
|
|
218
|
-
"ourin": "npm:ourin-baileys@latest"
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
```
|
|
1719
|
+
// Ambil koleksi produk (grouping produk di katalog)
|
|
1720
|
+
const collections = await sock.getCollections(businessJid, 10)
|
|
222
1721
|
|
|
223
|
-
|
|
224
|
-
|
|
1722
|
+
// Tambah produk baru ke katalog
|
|
1723
|
+
const newProduct = await sock.productCreate({
|
|
1724
|
+
name: 'Kaos Harps-MD',
|
|
1725
|
+
description: 'Kaos official merchandise',
|
|
1726
|
+
price: 15000000, // dalam sen/x1000 tergantung mata uang
|
|
1727
|
+
currency: 'IDR',
|
|
1728
|
+
images: [{ url: 'https://example.com/kaos.jpg' }]
|
|
1729
|
+
})
|
|
225
1730
|
|
|
226
|
-
|
|
1731
|
+
// Update produk
|
|
1732
|
+
await sock.productUpdate(productId, { price: 12000000 })
|
|
227
1733
|
|
|
228
|
-
|
|
229
|
-
|
|
1734
|
+
// Hapus produk
|
|
1735
|
+
await sock.productDelete([productId])
|
|
1736
|
+
|
|
1737
|
+
// Update profil bisnis (deskripsi, kategori, jam buka, dsb)
|
|
1738
|
+
await sock.updateBussinesProfile({ description: 'Toko resmi Harps-MD', address: 'Jakarta' })
|
|
1739
|
+
|
|
1740
|
+
// Update / hapus foto sampul profil bisnis
|
|
1741
|
+
await sock.updateCoverPhoto(imageBuffer)
|
|
1742
|
+
await sock.removeCoverPhoto()
|
|
230
1743
|
```
|
|
231
1744
|
|
|
232
|
-
|
|
1745
|
+
---
|
|
233
1746
|
|
|
234
|
-
|
|
235
|
-
import makeWASocket, {
|
|
236
|
-
useMultiFileAuthState,
|
|
237
|
-
DisconnectReason,
|
|
238
|
-
Browsers,
|
|
239
|
-
} from "ourin-baileys";
|
|
240
|
-
import pino from "pino";
|
|
241
|
-
import qrcode from "qrcode-terminal";
|
|
1747
|
+
## 📰 Newsletter / Channel API
|
|
242
1748
|
|
|
243
|
-
|
|
1749
|
+
Untuk fitur **WhatsApp Channel** (sebelumnya disebut "Newsletter" secara internal oleh protokol WA).
|
|
244
1750
|
|
|
245
|
-
|
|
246
|
-
|
|
1751
|
+
```js
|
|
1752
|
+
// Buat channel baru
|
|
1753
|
+
const channel = await sock.newsletterCreate('Nama Channel', 'Deskripsi channel')
|
|
247
1754
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
browser: Browsers.ubuntu("Chrome"),
|
|
252
|
-
syncFullHistory: false,
|
|
253
|
-
});
|
|
1755
|
+
// Ambil metadata channel (by invite code atau by jid)
|
|
1756
|
+
const metaByJid = await sock.newsletterMetadata('jid', channelJid)
|
|
1757
|
+
const metaByInvite = await sock.newsletterMetadata('invite', inviteCode)
|
|
254
1758
|
|
|
255
|
-
|
|
1759
|
+
// Update info channel
|
|
1760
|
+
await sock.newsletterUpdateName(channelJid, 'Nama Baru')
|
|
1761
|
+
await sock.newsletterUpdateDescription(channelJid, 'Deskripsi baru')
|
|
1762
|
+
await sock.newsletterUpdatePicture(channelJid, imageBuffer)
|
|
1763
|
+
await sock.newsletterRemovePicture(channelJid)
|
|
256
1764
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
qrcode.generate(qr, { small: true });
|
|
260
|
-
}
|
|
1765
|
+
// Lihat daftar subscriber
|
|
1766
|
+
const subs = await sock.newsletterSubscribers(channelJid)
|
|
261
1767
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
lastDisconnect?.error?.output?.statusCode !==
|
|
265
|
-
DisconnectReason.loggedOut;
|
|
266
|
-
if (shouldReconnect) startBot();
|
|
267
|
-
}
|
|
268
|
-
if (connection === "open") console.log("Connected!");
|
|
269
|
-
});
|
|
1768
|
+
// React ke sebuah post channel
|
|
1769
|
+
await sock.newsletterReactMessage(channelJid, serverMessageId, '❤️')
|
|
270
1770
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
if (!msg?.message || msg.key.fromMe) return;
|
|
1771
|
+
// Ambil pesan-pesan channel (untuk ditampilkan / diarsipkan)
|
|
1772
|
+
const messages = await sock.newsletterFetchMessages(channelJid, 20 /* count */)
|
|
274
1773
|
|
|
275
|
-
|
|
276
|
-
|
|
1774
|
+
// Berlangganan update real-time dari sebuah channel
|
|
1775
|
+
await sock.subscribeNewsletterUpdates(channelJid)
|
|
277
1776
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
}
|
|
1777
|
+
// Manajemen admin
|
|
1778
|
+
const adminCount = await sock.newsletterAdminCount(channelJid)
|
|
1779
|
+
await sock.newsletterChangeOwner(channelJid, newOwnerJid)
|
|
1780
|
+
await sock.newsletterDemote(channelJid, adminJid)
|
|
283
1781
|
|
|
284
|
-
|
|
1782
|
+
// Hapus channel
|
|
1783
|
+
await sock.newsletterDelete(channelJid)
|
|
285
1784
|
```
|
|
286
1785
|
|
|
287
|
-
|
|
1786
|
+
Event terkait channel yang perlu didengarkan: `newsletter.view`, `newsletter.reaction`, `newsletter-settings.update`, `newsletter-participants.update` (lihat [Sistem Event](#-sistem-event)).
|
|
288
1787
|
|
|
289
|
-
|
|
290
|
-
node index.js
|
|
291
|
-
```
|
|
1788
|
+
---
|
|
292
1789
|
|
|
293
|
-
|
|
1790
|
+
## 💬 Chats, Profil & Privasi
|
|
294
1791
|
|
|
295
|
-
|
|
1792
|
+
Layer `makeChatsSocket` menyediakan mayoritas method operasional sehari-hari.
|
|
296
1793
|
|
|
297
|
-
|
|
1794
|
+
### Manajemen Chat
|
|
298
1795
|
|
|
299
1796
|
```js
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
})
|
|
1797
|
+
// Arsipkan chat
|
|
1798
|
+
await sock.chatModify({ archive: true, lastMessages: [msg] }, jid)
|
|
1799
|
+
|
|
1800
|
+
// Pin / unpin chat
|
|
1801
|
+
await sock.chatModify({ pin: true }, jid)
|
|
1802
|
+
|
|
1803
|
+
// Mute chat 8 jam (dalam ms, atau `null` untuk unmute)
|
|
1804
|
+
await sock.chatModify({ mute: 8 * 60 * 60 * 1000 }, jid)
|
|
305
1805
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
1806
|
+
// Tandai chat sudah dibaca / belum dibaca
|
|
1807
|
+
await sock.chatModify({ markRead: true, lastMessages: [msg] }, jid)
|
|
1808
|
+
|
|
1809
|
+
// Hapus chat
|
|
1810
|
+
await sock.chatModify({ delete: true, lastMessages: [msg] }, jid)
|
|
1811
|
+
|
|
1812
|
+
// Bintangi / batalkan pesan tertentu
|
|
1813
|
+
await sock.star([{ id: msg.key.id, remoteJid: jid, fromMe: msg.key.fromMe }], true)
|
|
312
1814
|
```
|
|
313
1815
|
|
|
314
|
-
|
|
1816
|
+
### Label Chat & Pesan (WhatsApp Business)
|
|
315
1817
|
|
|
316
1818
|
```js
|
|
317
|
-
|
|
318
|
-
|
|
1819
|
+
await sock.addLabel(jid, { labelId1: 1, labelId2: 0 }) // 1 = tambah, 0 = hapus
|
|
1820
|
+
await sock.addChatLabel(jid, 'labelId')
|
|
1821
|
+
await sock.removeChatLabel(jid, 'labelId')
|
|
1822
|
+
await sock.addMessageLabel(jid, messageId, 'labelId')
|
|
1823
|
+
await sock.removeMessageLabel(jid, messageId, 'labelId')
|
|
319
1824
|
```
|
|
320
1825
|
|
|
321
|
-
|
|
1826
|
+
### Balasan Cepat (Quick Reply)
|
|
1827
|
+
|
|
1828
|
+
```js
|
|
1829
|
+
await sock.addOrEditQuickReply({ shortcut: '/halo', message: 'Halo! Ada yang bisa dibantu?' })
|
|
1830
|
+
await sock.removeQuickReply(timestamp)
|
|
1831
|
+
```
|
|
322
1832
|
|
|
323
|
-
|
|
324
|
-
> `printQRInTerminal` still exists in the type surface for compatibility, but it is **deprecated** in the current build. Prefer handling the `qr` value from `connection.update` yourself.
|
|
1833
|
+
### Kontak
|
|
325
1834
|
|
|
326
|
-
|
|
1835
|
+
```js
|
|
1836
|
+
await sock.addOrEditContact(jid, { firstName: 'Budi', fullName: 'Budi Santoso' })
|
|
1837
|
+
await sock.removeContact(jid)
|
|
1838
|
+
```
|
|
327
1839
|
|
|
328
|
-
|
|
1840
|
+
### Profil Akun Sendiri
|
|
329
1841
|
|
|
330
|
-
|
|
1842
|
+
```js
|
|
1843
|
+
// Ganti nama tampilan (push name)
|
|
1844
|
+
await sock.updateProfileName('Nama Bot Baru')
|
|
331
1845
|
|
|
332
|
-
|
|
1846
|
+
// Ganti status "about"
|
|
1847
|
+
await sock.updateProfileStatus('Sibuk melayani pengguna 🤖')
|
|
333
1848
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
makeBusinessSocket → Product catalog + business profile
|
|
341
|
-
makeCommunitiesSocket → Community CRUD + sub-groups
|
|
342
|
-
makeNewsletterSocket → Newsletter follow/unfollow/metadata
|
|
343
|
-
makeWASocket ← TOP LEVEL EXPORT
|
|
1849
|
+
// Ganti foto profil
|
|
1850
|
+
await sock.updateProfilePicture(sock.user.id, imageBuffer)
|
|
1851
|
+
await sock.removeProfilePicture(sock.user.id)
|
|
1852
|
+
|
|
1853
|
+
// Ambil URL foto profil (jid apa pun)
|
|
1854
|
+
const url = await sock.profilePictureUrl(jid, 'image') // 'preview' untuk thumbnail kecil
|
|
344
1855
|
```
|
|
345
1856
|
|
|
346
|
-
###
|
|
1857
|
+
### Pengaturan Privasi
|
|
347
1858
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
1859
|
+
```js
|
|
1860
|
+
await sock.updateLastSeenPrivacy('contacts') // all | contacts | contact_blacklist | none
|
|
1861
|
+
await sock.updateOnlinePrivacy('all') // all | match_last_seen
|
|
1862
|
+
await sock.updateProfilePicturePrivacy('contacts')
|
|
1863
|
+
await sock.updateStatusPrivacy('contacts')
|
|
1864
|
+
await sock.updateReadReceiptsPrivacy('all') // all | none
|
|
1865
|
+
await sock.updateGroupsAddPrivacy('contacts')
|
|
1866
|
+
await sock.updateCallPrivacy('all') // all | known
|
|
1867
|
+
await sock.updateMessagesPrivacy('all')
|
|
1868
|
+
await sock.updateDefaultDisappearingMode(7 * 24 * 60 * 60)
|
|
1869
|
+
await sock.updateBlockStatus(jid, 'block') // 'block' | 'unblock'
|
|
1870
|
+
|
|
1871
|
+
const settings = await sock.fetchPrivacySettings()
|
|
1872
|
+
const blocklist = await sock.fetchBlocklist()
|
|
1873
|
+
const duration = await sock.fetchDisappearingDuration(jid)
|
|
1874
|
+
const businessProfile = await sock.getBusinessProfile(jid)
|
|
1875
|
+
```
|
|
358
1876
|
|
|
359
|
-
###
|
|
1877
|
+
### Presence (Online/Typing)
|
|
360
1878
|
|
|
361
|
-
|
|
1879
|
+
```js
|
|
1880
|
+
await sock.sendPresenceUpdate('available') // online
|
|
1881
|
+
await sock.sendPresenceUpdate('unavailable') // offline
|
|
1882
|
+
await sock.sendPresenceUpdate('composing', jid) // "sedang mengetik..."
|
|
1883
|
+
await sock.sendPresenceUpdate('recording', jid) // "sedang merekam suara..."
|
|
1884
|
+
await sock.sendPresenceUpdate('paused', jid) // berhenti mengetik/merekam
|
|
1885
|
+
|
|
1886
|
+
// Berlangganan update presence seseorang (perlu untuk melihat "online"/"typing" mereka)
|
|
1887
|
+
await sock.presenceSubscribe(jid)
|
|
1888
|
+
```
|
|
362
1889
|
|
|
363
|
-
|
|
1890
|
+
### Call Link
|
|
364
1891
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
- `lib/index.d.ts`
|
|
369
|
-
- `lib/Socket/*.d.ts`
|
|
370
|
-
- `lib/Utils/*.d.ts`
|
|
371
|
-
- Consumers should treat this repo as a **ready-to-install runtime artifact**, not the authoring source tree
|
|
1892
|
+
```js
|
|
1893
|
+
const callToken = await sock.createCallLink('video') // atau 'audio'
|
|
1894
|
+
```
|
|
372
1895
|
|
|
373
|
-
###
|
|
1896
|
+
### Sinkronisasi App-State Manual
|
|
374
1897
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
5. Buffer events → process offline notifications → flush → `receivedPendingNotifications: true`
|
|
1898
|
+
```js
|
|
1899
|
+
// Paksa resync ulang seluruh app-state (kontak, chat, label, dst) — berguna jika data terasa basi
|
|
1900
|
+
await sock.resyncAppState(['critical_unblock_low', 'regular'], false)
|
|
1901
|
+
```
|
|
380
1902
|
|
|
381
1903
|
---
|
|
382
1904
|
|
|
383
|
-
##
|
|
1905
|
+
## ⬇️ Mengunduh & Memperbarui Media
|
|
384
1906
|
|
|
385
|
-
###
|
|
1907
|
+
### `downloadMediaMessage`
|
|
386
1908
|
|
|
387
1909
|
```js
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
1910
|
+
import { downloadMediaMessage } from '@vinzsocket/baileys'
|
|
1911
|
+
|
|
1912
|
+
sock.ev.on('messages.upsert', async ({ messages }) => {
|
|
1913
|
+
const msg = messages[0]
|
|
1914
|
+
const mediaType = Object.keys(msg.message || {})[0]
|
|
1915
|
+
if (['imageMessage', 'videoMessage', 'audioMessage', 'documentMessage', 'stickerMessage'].includes(mediaType)) {
|
|
1916
|
+
const buffer = await downloadMediaMessage(
|
|
1917
|
+
msg,
|
|
1918
|
+
'buffer', // atau 'stream'
|
|
1919
|
+
{},
|
|
1920
|
+
{
|
|
1921
|
+
logger: sock.logger,
|
|
1922
|
+
reuploadRequest: sock.updateMediaMessage
|
|
1923
|
+
}
|
|
1924
|
+
)
|
|
1925
|
+
fs.writeFileSync('./media-diterima', buffer)
|
|
1926
|
+
}
|
|
1927
|
+
})
|
|
1928
|
+
```
|
|
407
1929
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
logger,
|
|
412
|
-
browser: Browsers.windows("Chrome"),
|
|
413
|
-
});
|
|
1930
|
+
Parameter ke-4 (`ctx`) menyediakan `reuploadRequest` — jika media sudah kedaluwarsa di server WA (biasanya setelah beberapa hari/re-fetch gagal), Baileys otomatis meminta pengirim untuk mengunggah ulang media tersebut lewat mekanisme *media retry*.
|
|
1931
|
+
|
|
1932
|
+
### `updateMediaMessage`
|
|
414
1933
|
|
|
415
|
-
|
|
416
|
-
if (qr) {
|
|
417
|
-
// QR code available (fallback)
|
|
418
|
-
}
|
|
419
|
-
});
|
|
1934
|
+
Dipakai secara internal oleh `downloadMediaMessage` saat retry, tapi bisa dipanggil manual jika Anda tahu sebuah media perlu di-refresh URL/direct path-nya:
|
|
420
1935
|
|
|
421
|
-
|
|
422
|
-
const
|
|
423
|
-
|
|
1936
|
+
```js
|
|
1937
|
+
const refreshed = await sock.updateMediaMessage(msg)
|
|
1938
|
+
// msg.message.imageMessage.url sekarang sudah diperbarui, siap didownload ulang
|
|
424
1939
|
```
|
|
425
1940
|
|
|
426
|
-
|
|
1941
|
+
---
|
|
1942
|
+
|
|
1943
|
+
## 🛡️ Penanganan Error
|
|
427
1944
|
|
|
428
|
-
|
|
429
|
-
import { useMultiFileAuthState } from "ourin-baileys";
|
|
1945
|
+
Harps-Baileys secara konsisten melempar error sebagai instance **`Boom`** (dari `@hapi/boom`), yang membawa `error.output.statusCode` mirip HTTP status code.
|
|
430
1946
|
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
1947
|
+
```js
|
|
1948
|
+
import { Boom } from '@hapi/boom'
|
|
1949
|
+
import { DisconnectReason } from '@vinzsocket/baileys'
|
|
1950
|
+
|
|
1951
|
+
sock.ev.on('connection.update', (update) => {
|
|
1952
|
+
const { connection, lastDisconnect } = update
|
|
1953
|
+
if (connection === 'close') {
|
|
1954
|
+
const statusCode = (lastDisconnect?.error instanceof Boom)
|
|
1955
|
+
? lastDisconnect.error.output?.statusCode
|
|
1956
|
+
: undefined
|
|
1957
|
+
|
|
1958
|
+
switch (statusCode) {
|
|
1959
|
+
case DisconnectReason.badSession:
|
|
1960
|
+
console.log('Sesi rusak, hapus folder auth dan pairing ulang.')
|
|
1961
|
+
break
|
|
1962
|
+
case DisconnectReason.connectionClosed:
|
|
1963
|
+
case DisconnectReason.connectionLost:
|
|
1964
|
+
case DisconnectReason.timedOut:
|
|
1965
|
+
console.log('Koneksi putus sementara, reconnect otomatis.')
|
|
1966
|
+
startBot()
|
|
1967
|
+
break
|
|
1968
|
+
case DisconnectReason.connectionReplaced:
|
|
1969
|
+
console.log('Sesi diambil alih perangkat lain, hentikan instance ini.')
|
|
1970
|
+
break
|
|
1971
|
+
case DisconnectReason.loggedOut:
|
|
1972
|
+
console.log('Akun logout dari HP, perlu pairing ulang dari nol.')
|
|
1973
|
+
break
|
|
1974
|
+
case DisconnectReason.restartRequired:
|
|
1975
|
+
console.log('WhatsApp minta restart socket, reconnect.')
|
|
1976
|
+
startBot()
|
|
1977
|
+
break
|
|
1978
|
+
case DisconnectReason.multideviceMismatch:
|
|
1979
|
+
console.log('Perangkat tidak mendukung multi-device, cek versi WA.')
|
|
1980
|
+
break
|
|
1981
|
+
default:
|
|
1982
|
+
console.log('Terputus, alasan tidak diketahui:', statusCode)
|
|
1983
|
+
startBot()
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
})
|
|
435
1987
|
```
|
|
436
1988
|
|
|
437
|
-
**
|
|
1989
|
+
**Praktik yang disarankan saat memanggil method socket:**
|
|
438
1990
|
|
|
439
1991
|
```js
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
1992
|
+
try {
|
|
1993
|
+
await sock.sendMessage(jid, { text: 'Halo' })
|
|
1994
|
+
} catch (err) {
|
|
1995
|
+
if (err instanceof Boom) {
|
|
1996
|
+
console.error('Gagal kirim pesan:', err.output?.statusCode, err.message)
|
|
1997
|
+
} else {
|
|
1998
|
+
console.error('Error tidak terduga:', err)
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
```
|
|
445
2002
|
|
|
446
|
-
|
|
447
|
-
const keyStoreData = new Map();
|
|
2003
|
+
---
|
|
448
2004
|
|
|
449
|
-
|
|
2005
|
+
## 🔁 Reliabilitas & Retry
|
|
450
2006
|
|
|
451
|
-
|
|
452
|
-
get: async (type, ids) => {
|
|
453
|
-
const data = {};
|
|
454
|
-
for (const id of ids) {
|
|
455
|
-
data[id] = keyStoreData.get(`${type}:${id}`);
|
|
456
|
-
}
|
|
457
|
-
return data;
|
|
458
|
-
},
|
|
459
|
-
set: async (data) => {
|
|
460
|
-
for (const category in data) {
|
|
461
|
-
for (const id in data[category]) {
|
|
462
|
-
const value = data[category][id];
|
|
463
|
-
const key = `${category}:${id}`;
|
|
464
|
-
if (value == null) keyStoreData.delete(key);
|
|
465
|
-
else keyStoreData.set(key, value);
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
},
|
|
469
|
-
});
|
|
2007
|
+
Beberapa mekanisme bawaan yang membuat koneksi lebih tahan banting terhadap gangguan jaringan/protokol:
|
|
470
2008
|
|
|
471
|
-
|
|
2009
|
+
- **`enableAutoSessionRecreation`** (default `true`) — otomatis membuat ulang sesi Signal Protocol jika terdeteksi rusak/kadaluarsa saat decrypt gagal, tanpa perlu intervensi manual.
|
|
2010
|
+
- **`message-retry-manager`** (`Utils/message-retry-manager.js`) — melacak percobaan ulang pengiriman pesan yang gagal terkirim ke device tertentu (di luar batas `maxMsgRetryCount`, pesan dianggap gagal permanen dan tidak diulang lagi).
|
|
2011
|
+
- **`transactionOpts`** — retry policy untuk transaksi app-state (`maxCommitRetries`, `delayBetweenTriesMs`) saat terjadi konflik konkuren pada sinkronisasi kontak/chat/label.
|
|
2012
|
+
- **`offline-node-processor`** (`Utils/offline-node-processor.js`) — memproses antrian node yang sempat diterima saat koneksi terputus (mis. pesan yang masuk saat bot offline sesaat) setelah koneksi pulih.
|
|
2013
|
+
- **`identity-change-handler`** (`Utils/identity-change-handler.js`) — menangani notifikasi perubahan identitas Signal (mis. lawan bicara ganti HP/install ulang WhatsApp), memastikan pesan berikutnya tetap terenkripsi dengan key yang benar alih-alih gagal diam-diam.
|
|
2014
|
+
- **`stanza-ack`** (`Utils/stanza-ack.js`) — melacak acknowledgment level-protokol dari server untuk setiap node yang dikirim, dengan timeout & retry.
|
|
2015
|
+
- **`pre-key-manager`** (`Utils/pre-key-manager.js`) — mengelola pool pre-key Signal Protocol, otomatis mengisi ulang (`MIN_PREKEY_COUNT: 5`, target `INITIAL_PREKEY_COUNT: 812`) saat stok menipis agar sesi enkripsi baru selalu bisa dibuat.
|
|
472
2016
|
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
2017
|
+
Untuk bot produksi, kombinasi berikut biasanya paling stabil:
|
|
2018
|
+
|
|
2019
|
+
```js
|
|
2020
|
+
const sock = makeWASocket({
|
|
2021
|
+
auth: state,
|
|
2022
|
+
enableAutoSessionRecreation: true,
|
|
2023
|
+
enableRecentMessageCache: true,
|
|
2024
|
+
getMessage: async (key) => await myMessageStore.get(key), // penting untuk retry & decrypt ulang
|
|
2025
|
+
cachedGroupMetadata: async (jid) => await myGroupCache.get(jid),
|
|
2026
|
+
transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3000 }
|
|
2027
|
+
})
|
|
482
2028
|
```
|
|
483
2029
|
|
|
484
|
-
|
|
2030
|
+
---
|
|
485
2031
|
|
|
486
|
-
|
|
2032
|
+
## 🗝️ Referensi Shorthand Field `sendMessage`
|
|
2033
|
+
|
|
2034
|
+
Tabel lengkap semua field shorthand yang dikenali `generateWAMessageContent()` pada parameter `content` dari `sendMessage(jid, content)`, untuk dijadikan referensi cepat saat lupa nama field yang tepat.
|
|
2035
|
+
|
|
2036
|
+
| Field | Menghasilkan Tipe Pesan | Field Pendamping |
|
|
2037
|
+
|---|---|---|
|
|
2038
|
+
| `text` | `conversation` / `extendedTextMessage` | `linkPreview`, `mentions`, `mentionAll`, `backgroundColor`, `font` |
|
|
2039
|
+
| `image` | `imageMessage` | `caption`, `viewOnce`, `jpegThumbnail` |
|
|
2040
|
+
| `video` | `videoMessage` | `caption`, `gifPlayback`, `ptv`, `viewOnce`, `seconds` |
|
|
2041
|
+
| `audio` | `audioMessage` | `ptt`, `mimetype`, `seconds` |
|
|
2042
|
+
| `sticker` | `stickerMessage` | — |
|
|
2043
|
+
| `document` | `documentMessage` | `mimetype`, `fileName`, `caption`, `jpegThumbnail` |
|
|
2044
|
+
| `contacts` | `contactMessage` / `contactsArrayMessage` | `displayName` |
|
|
2045
|
+
| `location` | `locationMessage` | `name`, `address` |
|
|
2046
|
+
| `react` | `reactionMessage` | `key` |
|
|
2047
|
+
| `poll` | `pollCreationMessage(V2/V3)` | `values`, `selectableCount`, `toAnnouncementGroup` |
|
|
2048
|
+
| `event` | `eventMessage` | `startDate`, `endDate`, `location`, `call`, `extraGuestsAllowed` |
|
|
2049
|
+
| `delete` | `protocolMessage` (REVOKE) | — |
|
|
2050
|
+
| `edit` | `protocolMessage` (MESSAGE_EDIT) | `text` |
|
|
2051
|
+
| `pin` | `pinInChatMessage` | `type`, `time` |
|
|
2052
|
+
| `forward` | (menyalin `message` dari sumber) | `force` |
|
|
2053
|
+
| `buttons` / `templateButtons` / `interactiveButtons` | `interactiveMessage.nativeFlowMessage` | `footer`, `image`/`video` header |
|
|
2054
|
+
| `sections` | `listMessage` | `title`, `buttonText`, `footer` |
|
|
2055
|
+
| `cards` | `interactiveMessage.carouselMessage` | `footer` |
|
|
2056
|
+
| `requestPaymentMessage` | `requestPaymentMessage` | `amount`, `currency`, `note`/`sticker` |
|
|
2057
|
+
| `productMessage` | `interactiveMessage` (viewOnce, header produk) | `title`, `thumbnail`, `buttons` |
|
|
2058
|
+
| `albumMessage` | `albumMessage` + item terpisah | array item media |
|
|
2059
|
+
| `pollResultMessage` | `pollResultMessage` | `name`, `pollVotes` |
|
|
2060
|
+
| `groupStatusMessage` | `groupStatusMessageV2` (khusus di grup) | `text`/`image`/`video`/`audio`/`sticker`/`document`/`card`/`message`/`raw` |
|
|
2061
|
+
| `multiSelectMessage` | `interactiveMessage` (multi `single_select`) | `selectors`, `extraButtons` |
|
|
2062
|
+
| `nestedListMessage` | `listMessage` (auto-flatten) | `sections` |
|
|
2063
|
+
|
|
2064
|
+
### Mentions & Konteks
|
|
2065
|
+
|
|
2066
|
+
| Field | Keterangan |
|
|
2067
|
+
|---|---|
|
|
2068
|
+
| `mentions` | Array JID yang di-mention di dalam teks. |
|
|
2069
|
+
| `mentionAll` | `true` untuk tag semua anggota grup tanpa menuliskan JID satu-satu. |
|
|
2070
|
+
| `quoted` | Bukan bagian dari `content`, melainkan opsi kedua `sendMessage` — pesan yang di-reply. |
|
|
2071
|
+
| `contextInfo` | Override manual `contextInfo` mentah (jarang perlu diisi langsung). |
|
|
2072
|
+
|
|
2073
|
+
### Aturan Prioritas Deteksi
|
|
2074
|
+
|
|
2075
|
+
`generateWAMessageContent()` memeriksa field dalam urutan tertentu — jika beberapa field "utama" hadir sekaligus (jarang terjadi, tapi penting diketahui saat debugging), prioritas umumnya mengikuti urutan: pesan sistem (`delete`/`edit`/`pin`/`react`) → pesan interaktif eksklusif fork (`groupStatusMessage`, `multiSelectMessage`, `nestedListMessage`, `requestPaymentMessage`, `productMessage`, `albumMessage`, `pollResultMessage`) → shorthand interaktif standar (`buttons`/`sections`/`cards`) → media dasar (`image`/`video`/`audio`/`sticker`/`document`) → `text` sebagai fallback paling akhir.
|
|
487
2076
|
|
|
488
|
-
|
|
489
|
-
- `initAuthCreds()` + custom `SignalKeyStore` for DB/Redis/in-memory persistence
|
|
490
|
-
- `makeCacheableSignalKeyStore()` when you want faster repeated key access with caching
|
|
2077
|
+
---
|
|
491
2078
|
|
|
492
|
-
|
|
493
|
-
|
|
2079
|
+
## 🧾 Tipe Data (Types) Penting
|
|
2080
|
+
|
|
2081
|
+
Semua definisi TypeScript diekspor dari `lib/Types/`. Berikut ringkasan tipe-tipe yang paling sering dipakai sehari-hari (lihat file `.d.ts` masing-masing untuk detail penuh):
|
|
2082
|
+
|
|
2083
|
+
| Tipe | Lokasi | Ringkasan |
|
|
2084
|
+
|---|---|---|
|
|
2085
|
+
| `WASocket` | `lib/index.d.ts` | Tipe hasil `ReturnType<typeof makeWASocket>` — objek `sock` lengkap. |
|
|
2086
|
+
| `WAMessage` | `Types/Message.d.ts` | Alias untuk `proto.IWebMessageInfo` — bentuk pesan lengkap dengan `key`, `message`, `messageTimestamp`, dst. |
|
|
2087
|
+
| `WAMessageKey` | `Types/Message.d.ts` | `{ remoteJid, fromMe, id, participant? }` — identitas unik sebuah pesan. |
|
|
2088
|
+
| `WAMessageContent` | `Types/Message.d.ts` | Alias `proto.IMessage` — isi pesan (`conversation`, `imageMessage`, dst). |
|
|
2089
|
+
| `AnyMessageContent` | `Types/Message.d.ts` | Union type dari semua shorthand yang diterima `sendMessage()` (`text`, `image`, `poll`, `buttons`, dst). |
|
|
2090
|
+
| `MiscMessageGenerationOptions` | `Types/Message.d.ts` | Opsi kedua `sendMessage()` — `quoted`, `mentions`, `ephemeralExpiration`, dst. |
|
|
2091
|
+
| `AuthenticationCreds` | `Types/Auth.d.ts` | Struktur kredensial identitas akun (`noiseKey`, `signedIdentityKey`, `me`, `account`, dst). |
|
|
2092
|
+
| `AuthenticationState` | `Types/Auth.d.ts` | `{ creds, keys }` — bentuk yang diterima config `auth`. |
|
|
2093
|
+
| `SignalDataTypeMap` | `Types/Auth.d.ts` | Union tipe key Signal (`pre-key`, `session`, `sender-key`, `app-state-sync-key`, dst) yang harus didukung `keys.get`/`keys.set`. |
|
|
2094
|
+
| `GroupMetadata` | `Types/GroupMetadata.d.ts` | Bentuk hasil `groupMetadata()` / `groupFetchAllParticipating()`. |
|
|
2095
|
+
| `GroupParticipant` | `Types/GroupMetadata.d.ts` | `{ id, admin, jid?, phoneNumber? }` — satu baris anggota grup. |
|
|
2096
|
+
| `Chat` | `Types/Chat.d.ts` | Representasi chat dalam sinkronisasi app-state. |
|
|
2097
|
+
| `Contact` | `Types/Contact.d.ts` | `{ id, name?, notify?, verifiedName?, imgUrl?, status? }`. |
|
|
2098
|
+
| `PresenceData` | `Types/Chat.d.ts` | `{ lastKnownPresence, lastSeen? }`. |
|
|
2099
|
+
| `BaileysEventMap` | `Types/Events.d.ts` | Interface pemetaan nama event → tipe payloadnya (dipakai untuk type-safety `sock.ev.on(...)`). |
|
|
2100
|
+
| `WAUSyncQuery` / `USyncUser` | `WAUSync/*.d.ts` | Query batch untuk cek status device banyak user sekaligus (dipakai internal saat kirim pesan). |
|
|
2101
|
+
| `BusinessProfile` | `Types/Bussines.d.ts` | Struktur profil bisnis (`description`, `email`, `website`, `category`, dst). |
|
|
2102
|
+
| `WAMessageStubType` | `Types/index.d.ts` | Enum tipe pesan "stub" (event sistem seperti ganti subjek grup, anggota keluar, dst — muncul sebagai pesan tanpa `message` asli). |
|
|
2103
|
+
| `WAMessageAddressingMode` | `Types/index.d.ts` | `'pn'` atau `'lid'` — mode pengalamatan grup (memengaruhi bagaimana `participant` JID terbentuk). |
|
|
2104
|
+
| `DisconnectReason` | `Types/index.d.ts` | Enum kode alasan disconnect (lihat tabel di bagian [Penanganan Error](#-penanganan-error)). |
|
|
2105
|
+
|
|
2106
|
+
### Type-Safety untuk Event Listener (TypeScript)
|
|
2107
|
+
|
|
2108
|
+
```ts
|
|
2109
|
+
import type { BaileysEventMap } from '@vinzsocket/baileys'
|
|
2110
|
+
|
|
2111
|
+
sock.ev.on('messages.upsert', (data) => {
|
|
2112
|
+
// `data` otomatis ter-infer sebagai BaileysEventMap['messages.upsert']
|
|
2113
|
+
const { messages, type } = data
|
|
2114
|
+
})
|
|
2115
|
+
```
|
|
494
2116
|
|
|
495
|
-
|
|
2117
|
+
### Enum `DisconnectReason` Lengkap
|
|
496
2118
|
|
|
497
2119
|
```js
|
|
498
|
-
import {
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
2120
|
+
import { DisconnectReason } from '@vinzsocket/baileys'
|
|
2121
|
+
|
|
2122
|
+
console.log(DisconnectReason)
|
|
2123
|
+
// {
|
|
2124
|
+
// connectionClosed: 428,
|
|
2125
|
+
// connectionLost: 408,
|
|
2126
|
+
// connectionReplaced: 440,
|
|
2127
|
+
// timedOut: 408,
|
|
2128
|
+
// loggedOut: 401,
|
|
2129
|
+
// badSession: 500,
|
|
2130
|
+
// restartRequired: 515,
|
|
2131
|
+
// multideviceMismatch: 411,
|
|
2132
|
+
// forbidden: 403,
|
|
2133
|
+
// unavailableService: 503
|
|
2134
|
+
// }
|
|
2135
|
+
```
|
|
2136
|
+
|
|
2137
|
+
> Catatan: `connectionLost` dan `timedOut` sengaja memakai kode HTTP status yang sama (`408`) — bedakan lewat pesan error (`lastDisconnect.error.message`) jika Anda perlu membedakan penyebabnya secara presisi.
|
|
2138
|
+
|
|
2139
|
+
---
|
|
2140
|
+
|
|
2141
|
+
## 🧬 WAProto
|
|
2142
|
+
|
|
2143
|
+
`WAProto/index.js` mengekspor `proto` — hasil kompilasi definisi [Protocol Buffers](https://protobuf.dev/) resmi WhatsApp (`WAProto.proto`) via `protobufjs`. Semua struktur pesan WhatsApp pada level paling mentah (`Message`, `WebMessageInfo`, `HistorySync`, `SyncdPatch`, dst) berasal dari sini.
|
|
2144
|
+
|
|
2145
|
+
```js
|
|
2146
|
+
import { proto } from '@vinzsocket/baileys'
|
|
2147
|
+
|
|
2148
|
+
// Membuat instance pesan protobuf secara manual (jarang dibutuhkan langsung,
|
|
2149
|
+
// biasanya sudah dibungkus oleh generateWAMessageContent dsb)
|
|
2150
|
+
const reaction = proto.Message.ReactionMessage.create({
|
|
2151
|
+
key: msg.key,
|
|
2152
|
+
text: '🔥',
|
|
2153
|
+
senderTimestampMs: Date.now()
|
|
2154
|
+
})
|
|
2155
|
+
|
|
2156
|
+
// Enum penting yang sering dipakai
|
|
2157
|
+
console.log(proto.Message.ProtocolMessage.Type.REVOKE)
|
|
2158
|
+
console.log(proto.Message.ListMessage.ListType.SINGLE_SELECT)
|
|
2159
|
+
console.log(proto.HistorySync.HistorySyncType.FULL)
|
|
2160
|
+
console.log(proto.MediaRetryNotification.ResultType.SUCCESS)
|
|
2161
|
+
```
|
|
2162
|
+
|
|
2163
|
+
Regenerasi definisi protobuf (untuk maintainer, jika WhatsApp merilis skema baru):
|
|
504
2164
|
|
|
505
|
-
|
|
506
|
-
|
|
2165
|
+
```bash
|
|
2166
|
+
npm run gen:protobuf # menjalankan WAProto/GenerateStatics.sh
|
|
507
2167
|
```
|
|
508
2168
|
|
|
2169
|
+
Anda **tidak perlu** melakukan ini sebagai konsumen library — cukup update ke versi terbaru `@vinzsocket/baileys` saat WhatsApp mengubah protokolnya.
|
|
2170
|
+
|
|
509
2171
|
---
|
|
510
2172
|
|
|
511
|
-
|
|
2173
|
+
## 🧩 Contoh Lengkap: Struktur Bot dengan Plugin
|
|
512
2174
|
|
|
513
|
-
|
|
2175
|
+
Pola umum yang dipakai di ekosistem Harps-MD — memisahkan koneksi socket dari logic per-perintah (plugin), sehingga mudah dikembangkan berkelanjutan.
|
|
514
2176
|
|
|
515
|
-
|
|
2177
|
+
```js
|
|
2178
|
+
// index.js — entry point
|
|
2179
|
+
import makeWASocket, { useMultiFileAuthState, DisconnectReason } from '@vinzsocket/baileys'
|
|
2180
|
+
import { Boom } from '@hapi/boom'
|
|
2181
|
+
import { handleMessage } from './handler.js'
|
|
2182
|
+
|
|
2183
|
+
async function connectToWhatsApp() {
|
|
2184
|
+
const { state, saveCreds } = await useMultiFileAuthState('sesi_auth')
|
|
2185
|
+
|
|
2186
|
+
const sock = makeWASocket({
|
|
2187
|
+
auth: state,
|
|
2188
|
+
syncFullHistory: false,
|
|
2189
|
+
markOnlineOnConnect: true,
|
|
2190
|
+
getMessage: async () => undefined
|
|
2191
|
+
})
|
|
2192
|
+
|
|
2193
|
+
sock.ev.on('creds.update', saveCreds)
|
|
2194
|
+
|
|
2195
|
+
sock.ev.on('connection.update', (update) => {
|
|
2196
|
+
const { connection, lastDisconnect, qr } = update
|
|
2197
|
+
if (qr) console.log('Scan QR ini:', qr)
|
|
2198
|
+
if (connection === 'close') {
|
|
2199
|
+
const code = (lastDisconnect?.error instanceof Boom) ? lastDisconnect.error.output?.statusCode : 0
|
|
2200
|
+
if (code !== DisconnectReason.loggedOut) {
|
|
2201
|
+
connectToWhatsApp()
|
|
2202
|
+
} else {
|
|
2203
|
+
console.log('Logged out. Hapus folder sesi_auth dan pairing ulang.')
|
|
2204
|
+
}
|
|
2205
|
+
}
|
|
2206
|
+
})
|
|
2207
|
+
|
|
2208
|
+
sock.ev.on('messages.upsert', async (m) => handleMessage(sock, m))
|
|
2209
|
+
|
|
2210
|
+
return sock
|
|
2211
|
+
}
|
|
2212
|
+
|
|
2213
|
+
connectToWhatsApp()
|
|
2214
|
+
```
|
|
516
2215
|
|
|
517
2216
|
```js
|
|
518
|
-
|
|
2217
|
+
// handler.js — router perintah sederhana
|
|
2218
|
+
const commands = new Map()
|
|
2219
|
+
|
|
2220
|
+
commands.set('ping', async (sock, msg) => {
|
|
2221
|
+
await sock.sendMessage(msg.key.remoteJid, { text: 'pong 🏓' }, { quoted: msg })
|
|
2222
|
+
})
|
|
2223
|
+
|
|
2224
|
+
commands.set('menu', async (sock, msg) => {
|
|
2225
|
+
await sock.sendMessage(msg.key.remoteJid, {
|
|
2226
|
+
text: 'Pilih menu:',
|
|
2227
|
+
footer: 'Harps-MD',
|
|
2228
|
+
buttons: [
|
|
2229
|
+
{ id: 'ping', text: '🏓 Ping' },
|
|
2230
|
+
{ id: 'info', text: 'ℹ️ Info' }
|
|
2231
|
+
]
|
|
2232
|
+
}, { quoted: msg })
|
|
2233
|
+
})
|
|
2234
|
+
|
|
2235
|
+
export async function handleMessage(sock, { messages, type }) {
|
|
2236
|
+
if (type !== 'notify') return
|
|
2237
|
+
const msg = messages[0]
|
|
2238
|
+
if (!msg.message || msg.key.fromMe) return
|
|
519
2239
|
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
2240
|
+
const text =
|
|
2241
|
+
msg.message.conversation ||
|
|
2242
|
+
msg.message.extendedTextMessage?.text ||
|
|
2243
|
+
msg.message.buttonsResponseMessage?.selectedButtonId ||
|
|
2244
|
+
msg.message.templateButtonReplyMessage?.selectedId ||
|
|
2245
|
+
msg.message.listResponseMessage?.singleSelectReply?.selectedRowId ||
|
|
2246
|
+
''
|
|
2247
|
+
|
|
2248
|
+
const prefix = '.'
|
|
2249
|
+
if (!text.startsWith(prefix)) return
|
|
2250
|
+
|
|
2251
|
+
const [cmd] = text.slice(prefix.length).trim().split(/\s+/)
|
|
2252
|
+
const handler = commands.get(cmd.toLowerCase())
|
|
2253
|
+
if (handler) {
|
|
2254
|
+
try {
|
|
2255
|
+
await handler(sock, msg)
|
|
2256
|
+
} catch (err) {
|
|
2257
|
+
console.error(`Error di command "${cmd}":`, err)
|
|
2258
|
+
await sock.sendMessage(msg.key.remoteJid, { text: '⚠️ Terjadi kesalahan saat memproses perintah.' })
|
|
2259
|
+
}
|
|
2260
|
+
}
|
|
525
2261
|
}
|
|
526
2262
|
```
|
|
527
2263
|
|
|
528
|
-
**
|
|
2264
|
+
**Catatan penting soal deteksi balasan tombol:** karena Harps-Baileys hanya menghasilkan Native Flow modern, balasan tombol/list akan masuk lewat salah satu dari:
|
|
2265
|
+
|
|
2266
|
+
- `msg.message.interactiveResponseMessage?.nativeFlowResponseMessage` — untuk balasan `quick_reply`, `single_select`, dst dari `interactiveMessage`. Payload aslinya berupa string JSON di field `.paramsJson` yang perlu di-`JSON.parse()`.
|
|
2267
|
+
- `msg.message.buttonsResponseMessage?.selectedButtonId` — untuk balasan yang dibuat dari shorthand `buttons` klasik (jika masih terdeteksi sebagai legacy oleh WhatsApp Anda sendiri — jarang terjadi di client terbaru).
|
|
2268
|
+
- `msg.message.listResponseMessage?.singleSelectReply?.selectedRowId` — untuk balasan `nestedListMessage` / list legacy.
|
|
2269
|
+
|
|
2270
|
+
Contoh parsing `nativeFlowResponseMessage`:
|
|
529
2271
|
|
|
530
2272
|
```js
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
audioSource: "silence", // Atau "mic" / "file" (butuh audio-feeder & ffmpeg)
|
|
536
|
-
});
|
|
537
|
-
|
|
538
|
-
call.on("ringing", () => console.log("Berdering..."));
|
|
539
|
-
call.on("connected", () => console.log("Terhubung!"));
|
|
540
|
-
call.on("ended", (reason) => console.log("Panggilan berakhir:", reason));
|
|
541
|
-
|
|
542
|
-
// Menunggu hingga panggilan selesai
|
|
543
|
-
await call.waitForEnd();
|
|
544
|
-
} catch (e) {
|
|
545
|
-
console.error("Gagal menelpon:", e);
|
|
2273
|
+
const nfResponse = msg.message?.interactiveResponseMessage?.nativeFlowResponseMessage
|
|
2274
|
+
if (nfResponse) {
|
|
2275
|
+
const params = JSON.parse(nfResponse.paramsJson)
|
|
2276
|
+
console.log('User memilih:', params.id || params.selectedRowId || params)
|
|
546
2277
|
}
|
|
547
2278
|
```
|
|
548
2279
|
|
|
549
2280
|
---
|
|
550
2281
|
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
```js
|
|
554
|
-
// Text
|
|
555
|
-
await sock.sendMessage(jid, { text: "Hello!" });
|
|
2282
|
+
## 🔄 Migrasi dari Baileys Upstream / Fork Lain
|
|
556
2283
|
|
|
557
|
-
|
|
558
|
-
await sock.sendMessage(jid, {
|
|
559
|
-
text: "Hello @628xxx!",
|
|
560
|
-
mentions: ["628xxx@s.whatsapp.net"],
|
|
561
|
-
});
|
|
2284
|
+
Harps-Baileys mempertahankan kompatibilitas API sebisa mungkin, tapi ada beberapa poin yang perlu diperhatikan saat migrasi:
|
|
562
2285
|
|
|
563
|
-
|
|
564
|
-
await sock.sendMessage(jid, {
|
|
565
|
-
image: { url: "./photo.jpg" },
|
|
566
|
-
caption: "A photo",
|
|
567
|
-
});
|
|
2286
|
+
### 1. Ganti Import
|
|
568
2287
|
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
gifPlayback: false,
|
|
574
|
-
});
|
|
2288
|
+
```diff
|
|
2289
|
+
- import makeWASocket from '@whiskeysockets/baileys'
|
|
2290
|
+
+ import makeWASocket from '@vinzsocket/baileys'
|
|
2291
|
+
```
|
|
575
2292
|
|
|
576
|
-
|
|
577
|
-
await sock.sendMessage(jid, {
|
|
578
|
-
audio: { url: "./audio.ogg" },
|
|
579
|
-
mimetype: "audio/ogg; codecs=opus",
|
|
580
|
-
ptt: true, // voice note
|
|
581
|
-
});
|
|
2293
|
+
Semua named export (`useMultiFileAuthState`, `DisconnectReason`, `Browsers`, `downloadMediaMessage`, `proto`, dst) tetap memakai nama yang sama, jadi umumnya cukup mengganti path import.
|
|
582
2294
|
|
|
583
|
-
|
|
584
|
-
await sock.sendMessage(jid, {
|
|
585
|
-
sticker: { url: "./sticker.webp" },
|
|
586
|
-
});
|
|
587
|
-
|
|
588
|
-
// Sticker pack
|
|
589
|
-
await sock.sendMessage(
|
|
590
|
-
jid,
|
|
591
|
-
makeStickerPack({
|
|
592
|
-
name: "Ourin Starter Pack",
|
|
593
|
-
publisher: "Ourin",
|
|
594
|
-
description: "Starter sticker pack",
|
|
595
|
-
stickers: [
|
|
596
|
-
{ url: "./stickers/1.webp", emojis: ["🔥"] },
|
|
597
|
-
{ url: "./stickers/2.webp", emojis: ["😎"] },
|
|
598
|
-
],
|
|
599
|
-
cover: { url: "./stickers/cover.webp" },
|
|
600
|
-
}),
|
|
601
|
-
);
|
|
602
|
-
|
|
603
|
-
// Document
|
|
604
|
-
await sock.sendMessage(jid, {
|
|
605
|
-
document: { url: "./file.pdf" },
|
|
606
|
-
fileName: "document.pdf",
|
|
607
|
-
mimetype: "application/pdf",
|
|
608
|
-
});
|
|
2295
|
+
### 2. `package.json` Harus Konsisten
|
|
609
2296
|
|
|
610
|
-
|
|
611
|
-
await sock.sendMessage(jid, {
|
|
612
|
-
react: { key: msg.key, text: "👍" },
|
|
613
|
-
});
|
|
2297
|
+
Jika bot Anda sebelumnya bercampur antara beberapa fork Baileys (mis. bekas migrasi dari `@kevin-b2t/baileys`, `@whiskeysockets/baileys`, dsb), pastikan **hanya satu** entri Baileys yang terpasang di `package.json` dan tidak ada duplikat di `node_modules` (bisa dicek dengan `npm ls baileys` atau memeriksa symlink di `node_modules/.bin`). Package name yang salah (mis. import dari fork A tapi `package.json` menunjuk fork B) adalah penyebab umum kegagalan silent — modul termuat tanpa error, tapi API yang dipakai tidak ada/berbeda perilaku.
|
|
614
2298
|
|
|
615
|
-
|
|
616
|
-
await sock.sendMessage(jid, {
|
|
617
|
-
location: {
|
|
618
|
-
degreesLatitude: -6.2,
|
|
619
|
-
degreesLongitude: 106.8,
|
|
620
|
-
name: "Jakarta",
|
|
621
|
-
},
|
|
622
|
-
});
|
|
623
|
-
|
|
624
|
-
// Contact
|
|
625
|
-
await sock.sendMessage(jid, {
|
|
626
|
-
contacts: {
|
|
627
|
-
displayName: "Contacts",
|
|
628
|
-
contacts: [
|
|
629
|
-
{ vcard: "BEGIN:VCARD\nVERSION:3.0\nFN:John\nTEL:+628xxx\nEND:VCARD" },
|
|
630
|
-
],
|
|
631
|
-
},
|
|
632
|
-
});
|
|
633
|
-
|
|
634
|
-
// Poll
|
|
635
|
-
await sock.sendMessage(jid, {
|
|
636
|
-
poll: {
|
|
637
|
-
name: "Vote!",
|
|
638
|
-
values: ["Option A", "Option B", "Option C"],
|
|
639
|
-
selectableCount: 1,
|
|
640
|
-
},
|
|
641
|
-
});
|
|
642
|
-
|
|
643
|
-
// Forward message
|
|
644
|
-
await sock.sendMessage(jid, {
|
|
645
|
-
forward: msg,
|
|
646
|
-
forwardingScore: 1,
|
|
647
|
-
isForwarded: true,
|
|
648
|
-
});
|
|
2299
|
+
### 3. Legacy Buttons Otomatis Dikonversi
|
|
649
2300
|
|
|
650
|
-
|
|
651
|
-
await sock.sendMessage(jid, { delete: msg.key });
|
|
2301
|
+
Kode lama yang memakai `buttonsMessage` atau `templateButtons` langsung (bukan lewat shorthand `sendMessage`) tetap bisa jalan, tapi disarankan pindah ke shorthand `buttons` / `nfButtonXxx` karena WhatsApp sudah men-deprecate rendering `buttonsMessage` mentah di banyak versi client.
|
|
652
2302
|
|
|
653
|
-
|
|
654
|
-
await sock.sendMessage(jid, {
|
|
655
|
-
text: "Edited text",
|
|
656
|
-
edit: msg.key,
|
|
657
|
-
});
|
|
658
|
-
```
|
|
2303
|
+
### 4. Native Flow Button Payload Tetap Sama
|
|
659
2304
|
|
|
660
|
-
|
|
2305
|
+
Jika fork lama Anda sudah memakai `interactiveMessage.nativeFlowMessage.buttons`, format `{ name, buttonParamsJson }` tetap identik — kode Anda kemungkinan besar langsung kompatibel tanpa perubahan.
|
|
661
2306
|
|
|
662
|
-
###
|
|
2307
|
+
### 5. `additionalNodes` Sudah Otomatis
|
|
663
2308
|
|
|
664
|
-
**
|
|
2309
|
+
Jika sebelumnya Anda menambahkan `additionalNodes` secara manual di setiap `relayMessage()` untuk pesan interaktif (pola umum di banyak fork/bot komunitas), Anda **bisa menghapusnya** dan biarkan `sendMessage()` menanganinya — atau biarkan saja jika Anda memakai `relayMessage()` langsung (`buildInteractiveAdditionalNodes` tetap diekspor untuk kasus itu).
|
|
665
2310
|
|
|
666
|
-
|
|
667
|
-
await sock.sendMessage(jid, {
|
|
668
|
-
interactiveMessage: {
|
|
669
|
-
title: "Welcome!",
|
|
670
|
-
footer: "Powered by Ourin",
|
|
671
|
-
buttons: [
|
|
672
|
-
{
|
|
673
|
-
name: "quick_reply",
|
|
674
|
-
buttonParamsJson: JSON.stringify({
|
|
675
|
-
display_text: "Menu",
|
|
676
|
-
id: "menu",
|
|
677
|
-
}),
|
|
678
|
-
},
|
|
679
|
-
{
|
|
680
|
-
name: "cta_url",
|
|
681
|
-
buttonParamsJson: JSON.stringify({
|
|
682
|
-
display_text: "Website",
|
|
683
|
-
url: "https://example.com",
|
|
684
|
-
}),
|
|
685
|
-
},
|
|
686
|
-
{
|
|
687
|
-
name: "cta_copy",
|
|
688
|
-
buttonParamsJson: JSON.stringify({
|
|
689
|
-
display_text: "Copy Code",
|
|
690
|
-
copy_code: "OURIN2024",
|
|
691
|
-
}),
|
|
692
|
-
},
|
|
693
|
-
],
|
|
694
|
-
header: "Choose an option",
|
|
695
|
-
image: { url: "https://example.com/banner.jpg" },
|
|
696
|
-
},
|
|
697
|
-
});
|
|
698
|
-
```
|
|
699
|
-
|
|
700
|
-
**List Menu (single_select):**
|
|
2311
|
+
### 6. Update Script `menu.js`/Handler Anda
|
|
701
2312
|
|
|
702
|
-
|
|
703
|
-
await sock.sendMessage(jid, {
|
|
704
|
-
interactiveMessage: {
|
|
705
|
-
title: "Select Category",
|
|
706
|
-
footer: "Powered by Ourin",
|
|
707
|
-
buttons: [
|
|
708
|
-
{
|
|
709
|
-
name: "single_select",
|
|
710
|
-
buttonParamsJson: JSON.stringify({
|
|
711
|
-
title: "Menu",
|
|
712
|
-
sections: [
|
|
713
|
-
{
|
|
714
|
-
title: "Games",
|
|
715
|
-
rows: [
|
|
716
|
-
{ title: "Quiz", id: ".quiz" },
|
|
717
|
-
{ title: "Tebak Gambar", id: ".tebakgambar" },
|
|
718
|
-
],
|
|
719
|
-
},
|
|
720
|
-
{
|
|
721
|
-
title: "Tools",
|
|
722
|
-
rows: [
|
|
723
|
-
{ title: "Sticker", id: ".sticker" },
|
|
724
|
-
{ title: "TTS", id: ".tts" },
|
|
725
|
-
],
|
|
726
|
-
},
|
|
727
|
-
],
|
|
728
|
-
}),
|
|
729
|
-
},
|
|
730
|
-
],
|
|
731
|
-
header: "Bot Menu",
|
|
732
|
-
},
|
|
733
|
-
});
|
|
734
|
-
```
|
|
2313
|
+
Jika handler lama Anda memiliki logic khusus untuk mem-parsing `buttonsResponseMessage` atau `templateButtonReplyMessage`, tambahkan juga penanganan `interactiveResponseMessage.nativeFlowResponseMessage` (lihat contoh parsing di bagian sebelumnya) karena itulah bentuk balasan yang dominan di client WhatsApp modern.
|
|
735
2314
|
|
|
736
2315
|
---
|
|
737
2316
|
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
```js
|
|
741
|
-
await sock.sendMessage(jid, {
|
|
742
|
-
albumMessage: [
|
|
743
|
-
{ image: { url: "./photo1.jpg" }, caption: "First" },
|
|
744
|
-
{ image: { url: "./photo2.jpg" }, caption: "Second" },
|
|
745
|
-
{ video: { url: "./clip.mp4" }, caption: "Video" },
|
|
746
|
-
],
|
|
747
|
-
});
|
|
748
|
-
```
|
|
2317
|
+
## ❓ Troubleshooting / FAQ
|
|
749
2318
|
|
|
750
|
-
|
|
751
|
-
> Albums automatically set `expectedImageCount` and `expectedVideoCount` based on array content.
|
|
2319
|
+
### Q: Bot terkoneksi tapi tombol/list yang saya kirim tidak muncul di HP penerima?
|
|
752
2320
|
|
|
753
|
-
|
|
2321
|
+
**A:** Ini hampir selalu soal `additionalNodes` binary hint yang hilang. Jika Anda memakai `sock.sendMessage()` biasa, ini seharusnya sudah otomatis. Jika Anda memakai `relayMessage()` secara manual, pastikan menyertakan `buildInteractiveAdditionalNodes(jid, message)` — lihat bagian [`buildInteractiveAdditionalNodes`](#buildinteractiveadditionalnodes--kenapa-wajib-ada). Pastikan juga Anda sedang menjalankan versi ≥ 3.3.0 untuk `groupStatusMessage`, karena bug ini pernah terjadi khusus untuk Group Status V2 sebelum versi tersebut.
|
|
754
2322
|
|
|
755
|
-
###
|
|
2323
|
+
### Q: Error `ERR_REQUIRE_ESM` saat `require('@vinzsocket/baileys')`?
|
|
756
2324
|
|
|
757
|
-
|
|
2325
|
+
**A:** Package ini murni ESM. Solusinya:
|
|
2326
|
+
1. Upgrade Node.js ke ≥ 20.19.0 (atau ≥ 22.12.0 / ≥ 23.x) agar `require(esm)` bawaan Node bisa dipakai, **atau**
|
|
2327
|
+
2. Ganti `require()` menjadi `import()` dinamis:
|
|
2328
|
+
```js
|
|
2329
|
+
const { default: makeWASocket } = await import('@vinzsocket/baileys')
|
|
2330
|
+
```
|
|
2331
|
+
3. Ubah `package.json` proyek Anda menjadi `"type": "module"` dan pakai `import` secara native.
|
|
758
2332
|
|
|
759
|
-
|
|
2333
|
+
### Q: Instalasi gagal / keluar pesan "This package requires Node.js 20+"?
|
|
760
2334
|
|
|
761
|
-
|
|
762
|
-
await sock.sendTable(
|
|
763
|
-
jid,
|
|
764
|
-
"Java vs JavaScript",
|
|
765
|
-
["Feature", "Java", "JavaScript"],
|
|
766
|
-
[
|
|
767
|
-
["Type", "Compiled", "Interpreted"],
|
|
768
|
-
["Typing", "Static", "Dynamic"],
|
|
769
|
-
["Main Use", "Enterprise", "Web, Full-stack"],
|
|
770
|
-
],
|
|
771
|
-
quoted,
|
|
772
|
-
{
|
|
773
|
-
headerText: "Comparison:",
|
|
774
|
-
footer: "Hope this helps!",
|
|
775
|
-
},
|
|
776
|
-
);
|
|
777
|
-
```
|
|
2335
|
+
**A:** `engine-requirements.js` (dijalankan lewat hook `preinstall`) sengaja menghentikan instalasi jika Node.js Anda di bawah versi 20, karena Harps-Baileys memakai fitur bahasa & API Node modern yang tidak tersedia di versi lebih lama. Upgrade Node.js Anda (disarankan memakai [nvm](https://github.com/nvm-sh/nvm) untuk memudahkan pergantian versi).
|
|
778
2336
|
|
|
779
|
-
|
|
2337
|
+
### Q: `renderStoryCard()` melempar error soal "jimp"?
|
|
780
2338
|
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
"Bot Info",
|
|
785
|
-
[
|
|
786
|
-
["Name", "Ourin AI"],
|
|
787
|
-
["Version", "2.4.0"],
|
|
788
|
-
["Developer", "Zann"],
|
|
789
|
-
],
|
|
790
|
-
quoted,
|
|
791
|
-
{ footer: "© Ourin AI" },
|
|
792
|
-
);
|
|
2339
|
+
**A:** Install peer dependency opsionalnya:
|
|
2340
|
+
```bash
|
|
2341
|
+
npm install jimp
|
|
793
2342
|
```
|
|
2343
|
+
Modul ini sengaja **lazy-imported** (tidak jadi hard dependency) supaya konsumen yang tidak memakai fitur story card tidak perlu menanggung ukuran bundle `jimp`.
|
|
794
2344
|
|
|
795
|
-
|
|
2345
|
+
### Q: Bagaimana cara menampilkan nomor telepon anggota grup, tapi kadang yang muncul cuma angka aneh/panjang?
|
|
796
2346
|
|
|
797
|
-
|
|
798
|
-
await sock.sendCodeBlock(
|
|
799
|
-
jid,
|
|
800
|
-
`const greeting = "Hello World"
|
|
801
|
-
function sayHello(name) {
|
|
802
|
-
return greeting + " " + name
|
|
803
|
-
}
|
|
804
|
-
sayHello("Ourin")`,
|
|
805
|
-
quoted,
|
|
806
|
-
{
|
|
807
|
-
language: "javascript",
|
|
808
|
-
title: "Example Code",
|
|
809
|
-
footer: "Powered by Ourin",
|
|
810
|
-
},
|
|
811
|
-
);
|
|
812
|
-
```
|
|
2347
|
+
**A:** Itu tandanya JID tersebut berformat `@lid` (Linked Identity — sistem privasi baru WhatsApp), bukan nomor telepon asli. WhatsApp memang **sengaja tidak selalu mengungkapkan** nomor telepon asli anggota grup ke anggota lain. Jangan menampilkan digit LID mentah sebagai nomor telepon — pakai `isLidUser(jid)` untuk mendeteksinya, dan gunakan `buildTagAllText()` (lihat [Mention Utilities](#-mention-utilities-mentionjs)) yang sudah menangani fallback nama/label secara aman.
|
|
813
2348
|
|
|
814
|
-
|
|
2349
|
+
### Q: Apakah Harps-Baileys mendukung WhatsApp Flow (form registrasi multi-field native)?
|
|
815
2350
|
|
|
816
|
-
**
|
|
2351
|
+
**A:** Dukungan native multi-field Flow form (`flow_json` dengan banyak field terstruktur, validasi server-side, dsb — fitur "WhatsApp Flows" penuh) **belum diverifikasi tersedia** secara native di fork ini pada versi 3.3.0. Alternatif yang bisa dipakai sekarang adalah **form terpandu bertahap** (guided step-by-step): kirim serangkaian pertanyaan satu per satu memakai `interactiveMessage` biasa (teks/tombol/list) dan simpan progres jawaban di state percakapan bot Anda sendiri, alih-alih mengandalkan satu payload Flow form native. Jika kebutuhan Anda spesifik untuk Flow form penuh, pantau `CHANGELOG.md` untuk update fitur ini di rilis mendatang.
|
|
817
2352
|
|
|
818
|
-
|
|
2353
|
+
### Q: Pesan text saya yang mengandung URL tidak menampilkan link preview?
|
|
819
2354
|
|
|
820
|
-
**
|
|
2355
|
+
**A:** Pastikan package opsional `link-preview-js` terpasang. Jika sudah terpasang tapi tetap tidak muncul, kemungkinan:
|
|
2356
|
+
- URL-nya tidak cocok dengan `URL_REGEX` bawaan (harus diawali `https://`).
|
|
2357
|
+
- Situs tujuan memblokir scraping metadata Open Graph.
|
|
2358
|
+
- Anda menyetel `linkPreview: null` secara eksplisit di payload.
|
|
821
2359
|
|
|
822
|
-
|
|
823
|
-
- Unified response sections with `GenATableUXPrimitive` / `GenAIMarkdownTextUXPrimitive` typenames
|
|
824
|
-
- Dual output: `rows` (for submessages) + `unified_rows` (for sections)
|
|
825
|
-
- Enhanced `contextInfo` with `botMessageSharingInfo`
|
|
2360
|
+
### Q: Bagaimana cara mengetahui apakah sebuah pesan berasal dari grup atau chat pribadi?
|
|
826
2361
|
|
|
2362
|
+
**A:**
|
|
827
2363
|
```js
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
"Java vs JavaScript", // title
|
|
832
|
-
"Feature | Java | JavaScript", // header (pipe-delimited)
|
|
833
|
-
"Type | Compiled | Interpreted;;Typing | Static | Dynamic;;Main Use | Enterprise | Web, Full-stack", // rows (;; separated, | or , delimited)
|
|
834
|
-
],
|
|
835
|
-
quoted,
|
|
836
|
-
{
|
|
837
|
-
headerText: "Comparison:",
|
|
838
|
-
text: "Here is a comparison table:",
|
|
839
|
-
footer: "Hope this helps!",
|
|
840
|
-
},
|
|
841
|
-
);
|
|
2364
|
+
import { isJidGroup } from '@vinzsocket/baileys'
|
|
2365
|
+
|
|
2366
|
+
const isGroupMsg = isJidGroup(msg.key.remoteJid)
|
|
842
2367
|
```
|
|
843
2368
|
|
|
844
|
-
|
|
2369
|
+
### Q: Sesi tiba-tiba logout sendiri tanpa saya scan ulang atau logout manual?
|
|
845
2370
|
|
|
846
|
-
|
|
847
|
-
-
|
|
848
|
-
- `
|
|
2371
|
+
**A:** Penyebab umum:
|
|
2372
|
+
- Anda login WhatsApp Web/Desktop resmi dengan akun yang sama dan memutus semua linked device.
|
|
2373
|
+
- Folder auth state (`sesi_auth`) rusak/terhapus sebagian — cek apakah semua file `session-*.json`, `creds.json` masih lengkap.
|
|
2374
|
+
- Terlalu banyak percobaan koneksi gagal beruntun terdeteksi sebagai aktivitas mencurigakan oleh WhatsApp.
|
|
849
2375
|
|
|
850
|
-
|
|
2376
|
+
Solusi paling aman: hapus folder auth state, lalu pairing ulang dari nol.
|
|
851
2377
|
|
|
852
|
-
|
|
853
|
-
| ------------ | -------- | ------- | ---------------------------------------------------- |
|
|
854
|
-
| `title` | `string` | — | Title (used if `headerText` not set) |
|
|
855
|
-
| `headerText` | `string` | — | Text shown before the table |
|
|
856
|
-
| `text` | `string` | — | Markdown text section (GenAIMarkdownTextUXPrimitive) |
|
|
857
|
-
| `footer` | `string` | — | Text shown after the table |
|
|
2378
|
+
### Q: `groupMetadata()` lambat dipanggil berulang kali untuk grup yang sama?
|
|
858
2379
|
|
|
859
|
-
|
|
2380
|
+
**A:** Manfaatkan opsi `cachedGroupMetadata` di config, dan invalidasi cache-nya saat event `groups.update` / `group-participants.update` terjadi — lihat contoh di bagian [Konfigurasi Koneksi](#-konfigurasi-koneksi).
|
|
860
2381
|
|
|
861
|
-
###
|
|
2382
|
+
### Q: Apakah aman menjalankan banyak instance bot dengan folder auth state yang sama?
|
|
862
2383
|
|
|
863
|
-
|
|
2384
|
+
**A:** **Tidak.** Setiap instance socket harus punya auth state (dan karenanya, satu "linked device slot") sendiri. Menjalankan dua proses dengan folder auth yang sama secara bersamaan akan menyebabkan konflik sesi Signal Protocol dan kemungkinan besar salah satu (atau keduanya) logout/rusak.
|
|
864
2385
|
|
|
865
|
-
|
|
2386
|
+
### Q: Bagaimana menangani rate limit saat mengirim pesan massal (broadcast)?
|
|
866
2387
|
|
|
867
|
-
-
|
|
868
|
-
- `/* */` block comment support
|
|
869
|
-
- `#` comment support for python/bash/lua
|
|
870
|
-
- Hex/binary/octal number literals
|
|
871
|
-
- Dual token output: numeric `codeBlock` + string-typed `unified_codeBlock`
|
|
872
|
-
- Unified response sections with `GenAICodeUXPrimitive` / `GenAIMarkdownTextUXPrimitive` typenames
|
|
873
|
-
- Enhanced `contextInfo` with `botMessageSharingInfo`
|
|
2388
|
+
**A:** Beri jeda antar pengiriman (mis. 1–3 detik) dan hindari mengirim ke ratusan/ribuan nomor dalam waktu sangat singkat — WhatsApp mendeteksi pola ini sebagai spam dan bisa memblokir/membanned akun. Pertimbangkan memakai antrian (queue) dengan concurrency terbatas, misalnya dengan `p-queue` (sudah menjadi dependency internal library ini, aman untuk dipakai juga di kode bot Anda).
|
|
874
2389
|
|
|
875
2390
|
```js
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
2391
|
+
import PQueue from 'p-queue'
|
|
2392
|
+
const queue = new PQueue({ concurrency: 1, interval: 2000, intervalCap: 1 })
|
|
2393
|
+
|
|
2394
|
+
for (const jid of daftarPenerima) {
|
|
2395
|
+
queue.add(() => sock.sendMessage(jid, { text: 'Pengumuman broadcast' }))
|
|
2396
|
+
}
|
|
2397
|
+
```
|
|
2398
|
+
|
|
2399
|
+
### Q: Apa bedanya `groupStatusMessage` dengan mengirim status pribadi biasa?
|
|
2400
|
+
|
|
2401
|
+
**A:** Status pribadi biasa dikirim ke `status@broadcast` dan tampil di tab Status semua kontak Anda. `groupStatusMessage` (Group Status V2) mengirim story **khusus untuk sebuah grup tertentu** — hanya anggota grup tersebut yang melihatnya sebagai ring status, terpisah dari status pribadi Anda.
|
|
879
2402
|
|
|
880
|
-
|
|
2403
|
+
### Q: Bisakah satu bot menangani banyak akun WhatsApp sekaligus?
|
|
881
2404
|
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
2405
|
+
**A:** Bisa, dengan menjalankan satu instance `makeWASocket()` **terpisah per akun**, masing-masing dengan folder auth state sendiri-sendiri:
|
|
2406
|
+
|
|
2407
|
+
```js
|
|
2408
|
+
const akunList = ['akun1', 'akun2', 'akun3']
|
|
2409
|
+
const sockets = {}
|
|
2410
|
+
|
|
2411
|
+
for (const nama of akunList) {
|
|
2412
|
+
const { state, saveCreds } = await useMultiFileAuthState(`./sesi_${nama}`)
|
|
2413
|
+
const sock = makeWASocket({ auth: state })
|
|
2414
|
+
sock.ev.on('creds.update', saveCreds)
|
|
2415
|
+
sockets[nama] = sock
|
|
2416
|
+
}
|
|
893
2417
|
```
|
|
894
2418
|
|
|
895
|
-
|
|
2419
|
+
Perhatikan penggunaan memori & CPU akan meningkat linear dengan jumlah akun yang dijalankan — pertimbangkan pemisahan proses (mis. lewat PM2 cluster atau container terpisah) untuk skala yang lebih besar.
|
|
2420
|
+
|
|
2421
|
+
### Q: Kenapa `groupMetadata()` kadang mengembalikan data anggota yang sudah tidak akurat (mis. admin yang sebenarnya sudah di-demote)?
|
|
896
2422
|
|
|
897
|
-
|
|
898
|
-
| ------------ | ------------------------ |
|
|
899
|
-
| `javascript` | `js`, `typescript`, `ts` |
|
|
900
|
-
| `python` | `py` |
|
|
901
|
-
| `go` | `golang` |
|
|
902
|
-
| `lua` | — |
|
|
903
|
-
| `bash` | `sh`, `shell` |
|
|
2423
|
+
**A:** Jika Anda memakai `cachedGroupMetadata`, pastikan cache tersebut **diinvalidasi** setiap kali event `group-participants.update` atau `groups.update` terjadi untuk grup terkait — lihat contoh invalidasi cache di bagian [Konfigurasi Koneksi](#-konfigurasi-koneksi). Tanpa invalidasi, data yang tersimpan di cache Anda akan menjadi basi (stale) seiring waktu.
|
|
904
2424
|
|
|
905
|
-
|
|
2425
|
+
---
|
|
906
2426
|
|
|
907
|
-
|
|
908
|
-
| ---------- | -------- | -------------- | ---------------------------------------------------- |
|
|
909
|
-
| `language` | `string` | `'javascript'` | Programming language for syntax highlighting |
|
|
910
|
-
| `title` | `string` | — | Title text shown before the code block |
|
|
911
|
-
| `text` | `string` | — | Markdown text section (GenAIMarkdownTextUXPrimitive) |
|
|
912
|
-
| `footer` | `string` | — | Footer text shown after the code block |
|
|
2427
|
+
## 🔢 Versi & Kompatibilitas WhatsApp
|
|
913
2428
|
|
|
914
|
-
|
|
2429
|
+
WhatsApp Web Multi-Device tidak memiliki dokumentasi resmi publik — protokolnya dipelajari lewat reverse-engineering berkelanjutan oleh komunitas. Konsekuensinya:
|
|
915
2430
|
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
| 1 | `KEYWORD` | `KEYWORD` | Language keywords (`const`, `func`, `if`, etc.) |
|
|
920
|
-
| 2 | `METHOD` | `METHOD` | Function/method calls (identifier followed by `(`) |
|
|
921
|
-
| 3 | `STRING` | `STR` | String literals (`"..."`, `'...'`, `` `...` ``) |
|
|
922
|
-
| 4 | `NUMBER` | `NUMBER` | Numeric values (int, float, hex, binary, octal) |
|
|
923
|
-
| 5 | `COMMENT` | `COMMENT` | Comments (`//`, `/* */`, `#`) |
|
|
2431
|
+
- Field `version` di konfigurasi (`[2, 3000, 1035194821]` per default saat ini) perlu sesekali diperbarui mengikuti rilis WhatsApp Web terbaru. Versi yang terlalu usang berisiko ditolak server (`connection.update` gagal terus-menerus) atau berperilaku tidak konsisten.
|
|
2432
|
+
- Selalu update ke rilis Harps-Baileys terbaru secara berkala, terutama jika Anda mengalami error koneksi yang sebelumnya tidak terjadi — kemungkinan besar WhatsApp baru saja mengubah sesuatu di level protokol dan rilis terbaru sudah menyesuaikan.
|
|
2433
|
+
- Jika sebuah fitur tiba-tiba berhenti berfungsi tanpa perubahan kode di sisi Anda, cek dulu [`CHANGELOG.md`](./CHANGELOG.md) dan issue tracker GitHub sebelum mengasumsikan itu bug baru — kemungkinan sudah ada laporan/fix serupa dari pengguna lain.
|
|
924
2434
|
|
|
925
2435
|
---
|
|
926
2436
|
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
|
965
|
-
|
|
|
966
|
-
| `
|
|
967
|
-
| `
|
|
968
|
-
| `
|
|
969
|
-
| `
|
|
970
|
-
| `
|
|
971
|
-
| `
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
|
976
|
-
|
|
|
977
|
-
| `
|
|
978
|
-
| `
|
|
979
|
-
| `
|
|
980
|
-
| `
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
|
985
|
-
|
|
986
|
-
| `
|
|
987
|
-
| `
|
|
988
|
-
| `
|
|
989
|
-
| `
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
2437
|
+
|
|
2438
|
+
|
|
2439
|
+
## 📋 Referensi Cepat: Semua Method `sock`
|
|
2440
|
+
|
|
2441
|
+
Tabel referensi cepat seluruh method yang tersedia di objek `sock`, dikelompokkan per kategori, untuk dicari dengan cepat tanpa harus membaca ulang seluruh dokumentasi di atas.
|
|
2442
|
+
|
|
2443
|
+
### Koneksi & Sesi
|
|
2444
|
+
|
|
2445
|
+
| Method | Deskripsi |
|
|
2446
|
+
|---|---|
|
|
2447
|
+
| `sock.end(error?)` | Menutup koneksi socket secara manual. |
|
|
2448
|
+
| `sock.logout(msg?)` | Logout dari WhatsApp (menghapus linked device dari HP). |
|
|
2449
|
+
| `sock.requestPairingCode(nomor)` | Meminta kode pairing untuk login tanpa scan QR. |
|
|
2450
|
+
| `sock.waitForConnectionUpdate(cb)` | Menunggu sampai kondisi tertentu terpenuhi pada `connection.update`. |
|
|
2451
|
+
| `sock.waitForSocketOpen()` | Menunggu socket WebSocket benar-benar terbuka. |
|
|
2452
|
+
|
|
2453
|
+
### Pesan
|
|
2454
|
+
|
|
2455
|
+
| Method | Deskripsi |
|
|
2456
|
+
|---|---|
|
|
2457
|
+
| `sock.sendMessage(jid, content, options?)` | Pintu utama mengirim segala jenis pesan. |
|
|
2458
|
+
| `sock.relayMessage(jid, message, options)` | Kirim payload protobuf mentah langsung (level rendah). |
|
|
2459
|
+
| `sock.readMessages(keys)` | Tandai daftar pesan sebagai sudah dibaca (kirim read receipt). |
|
|
2460
|
+
| `sock.sendReceipt(jid, participant, ids, type)` | Kirim receipt manual (delivered/read/played). |
|
|
2461
|
+
| `sock.sendReceipts(keys, type)` | Versi batch dari `sendReceipt`. |
|
|
2462
|
+
| `sock.updateMediaMessage(msg)` | Minta re-upload/refresh media yang kadaluarsa. |
|
|
2463
|
+
| `sock.refreshMediaConn(forceGet?)` | Refresh koneksi host upload media. |
|
|
2464
|
+
| `sock.generateWAMessage(jid, content, options)` | Hasilkan objek `WAMessage` lengkap tanpa mengirimnya. |
|
|
2465
|
+
| `sock.generateWAMessageContent(content, options)` | Hasilkan hanya isi (`message`) tanpa key/metadata. |
|
|
2466
|
+
| `sock.generateWAMessageFromContent(jid, content, options)` | Bungkus konten mentah jadi `WAMessage` siap kirim. |
|
|
2467
|
+
| `sock.prepareWAMessageMedia(content, options)` | Unggah & siapkan media (dipakai internal oleh generator pesan). |
|
|
2468
|
+
|
|
2469
|
+
### Grup
|
|
2470
|
+
|
|
2471
|
+
| Method | Deskripsi |
|
|
2472
|
+
|---|---|
|
|
2473
|
+
| `sock.groupMetadata(jid)` | Ambil metadata sebuah grup. |
|
|
2474
|
+
| `sock.groupCreate(subject, participants)` | Buat grup baru. |
|
|
2475
|
+
| `sock.groupLeave(jid)` | Keluar dari grup. |
|
|
2476
|
+
| `sock.groupUpdateSubject(jid, subject)` | Ganti nama grup. |
|
|
2477
|
+
| `sock.groupUpdateDescription(jid, desc)` | Ganti deskripsi grup. |
|
|
2478
|
+
| `sock.groupParticipantsUpdate(jid, participants, action)` | Tambah/keluarkan/promosikan/turunkan anggota. |
|
|
2479
|
+
| `sock.groupRequestParticipantsList(jid)` | Lihat daftar permintaan join pending. |
|
|
2480
|
+
| `sock.groupRequestParticipantsUpdate(jid, participants, action)` | Setujui/tolak permintaan join. |
|
|
2481
|
+
| `sock.groupInviteCode(jid)` | Ambil kode undangan aktif. |
|
|
2482
|
+
| `sock.groupRevokeInvite(jid)` | Cabut & buat ulang kode undangan. |
|
|
2483
|
+
| `sock.groupAcceptInvite(code)` | Terima undangan via kode. |
|
|
2484
|
+
| `sock.groupRevokeInviteV4(groupJid, invitedJid)` | Kirim undangan langsung ke JID tertentu. |
|
|
2485
|
+
| `sock.groupGetInviteInfo(code)` | Lihat info grup dari kode tanpa join. |
|
|
2486
|
+
| `sock.groupToggleEphemeral(jid, exp)` | Aktif/nonaktifkan pesan sekali lihat di grup. |
|
|
2487
|
+
| `sock.groupSettingUpdate(jid, setting)` | Ubah siapa yang boleh kirim pesan/edit info. |
|
|
2488
|
+
| `sock.groupMemberAddMode(jid, mode)` | Ubah siapa yang boleh menambah anggota. |
|
|
2489
|
+
| `sock.groupJoinApprovalMode(jid, mode)` | Aktif/nonaktifkan mode approval join. |
|
|
2490
|
+
| `sock.groupFetchAllParticipating()` | Ambil semua grup yang diikuti akun ini. |
|
|
2491
|
+
|
|
2492
|
+
### Komunitas
|
|
2493
|
+
|
|
2494
|
+
| Method | Deskripsi |
|
|
2495
|
+
|---|---|
|
|
2496
|
+
| `sock.communityMetadata(jid)` | Ambil metadata komunitas. |
|
|
2497
|
+
| `sock.communityCreate(subject, body)` | Buat komunitas baru. |
|
|
2498
|
+
| `sock.communityCreateGroup(subject, participants, parentJid)` | Buat grup baru di dalam komunitas. |
|
|
2499
|
+
| `sock.communityLeave(jid)` | Keluar dari komunitas. |
|
|
2500
|
+
| `sock.communityUpdateSubject(jid, subject)` | Ganti nama komunitas. |
|
|
2501
|
+
| `sock.communityLinkGroup(groupJid, parentJid)` | Hubungkan grup existing ke komunitas. |
|
|
2502
|
+
| `sock.communityUnlinkGroup(groupJid, parentJid)` | Lepaskan grup dari komunitas. |
|
|
2503
|
+
| `sock.communityFetchLinkedGroups(jid)` | Lihat semua grup yang terhubung. |
|
|
2504
|
+
| `sock.communityRequestParticipantsList(jid)` / `...Update(...)` | Kelola permintaan join komunitas. |
|
|
2505
|
+
| `sock.communityParticipantsUpdate(jid, participants, action)` | Kelola anggota komunitas. |
|
|
2506
|
+
| `sock.communityInviteCode(jid)` / `communityRevokeInvite(jid)` / `communityAcceptInvite(code)` | Kelola undangan komunitas. |
|
|
2507
|
+
| `sock.communityToggleEphemeral(jid, exp)` | Pesan sekali lihat tingkat komunitas. |
|
|
2508
|
+
| `sock.communitySettingUpdate` / `communityMemberAddMode` / `communityJoinApprovalMode` | Pengaturan komunitas. |
|
|
2509
|
+
| `sock.communityFetchAllParticipating()` | Ambil semua komunitas yang diikuti. |
|
|
2510
|
+
|
|
2511
|
+
### Business
|
|
2512
|
+
|
|
2513
|
+
| Method | Deskripsi |
|
|
2514
|
+
|---|---|
|
|
2515
|
+
| `sock.getOrderDetails(orderId, token)` | Ambil detail order dari sebuah payload order. |
|
|
2516
|
+
| `sock.getCatalog(opts)` | Ambil katalog produk. |
|
|
2517
|
+
| `sock.getCollections(jid, limit)` | Ambil koleksi produk. |
|
|
2518
|
+
| `sock.productCreate(product)` | Tambah produk baru. |
|
|
2519
|
+
| `sock.productUpdate(id, update)` | Update produk. |
|
|
2520
|
+
| `sock.productDelete(ids)` | Hapus produk. |
|
|
2521
|
+
| `sock.updateBussinesProfile(profile)` | Update profil bisnis. |
|
|
2522
|
+
| `sock.updateCoverPhoto(buffer)` / `removeCoverPhoto()` | Kelola foto sampul bisnis. |
|
|
2523
|
+
|
|
2524
|
+
### Newsletter / Channel
|
|
2525
|
+
|
|
2526
|
+
| Method | Deskripsi |
|
|
2527
|
+
|---|---|
|
|
2528
|
+
| `sock.newsletterCreate(name, desc)` | Buat channel baru. |
|
|
2529
|
+
| `sock.newsletterMetadata(type, key)` | Ambil metadata channel. |
|
|
2530
|
+
| `sock.newsletterUpdateName/Description/Picture(...)` | Update info channel. |
|
|
2531
|
+
| `sock.newsletterRemovePicture(jid)` | Hapus foto channel. |
|
|
2532
|
+
| `sock.newsletterSubscribers(jid)` | Lihat daftar subscriber. |
|
|
2533
|
+
| `sock.newsletterReactMessage(jid, serverId, reaction)` | React ke post channel. |
|
|
2534
|
+
| `sock.newsletterFetchMessages(jid, count, since, after)` | Ambil histori post channel. |
|
|
2535
|
+
| `sock.subscribeNewsletterUpdates(jid)` | Berlangganan update real-time channel. |
|
|
2536
|
+
| `sock.newsletterAdminCount(jid)` | Hitung jumlah admin channel. |
|
|
2537
|
+
| `sock.newsletterChangeOwner(jid, newOwnerJid)` | Pindah kepemilikan channel. |
|
|
2538
|
+
| `sock.newsletterDemote(jid, userJid)` | Copot admin channel. |
|
|
2539
|
+
| `sock.newsletterDelete(jid)` | Hapus channel. |
|
|
2540
|
+
|
|
2541
|
+
### Chat, Profil & Privasi
|
|
2542
|
+
|
|
2543
|
+
| Method | Deskripsi |
|
|
2544
|
+
|---|---|
|
|
2545
|
+
| `sock.chatModify(mod, jid)` | Primitif dasar untuk semua modifikasi chat (arsip/pin/mute/dll). |
|
|
2546
|
+
| `sock.star(keys, star)` | Bintangi/batalkan bintang pesan. |
|
|
2547
|
+
| `sock.addLabel/addChatLabel/removeChatLabel/addMessageLabel/removeMessageLabel` | Kelola label (Business). |
|
|
2548
|
+
| `sock.addOrEditQuickReply(qr)` / `removeQuickReply(ts)` | Kelola balasan cepat. |
|
|
2549
|
+
| `sock.addOrEditContact(jid, contact)` / `removeContact(jid)` | Kelola kontak. |
|
|
2550
|
+
| `sock.updateProfileName/Status/Picture` | Update profil akun sendiri. |
|
|
2551
|
+
| `sock.removeProfilePicture(jid)` | Hapus foto profil. |
|
|
2552
|
+
| `sock.profilePictureUrl(jid, type)` | Ambil URL foto profil siapa pun. |
|
|
2553
|
+
| `sock.getBusinessProfile(jid)` | Ambil profil bisnis JID tertentu. |
|
|
2554
|
+
| `sock.update*Privacy(...)` (last seen, online, dsb) | Semua pengaturan privasi. |
|
|
2555
|
+
| `sock.fetchPrivacySettings()` / `fetchBlocklist()` / `fetchDisappearingDuration(jid)` | Ambil pengaturan privasi saat ini. |
|
|
2556
|
+
| `sock.updateBlockStatus(jid, action)` | Blokir/buka blokir kontak. |
|
|
2557
|
+
| `sock.sendPresenceUpdate(type, jid?)` | Kirim status online/typing/recording. |
|
|
2558
|
+
| `sock.presenceSubscribe(jid)` | Berlangganan presence seseorang. |
|
|
2559
|
+
| `sock.createCallLink(type)` | Buat link panggilan audio/video. |
|
|
2560
|
+
| `sock.resyncAppState(collections, isInitial)` | Paksa resync app-state. |
|
|
1019
2561
|
|
|
1020
2562
|
---
|
|
1021
2563
|
|
|
1022
|
-
|
|
2564
|
+
## 🎮 Contoh Penerapan di Sistem RPG
|
|
1023
2565
|
|
|
1024
|
-
**
|
|
2566
|
+
Bagian ini mengumpulkan pola-pola pemakaian Harps-Baileys yang relevan untuk bot bergaya **RPG/game system** (nation-building, ekonomi, teknologi, dst) — menggabungkan beberapa fitur eksklusif fork ini sekaligus.
|
|
2567
|
+
|
|
2568
|
+
### Menu Konfigurasi Karakter dengan Multi-Select
|
|
1025
2569
|
|
|
1026
2570
|
```js
|
|
1027
2571
|
await sock.sendMessage(jid, {
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
2572
|
+
multiSelectMessage: {
|
|
2573
|
+
title: '⚙️ Setup Awal Karakter',
|
|
2574
|
+
footer: 'Pilih kelas & fraksi untuk memulai',
|
|
2575
|
+
selectors: [
|
|
2576
|
+
{
|
|
2577
|
+
displayText: '🧙 Pilih Kelas',
|
|
2578
|
+
sections: [
|
|
2579
|
+
{ title: 'Kelas Tempur', rows: [
|
|
2580
|
+
{ id: 'warrior', title: '⚔️ Warrior', description: 'HP tinggi, damage fisik' },
|
|
2581
|
+
{ id: 'mage', title: '🔮 Mage', description: 'Damage sihir, HP rendah' }
|
|
2582
|
+
]}
|
|
2583
|
+
]
|
|
2584
|
+
},
|
|
2585
|
+
{
|
|
2586
|
+
displayText: '🏳️ Pilih Fraksi Negara',
|
|
2587
|
+
sections: [
|
|
2588
|
+
{ title: 'Fraksi', rows: [
|
|
2589
|
+
{ id: 'kerajaan_utara', title: '❄️ Kerajaan Utara' },
|
|
2590
|
+
{ id: 'republik_selatan', title: '☀️ Republik Selatan' }
|
|
2591
|
+
]}
|
|
2592
|
+
]
|
|
2593
|
+
}
|
|
2594
|
+
]
|
|
2595
|
+
}
|
|
2596
|
+
}, { quoted: msg })
|
|
1035
2597
|
```
|
|
1036
2598
|
|
|
1037
|
-
|
|
2599
|
+
### Notifikasi Event Negara ke Grup via Story
|
|
2600
|
+
|
|
2601
|
+
Untuk sistem `rpg-negara.js` yang punya mekanik geopolitik (full-conquest, food crisis, ceasefire, dst), Group Status V2 + `renderStoryCard` cocok dipakai sebagai notifikasi visual otomatis:
|
|
1038
2602
|
|
|
1039
2603
|
```js
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
}
|
|
2604
|
+
async function umumkanPerangNegara(sock, groupJid, negaraA, negaraB) {
|
|
2605
|
+
await sock.sendMessage(groupJid, {
|
|
2606
|
+
groupStatusMessage: {
|
|
2607
|
+
card: {
|
|
2608
|
+
title: '⚔️ PERANG PECAH!',
|
|
2609
|
+
body: `${negaraA} menyatakan perang terhadap ${negaraB}`,
|
|
2610
|
+
footer: 'Sistem Geopolitik Harps-MD',
|
|
2611
|
+
gradient: 'fire'
|
|
2612
|
+
},
|
|
2613
|
+
caption: 'Ketuk untuk lihat detail peperangan.'
|
|
2614
|
+
}
|
|
2615
|
+
})
|
|
2616
|
+
}
|
|
1053
2617
|
```
|
|
1054
2618
|
|
|
1055
|
-
|
|
2619
|
+
### Katalog Perusahaan dengan Carousel
|
|
2620
|
+
|
|
2621
|
+
Untuk `rpg-perusahaan.js` yang menampilkan daftar aset/saham:
|
|
1056
2622
|
|
|
1057
2623
|
```js
|
|
1058
2624
|
await sock.sendMessage(jid, {
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
}
|
|
2625
|
+
text: 'Portofolio investasi Anda:',
|
|
2626
|
+
footer: 'Bursa Saham Harps-MD',
|
|
2627
|
+
cards: perusahaanList.map(p => ({
|
|
2628
|
+
image: { url: p.logoUrl },
|
|
2629
|
+
title: p.nama,
|
|
2630
|
+
body: `Harga saham: ${p.harga} | Pertumbuhan: ${p.pertumbuhan}%`,
|
|
2631
|
+
buttons: [
|
|
2632
|
+
{ id: `beli_saham_${p.id}`, text: '📈 Beli' },
|
|
2633
|
+
{ id: `jual_saham_${p.id}`, text: '📉 Jual' }
|
|
2634
|
+
]
|
|
2635
|
+
}))
|
|
2636
|
+
})
|
|
1068
2637
|
```
|
|
1069
2638
|
|
|
1070
|
-
|
|
2639
|
+
### List Bersarang untuk Katalog Teknologi/Chipset
|
|
2640
|
+
|
|
2641
|
+
Untuk `rpg-teknologi.js` dengan arsitektur chipset/GPU berjenjang (kategori → sub-kategori → item):
|
|
1071
2642
|
|
|
1072
2643
|
```js
|
|
1073
|
-
await sock.
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
2644
|
+
await sock.sendMessage(jid, {
|
|
2645
|
+
nestedListMessage: {
|
|
2646
|
+
title: '🖥️ Katalog Chipset',
|
|
2647
|
+
buttonText: 'Lihat Chipset',
|
|
2648
|
+
footer: 'Sistem Teknologi Harps-MD',
|
|
2649
|
+
sections: [
|
|
2650
|
+
{
|
|
2651
|
+
title: '⚡ Chipset Tier 1',
|
|
2652
|
+
rows: [
|
|
2653
|
+
{ rowId: 'chip_a1', title: 'NeoCore X1', description: '3.2 GHz, 8 core' },
|
|
2654
|
+
{
|
|
2655
|
+
title: '🎮 GPU Sub-Kategori',
|
|
2656
|
+
rows: [
|
|
2657
|
+
{ rowId: 'gpu_x1', title: 'VoltEdge RTX-Z', description: '16GB VRAM' }
|
|
2658
|
+
]
|
|
2659
|
+
}
|
|
2660
|
+
]
|
|
2661
|
+
}
|
|
2662
|
+
]
|
|
2663
|
+
}
|
|
2664
|
+
}, { quoted: msg })
|
|
1077
2665
|
```
|
|
1078
2666
|
|
|
1079
|
-
|
|
2667
|
+
### Tag Semua Investor Saat Ada Pergerakan Pasar Besar
|
|
2668
|
+
|
|
2669
|
+
Menggabungkan `buildTagAllText` dengan notifikasi pasar saham NPC whale:
|
|
1080
2670
|
|
|
1081
2671
|
```js
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
footer: "Ourin Shop",
|
|
1094
|
-
buttons: [
|
|
1095
|
-
{
|
|
1096
|
-
name: "quick_reply",
|
|
1097
|
-
buttonParamsJson: JSON.stringify({
|
|
1098
|
-
display_text: "Buy Now",
|
|
1099
|
-
id: "buy_wh001",
|
|
1100
|
-
}),
|
|
1101
|
-
},
|
|
1102
|
-
],
|
|
1103
|
-
},
|
|
1104
|
-
});
|
|
1105
|
-
```
|
|
1106
|
-
|
|
1107
|
-
**Mixed Rich Message (custom submessages):**
|
|
1108
|
-
|
|
1109
|
-
```js
|
|
1110
|
-
await sock.sendRichMessage(
|
|
1111
|
-
jid,
|
|
1112
|
-
[
|
|
1113
|
-
{ messageType: 2, messageText: "Here is some info:" },
|
|
1114
|
-
{
|
|
1115
|
-
messageType: 4,
|
|
1116
|
-
tableMetadata: {
|
|
1117
|
-
title: "Stats",
|
|
1118
|
-
rows: [
|
|
1119
|
-
{ items: ["Metric", "Value"], isHeading: true },
|
|
1120
|
-
{ items: ["Users", "1000"] },
|
|
1121
|
-
{ items: ["Uptime", "99.9%"] },
|
|
1122
|
-
],
|
|
1123
|
-
},
|
|
1124
|
-
},
|
|
1125
|
-
{ messageType: 2, messageText: "And some code:" },
|
|
1126
|
-
{
|
|
1127
|
-
messageType: 5,
|
|
1128
|
-
codeMetadata: {
|
|
1129
|
-
codeLanguage: "javascript",
|
|
1130
|
-
codeBlocks: [{ highlightType: 0, codeContent: 'console.log("OK")' }],
|
|
1131
|
-
},
|
|
1132
|
-
},
|
|
1133
|
-
],
|
|
1134
|
-
quoted,
|
|
1135
|
-
);
|
|
1136
|
-
```
|
|
1137
|
-
|
|
1138
|
-
**SubMessage Types:**
|
|
1139
|
-
|
|
1140
|
-
| messageType | Name | Payload Field |
|
|
1141
|
-
| ----------- | ------------- | ---------------------- |
|
|
1142
|
-
| 0 | UNKNOWN | — |
|
|
1143
|
-
| 1 | GRID_IMAGE | `gridImageMetadata` |
|
|
1144
|
-
| 2 | TEXT | `messageText` |
|
|
1145
|
-
| 3 | INLINE_IMAGE | `imageMetadata` |
|
|
1146
|
-
| 4 | TABLE | `tableMetadata` |
|
|
1147
|
-
| 5 | CODE | `codeMetadata` |
|
|
1148
|
-
| 6 | DYNAMIC | `dynamicMetadata` |
|
|
1149
|
-
| 7 | MAP | `mapMetadata` |
|
|
1150
|
-
| 8 | LATEX | `latexMetadata` |
|
|
1151
|
-
| 9 | CONTENT_ITEMS | `contentItemsMetadata` |
|
|
2672
|
+
import { buildTagAllText } from '@vinzsocket/baileys/lib/Utils/mention.js'
|
|
2673
|
+
|
|
2674
|
+
async function notifikasiCrashPasar(sock, groupJid) {
|
|
2675
|
+
const metadata = await sock.groupMetadata(groupJid)
|
|
2676
|
+
const { text, mentions } = buildTagAllText(metadata.participants, {
|
|
2677
|
+
header: '🚨 PASAR SAHAM ANJLOK! NPC Whale baru saja melakukan aksi jual besar-besaran.',
|
|
2678
|
+
footer: 'Cek portofolio Anda sekarang sebelum kerugian bertambah.'
|
|
2679
|
+
})
|
|
2680
|
+
await sock.sendMessage(groupJid, { text, mentions })
|
|
2681
|
+
}
|
|
2682
|
+
```
|
|
1152
2683
|
|
|
1153
2684
|
---
|
|
1154
2685
|
|
|
1155
|
-
|
|
2686
|
+
## ⚡ Tips Performa
|
|
1156
2687
|
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
2688
|
+
- **Matikan `syncFullHistory`** (`false`) jika bot Anda tidak butuh riwayat chat lengkap saat pairing pertama — mempercepat waktu koneksi awal secara signifikan pada akun dengan riwayat chat besar.
|
|
2689
|
+
- **Selalu isi `cachedGroupMetadata`** dengan cache Anda sendiri (in-memory `NodeCache`, Redis, dsb) — tanpa ini, setiap pengiriman pesan ke grup memicu query `groupMetadata` baru ke server.
|
|
2690
|
+
- **Selalu isi `getMessage`** dengan resolver dari store pesan Anda — dibutuhkan untuk retry pengiriman gagal, decrypt ulang, dan proses edit/pin pesan lama. Tanpa ini, operasi tersebut bisa gagal senyap.
|
|
2691
|
+
- **Gunakan `enableRecentMessageCache: true`** (default) supaya lookup pesan terbaru tidak perlu selalu memanggil `getMessage` custom Anda.
|
|
2692
|
+
- **Batasi `logger` ke level `warn`/`error`** di produksi (`pino({ level: 'warn' })`) — logging level `debug` sangat verbose dan bisa memperlambat proses I/O pada bot dengan traffic tinggi.
|
|
2693
|
+
- **Gunakan `sock.ev.buffer()` / `sock.ev.flush()`** saat melakukan operasi massal (mis. restore ratusan kontak) agar handler event Anda tidak terpanggil berkali-kali secara terpisah.
|
|
2694
|
+
- **Hindari memanggil `groupMetadata()` di dalam loop** untuk banyak grup sekaligus — gunakan `groupFetchAllParticipating()` sekali saja lalu simpan hasilnya ke cache.
|
|
2695
|
+
- **Batasi concurrency saat broadcast** (lihat contoh `p-queue` di bagian FAQ) untuk menghindari flag spam dari WhatsApp sekaligus menjaga stabilitas koneksi socket.
|
|
2696
|
+
- **Gunakan `viewOnce: true` secukupnya** — media view-once tetap perlu diunggah penuh ke server WA seperti media biasa, tidak ada penghematan bandwidth dari sisi pengiriman.
|
|
1161
2697
|
|
|
1162
|
-
|
|
1163
|
-
await sock.newsletterMultipleFollow("id1@newsletter id2@newsletter");
|
|
2698
|
+
---
|
|
1164
2699
|
|
|
1165
|
-
|
|
1166
|
-
const channels = await sock.newsletterFetchAllSubscribe();
|
|
2700
|
+
## 🔒 Keamanan & Best Practices
|
|
1167
2701
|
|
|
1168
|
-
|
|
1169
|
-
|
|
2702
|
+
- **Jangan pernah commit folder auth state** (`sesi_auth/`, `creds.json`, dsb) ke git — file-file ini setara dengan kredensial login penuh ke akun WhatsApp terkait. Tambahkan ke `.gitignore`.
|
|
2703
|
+
- **Jangan bagikan `creds.json`** ke pihak lain atau upload ke layanan publik (paste bin, forum, dsb) — siapa pun yang memilikinya bisa menyamar sebagai linked device Anda.
|
|
2704
|
+
- **Validasi input dari pengguna** sebelum diteruskan ke `sendMessage` (mis. `jid` tujuan) untuk mencegah bot disalahgunakan mengirim pesan ke JID yang tidak dimaksud.
|
|
2705
|
+
- **Batasi command sensitif** (broadcast massal, kick anggota, hapus data) hanya untuk JID admin yang sudah diverifikasi — jangan hanya mengandalkan prefix command tanpa pengecekan pengirim.
|
|
2706
|
+
- **Gunakan `shouldIgnoreJid`** di config untuk secara eksplisit mengabaikan JID tertentu (mis. broadcast list, JID yang diketahui sebagai sumber spam) sebelum diproses lebih jauh oleh event handler Anda.
|
|
2707
|
+
- **Selalu bungkus handler pesan dengan `try/catch`** — satu error tak tertangani di handler tidak boleh sampai membuat seluruh proses bot crash.
|
|
2708
|
+
- **Perhatikan rate limit WhatsApp** — pengiriman pesan dalam volume sangat tinggi dalam waktu singkat berisiko membuat akun terkena flag spam atau bahkan banned permanen. Ini bukan batasan dari Harps-Baileys, melainkan kebijakan WhatsApp di level protokol/server.
|
|
2709
|
+
- **Update library secara berkala** — WhatsApp cukup sering mengubah detail protokol level rendah; versi Harps-Baileys yang usang berisiko berhenti berfungsi tanpa peringatan (mis. `version` di config perlu disesuaikan dengan rilis WA Web terbaru).
|
|
1170
2710
|
|
|
1171
|
-
|
|
1172
|
-
const nl = await sock.newsletterCreate("My Channel", "Description");
|
|
2711
|
+
---
|
|
1173
2712
|
|
|
1174
|
-
|
|
1175
|
-
await sock.newsletterUpdate("id@newsletter", { name: "New Name" });
|
|
2713
|
+
## 🆚 Perbandingan dengan Baileys Upstream
|
|
1176
2714
|
|
|
1177
|
-
|
|
1178
|
-
const { subscribers } = await sock.newsletterSubscribers("id@newsletter");
|
|
2715
|
+
Tabel ini merangkum perbedaan utama antara Harps-Baileys dan Baileys upstream (`@whiskeysockets/baileys`), khusus untuk fitur-fitur yang relevan bagi pengembang bot.
|
|
1179
2716
|
|
|
1180
|
-
|
|
1181
|
-
|
|
2717
|
+
| Fitur | Baileys Upstream | Harps-Baileys |
|
|
2718
|
+
|---|---|---|
|
|
2719
|
+
| Kirim teks, media dasar, kontak, lokasi, reaksi, poll | ✅ | ✅ |
|
|
2720
|
+
| Native Flow buttons (`quick_reply`, `cta_url`, dll) | ✅ (manual, perlu tahu shape proto) | ✅ + shorthand `buttons`/`templateButtons` yang lebih ringkas |
|
|
2721
|
+
| List message | ✅ | ✅ + `nestedListMessage` dengan auto-flatten section bersarang |
|
|
2722
|
+
| Carousel (`cards`) | Tergantung versi, sering perlu payload manual | ✅ shorthand `cards` siap pakai |
|
|
2723
|
+
| Multi-dropdown dalam satu pesan | ❌ tidak ada bawaan | ✅ `multiSelectMessage` |
|
|
2724
|
+
| Story/status ke grup tertentu | ❌ tidak ada bawaan | ✅ `groupStatusMessage` (Group Status V2), semua tipe media |
|
|
2725
|
+
| Generator gambar story otomatis | ❌ | ✅ `renderStoryCard()` berbasis Jimp |
|
|
2726
|
+
| `additionalNodes` otomatis untuk semua pesan interaktif | Tergantung versi & implementasi pengguna | ✅ otomatis via `buildInteractiveAdditionalNodes` di semua jalur pengiriman relevan |
|
|
2727
|
+
| Payment request message | Tergantung versi | ✅ `requestPaymentMessage` shorthand |
|
|
2728
|
+
| Product message tunggal | Tergantung versi | ✅ `productMessage` shorthand |
|
|
2729
|
+
| Album (grup foto/video) | Tergantung versi | ✅ `albumMessage` shorthand |
|
|
2730
|
+
| Poll result snapshot | ❌ | ✅ `pollResultMessage` |
|
|
2731
|
+
| Dokumen dengan thumbnail preview | Tergantung versi | ✅ dipatch agar konsisten menampilkan `jpegThumbnail` |
|
|
1182
2732
|
|
|
1183
|
-
|
|
1184
|
-
await sock.newsletterFollow("id@newsletter");
|
|
1185
|
-
await sock.newsletterUnfollow("id@newsletter");
|
|
2733
|
+
> Tabel ini merefleksikan fitur pada level API permukaan yang relevan untuk pengembangan bot sehari-hari, bukan perbandingan menyeluruh setiap detail implementasi protokol level rendah kedua library.
|
|
1186
2734
|
|
|
1187
|
-
|
|
1188
|
-
await sock.newsletterMute("id@newsletter");
|
|
1189
|
-
await sock.newsletterUnmute("id@newsletter");
|
|
2735
|
+
---
|
|
1190
2736
|
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
2737
|
+
## 📖 Glosarium Istilah
|
|
2738
|
+
|
|
2739
|
+
| Istilah | Penjelasan |
|
|
2740
|
+
|---|---|
|
|
2741
|
+
| **JID** | *Jabber ID* — pengenal unik entitas WhatsApp (user, grup, channel), format `user@server`. |
|
|
2742
|
+
| **LID** | *Linked Identity* — JID tersamar (`@lid`) yang menggantikan nomor telepon asli demi privasi, terutama di grup besar. |
|
|
2743
|
+
| **PN** | *Phone Number* — JID berbasis nomor telepon asli (`@s.whatsapp.net`), lawan dari LID. |
|
|
2744
|
+
| **Native Flow** | Sistem tombol/interaktif modern WhatsApp (`interactiveMessage.nativeFlowMessage`), pengganti `buttonsMessage`/`templateMessage` legacy. |
|
|
2745
|
+
| **NF V7** | Istilah internal fork ini untuk generasi ke-7 builder Native Flow yang mencakup 13 jenis tombol (URL, call, copy, reminder, dst). |
|
|
2746
|
+
| **Additional Nodes** | Node XML biner tambahan yang dikirim bersamaan dengan payload pesan lewat `relayMessage()`, memberi hint ke client cara merender pesan tersebut. |
|
|
2747
|
+
| **Relay Message** | Proses inti mengenkripsi & mengirim sebuah pesan ke satu/banyak device tujuan lewat protokol Signal. |
|
|
2748
|
+
| **App-State** | Data tersinkronisasi lintas device (kontak, chat, label, pengaturan) yang disimpan sebagai *patch* terenkripsi di server WhatsApp. |
|
|
2749
|
+
| **Pre-Key** | Kunci kriptografi sekali pakai (Signal Protocol) yang perlu selalu tersedia agar device lain bisa memulai sesi terenkripsi baru dengan Anda. |
|
|
2750
|
+
| **Sender Key** | Kunci untuk enkripsi pesan grup (agar tidak perlu enkripsi 1-1 ke tiap anggota). |
|
|
2751
|
+
| **Stub Message** | Pesan sistem tanpa konten asli (`message: null`), merepresentasikan event seperti "X mengubah nama grup" — dibaca dari `messageStubType`. |
|
|
2752
|
+
| **Ephemeral** | Pesan sekali lihat (*disappearing message*) — otomatis terhapus setelah durasi tertentu. |
|
|
2753
|
+
| **PTT** | *Push To Talk* — voice note (pesan suara), lawan dari audio musik biasa. |
|
|
2754
|
+
| **PTV** | *Push To Video* — video pesan bulat gaya voice note. |
|
|
2755
|
+
| **Boom** | Kelas error dari `@hapi/boom`, membawa `output.statusCode` mirip kode status HTTP. |
|
|
2756
|
+
| **Noise Protocol** | Protokol handshake kriptografi yang dipakai WhatsApp Web untuk membangun koneksi WebSocket aman sebelum otentikasi Signal berlangsung. |
|
|
2757
|
+
| **USync** | Protokol WhatsApp untuk query status banyak user/device sekaligus (dipakai untuk cek siapa yang online di WhatsApp sebelum mengirim pesan). |
|
|
2758
|
+
| **WAM** | *WhatsApp Analytics/Metrics* — encoder biner untuk data telemetri internal client (bukan untuk data pengguna). |
|
|
1196
2759
|
|
|
1197
|
-
|
|
1198
|
-
await sock.newsletterReactMessage("id@newsletter", serverId, "👍");
|
|
2760
|
+
---
|
|
1199
2761
|
|
|
1200
|
-
|
|
1201
|
-
|
|
2762
|
+
## ⚙️ Opsi Lengkap `sendMessage(jid, content, options)`
|
|
2763
|
+
|
|
2764
|
+
Parameter ketiga (`options`) bersifat opsional dan memengaruhi bagaimana pesan dibangun & dikirim:
|
|
2765
|
+
|
|
2766
|
+
| Opsi | Tipe | Keterangan |
|
|
2767
|
+
|---|---|---|
|
|
2768
|
+
| `quoted` | `WAMessage` | Pesan yang ingin di-reply/kutip. |
|
|
2769
|
+
| `messageId` | `string` | Override ID pesan (default: digenerate otomatis, format `3EB0` + random hex). |
|
|
2770
|
+
| `timestamp` | `Date` | Override waktu pesan (default: `new Date()` saat ini). |
|
|
2771
|
+
| `ephemeralExpiration` | `number` | Durasi pesan sekali lihat dalam detik (default: `WA_DEFAULT_EPHEMERAL` jika chat sedang ephemeral). |
|
|
2772
|
+
| `mediaCache` | objek cache | Cache upload media agar file yang sama tidak diunggah ulang (mengurangi request upload berulang). |
|
|
2773
|
+
| `mediaUploadTimeoutMs` | `number` | Timeout khusus untuk proses upload media. |
|
|
2774
|
+
| `backgroundColor` | `string`/`number` | Warna latar untuk teks bergaya atau audio dengan visual (lihat bagian [Teks & Link Preview](#teks--link-preview)). |
|
|
2775
|
+
| `font` | `number` | Indeks font (0-5) untuk teks bergaya. |
|
|
2776
|
+
| `getUrlInfo` | `function` | Override resolver link preview kustom (default memakai `link-preview-js`). |
|
|
2777
|
+
| `getProfilePicUrl` | `function` | Dipakai saat mengirim `groupInvite` agar bisa menampilkan foto profil grup di pesan undangan. |
|
|
2778
|
+
| `getCallLink` | `function` | Resolver untuk membuat link panggilan otomatis pada `event.call`. |
|
|
2779
|
+
| `useCachedGroupMetadata` | `boolean` | Paksa pakai/lewati cache `cachedGroupMetadata` khusus untuk pengiriman ini. |
|
|
2780
|
+
| `statusJidList` | `string[]` | Daftar JID penerima khusus untuk pesan status (`status@broadcast`) — hanya JID ini yang akan melihat status Anda. |
|
|
2781
|
+
| `broadcast` | `boolean` | Tandai pesan sebagai broadcast list. |
|
|
2782
|
+
| `additionalNodes` | `BinaryNode[]` | Node binari tambahan manual (lihat [`buildInteractiveAdditionalNodes`](#buildinteractiveadditionalnodes--kenapa-wajib-ada)) — jarang perlu diisi manual karena sudah otomatis. |
|
|
2783
|
+
| `forceForward` | `boolean` | Paksa tandai pesan sebagai "diteruskan" walau baru pertama kali diteruskan. |
|
|
2784
|
+
| `logger` | pino logger | Override logger khusus untuk pengiriman pesan ini saja. |
|
|
2785
|
+
|
|
2786
|
+
### Contoh Menggabungkan Beberapa Opsi Sekaligus
|
|
1202
2787
|
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
2788
|
+
```js
|
|
2789
|
+
await sock.sendMessage(jid, {
|
|
2790
|
+
text: 'Pesan penting yang akan hilang dalam 1 jam'
|
|
2791
|
+
}, {
|
|
2792
|
+
quoted: msg,
|
|
2793
|
+
ephemeralExpiration: 3600,
|
|
2794
|
+
messageId: `CUSTOM-${Date.now()}`,
|
|
2795
|
+
logger: sock.logger.child({ feature: 'reminder' })
|
|
2796
|
+
})
|
|
1208
2797
|
```
|
|
1209
2798
|
|
|
1210
2799
|
---
|
|
1211
2800
|
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
```js
|
|
1215
|
-
// Fetch group metadata
|
|
1216
|
-
const meta = await sock.groupMetadata("id@g.us");
|
|
2801
|
+
## 🚢 Deployment
|
|
1217
2802
|
|
|
1218
|
-
|
|
1219
|
-
const group = await sock.groupCreate("My Group", ["628xxx@s.whatsapp.net"]);
|
|
2803
|
+
Beberapa pola umum menjalankan bot Harps-MD berbasis Harps-Baileys di server produksi.
|
|
1220
2804
|
|
|
1221
|
-
|
|
1222
|
-
await sock.groupLeave("id@g.us");
|
|
2805
|
+
### PM2 (Process Manager)
|
|
1223
2806
|
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
2807
|
+
```bash
|
|
2808
|
+
npm install -g pm2
|
|
2809
|
+
pm2 start index.js --name harps-md --time
|
|
2810
|
+
pm2 save
|
|
2811
|
+
pm2 startup # ikuti instruksi agar bot auto-start saat server reboot
|
|
2812
|
+
```
|
|
1227
2813
|
|
|
1228
|
-
|
|
1229
|
-
const result = await sock.groupParticipantsUpdate(
|
|
1230
|
-
"id@g.us",
|
|
1231
|
-
["628xxx@s.whatsapp.net"],
|
|
1232
|
-
"add", // 'remove' | 'promote' | 'demote'
|
|
1233
|
-
);
|
|
2814
|
+
Contoh `ecosystem.config.cjs` untuk konfigurasi lebih rapi:
|
|
1234
2815
|
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
2816
|
+
```js
|
|
2817
|
+
module.exports = {
|
|
2818
|
+
apps: [{
|
|
2819
|
+
name: 'harps-md',
|
|
2820
|
+
script: './index.js',
|
|
2821
|
+
watch: false,
|
|
2822
|
+
autorestart: true,
|
|
2823
|
+
max_restarts: 20,
|
|
2824
|
+
restart_delay: 3000,
|
|
2825
|
+
env: {
|
|
2826
|
+
NODE_ENV: 'production'
|
|
2827
|
+
}
|
|
2828
|
+
}]
|
|
2829
|
+
}
|
|
2830
|
+
```
|
|
1242
2831
|
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
await sock.groupAcceptInvite("ABCDE12345");
|
|
1247
|
-
const info = await sock.groupGetInviteInfo("ABCDE12345");
|
|
2832
|
+
```bash
|
|
2833
|
+
pm2 start ecosystem.config.cjs
|
|
2834
|
+
```
|
|
1248
2835
|
|
|
1249
|
-
|
|
1250
|
-
await sock.groupSettingUpdate("id@g.us", "announcement");
|
|
1251
|
-
await sock.groupSettingUpdate("id@g.us", "locked");
|
|
2836
|
+
### Docker
|
|
1252
2837
|
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
await sock.groupJoinApprovalMode("id@g.us", "on");
|
|
2838
|
+
```dockerfile
|
|
2839
|
+
FROM node:20-slim
|
|
1256
2840
|
|
|
1257
|
-
|
|
1258
|
-
|
|
2841
|
+
WORKDIR /app
|
|
2842
|
+
COPY package*.json ./
|
|
2843
|
+
RUN npm install --omit=dev
|
|
1259
2844
|
|
|
1260
|
-
|
|
1261
|
-
const groups = await sock.groupFetchAllParticipating();
|
|
2845
|
+
COPY . .
|
|
1262
2846
|
|
|
1263
|
-
|
|
1264
|
-
await sock.updateMemberLabel("id@g.us", "VIP");
|
|
2847
|
+
CMD ["node", "index.js"]
|
|
1265
2848
|
```
|
|
1266
2849
|
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
```js
|
|
1272
|
-
// Fetch community metadata
|
|
1273
|
-
const meta = await sock.communityMetadata("communityid@g.us");
|
|
1274
|
-
|
|
1275
|
-
// Create community
|
|
1276
|
-
const community = await sock.communityCreate(
|
|
1277
|
-
"Our Community",
|
|
1278
|
-
"Community description",
|
|
1279
|
-
);
|
|
1280
|
-
|
|
1281
|
-
// Create a subgroup under a community
|
|
1282
|
-
const subgroup = await sock.communityCreateGroup(
|
|
1283
|
-
"Announcements",
|
|
1284
|
-
["628xxx@s.whatsapp.net"],
|
|
1285
|
-
"communityid@g.us",
|
|
1286
|
-
);
|
|
1287
|
-
|
|
1288
|
-
// Link / unlink an existing group
|
|
1289
|
-
await sock.communityLinkGroup("groupid@g.us", "communityid@g.us");
|
|
1290
|
-
await sock.communityUnlinkGroup("groupid@g.us", "communityid@g.us");
|
|
1291
|
-
|
|
1292
|
-
// Fetch linked groups
|
|
1293
|
-
const linked = await sock.communityFetchLinkedGroups("communityid@g.us");
|
|
1294
|
-
|
|
1295
|
-
// Invite handling
|
|
1296
|
-
const code = await sock.communityInviteCode("communityid@g.us");
|
|
1297
|
-
await sock.communityRevokeInvite("communityid@g.us");
|
|
1298
|
-
await sock.communityAcceptInvite(code);
|
|
1299
|
-
const inviteInfo = await sock.communityGetInviteInfo(code);
|
|
1300
|
-
|
|
1301
|
-
// Requests / participants
|
|
1302
|
-
const requests =
|
|
1303
|
-
await sock.communityRequestParticipantsList("communityid@g.us");
|
|
1304
|
-
await sock.communityRequestParticipantsUpdate(
|
|
1305
|
-
"communityid@g.us",
|
|
1306
|
-
["628xxx@s.whatsapp.net"],
|
|
1307
|
-
"approve",
|
|
1308
|
-
);
|
|
1309
|
-
await sock.communityParticipantsUpdate(
|
|
1310
|
-
"communityid@g.us",
|
|
1311
|
-
["628xxx@s.whatsapp.net"],
|
|
1312
|
-
"add",
|
|
1313
|
-
);
|
|
1314
|
-
|
|
1315
|
-
// Settings
|
|
1316
|
-
await sock.communityUpdateSubject("communityid@g.us", "New Subject");
|
|
1317
|
-
await sock.communityUpdateDescription("communityid@g.us", "New Description");
|
|
1318
|
-
await sock.communityToggleEphemeral("communityid@g.us", 86400);
|
|
1319
|
-
await sock.communitySettingUpdate("communityid@g.us", "announcement");
|
|
1320
|
-
await sock.communityMemberAddMode("communityid@g.us", "admin_add");
|
|
1321
|
-
await sock.communityJoinApprovalMode("communityid@g.us", "on");
|
|
1322
|
-
|
|
1323
|
-
// Leave / list all
|
|
1324
|
-
await sock.communityLeave("communityid@g.us");
|
|
1325
|
-
const communities = await sock.communityFetchAllParticipating();
|
|
2850
|
+
```bash
|
|
2851
|
+
docker build -t harps-md .
|
|
2852
|
+
docker run -d --name harps-md -v $(pwd)/sesi_auth:/app/sesi_auth harps-md
|
|
1326
2853
|
```
|
|
1327
2854
|
|
|
1328
|
-
|
|
2855
|
+
> Penting: mount folder auth state (`sesi_auth`) sebagai **volume**, bukan menyimpannya di dalam layer image — jika tidak, sesi login akan hilang setiap kali container dibuat ulang.
|
|
1329
2856
|
|
|
1330
|
-
###
|
|
1331
|
-
|
|
1332
|
-
```
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
const { collections } = await sock.getCollections("628xxx@s.whatsapp.net", 10);
|
|
1340
|
-
|
|
1341
|
-
// Orders
|
|
1342
|
-
const order = await sock.getOrderDetails(orderId, tokenBase64);
|
|
1343
|
-
|
|
1344
|
-
// Product CRUD
|
|
1345
|
-
const product = await sock.productCreate({
|
|
1346
|
-
name: "Premium Package",
|
|
1347
|
-
description: "Official premium plan",
|
|
1348
|
-
price: 150000,
|
|
1349
|
-
currency: "IDR",
|
|
1350
|
-
originCountryCode: "ID",
|
|
1351
|
-
images: [mediaUpload],
|
|
1352
|
-
});
|
|
1353
|
-
|
|
1354
|
-
await sock.productUpdate(product.id, {
|
|
1355
|
-
name: "Premium Package Plus",
|
|
1356
|
-
description: "Official premium plan plus",
|
|
1357
|
-
price: 175000,
|
|
1358
|
-
currency: "IDR",
|
|
1359
|
-
images: [mediaUpload],
|
|
1360
|
-
});
|
|
1361
|
-
|
|
1362
|
-
await sock.productDelete([product.id]);
|
|
1363
|
-
|
|
1364
|
-
// Business profile
|
|
1365
|
-
await sock.updateBusinessProfile({
|
|
1366
|
-
address: "Jakarta, Indonesia",
|
|
1367
|
-
description: "Official store",
|
|
1368
|
-
websites: ["https://example.com"],
|
|
1369
|
-
email: "hello@example.com",
|
|
1370
|
-
hours: {
|
|
1371
|
-
timezone: "Asia/Jakarta",
|
|
1372
|
-
days: [{ day: "mon", mode: "open_24h" }],
|
|
1373
|
-
},
|
|
1374
|
-
});
|
|
1375
|
-
|
|
1376
|
-
// Legacy alias is still available for backward compatibility
|
|
1377
|
-
await sock.updateBussinesProfile({
|
|
1378
|
-
description: "Legacy alias still works",
|
|
1379
|
-
});
|
|
1380
|
-
|
|
1381
|
-
await sock.updateCoverPhoto(mediaUpload);
|
|
1382
|
-
await sock.removeCoverPhoto(coverId);
|
|
1383
|
-
|
|
1384
|
-
// Quick replies
|
|
1385
|
-
await sock.addOrEditQuickReply({
|
|
1386
|
-
shortcut: "hello",
|
|
1387
|
-
message: "Hello from business account",
|
|
1388
|
-
});
|
|
1389
|
-
|
|
1390
|
-
await sock.removeQuickReply(timestamp);
|
|
2857
|
+
### Auto-Restart Sederhana Tanpa PM2/Docker
|
|
2858
|
+
|
|
2859
|
+
```bash
|
|
2860
|
+
while true; do
|
|
2861
|
+
node index.js
|
|
2862
|
+
echo "Bot berhenti, restart dalam 5 detik..."
|
|
2863
|
+
sleep 5
|
|
2864
|
+
done
|
|
1391
2865
|
```
|
|
1392
2866
|
|
|
1393
2867
|
---
|
|
1394
2868
|
|
|
1395
|
-
|
|
2869
|
+
## 📝 Changelog Ringkas
|
|
1396
2870
|
|
|
1397
|
-
|
|
1398
|
-
// Profile picture
|
|
1399
|
-
const url = await sock.profilePictureUrl(jid, "image");
|
|
1400
|
-
await sock.updateProfilePicture(jid, mediaUpload);
|
|
1401
|
-
await sock.removeProfilePicture(jid);
|
|
1402
|
-
|
|
1403
|
-
// Profile name / status
|
|
1404
|
-
await sock.updateProfileName("My Name");
|
|
1405
|
-
await sock.updateProfileStatus("Available");
|
|
2871
|
+
Riwayat perubahan lengkap ada di [`CHANGELOG.md`](./CHANGELOG.md). Ringkasan rilis terbaru:
|
|
1406
2872
|
|
|
1407
|
-
|
|
1408
|
-
await sock.sendPresenceUpdate("available", jid);
|
|
1409
|
-
await sock.presenceSubscribe(jid);
|
|
2873
|
+
### v3.3.0 (2026-07-06) — Bug Fix Kritis Group Status
|
|
1410
2874
|
|
|
1411
|
-
|
|
1412
|
-
await sock.readMessages([msg.key]);
|
|
1413
|
-
await sock.sendReceipt(jid, participant, [msgId], "read");
|
|
2875
|
+
**Masalah:** status/story grup (`groupStatusMessage`) tidak pernah muncul sebagai ring status untuk anggota lain, walaupun `relayMessage()` berhasil tanpa error sama sekali.
|
|
1414
2876
|
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
2877
|
+
**Akar masalah:**
|
|
2878
|
+
1. `ExtendedMessageBuilder` (`dugong.js`) tidak menerima fungsi `buildInteractiveAdditionalNodes` lewat `this.utils` — fungsi tersebut tidak ikut di-passing dari `messages-send.js` saat instansiasi builder.
|
|
2879
|
+
2. `handleGroupStory()` memanggil `relayMessage()` di ketiga mode-nya (`raw`, `message`, dan generate dari media/teks) **tanpa** `additionalNodes` sama sekali — berbeda dengan case `PRODUCT` / `INTERACTIVE` / `NESTED_LIST` / `MULTI_SELECT` yang sudah benar menyertakannya sejak awal.
|
|
1418
2880
|
|
|
1419
|
-
|
|
1420
|
-
const list = await sock.fetchBlocklist();
|
|
2881
|
+
**Dampak:** pesan status grup terkirim & ter-enkripsi normal (server menerima tanpa exception), tapi client penerima tidak memiliki sinyal `<meta is_vsn2="1">` yang memberitahu bahwa payload tersebut harus dirender sebagai story/status grup — sehingga hanya sesi pengirim sendiri yang bisa "melihatnya" (tampil sebagai kartu pesan biasa/forward, bukan story sungguhan).
|
|
1421
2882
|
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
archive: true,
|
|
1426
|
-
lastMessageOrig: msg,
|
|
1427
|
-
lastMessage: msg,
|
|
1428
|
-
},
|
|
1429
|
-
jid,
|
|
1430
|
-
);
|
|
2883
|
+
**Perbaikan:**
|
|
2884
|
+
- `Socket/messages-send.js`: menambahkan `buildInteractiveAdditionalNodes` ke object `utils` yang di-passing ke `new ExtendedMessageBuilder(...)`.
|
|
2885
|
+
- `Socket/dugong.js` (`handleGroupStory`): menghitung `additionalNodes` via `this.utils.buildInteractiveAdditionalNodes(jid, wrapped)` dan menyertakannya di **setiap** pemanggilan `relayMessage()` — mode `raw`, mode `message` (WAMessage inner siap pakai), dan mode generate dari media/teks (image/video/audio/sticker/document/card/text).
|
|
1431
2886
|
|
|
1432
|
-
|
|
1433
|
-
await sock.star(jid, [{ id: msgId, fromMe: true }], true);
|
|
2887
|
+
Tidak ada breaking change pada bentuk input `content.groupStatusMessage` — semua mode (`text`, `image`, `video`, `audio`, `sticker`, `document`, `card`, `message`, `raw`) tetap identik seperti sebelumnya.
|
|
1434
2888
|
|
|
1435
|
-
|
|
1436
|
-
await sock.addOrEditContact(jid, { displayName: "Name" });
|
|
1437
|
-
await sock.removeContact(jid);
|
|
2889
|
+
> Catatan dari maintainer: `is_vsn2` adalah hint yang sudah diketahui diperlukan, tapi belum divalidasi lewat capture trafik client WA resmi apakah ada atribut/node tambahan lain yang dibutuhkan untuk seluruh kombinasi media. Jika setelah update masih ada kasus story tidak muncul untuk kombinasi tertentu, dibutuhkan capture trafik pembanding lebih lanjut.
|
|
1438
2890
|
|
|
1439
|
-
|
|
1440
|
-
await sock.addChatLabel(jid, labelId);
|
|
1441
|
-
await sock.removeChatLabel(jid, labelId);
|
|
1442
|
-
await sock.addMessageLabel(jid, messageId, labelId);
|
|
2891
|
+
### v3.2.9 (2026-06-30) — Group Status V2, Carousel, Multi-Select, Nested List
|
|
1443
2892
|
|
|
1444
|
-
|
|
1445
|
-
|
|
2893
|
+
**Fitur baru:**
|
|
2894
|
+
- `cards` shorthand → `interactiveMessage.carouselMessage` (carousel horizontal-scroll).
|
|
2895
|
+
- `Utils/story-card.js` (baru) — `renderStoryCard()`, generator visual story/status berbasis Jimp.
|
|
2896
|
+
- `handleGroupStory` mode baru `card` — kirim story langsung dari `renderStoryCard()` tanpa buffer manual.
|
|
2897
|
+
- `handleGroupStory`: dukungan semua tipe media dengan caption (`text`, `image`, `video`, `audio`, `sticker`, `document`, `message`, `raw`).
|
|
2898
|
+
- `multiSelectMessage` — satu pesan dengan beberapa `single_select` buttons terpisah.
|
|
2899
|
+
- `nestedListMessage` — `listMessage` dengan auto-flatten nested rows.
|
|
2900
|
+
- Ekspor semua NF V7 builders: `nfButtonUrl`, `nfButtonCall`, `nfButtonCopy`, `nfButtonReminder`, `nfButtonCancelReminder`, `nfButtonAddress`, `nfButtonLocation`, `nfButtonQuickReply`, `nfButtonSingleSelect`, `nfButtonMultiSelect`, `nfButtonReviewPay`, `nfButtonReviewOrder`, `nfButtonMPM`.
|
|
2901
|
+
- Ekspor `buildNestedListMessage()` sebagai helper standalone.
|
|
2902
|
+
- `messages-send.js`: wiring case `NESTED_LIST` dan `MULTI_SELECT`.
|
|
2903
|
+
- `buildInteractiveAdditionalNodes` menambah dukungan `groupStatusMessageV2` → inject `<meta is_vsn2="1">` di dalam grup.
|
|
1446
2904
|
|
|
1447
|
-
|
|
1448
|
-
const biz = await sock.getBusinessProfile(jid);
|
|
1449
|
-
```
|
|
2905
|
+
Lihat file [`CHANGELOG.md`](./CHANGELOG.md) untuk detail teknis penuh dari setiap rilis, termasuk rilis-rilis sebelum v3.2.9.
|
|
1450
2906
|
|
|
1451
2907
|
---
|
|
1452
2908
|
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
```js
|
|
1456
|
-
await sock.updateLastSeenPrivacy("all"); // 'all' | 'contacts' | 'contact_blacklist' | 'nobody'
|
|
1457
|
-
await sock.updateOnlinePrivacy("all"); // 'all' | 'match_last_seen'
|
|
1458
|
-
await sock.updateProfilePicturePrivacy("contacts");
|
|
1459
|
-
await sock.updateStatusPrivacy("contacts");
|
|
1460
|
-
await sock.updateReadReceiptsPrivacy("all"); // 'all' | 'none'
|
|
1461
|
-
await sock.updateGroupsAddPrivacy("all"); // 'all' | 'contacts'
|
|
1462
|
-
await sock.updateMessagesPrivacy("all"); // 'all' | 'contacts' | 'nobody'
|
|
1463
|
-
await sock.updateCallPrivacy("everyone");
|
|
1464
|
-
await sock.updateDefaultDisappearingMode(86400);
|
|
1465
|
-
await sock.updateDisableLinkPreviewsPrivacy(true);
|
|
1466
|
-
```
|
|
1467
|
-
|
|
1468
|
-
---
|
|
2909
|
+
## 🤝 Kontribusi
|
|
1469
2910
|
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
```js
|
|
1473
|
-
sock.ev.on('connection.update', ({ connection, lastDisconnect, qr, isNewLogin, receivedPendingNotifications, isOnline }) => {})
|
|
1474
|
-
sock.ev.on('creds.update', (update) => {})
|
|
1475
|
-
sock.ev.on('messaging-history.set', ({ chats, contacts, messages, isLatest }) => {})
|
|
1476
|
-
sock.ev.on('chats.upsert', (chats) => {})
|
|
1477
|
-
sock.ev.on('chats.update', (updates) => {})
|
|
1478
|
-
sock.ev.on('chats.delete', (jids) => {})
|
|
1479
|
-
sock.ev.on('contacts.upsert', (contacts) => {})
|
|
1480
|
-
sock.ev.on('contacts.update', (updates) => {})
|
|
1481
|
-
sock.ev.on('messages.upsert', ({ messages, type }) => {})
|
|
1482
|
-
sock.ev.on('messages.update', (updates) => {})
|
|
1483
|
-
sock.ev.on('messages.delete', (keys) => {})
|
|
1484
|
-
sock.ev.on('messages.reaction', (reactions) => {})
|
|
1485
|
-
sock.ev.on('message-receipt.update', (updates) => {})
|
|
1486
|
-
sock.ev.on('groups.update', (updates) => {})
|
|
1487
|
-
sock.ev.on('group-participants.update', (update) => {})
|
|
1488
|
-
sock.ev.on('group.join-request', (update) => {})
|
|
1489
|
-
sock.ev.on('call', (calls) => {})
|
|
1490
|
-
sock.ev.on('labels.edit', (label) => {})
|
|
1491
|
-
sock.ev.on('labels.associations', ({ associated, label, type }) => {})
|
|
1492
|
-
sock.ev.on('newsletter.update', (updates) => {})
|
|
1493
|
-
sock.ev.on('newsletter.follow', (jid) => {})
|
|
1494
|
-
sock.ev.on('newsletter.unfollow', (jid) => {})
|
|
1495
|
-
sock.ev.on('settings.update', ({ isAutoEmojiEnabled, isReadReceiptsEnabled, ... }) => {})
|
|
1496
|
-
```
|
|
2911
|
+
Repositori ini dirawat sebagai bagian dari ekosistem **Harps-MD**. Kontribusi, laporan bug, dan saran fitur dipersilakan lewat GitHub:
|
|
1497
2912
|
|
|
1498
|
-
|
|
2913
|
+
**https://github.com/VinzSocket/Baileys**
|
|
1499
2914
|
|
|
1500
|
-
|
|
2915
|
+
### Alur Kontribusi yang Disarankan
|
|
1501
2916
|
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
// Code tokenization
|
|
1512
|
-
tokenizeCode,
|
|
1513
|
-
tokenizeCodeV2,
|
|
1514
|
-
CodeHighlightType,
|
|
1515
|
-
RichSubMessageType,
|
|
1516
|
-
|
|
1517
|
-
// Rich message generators
|
|
1518
|
-
generateTableContent,
|
|
1519
|
-
generateTableContentV2,
|
|
1520
|
-
toTableMetadataV2,
|
|
1521
|
-
generateListContent,
|
|
1522
|
-
generateCodeBlockContent,
|
|
1523
|
-
generateCodeBlockContentV2,
|
|
1524
|
-
generateLinkContent,
|
|
1525
|
-
generateLinkContentV2,
|
|
1526
|
-
generateRichMessageContent,
|
|
1527
|
-
generateLatexContent,
|
|
1528
|
-
generateLatexImageContent,
|
|
1529
|
-
generateLatexInlineImageContent,
|
|
1530
|
-
generateUnifiedResponseContent,
|
|
1531
|
-
captureUnifiedResponse,
|
|
1532
|
-
|
|
1533
|
-
// Rich message builders
|
|
1534
|
-
buildRichContextInfo,
|
|
1535
|
-
buildBotForwardedMessage,
|
|
1536
|
-
|
|
1537
|
-
// Sticker pack helper
|
|
1538
|
-
makeStickerPack,
|
|
1539
|
-
|
|
1540
|
-
// Language keyword sets
|
|
1541
|
-
JS_KEYWORDS,
|
|
1542
|
-
PYTHON_KEYWORDS,
|
|
1543
|
-
GO_KEYWORDS,
|
|
1544
|
-
LUA_KEYWORDS,
|
|
1545
|
-
BASH_KEYWORDS,
|
|
1546
|
-
LANGUAGE_KEYWORDS,
|
|
1547
|
-
|
|
1548
|
-
// Crypto
|
|
1549
|
-
Curve,
|
|
1550
|
-
signedKeyPair,
|
|
1551
|
-
aesEncryptGCM,
|
|
1552
|
-
aesDecryptGCM,
|
|
1553
|
-
|
|
1554
|
-
// JID utilities
|
|
1555
|
-
jidEncode,
|
|
1556
|
-
jidDecode,
|
|
1557
|
-
jidNormalizedUser,
|
|
1558
|
-
areJidsSameUser,
|
|
1559
|
-
isJidGroup,
|
|
1560
|
-
isJidNewsletter,
|
|
1561
|
-
isLidUser,
|
|
1562
|
-
isPnUser,
|
|
1563
|
-
isJidBot,
|
|
1564
|
-
isJidMetaAI,
|
|
1565
|
-
isJidBroadcast,
|
|
1566
|
-
isJidStatusBroadcast,
|
|
1567
|
-
|
|
1568
|
-
// Connection
|
|
1569
|
-
DisconnectReason,
|
|
1570
|
-
Browsers,
|
|
1571
|
-
|
|
1572
|
-
// Dugong (advanced message types)
|
|
1573
|
-
Dugong,
|
|
1574
|
-
|
|
1575
|
-
// Types
|
|
1576
|
-
WASocket,
|
|
1577
|
-
} from "ourin-baileys";
|
|
1578
|
-
```
|
|
1579
|
-
|
|
1580
|
-
> [!NOTE]
|
|
1581
|
-
> In this build, some advanced helper typings may appear first in `lib/Socket/messages-send.d.ts` before they are reflected everywhere else in aggregated socket declarations. If your editor autocomplete lags behind runtime behavior, inspect `lib/Socket/messages-send.js` and `lib/Utils/rich-messages.d.ts` for the most complete helper surface.
|
|
2917
|
+
1. Fork repositori ini.
|
|
2918
|
+
2. Buat branch baru dari `main` dengan nama deskriptif, mis. `fix/group-status-additional-nodes`.
|
|
2919
|
+
3. Jalankan lint & test sebelum membuat PR:
|
|
2920
|
+
```bash
|
|
2921
|
+
npm run lint
|
|
2922
|
+
npm test
|
|
2923
|
+
```
|
|
2924
|
+
4. Tulis pesan commit mengikuti [Conventional Commits](https://www.conventionalcommits.org/) (`feat:`, `fix:`, `docs:`, `refactor:`, dst) — ini dipakai otomatis oleh `conventional-changelog` untuk menghasilkan `CHANGELOG.md`.
|
|
2925
|
+
5. Jelaskan **akar masalah** dan **dampaknya** di deskripsi PR, bukan cuma "fix bug X" — pola ini memudahkan audit perubahan di masa depan (lihat gaya penulisan `CHANGELOG.md` yang sudah ada sebagai referensi).
|
|
1582
2926
|
|
|
1583
|
-
|
|
2927
|
+
### Melaporkan Bug
|
|
1584
2928
|
|
|
1585
|
-
|
|
2929
|
+
Sertakan informasi berikut agar mudah direproduksi:
|
|
2930
|
+
- Versi `@vinzsocket/baileys` yang dipakai (`npm ls @vinzsocket/baileys`).
|
|
2931
|
+
- Versi Node.js (`node -v`).
|
|
2932
|
+
- Cuplikan kode minimal yang memicu masalah.
|
|
2933
|
+
- Perilaku yang diharapkan vs. yang benar-benar terjadi.
|
|
2934
|
+
- Log error lengkap (`logger` level `debug` jika memungkinkan, dengan data sensitif disensor).
|
|
1586
2935
|
|
|
1587
|
-
|
|
2936
|
+
### Menjalankan Build Lokal
|
|
1588
2937
|
|
|
1589
2938
|
```bash
|
|
2939
|
+
git clone https://github.com/VinzSocket/Baileys.git
|
|
2940
|
+
cd Baileys
|
|
1590
2941
|
npm install
|
|
1591
|
-
npm run build
|
|
2942
|
+
npm run build # kompilasi TypeScript ke lib/
|
|
2943
|
+
npm run build:docs # generate dokumentasi API (typedoc)
|
|
2944
|
+
npm test # unit test
|
|
1592
2945
|
```
|
|
1593
2946
|
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
- runs TypeScript with `tsconfig.build.json`
|
|
1597
|
-
- emits JavaScript and declaration files into `lib/`
|
|
1598
|
-
- runs `tsc-esm-fix` so generated ESM imports resolve cleanly
|
|
1599
|
-
|
|
1600
|
-
Important build notes:
|
|
2947
|
+
---
|
|
1601
2948
|
|
|
1602
|
-
|
|
1603
|
-
- `tsconfig.build.json` flips emit back on and excludes test files
|
|
1604
|
-
- published package files are limited to `lib/**/*` and `WAProto/**/*`
|
|
2949
|
+
## 🙏 Ucapan Terima Kasih
|
|
1605
2950
|
|
|
1606
|
-
|
|
2951
|
+
Harps-Baileys tidak akan ada tanpa fondasi yang dibangun komunitas open-source WhatsApp Web protocol reverse-engineering selama bertahun-tahun:
|
|
1607
2952
|
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
| Interactive messages | No native support | Full support via Dugong |
|
|
1613
|
-
| Album messages | Not supported | Multi-media albums |
|
|
1614
|
-
| AI Rich Response | Not available | Table, code block, rich text |
|
|
1615
|
-
| Table V1 | Not available | Basic table with headers |
|
|
1616
|
-
| Table V2 | Not available | Unified response + GenATableUXPrimitive |
|
|
1617
|
-
| Code Block V1 | Not available | Syntax highlighting (JS/TS/Python) |
|
|
1618
|
-
| Code Block V2 | Not available | Unified response + 6 languages |
|
|
1619
|
-
| Link Message | Not available | Inline embeds + citations + verification |
|
|
1620
|
-
| Business nodes | Manual injection | Auto-inject on relay |
|
|
1621
|
-
| Newsletter extras | Basic only | Auto-follow, bulk follow, URL resolve |
|
|
1622
|
-
| Button detection | Not available | `getButtonType()` auto-detect |
|
|
1623
|
-
| Payment messages | Not supported | Full support |
|
|
1624
|
-
| Event messages | Basic | Enhanced all fields |
|
|
1625
|
-
| Status mentions | Not available | `sendStatusMention()` |
|
|
1626
|
-
| Product messages | Not supported | Catalog + buttons |
|
|
1627
|
-
| LID support | Basic | Full LID↔PN mapping + session migration |
|
|
1628
|
-
| Identity changes | No handling | Debounced session refresh |
|
|
1629
|
-
| Message retry | Basic | `MessageRetryManager` with cache |
|
|
2953
|
+
- **[WhiskeySockets/Baileys](https://github.com/WhiskeySockets/Baileys)** — proyek induk yang menjadi basis seluruh fork ini, termasuk implementasi Signal Protocol, WABinary, dan arsitektur socket berlapis.
|
|
2954
|
+
- **Adiwajshing** (pencipta awal Baileys) dan seluruh kontributor upstream yang telah melakukan reverse-engineering protokol WhatsApp Web Multi-Device dari nol.
|
|
2955
|
+
- Komunitas fork Baileys lain (mis. Lily-Baileys, Whiskey, dan berbagai fork komunitas Indonesia lainnya) yang ide dan implementasinya turut menginspirasi beberapa fitur di Harps-Baileys, khususnya area mention utilities dan pola Native Flow button.
|
|
2956
|
+
- Seluruh pengguna & tester **Harps-MD** yang laporan bug dan masukannya secara langsung membentuk arah pengembangan fitur-fitur eksklusif di fork ini (Group Status V2, Multi-Select, Nested List, Story Card Generator, dan seterusnya).
|
|
1630
2957
|
|
|
1631
|
-
|
|
2958
|
+
## 📚 Sumber Daya Tambahan
|
|
1632
2959
|
|
|
1633
|
-
|
|
2960
|
+
- Repositori GitHub: **https://github.com/VinzSocket/Baileys**
|
|
2961
|
+
- Baileys upstream (referensi protokol dasar): **https://github.com/WhiskeySockets/Baileys**
|
|
2962
|
+
- Dokumentasi Protocol Buffers (untuk memahami `WAProto`): **https://protobuf.dev**
|
|
2963
|
+
- `@hapi/boom` (struktur error yang dipakai di seluruh library): **https://hapi.dev/module/boom**
|
|
2964
|
+
- Jimp (dependency opsional untuk `renderStoryCard`): **https://github.com/jimp-dev/jimp**
|
|
1634
2965
|
|
|
1635
|
-
|
|
1636
|
-
2. Create a branch (`git checkout -b feature/name`)
|
|
1637
|
-
3. Commit changes (`git commit -m 'feat: add feature'`)
|
|
1638
|
-
4. Push to branch (`git push origin feature/name`)
|
|
1639
|
-
5. Open a Pull Request
|
|
2966
|
+
Untuk pertanyaan seputar pengembangan plugin Harps-MD secara spesifik (di luar cakupan library Harps-Baileys ini), rujuk dokumentasi/README repositori Harps-MD terpisah.
|
|
1640
2967
|
|
|
1641
2968
|
---
|
|
1642
2969
|
|
|
1643
|
-
## 📄
|
|
2970
|
+
## 📄 Lisensi
|
|
1644
2971
|
|
|
1645
|
-
|
|
2972
|
+
Didistribusikan di bawah **Lisensi MIT**.
|
|
1646
2973
|
|
|
1647
|
-
|
|
1648
|
-
|
|
2974
|
+
```
|
|
2975
|
+
MIT License
|
|
2976
|
+
|
|
2977
|
+
Copyright (c) Alvin-B2T / VinzSocket
|
|
2978
|
+
|
|
2979
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
2980
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
2981
|
+
in the Software without restriction, including without limitation the rights
|
|
2982
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
2983
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
2984
|
+
furnished to do so, subject to the following conditions:
|
|
2985
|
+
|
|
2986
|
+
The above copyright notice and this permission notice shall be included in all
|
|
2987
|
+
copies or substantial portions of the Software.
|
|
2988
|
+
|
|
2989
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
2990
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
2991
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
2992
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
2993
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
2994
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
2995
|
+
SOFTWARE.
|
|
2996
|
+
```
|
|
1649
2997
|
|
|
1650
2998
|
---
|
|
1651
2999
|
|
|
1652
3000
|
<div align="center">
|
|
1653
3001
|
|
|
1654
|
-
**
|
|
3002
|
+
**Dibuat & dirawat oleh Alvin (VinzSocket) untuk ekosistem Harps-MD**
|
|
1655
3003
|
|
|
1656
|
-
|
|
3004
|
+
Jika library ini membantu proyek Anda, pertimbangkan memberi ⭐ di [GitHub](https://github.com/VinzSocket/Baileys).
|
|
1657
3005
|
|
|
1658
3006
|
</div>
|