astrabail 1.0.7 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (223) hide show
  1. package/WAProto/GenerateStatics.sh +3 -0
  2. package/WAProto/WAProto.proto +3 -0
  3. package/WAProto/fix-imports.js +3 -0
  4. package/WAProto/index.d.ts +3 -0
  5. package/WAProto/index.js +3 -0
  6. package/WAProto/p.html +3 -0
  7. package/lib/Defaults/astrabail-version.json +3 -0
  8. package/lib/Defaults/index.d.ts +3 -1
  9. package/lib/Defaults/index.js +10 -3
  10. package/lib/Defaults/phonenumber-mcc.json +3 -0
  11. package/lib/Defaults/update-wa-version.js +3 -1
  12. package/lib/Signal/Group/ciphertext-message.d.ts +3 -1
  13. package/lib/Signal/Group/ciphertext-message.js +3 -0
  14. package/lib/Signal/Group/group-session-builder.d.ts +3 -1
  15. package/lib/Signal/Group/group-session-builder.js +3 -0
  16. package/lib/Signal/Group/group_cipher.d.ts +3 -1
  17. package/lib/Signal/Group/group_cipher.js +3 -0
  18. package/lib/Signal/Group/index.d.ts +3 -1
  19. package/lib/Signal/Group/index.js +3 -0
  20. package/lib/Signal/Group/keyhelper.d.ts +3 -1
  21. package/lib/Signal/Group/keyhelper.js +3 -0
  22. package/lib/Signal/Group/queue-job.js +3 -0
  23. package/lib/Signal/Group/sender-chain-key.d.ts +3 -1
  24. package/lib/Signal/Group/sender-chain-key.js +3 -0
  25. package/lib/Signal/Group/sender-key-distribution-message.d.ts +3 -1
  26. package/lib/Signal/Group/sender-key-distribution-message.js +3 -0
  27. package/lib/Signal/Group/sender-key-message.d.ts +3 -1
  28. package/lib/Signal/Group/sender-key-message.js +3 -0
  29. package/lib/Signal/Group/sender-key-name.d.ts +3 -1
  30. package/lib/Signal/Group/sender-key-name.js +3 -0
  31. package/lib/Signal/Group/sender-key-record.d.ts +3 -1
  32. package/lib/Signal/Group/sender-key-record.js +3 -0
  33. package/lib/Signal/Group/sender-key-state.d.ts +3 -1
  34. package/lib/Signal/Group/sender-key-state.js +3 -0
  35. package/lib/Signal/Group/sender-message-key.d.ts +3 -1
  36. package/lib/Signal/Group/sender-message-key.js +3 -0
  37. package/lib/Signal/libsignal.d.ts +3 -1
  38. package/lib/Signal/libsignal.js +3 -0
  39. package/lib/Signal/lid-mapping.d.ts +3 -1
  40. package/lib/Signal/lid-mapping.js +3 -0
  41. package/lib/Socket/Client/index.d.ts +3 -1
  42. package/lib/Socket/Client/index.js +3 -0
  43. package/lib/Socket/Client/types.d.ts +3 -1
  44. package/lib/Socket/Client/types.js +3 -0
  45. package/lib/Socket/Client/websocket.d.ts +3 -1
  46. package/lib/Socket/Client/websocket.js +3 -0
  47. package/lib/Socket/business.d.ts +5 -3
  48. package/lib/Socket/business.js +3 -0
  49. package/lib/Socket/chats.d.ts +5 -3
  50. package/lib/Socket/chats.js +4 -1
  51. package/lib/Socket/communities.d.ts +5 -3
  52. package/lib/Socket/communities.js +3 -0
  53. package/lib/Socket/community.js +3 -0
  54. package/lib/Socket/groups.d.ts +5 -3
  55. package/lib/Socket/groups.js +3 -0
  56. package/lib/Socket/index.d.ts +5 -3
  57. package/lib/Socket/index.js +3 -0
  58. package/lib/Socket/messages-recv.d.ts +5 -3
  59. package/lib/Socket/messages-recv.js +3 -0
  60. package/lib/Socket/messages-send.d.ts +5 -3
  61. package/lib/Socket/messages-send.js +111 -1
  62. package/lib/Socket/mex.d.ts +3 -1
  63. package/lib/Socket/mex.js +3 -0
  64. package/lib/Socket/newsletter.d.ts +5 -3
  65. package/lib/Socket/newsletter.js +3 -0
  66. package/lib/Socket/socket.d.ts +5 -3
  67. package/lib/Socket/socket.js +4 -1
  68. package/lib/Socket/usync.js +3 -0
  69. package/lib/Store/index.js +3 -0
  70. package/lib/Store/make-cache-manager-store.js +3 -0
  71. package/lib/Store/make-in-memory-store.js +4 -1
  72. package/lib/Store/make-ordered-dictionary.js +3 -0
  73. package/lib/Store/object-repository.js +3 -0
  74. package/lib/Types/Auth.d.ts +3 -1
  75. package/lib/Types/Auth.js +3 -0
  76. package/lib/Types/Bussines.d.ts +3 -1
  77. package/lib/Types/Bussines.js +3 -0
  78. package/lib/Types/Call.d.ts +3 -1
  79. package/lib/Types/Call.js +3 -0
  80. package/lib/Types/Chat.d.ts +3 -1
  81. package/lib/Types/Chat.js +3 -0
  82. package/lib/Types/Contact.d.ts +3 -1
  83. package/lib/Types/Contact.js +3 -0
  84. package/lib/Types/Events.d.ts +10 -8
  85. package/lib/Types/Events.js +3 -0
  86. package/lib/Types/GroupMetadata.d.ts +3 -1
  87. package/lib/Types/GroupMetadata.js +3 -0
  88. package/lib/Types/Label.d.ts +3 -1
  89. package/lib/Types/Label.js +3 -0
  90. package/lib/Types/LabelAssociation.d.ts +3 -1
  91. package/lib/Types/LabelAssociation.js +3 -0
  92. package/lib/Types/Message.d.ts +3 -1
  93. package/lib/Types/Message.js +3 -0
  94. package/lib/Types/MexUpdates.js +3 -0
  95. package/lib/Types/Newsletter.d.ts +3 -1
  96. package/lib/Types/Newsletter.js +3 -0
  97. package/lib/Types/Product.d.ts +3 -1
  98. package/lib/Types/Product.js +3 -0
  99. package/lib/Types/Signal.d.ts +3 -1
  100. package/lib/Types/Signal.js +3 -0
  101. package/lib/Types/Socket.d.ts +6 -4
  102. package/lib/Types/Socket.js +3 -0
  103. package/lib/Types/State.d.ts +3 -1
  104. package/lib/Types/State.js +3 -0
  105. package/lib/Types/USync.d.ts +3 -1
  106. package/lib/Types/USync.js +3 -0
  107. package/lib/Types/index.d.ts +4 -2
  108. package/lib/Types/index.js +3 -0
  109. package/lib/Utils/astrabail-event-stream.js +61 -1
  110. package/lib/Utils/audioToBuffer.js +3 -0
  111. package/lib/Utils/auth-utils.d.ts +3 -1
  112. package/lib/Utils/auth-utils.js +3 -0
  113. package/lib/Utils/bridge-runtime.d.ts +3 -0
  114. package/lib/Utils/bridge-runtime.js +3 -0
  115. package/lib/Utils/browser-utils.d.ts +3 -1
  116. package/lib/Utils/browser-utils.js +6 -3
  117. package/lib/Utils/business.d.ts +3 -1
  118. package/lib/Utils/business.js +3 -0
  119. package/lib/Utils/chat-utils.d.ts +5 -3
  120. package/lib/Utils/chat-utils.js +3 -0
  121. package/lib/Utils/crypto.d.ts +3 -1
  122. package/lib/Utils/crypto.js +3 -0
  123. package/lib/Utils/decode-wa-message.d.ts +3 -1
  124. package/lib/Utils/decode-wa-message.js +3 -0
  125. package/lib/Utils/event-buffer.d.ts +8 -6
  126. package/lib/Utils/event-buffer.js +4 -1
  127. package/lib/Utils/generics.d.ts +9 -7
  128. package/lib/Utils/generics.js +15 -12
  129. package/lib/Utils/history.d.ts +3 -1
  130. package/lib/Utils/history.js +3 -0
  131. package/lib/Utils/identity-change-handler.d.ts +3 -1
  132. package/lib/Utils/identity-change-handler.js +3 -0
  133. package/lib/Utils/index.d.ts +3 -1
  134. package/lib/Utils/index.js +3 -1
  135. package/lib/Utils/link-preview.d.ts +3 -1
  136. package/lib/Utils/link-preview.js +3 -0
  137. package/lib/Utils/logger.d.ts +3 -1
  138. package/lib/Utils/logger.js +3 -0
  139. package/lib/Utils/lt-hash.d.ts +3 -1
  140. package/lib/Utils/lt-hash.js +3 -0
  141. package/lib/Utils/make-mutex.d.ts +3 -1
  142. package/lib/Utils/make-mutex.js +3 -0
  143. package/lib/Utils/message-retry-manager.d.ts +3 -1
  144. package/lib/Utils/message-retry-manager.js +3 -0
  145. package/lib/Utils/messages-media.d.ts +3 -1
  146. package/lib/Utils/messages-media.js +4 -1
  147. package/lib/Utils/messages-newsletter.d.ts +3 -0
  148. package/lib/Utils/messages-newsletter.js +3 -0
  149. package/lib/Utils/messages.d.ts +3 -1
  150. package/lib/Utils/messages.js +4 -1
  151. package/lib/Utils/noise-handler.d.ts +3 -1
  152. package/lib/Utils/noise-handler.js +3 -0
  153. package/lib/Utils/pre-key-manager.d.ts +3 -1
  154. package/lib/Utils/pre-key-manager.js +3 -0
  155. package/lib/Utils/process-message.d.ts +5 -3
  156. package/lib/Utils/process-message.js +3 -0
  157. package/lib/Utils/reporting-utils.d.ts +3 -1
  158. package/lib/Utils/reporting-utils.js +3 -0
  159. package/lib/Utils/resolve-jid.d.ts +3 -0
  160. package/lib/Utils/resolve-jid.js +3 -0
  161. package/lib/Utils/rust-bridge-shim.d.ts +3 -0
  162. package/lib/Utils/rust-bridge-shim.js +3 -0
  163. package/lib/Utils/serial-task-queue.js +3 -0
  164. package/lib/Utils/signal.d.ts +3 -1
  165. package/lib/Utils/signal.js +3 -0
  166. package/lib/Utils/streamToBuffer.js +3 -0
  167. package/lib/Utils/sync-action-utils.d.ts +6 -4
  168. package/lib/Utils/sync-action-utils.js +3 -0
  169. package/lib/Utils/tc-token-utils.d.ts +3 -1
  170. package/lib/Utils/tc-token-utils.js +3 -0
  171. package/lib/Utils/use-mongo-file-auth-state.js +3 -0
  172. package/lib/Utils/use-multi-file-auth-state.d.ts +3 -1
  173. package/lib/Utils/use-multi-file-auth-state.js +4 -1
  174. package/lib/Utils/use-single-file-auth-state.js +3 -0
  175. package/lib/Utils/validate-connection.d.ts +3 -1
  176. package/lib/Utils/validate-connection.js +3 -0
  177. package/lib/WABinary/constants.d.ts +3 -1
  178. package/lib/WABinary/constants.js +3 -0
  179. package/lib/WABinary/decode.d.ts +3 -1
  180. package/lib/WABinary/decode.js +3 -0
  181. package/lib/WABinary/encode.d.ts +3 -1
  182. package/lib/WABinary/encode.js +3 -0
  183. package/lib/WABinary/generic-utils.d.ts +3 -1
  184. package/lib/WABinary/generic-utils.js +3 -0
  185. package/lib/WABinary/index.d.ts +3 -1
  186. package/lib/WABinary/index.js +3 -0
  187. package/lib/WABinary/jid-utils.d.ts +3 -1
  188. package/lib/WABinary/jid-utils.js +3 -0
  189. package/lib/WABinary/types.d.ts +3 -1
  190. package/lib/WABinary/types.js +3 -0
  191. package/lib/WAM/BinaryInfo.d.ts +3 -1
  192. package/lib/WAM/BinaryInfo.js +3 -0
  193. package/lib/WAM/constants.d.ts +3 -1
  194. package/lib/WAM/constants.js +3 -0
  195. package/lib/WAM/encode.d.ts +3 -1
  196. package/lib/WAM/encode.js +3 -0
  197. package/lib/WAM/index.d.ts +3 -1
  198. package/lib/WAM/index.js +3 -0
  199. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +3 -1
  200. package/lib/WAUSync/Protocols/USyncContactProtocol.js +3 -0
  201. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +3 -1
  202. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +3 -0
  203. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +3 -1
  204. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +3 -0
  205. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +3 -1
  206. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +3 -0
  207. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +3 -1
  208. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +3 -0
  209. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +3 -1
  210. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +3 -0
  211. package/lib/WAUSync/Protocols/index.d.ts +3 -1
  212. package/lib/WAUSync/Protocols/index.js +3 -0
  213. package/lib/WAUSync/USyncQuery.d.ts +3 -1
  214. package/lib/WAUSync/USyncQuery.js +3 -0
  215. package/lib/WAUSync/USyncUser.d.ts +3 -1
  216. package/lib/WAUSync/USyncUser.js +3 -0
  217. package/lib/WAUSync/index.d.ts +3 -1
  218. package/lib/WAUSync/index.js +3 -0
  219. package/lib/index.d.ts +3 -0
  220. package/lib/index.js +3 -0
  221. package/package.json +4 -4
  222. package/readme.md +1956 -1956
  223. package/lib/Utils/baileys-event-stream.js +0 -60
package/readme.md CHANGED
@@ -1,1956 +1,1956 @@
1
- <div align="center">
2
-
3
- <h1>
4
- <img src="https://img.shields.io/badge/⚡-AstraBail-0f0f0f?style=for-the-badge&labelColor=0f0f0f&color=6c63ff" height="45" alt="AstraBail" />
5
- </h1>
6
-
7
- <p align="center">
8
- <strong>Professional WhatsApp Web API Library — Built for the Next Generation of Bots</strong><br/>
9
- <sub>Fork-optimized from Baileys · Maintained by <a href="https://github.com/Danimaru-ze">Danimaru-ze</a></sub>
10
- </p>
11
-
12
- <p align="center">
13
- <a href="https://www.npmjs.com/package/astrabail">
14
- <img src="https://img.shields.io/npm/v/astrabail.svg?style=flat-square&label=npm&color=6c63ff&logo=npm&logoColor=white" alt="npm version" />
15
- </a>
16
- <a href="https://www.npmjs.com/package/astrabail">
17
- <img src="https://img.shields.io/npm/dm/astrabail.svg?style=flat-square&label=downloads&color=38bdf8&logo=npm&logoColor=white" alt="downloads" />
18
- </a>
19
- <a href="https://github.com/Danimaru-ze/AstraBail/blob/main/LICENSE">
20
- <img src="https://img.shields.io/npm/l/astrabail.svg?style=flat-square&label=license&color=22c55e" alt="license" />
21
- </a>
22
- <a href="https://github.com/Danimaru-ze/AstraBail">
23
- <img src="https://img.shields.io/badge/GitHub-AstraBail-181717?style=flat-square&logo=github" alt="github" />
24
- </a>
25
- <a href="https://whatsapp.com/channel/0029Vazo6KM8kyyJ4eWh3A25">
26
- <img src="https://img.shields.io/badge/WhatsApp-Channel-25D366?style=flat-square&logo=whatsapp&logoColor=white" alt="WhatsApp Channel" />
27
- </a>
28
- </p>
29
-
30
- </div>
31
-
32
- ---
33
-
34
- ## ✨ Tentang AstraBail
35
-
36
- **AstraBail** adalah library WhatsApp Web API profesional yang dioptimalkan dari basis *Baileys*. Dikelola oleh **Danimaru-ze**, library ini dirancang untuk performa tinggi, stabilitas maksimal, dan kemudahan integrasi ke berbagai proyek bot WhatsApp modern.
37
-
38
- ### 🚀 Fitur Unggulan
39
-
40
- | Fitur | Keterangan |
41
- |-------|-----------|
42
- | 🔀 **Multi-Device** | Dukungan penuh sistem multi-device WhatsApp terbaru |
43
- | 🔐 **End-to-End Encryption** | Enkripsi pesan standar industri |
44
- | ⚡ **Turbo Handshake** | Inisialisasi koneksi yang sangat cepat |
45
- | 🧠 **Memory Optimized** | Penggunaan RAM yang ringan dan efisien |
46
- | 📦 **Semua Jenis Pesan** | Teks, Media, Button, Poll, Sticker, dan lainnya |
47
- | 🆔 **LID & JID Mapping** | Pemetaan `@lid` dan `@jid` lengkap |
48
-
49
- ---
50
-
51
- ## 📦 Instalasi
52
-
53
- ```bash
54
- npm install astrabail
55
- # atau
56
- yarn add astrabail
57
- ```
58
-
59
- ---
60
-
61
- ## ⚡ Mulai Cepat
62
-
63
- ### Instalasi & Koneksi Dasar
64
-
65
- ```javascript
66
- const { default: makeWASocket, useMultiFileAuthState } = require("astrabail")
67
-
68
- async function startBot() {
69
- const { state, saveCreds } = await useMultiFileAuthState('./session')
70
-
71
- const sock = makeWASocket({
72
- auth: state,
73
- printQRInTerminal: true
74
- })
75
-
76
- sock.ev.on('creds.update', saveCreds)
77
-
78
- sock.ev.on('connection.update', ({ connection }) => {
79
- if (connection === 'open') console.log('✅ AstraBail: Bot Connected!')
80
- })
81
- }
82
-
83
- startBot()
84
- ```
85
-
86
-
87
-
88
- ## Kirim Sticker Pack
89
-
90
- ```javascript
91
- await sock.sendMessage('6281234567890@s.whatsapp.net', {
92
- stickerPack: {
93
- name: 'AstraBail Sticker',
94
- publisher: 'AstraBail',
95
- description: 'Sticker pack custom dari AstraBail',
96
- cover: { url: './assets/cover.png' },
97
- stickers: [
98
- { sticker: { url: './assets/sticker-1.webp' }, emojis: ['😀'] },
99
- { sticker: { url: './assets/sticker-2.webp' }, emojis: ['🔥'] },
100
- { sticker: { url: './assets/sticker-3.png' }, emojis: ['🚀'] }
101
- ]
102
- }
103
- })
104
- ```
105
-
106
- ### Format object `stickerPack`
107
-
108
- - `name`: nama pack sticker
109
- - `publisher`: nama author/publisher
110
- - `description`: deskripsi pack
111
- - `cover`: cover/tray icon, bisa file path, buffer, stream, atau URL
112
- - `stickers`: array isi sticker, minimal 1 maksimal 60
113
- - `sticker`: media tiap sticker, bisa WebP/PNG/JPG. Jika bukan WebP akan dicoba dikonversi otomatis
114
- - `emojis`: emoji untuk sticker terkait
115
- - `accessibilityLabel`: label opsional
116
- - `packId`: opsional, jika tidak diisi akan dibuat otomatis
117
-
118
- ### Catatan
119
-
120
- - Sangat disarankan install `sharp` agar konversi gambar ke WebP lebih stabil.
121
- - Jika `sharp` tidak ada, library akan mencoba memakai `jimp`.
122
- - Ukuran tiap sticker maksimal 1 MB.
123
- - Jumlah sticker maksimal 60 per pack.
124
-
125
- ---
126
-
127
- # Documentation
128
-
129
- - [Connecting Account](#connecting-account)
130
- - [Connect with QR-CODE](#starting-socket-with-qr-code)
131
- - [Connect with Pairing Code](#starting-socket-with-pairing-code)
132
- - [Receive Full History](#receive-full-history)
133
- - [Important Notes About Socket Config](#important-notes-about-socket-config)
134
- - [Caching Group Metadata (Recommended)](#caching-group-metadata-recommended)
135
- - [Improve Retry System & Decrypt Poll Votes](#improve-retry-system--decrypt-poll-votes)
136
- - [Receive Notifications in Whatsapp App](#receive-notifications-in-whatsapp-app)
137
-
138
- - [Save Auth Info](#saving--restoring-sessions)
139
- - [Handling Events](#handling-events)
140
- - [Example to Start](#example-to-start)
141
- - [Decrypt Poll Votes](#decrypt-poll-votes)
142
- - [Summary of Events on First Connection](#summary-of-events-on-first-connection)
143
- - [Implementing a Data Store](#implementing-a-data-store)
144
- - [Whatsapp IDs Explain](#whatsapp-ids-explain)
145
- - [Utility Functions](#utility-functions)
146
- - [Broadcast Lists & Stories](#broadcast-lists--stories)
147
- - [Send Broadcast & Stories](#send-broadcast--stories)
148
- - [Send Global Channel (upswgc)](#send-global-channel-upswgc)
149
- - [Query a Broadcast List's Recipients & Name](#query-a-broadcast-lists-recipients--name)
150
- - [Sending Messages](#sending-messages)
151
- - [Non-Media Messages](#non-media-messages)
152
- - [Buttons Message](#buttons-message)
153
- - [Buttons Flow](#buttons-flow)
154
- - [Interactive Message](#interactive-message)
155
- - [Text Message](#text-message)
156
- - [Quote Message](#quote-message-works-with-all-types)
157
- - [Mention User](#mention-user-works-with-most-types)
158
- - [Mention Status](#mention-status)
159
- - [Result Poll From Newsletter](#result-poll-from-newsletter)
160
- - [SendAlbumMessage](#send-album-message)
161
- - [Interactive Response](#interactive-response)
162
- - [Request Payment](#request-payment)
163
- - [Event Message](#event-message)
164
- - [Interactive](#interactive)
165
- - [Forward Messages](#forward-messages)
166
- - [Location Message](#location-message)
167
- - [Contact Message](#contact-message)
168
- - [Reaction Message](#reaction-message)
169
- - [Pin Message](#pin-message)
170
- - [Poll Message](#poll-message)
171
- - [Sending with Link Preview](#sending-messages-with-link-previews)
172
- - [Media Messages](#media-messages)
173
- - [Gif Message](#gif-message)
174
- - [Video Message](#video-message)
175
- - [Audio Message](#audio-message)
176
- - [Image Message](#image-message)
177
- - [ViewOnce Message](#view-once-message)
178
- - [Sticker Pack Message](#kirim-sticker-pack)
179
- - [Modify Messages](#modify-messages)
180
- - [Delete Messages (for everyone)](#deleting-messages-for-everyone)
181
- - [Edit Messages](#editing-messages)
182
- - [Manipulating Media Messages](#manipulating-media-messages)
183
- - [Thumbnail in Media Messages](#thumbnail-in-media-messages)
184
- - [Downloading Media Messages](#downloading-media-messages)
185
- - [Re-upload Media Message to Whatsapp](#re-upload-media-message-to-whatsapp)
186
- - [Reject Call](#reject-call)
187
- - [Send States in Chat](#send-states-in-chat)
188
- - [Reading Messages](#reading-messages)
189
- - [Update Presence](#update-presence)
190
- - [Modifying Chats](#modifying-chats)
191
- - [Archive a Chat](#archive-a-chat)
192
- - [Mute/Unmute a Chat](#muteunmute-a-chat)
193
- - [Mark a Chat Read/Unread](#mark-a-chat-readunread)
194
- - [Delete a Message for Me](#delete-a-message-for-me)
195
- - [Delete a Chat](#delete-a-chat)
196
- - [Star/Unstar a Message](#starunstar-a-message)
197
- - [Disappearing Messages](#disappearing-messages)
198
- - [User Querys](#user-querys)
199
- - [Check If ID Exists in Whatsapp](#check-if-id-exists-in-whatsapp)
200
- - [Query Chat History (groups too)](#query-chat-history-groups-too)
201
- - [Fetch Status](#fetch-status)
202
- - [Fetch Profile Picture (groups too)](#fetch-profile-picture-groups-too)
203
- - [Fetch Bussines Profile (such as description or category)](#fetch-bussines-profile-such-as-description-or-category)
204
- - [Fetch Someone's Presence (if they're typing or online)](#fetch-someones-presence-if-theyre-typing-or-online)
205
- - [Change Profile](#change-profile)
206
- - [Change Profile Status](#change-profile-status)
207
- - [Change Profile Name](#change-profile-name)
208
- - [Change Display Picture (groups too)](#change-display-picture-groups-too)
209
- - [Remove display picture (groups too)](#remove-display-picture-groups-too)
210
- - [Groups](#groups)
211
- - [Create a Group](#create-a-group)
212
- - [Add/Remove or Demote/Promote](#addremove-or-demotepromote)
213
- - [Change Subject (name)](#change-subject-name)
214
- - [Change Description](#change-description)
215
- - [Change Settings](#change-settings)
216
- - [Leave a Group](#leave-a-group)
217
- - [Get Invite Code](#get-invite-code)
218
- - [Revoke Invite Code](#revoke-invite-code)
219
- - [Join Using Invitation Code](#join-using-invitation-code)
220
- - [Get Group Info by Invite Code](#get-group-info-by-invite-code)
221
- - [Query Metadata (participants, name, description...)](#query-metadata-participants-name-description)
222
- - [Join using groupInviteMessage](#join-using-groupinvitemessage)
223
- - [Get Request Join List](#get-request-join-list)
224
- - [Approve/Reject Request Join](#approvereject-request-join)
225
- - [Get All Participating Groups Metadata](#get-all-participating-groups-metadata)
226
- - [Toggle Ephemeral](#toggle-ephemeral)
227
- - [Change Add Mode](#change-add-mode)
228
- - [Privacy](#privacy)
229
- - [Block/Unblock User](#blockunblock-user)
230
- - [Get Privacy Settings](#get-privacy-settings)
231
- - [Get BlockList](#get-blocklist)
232
- - [Update LastSeen Privacy](#update-lastseen-privacy)
233
- - [Update Online Privacy](#update-online-privacy)
234
- - [Update Profile Picture Privacy](#update-profile-picture-privacy)
235
- - [Update Status Privacy](#update-status-privacy)
236
- - [Update Read Receipts Privacy](#update-read-receipts-privacy)
237
- - [Update Groups Add Privacy](#update-groups-add-privacy)
238
- - [Update Default Disappearing Mode](#update-default-disappearing-mode)
239
- - [Broadcast Lists & Stories](#broadcast-lists--stories)
240
- - [Send Broadcast & Stories](#send-broadcast--stories)
241
- - [Query a Broadcast List's Recipients & Name](#query-a-broadcast-lists-recipients--name)
242
- - [Writing Custom Functionality](#writing-custom-functionality)
243
- - [Enabling Debug Level in Baileys Logs](#enabling-debug-level-in-baileys-logs)
244
- - [How Whatsapp Communicate With Us](#how-whatsapp-communicate-with-us)
245
- - [Register a Callback for Websocket Events](#register-a-callback-for-websocket-events)
246
-
247
- <a id="connecting-account"></a>
248
- ## 🔗 Menghubungkan Akun
249
-
250
- WhatsApp provides a multi-device API that allows Baileys to be authenticated as a second WhatsApp client by scanning a **QR code** or **Pairing Code** with WhatsApp on your phone.
251
-
252
- <a id="starting-socket-with-qr-code"></a>
253
- ### 🔹 Memulai Socket dengan Kode QR
254
-
255
- > [!TIP]
256
- > You can customize browser name if you connect with **QR-CODE**, with `Browser` constant, we have some browsers config, **see [here](https://baileys.whiskeysockets.io/types/BrowsersMap.html)**
257
-
258
- ```javascript
259
- const { default: makeWASocket } = require("astrabail")
260
-
261
-
262
- const sock = makeWASocket({
263
- // can provide additional config here
264
- browser: Browsers.ubuntu('My App'),
265
- printQRInTerminal: true
266
- })
267
- ```
268
-
269
- If the connection is successful, you will see a QR code printed on your terminal screen, scan it with WhatsApp on your phone and you'll be logged in!
270
-
271
- <a id="starting-socket-with-pairing-code"></a>
272
- ### 🔹 Memulai Socket dengan **Kode Pairing**
273
-
274
-
275
- > [!IMPORTANT]
276
- > Pairing Code isn't Mobile API, it's a method to connect Whatsapp Web without QR-CODE, you can connect only with one device, see [here](https://faq.whatsapp.com/1324084875126592/?cms_platform=web)
277
-
278
- The phone number can't have `+` or `()` or `-`, only numbers, you must provide country code
279
-
280
- ```javascript
281
- const { default: makeWASocket } = require("astrabail")
282
-
283
- const sock = makeWASocket({
284
- // can provide additional config here
285
- printQRInTerminal: false //need to be false
286
- })
287
-
288
- - Normal Pairing
289
- if (!sock.authState.creds.registered) {
290
- const number = 'XXXXXXXXXXX'
291
- const code = await sock.requestPairingCode(number)
292
- console.log(code)
293
- }
294
-
295
- - Costum Pairing
296
- if (!sock.authState.creds.registered) {
297
- const pair = "12345678" // only 8 digit numbers or letters (no more or less)
298
- const number = 'XXXXXXXXXXX'
299
- const code = await sock.requestPairingCode(number, pair)
300
- console.log(code)
301
- }
302
- ```
303
-
304
- <a id="receive-full-history"></a>
305
- ### 🔹 Menerima Riwayat Penuh
306
-
307
- 1. Set `syncFullHistory` as `true`
308
- 2. Baileys, by default, use chrome browser config
309
- - If you'd like to emulate a desktop connection (and receive more message history), this browser setting to your Socket config:
310
-
311
- ```javascript
312
- const sock = makeWASocket({
313
- ...otherOpts,
314
- // can use Windows, Ubuntu here too
315
- browser: Browsers.macOS('Desktop'),
316
- syncFullHistory: true
317
- })
318
- ```
319
-
320
- <a id="important-notes-about-socket-config"></a>
321
- ## ⚙️ Catatan Penting tentang Konfigurasi Socket
322
-
323
- <a id="caching-group-metadata-recommended"></a>
324
- ### 🧠 Caching Metadata Grup (Direkomendasikan)
325
- - If you use baileys for groups, we recommend you to set `cachedGroupMetadata` in socket config, you need to implement a cache like this:
326
-
327
- ```javascript
328
- const groupCache = new NodeCache({stdTTL: 5 * 60, useClones: false})
329
-
330
- const sock = makeWASocket({
331
- cachedGroupMetadata: async (jid) => groupCache.get(jid)
332
- })
333
-
334
- sock.ev.on('groups.update', async ([event]) => {
335
- const metadata = await sock.groupMetadata(event.id)
336
- groupCache.set(event.id, metadata)
337
- })
338
-
339
- sock.ev.on('group-participants.update', async (event) => {
340
- const metadata = await sock.groupMetadata(event.id)
341
- groupCache.set(event.id, metadata)
342
- })
343
- ```
344
-
345
- <a id="handling-events"></a>
346
- ### 🔁 Perbaiki Sistem Retry & Dekripsi Polling
347
- - If you want to improve sending message, retrying when error occurs and decrypt poll votes, you need to have a store and set `getMessage` config in socket like this:
348
- ```javascript
349
- const sock = makeWASocket({
350
- getMessage: async (key) => await getMessageFromStore(key)
351
- })
352
- ```
353
- <a id="handling-events"></a>
354
- ### 🔔 Menerima Notifikasi di Aplikasi WhatsApp
355
- - If you want to receive notifications in whatsapp app, set `markOnlineOnConnect` to `false`
356
- ```javascript
357
- const sock = makeWASocket({
358
- markOnlineOnConnect: false
359
- })
360
- ```
361
- <a id="handling-events"></a>
362
- ## 📦 Menyimpan & Mengembalikan Sesi
363
-
364
- You obviously don't want to keep scanning the QR code every time you want to connect.
365
-
366
- So, you can load the credentials to log back in:
367
- ```javascript
368
- const makeWASocket = require("astrabail").default;
369
- const { useMultiFileAuthState } = require("astrabail");
370
-
371
- const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')
372
-
373
- // will use the given state to connect
374
- // so if valid credentials are available -- it'll connect without QR
375
- const sock = makeWASocket({ auth: state })
376
-
377
- // this will be called as soon as the credentials are updated
378
- sock.ev.on('creds.update', saveCreds)
379
- ```
380
-
381
- > [!IMPORTANT]
382
- > `useMultiFileAuthState` is a utility function to help save the auth state in a single folder, this function serves as a good guide to help write auth & key states for SQL/no-SQL databases, which I would recommend in any production grade system.
383
-
384
- > [!NOTE]
385
- > When a message is received/sent, due to signal sessions needing updating, the auth keys (`authState.keys`) will update. Whenever that happens, you must save the updated keys (`authState.keys.set()` is called). Not doing so will prevent your messages from reaching the recipient & cause other unexpected consequences. The `useMultiFileAuthState` function automatically takes care of that, but for any other serious implementation -- you will need to be very careful with the key state management.
386
-
387
- <a id="handling-events"></a>
388
- ## 📡 Penanganan Event
389
-
390
- - Baileys uses the EventEmitter syntax for events.
391
- They're all nicely typed up, so you shouldn't have any issues with an Intellisense editor like VS Code.
392
-
393
- > [!IMPORTANT]
394
- > **The events are [these](https://baileys.whiskeysockets.io/types/BaileysEventMap.html)**, it's important you see all events
395
-
396
- You can listen to these events like this:
397
- ```javascript
398
- const sock = makeWASocket()
399
- sock.ev.on('messages.upsert', ({ messages }) => {
400
- console.log('got messages', messages)
401
- })
402
- ```
403
-
404
- <a id="handling-events"></a>
405
- ### 🛠️ Contoh Awal
406
-
407
- > [!NOTE]
408
- > This example includes basic auth storage too
409
-
410
- ```javascript
411
- const makeWASocket = require("astrabail").default;
412
- const { DisconnectReason, useMultiFileAuthState } = require("astrabail");
413
- const Boom = require('@hapi/boom');
414
-
415
- async function connectToWhatsApp () {
416
- const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')
417
- const sock = makeWASocket({
418
- // can provide additional config here
419
- auth: state,
420
- printQRInTerminal: true
421
- })
422
- sock.ev.on('connection.update', (update) => {
423
- const { connection, lastDisconnect } = update
424
- if(connection === 'close') {
425
- const shouldReconnect = (lastDisconnect.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut
426
- console.log('connection closed due to ', lastDisconnect.error, ', reconnecting ', shouldReconnect)
427
- // reconnect if not logged out
428
- if(shouldReconnect) {
429
- connectToWhatsApp()
430
- }
431
- } else if(connection === 'open') {
432
- console.log('opened connection')
433
- }
434
- })
435
- sock.ev.on('messages.upsert', event => {
436
- for (const m of event.messages) {
437
- console.log(JSON.stringify(m, undefined, 2))
438
-
439
- console.log('replying to', m.key.remoteJid)
440
- await sock.sendMessage(m.key.remoteJid!, { text: 'Hello Word' })
441
- }
442
- })
443
-
444
- // to storage creds (session info) when it updates
445
- sock.ev.on('creds.update', saveCreds)
446
- }
447
- // run in main file
448
- connectToWhatsApp()
449
- ```
450
-
451
- > [!IMPORTANT]
452
- > In `messages.upsert` it's recommended to use a loop like `for (const message of event.messages)` to handle all messages in array
453
-
454
- <a id="handling-events"></a>
455
- ### 🔐 Dekripsi Pilihan Polling
456
-
457
- - By default poll votes are encrypted and handled in `messages.update`
458
- - That's a simple example
459
- ```javascript
460
- sock.ev.on('messages.update', event => {
461
- for(const { key, update } of event) {
462
- if(update.pollUpdates) {
463
- const pollCreation = await getMessage(key)
464
- if(pollCreation) {
465
- console.log(
466
- 'got poll update, aggregation: ',
467
- getAggregateVotesInPollMessage({
468
- message: pollCreation,
469
- pollUpdates: update.pollUpdates,
470
- })
471
- )
472
- }
473
- }
474
- }
475
- })
476
- ```
477
-
478
- - `getMessage` is a [store](#implementing-a-data-store) implementation (in your end)
479
-
480
- <a id="handling-events"></a>
481
- ### 🔎 Ringkasan Event pada Koneksi Pertama
482
-
483
- 1. When you connect first time, `connection.update` will be fired requesting you to restart sock
484
- 2. Then, history messages will be received in `messaging.history-set`
485
-
486
- <a id="handling-events"></a>
487
- ## 💾 Mengimplementasikan Data Store
488
-
489
- - Baileys does not come with a defacto storage for chats, contacts, or messages. However, a simple in-memory implementation has been provided. The store listens for chat updates, new messages, message updates, etc., to always have an up-to-date version of the data.
490
-
491
- > [!IMPORTANT]
492
- > I highly recommend building your own data store, as storing someone's entire chat history in memory is a terrible waste of RAM.
493
-
494
- It can be used as follows:
495
-
496
- ```javascript
497
- const makeWASocket = require("astrabail").default;
498
- const { makeInMemoryStore } = require("astrabail");
499
- // the store maintains the data of the WA connection in memory
500
- // can be written out to a file & read from it
501
- const store = makeInMemoryStore({ })
502
- // can be read from a file
503
- store.readFromFile('./baileys_store.json')
504
- // saves the state to a file every 10s
505
- setInterval(() => {
506
- store.writeToFile('./baileys_store.json')
507
- }, 10_000)
508
-
509
- const sock = makeWASocket({ })
510
- // will listen from this socket
511
- // the store can listen from a new socket once the current socket outlives its lifetime
512
- store.bind(sock.ev)
513
-
514
- sock.ev.on('chats.upsert', () => {
515
- // can use 'store.chats' however you want, even after the socket dies out
516
- // 'chats' => a KeyedDB instance
517
- console.log('got chats', store.chats.all())
518
- })
519
-
520
- sock.ev.on('contacts.upsert', () => {
521
- console.log('got contacts', Object.values(store.contacts))
522
- })
523
-
524
- ```
525
-
526
- The store also provides some simple functions such as `loadMessages` that utilize the store to speed up data retrieval.
527
-
528
- <a id="handling-events"></a>
529
- ## 🆔 Penjelasan ID WhatsApp
530
-
531
- - `id` is the WhatsApp ID, called `jid` too, of the person or group you're sending the message to.
532
- - It must be in the format ```[country code][phone number]@s.whatsapp.net```
533
- - Example for people: ```+19999999999@s.whatsapp.net```.
534
- - For groups, it must be in the format ``` 123456789-123345@g.us ```.
535
- - For broadcast lists, it's `[timestamp of creation]@broadcast`.
536
- - For stories, the ID is `status@broadcast`.
537
-
538
- <a id="handling-events"></a>
539
- ## 🧰 Fungsi Utilitas
540
-
541
- - `getContentType`, returns the content type for any message
542
- - `getDevice`, returns the device from message
543
- - `makeCacheableSignalKeyStore`, make auth store more fast
544
- - `downloadContentFromMessage`, download content from any message
545
-
546
-
547
- ---
548
- <a id="broadcast-lists--stories"></a>
549
- ## 💫 Status Mention Grup (upswgc)
550
-
551
- Digunakan untuk mengirim status WhatsApp (story) Grup baik berupa teks maupun media ke status@broadcast.
552
-
553
- `
554
- [!NOTE]
555
- Fungsi ini sudah otomatis mendeteksi tipe konten (teks, gambar, video, audio).
556
- Jika teks dan media digabung, hanya satu yang akan dikirim tergantung prioritas konten.
557
- `
558
-
559
- ### Kirim teks ke status WhatsApp
560
- ```javascript
561
- await conn.upswgc(m.chat, { text: "Halo dari upswgc versi final!" })
562
- ```
563
-
564
- ### Kirim gambar ke status WhatsApp
565
- ```javascript
566
- await conn.upswgc(m.chat, {
567
- image: { url: "https://m.media-amazon.com/images/S/pv-target-images/f75db71efd62ea2eff81bd7cc01c44a9344b4ac18615ab71a80f58459ddf8791.jpg" },
568
- caption : "apasi"
569
-       });
570
-
571
- ```
572
- ### Kirim video ke status WhatsApp
573
- ```javascript
574
- await conn.upswgc(m.chat, {
575
- video: { url: "https://m.media-amazon.com/images/S/pv-target-images/f75db71efd62ea2eff81bd7cc01c44a9344b4ac18615ab71a80f58459ddf8791.jpg" },
576
- caption : "apasi"
577
-       });
578
- ```
579
- ### Kirim audio (voice note) ke status WhatsApp
580
- ```javascript
581
- await conn.upswgc(m.chat, {
582
- audio: { url: "https://cdn.yupra.my.id/yp/xkv99g06.opus" },
583
- caption : "apasi"
584
-       });
585
- ```
586
-
587
- `[!TIP]
588
- Jika kamu ingin mengirim ke story + broadcast sekaligus, gunakan fungsi sendMessage()
589
- dengan broadcast: true seperti dijelaskan pada bagian sebelumnya.`
590
-
591
- ---
592
-
593
- <a id="handling-events"></a>
594
- ## 💬 Mengirim Pesan
595
-
596
- - Send all types of messages with a single function
597
- - **[Here](https://baileys.whiskeysockets.io/types/AnyMessageContent.html) you can see all message contents supported, like text message**
598
- - **[Here](https://baileys.whiskeysockets.io/types/MiscMessageGenerationOptions.html) you can see all options supported, like quote message**
599
-
600
- ```javascript
601
- const jid: string
602
- const content: AnyMessageContent
603
- const options: MiscMessageGenerationOptions
604
-
605
- sock.sendMessage(jid, content, options)
606
- ```
607
-
608
- <a id="handling-events"></a>
609
- ### ✉️ Pesan Non-Media
610
-
611
- <a id="handling-events"></a>
612
- #### 🔘 Pesan Tombol (Buttons)
613
- ```javascript
614
- // send a buttons message!
615
- sock.sendMessage(jid, {
616
- text: "Hello World !",
617
- footer: "AstraBail - 2026",
618
- buttons: [
619
- {
620
- buttonId: `🚀`,
621
- buttonText: {
622
- displayText: '🗿'
623
- },
624
- type: 1
625
- }
626
- ],
627
- headerType: 1,
628
- viewOnce: true
629
- },{ quoted: null })
630
- ```
631
-
632
- <a id="handling-events"></a>
633
- #### 🔁 Alur Tombol
634
- ```javascript
635
- sock.sendMessage(jid, {
636
- text: "Hello Wolrd !;",
637
- footer: "© Danimaru-ze Dev",
638
- buttons: [
639
- {
640
- buttonId: '.tes',
641
- buttonText: {
642
- displayText: 'TESTING BOT'
643
- },
644
- type: 1,
645
- },
646
- {
647
- buttonId: ' ',
648
- buttonText: {
649
- displayText: 'PRIVATE SCRIPT'
650
- },
651
- type: 1,
652
- },
653
- {
654
- buttonId: 'action',
655
- buttonText: {
656
- displayText: 'ini pesan interactiveMeta'
657
- },
658
- type: 4,
659
- nativeFlowInfo: {
660
- name: 'single_select',
661
- paramsJson: JSON.stringify({
662
- title: 'message',
663
- sections: [
664
- {
665
- title: 'AstraBail - 2026',
666
- highlight_label: '😜',
667
- rows: [
668
- {
669
- header: 'HEADER',
670
- title: 'TITLE',
671
- description: 'DESCRIPTION',
672
- id: 'YOUR ID',
673
- },
674
- {
675
- header: 'HEADER',
676
- title: 'TITLE',
677
- description: 'DESCRIPTION',
678
- id: 'YOUR ID',
679
- },
680
- ],
681
- },
682
- ],
683
- }),
684
- },
685
- },
686
- ],
687
- headerType: 1,
688
- viewOnce: true
689
- }, { quoted: m });
690
- ```
691
-
692
- <a id="handling-events"></a>
693
- #### 🧩 Pesan Interaktif
694
- ```javascript
695
- let msg = generateWAMessageFromContent(m.chat, {
696
- viewOnceMessage: {
697
- message: {
698
- "messageContextInfo": {
699
- "deviceListMetadata": {},
700
- "deviceListMetadataVersion": 2
701
- },
702
- interactiveMessage: proto.Message.InteractiveMessage.create({
703
- body: proto.Message.InteractiveMessage.Body.create({
704
- text: "Danimaru-ze"
705
- }),
706
- footer: proto.Message.InteractiveMessage.Footer.create({
707
- text: "Bot"
708
- }),
709
- header: proto.Message.InteractiveMessage.Header.create({
710
- title: "Igna",
711
- subtitle: "test",
712
- hasMediaAttachment: false
713
- }),
714
- nativeFlowMessage: proto.Message.InteractiveMessage.NativeFlowMessage.create({
715
- buttons: [
716
- {
717
- "name": "single_select",
718
- "buttonParamsJson": "{\"title\":\"title\",\"sections\":[{\".menu\":\".play dj webito\",\"highlight_label\":\"label\",\"rows\":[{\"header\":\"header\",\"title\":\"title\",\"description\":\"description\",\"id\":\"id\"},{\"header\":\"header\",\"title\":\"title\",\"description\":\"description\",\"id\":\"id\"}]}]}"
719
- },
720
- {
721
- "name": "cta_reply",
722
- "buttonParamsJson": "{\"display_text\":\"quick_reply\",\"id\":\"message\"}"
723
- },
724
- {
725
- "name": "cta_url",
726
- "buttonParamsJson": "{\"display_text\":\"url\",\"url\":\"https://www.google.com\",\"merchant_url\":\"https://www.google.com\"}"
727
- },
728
- {
729
- "name": "cta_call",
730
- "buttonParamsJson": "{\"display_text\":\"call\",\"id\":\"message\"}"
731
- },
732
- {
733
- "name": "cta_copy",
734
- "buttonParamsJson": "{\"display_text\":\"copy\",\"id\":\"123456789\",\"copy_code\":\"message\"}"
735
- },
736
- {
737
- "name": "cta_reminder",
738
- "buttonParamsJson": "{\"display_text\":\"Recordatorio\",\"id\":\"message\"}"
739
- },
740
- {
741
- "name": "cta_cancel_reminder",
742
- "buttonParamsJson": "{\"display_text\":\"cta_cancel_reminder\",\"id\":\"message\"}"
743
- },
744
- {
745
- "name": "address_message",
746
- "buttonParamsJson": "{\"display_text\":\"address_message\",\"id\":\"message\"}"
747
- },
748
- {
749
- "name": "send_location",
750
- "buttonParamsJson": ""
751
- }
752
- ],
753
- })
754
- })
755
- }
756
- }
757
- }, {})
758
-
759
- return sock.relayMessage(msg.key.remoteJid, msg.message, { messageId: msg.key.id })
760
- ```
761
-
762
- <a id="handling-events"></a>
763
- #### 📝 Pesan Teks
764
- ```javascript
765
- await sock.sendMessage(jid, { text: 'hello word' })
766
- ```
767
-
768
- <a id="handling-events"></a>
769
- #### ❝ Pesan Quote (bekerja untuk semua tipe)
770
- ```javascript
771
- await sock.sendMessage(jid, { text: 'hello word' }, { quoted: message })
772
- ```
773
-
774
- <a id="handling-events"></a>
775
- #### 🏷️ Mention Pengguna (bekerja di kebanyakan tipe)
776
- - @number is to mention in text, it's optional
777
- ```javascript
778
- await sock.sendMessage(
779
- jid,
780
- {
781
- text: '@12345678901',
782
- mentions: ['12345678901@s.whatsapp.net']
783
- }
784
- )
785
- ```
786
-
787
- <a id="handling-events"></a>
788
- #### 📣 Mention Status
789
- - [ jid ] If the Jid Group and Jid Private Chat are included in the JID list, try to make the JID group first starting from the Jid Private Chat or Jid Private Chat in the middle between the group Jid
790
- ```javascript
791
- await sock.StatusMentions(
792
- {
793
- text: "Hello", // or image / video / audio ( url or buffer )
794
- },
795
- [
796
- "123456789123456789@g.us",
797
- "123456789@s.whatsapp.net",
798
- // Enter jid chat here
799
- ]
800
- )
801
- ```
802
-
803
- <a id="handling-events"></a>
804
- #### 📊 Hasil Poll dari Newsletter
805
- ```javascript
806
- await client.sendMessage(
807
- jid,
808
- {
809
- pollResult: {
810
- name: "Text poll",
811
- votes: [["Options 1", 10], ["Options 2", 10]], // 10 For Fake Polling Count Results
812
- }
813
- }, { quoted : message }
814
- )
815
- ```
816
-
817
- <a id="handling-events"></a>
818
- #### 🖼️ Mengirim Pesan Album
819
- - url or buffer ( image or video )
820
- ```javascript
821
- await sock.sendAlbumMessage(
822
- jid,
823
- [
824
- {
825
- image: { url: "https://example.jpg" }, // or buffer
826
- caption: "Hello World",
827
- },
828
- {
829
- video: { url: "https://example.mp4" }, // or buffer
830
- caption: "Hello World",
831
- },
832
- ],
833
- {
834
- quoted : message,
835
- delay : 2000 // number in seconds
836
- }
837
- )
838
-
839
- ```
840
-
841
- <a id="handling-events"></a>
842
- #### 🔔 Respon Interaktif
843
- ```javascript
844
- await client.sendMessage(
845
- jid,
846
- {
847
- buttonReply: {
848
- text: 'Text',
849
- nativeFlow: {
850
- version: 3,
851
- },
852
- },
853
- type: 'interactive',
854
- ephemeral: true,
855
- }
856
- )
857
-
858
- ```
859
-
860
- <a id="handling-events"></a>
861
- #### 💳 Permintaan Pembayaran
862
- ```javascript
863
- - Example non media sticker
864
- await client.sendMessage(
865
- jid,
866
- {
867
- requestPayment: {
868
- currency: "IDR",
869
- amount: "10000000",
870
- from: "123456@s.whatsapp.net",
871
- note: "Hai Guys",
872
- background: { ...background of the message }
873
- }
874
- },
875
- { quoted : message }
876
- )
877
-
878
- - with media sticker buffer
879
- await client.sendMessage(
880
- jid,
881
- {
882
- requestPayment: {
883
- currency: "IDR",
884
- amount: "10000000",
885
- from: "123456@s.whatsapp.net",
886
- sticker: Buffer,
887
- background: { ...background of the message }
888
- }
889
- },
890
- { quoted : message }
891
- )
892
-
893
- - with media sticker url
894
- await client.sendMessage(
895
- jid,
896
- {
897
- requestPayment: {
898
- currency: "IDR",
899
- amount: "10000000",
900
- from: "123456@s.whatsapp.net",
901
- sticker: { url: Sticker Url },
902
- background: { ...background of the message }
903
- }
904
- },
905
- { quoted : message }
906
- )
907
- ```
908
-
909
- <a id="handling-events"></a>
910
- #### 📆 Pesan Event
911
- ```javascript
912
- await client.sendMessage(
913
- jid,
914
- {
915
- event: {
916
- isCanceled: false, // or true for cancel event
917
- name: "Name Event",
918
- description: "Description Event",
919
- location: {
920
- degressLatitude: -0,
921
- degressLongitude: - 0
922
- },
923
- link: Call Link,
924
- startTime: m.messageTimestamp.low,
925
- endTime: m.messageTimestamp.low + 86400, // 86400 is day in seconds
926
- extraGuestsAllowed: true // or false
927
- }
928
- },
929
- { quoted : message }
930
- )
931
- ```
932
-
933
- <a id="handling-events"></a>
934
- #### 🔗 Interaktif
935
- ```javascript
936
- - Example non header media
937
- await client.sendMessage(
938
- jid,
939
- {
940
- text: "Description Of Messages", //Additional information
941
- title: "Title Of Messages",
942
- subtitle: "Subtitle Message",
943
- footer: "Footer Messages",
944
- interactiveButtons: [
945
- {
946
- name: "quick_reply",
947
- buttonParamsJson: JSON.stringify({
948
- display_text: "Display Button",
949
- id: "ID"
950
- })
951
- },
952
- {
953
- name: "cta_url",
954
- buttonParamsJson: JSON.stringify({
955
- display_text: "Display Button",
956
- url: "https://www.example.com"
957
- })
958
- }
959
- ]
960
- },
961
- {
962
- quoted : message
963
- }
964
- )
965
-
966
- - Example with media
967
- await client.sendMessage(
968
- jid,
969
- {
970
- image: { url : "https://example.jpg" }, // Can buffer
971
- caption: "Description Of Messages", //Additional information
972
- title: "Title Of Messages",
973
- subtitle: "Subtile Message",
974
- footer: "Footer Messages",
975
- media: true,
976
- interactiveButtons: [
977
- {
978
- name: "quick_reply",
979
- buttonParamsJson: JSON.stringify({
980
- display_text: "Display Button",
981
- id: "ID"
982
- })
983
- },
984
- {
985
- name: "cta_url",
986
- buttonParamsJson: JSON.stringify({
987
- display_text: "Display Button",
988
- url: "https://www.example.com"
989
- })
990
- }
991
- ]
992
- },
993
- {
994
- quoted : message
995
- }
996
- )
997
-
998
- - Example with header product
999
- await client.sendMessage(
1000
- jid,
1001
- {
1002
- product: {
1003
- productImage: { url: "https://example.jpg }, //or buffer
1004
- productImageCount: 1,
1005
- title: "Title Product",
1006
- description: "Description Product",
1007
- priceAmount1000: 20000 * 1000,
1008
- currencyCode: "IDR",
1009
- retailerId: "Retail",
1010
- url: "https://example.com",
1011
- },
1012
- businessOwnerJid: "1234@s.whatsapp.net",
1013
- caption: "Description Of Messages", //Additional information
1014
- title: "Title Of Messages",
1015
- footer: "Footer Messages",
1016
- media: true,
1017
- interactiveButtons: [
1018
- {
1019
- name: "quick_reply",
1020
- buttonParamsJson: JSON.stringify({
1021
- display_text: "Display Button",
1022
- id: "ID"
1023
- })
1024
- },
1025
- {
1026
- name: "cta_url",
1027
- buttonParamsJson: JSON.stringify({
1028
- display_text: "Display Button",
1029
- url: "https://www.example.com"
1030
- })
1031
- }
1032
- ]
1033
- },
1034
- {
1035
- quoted : message
1036
- }
1037
- )
1038
- ```
1039
-
1040
- <a id="handling-events"></a>
1041
- #### 📤 Meneruskan Pesan
1042
- - You need to have message object, can be retrieved from [store](#implementing-a-data-store) or use a [message](https://baileys.whiskeysockets.io/types/WAMessage.html) object
1043
- ```javascript
1044
- const msg = getMessageFromStore() // implement this on your end
1045
- await sock.sendMessage(jid, { forward: msg }) // WA forward the message!
1046
- ```
1047
-
1048
- <a id="handling-events"></a>
1049
- #### 📍 Pesan Lokasi
1050
- ```javascript
1051
- await sock.sendMessage(
1052
- jid,
1053
- {
1054
- location: {
1055
- degreesLatitude: 24.121231,
1056
- degreesLongitude: 55.1121221
1057
- }
1058
- }
1059
- )
1060
- ```
1061
-
1062
- <a id="handling-events"></a>
1063
- #### 👤 Pesan Kontak
1064
- ```javascript
1065
- const vcard = 'BEGIN:VCARD\n' // metadata of the contact card
1066
- + 'VERSION:3.0\n'
1067
- + 'FN:Jeff Singh\n' // full name
1068
- + 'ORG:Ashoka Uni;\n' // the organization of the contact
1069
- + 'TEL;type=CELL;type=VOICE;waid=911234567890:+91 12345 67890\n' // WhatsApp ID + phone number
1070
- + 'END:VCARD'
1071
-
1072
- await sock.sendMessage(
1073
- id,
1074
- {
1075
- contacts: {
1076
- displayName: 'Jeff',
1077
- contacts: [{ vcard }]
1078
- }
1079
- }
1080
- )
1081
- ```
1082
-
1083
- <a id="handling-events"></a>
1084
- #### ❤️ Pesan Reaksi
1085
- - You need to pass the key of message, you can retrieve from [store](#implementing-a-data-store) or use a [key](https://baileys.whiskeysockets.io/types/WAMessageKey.html) object
1086
- ```javascript
1087
- await sock.sendMessage(
1088
- jid,
1089
- {
1090
- react: {
1091
- text: '💖', // use an empty string to remove the reaction
1092
- key: message.key
1093
- }
1094
- }
1095
- )
1096
- ```
1097
-
1098
- <a id="handling-events"></a>
1099
- #### 📌 Pesan Pin
1100
- - You need to pass the key of message, you can retrieve from [store](#implementing-a-data-store) or use a [key](https://baileys.whiskeysockets.io/types/WAMessageKey.html) object
1101
-
1102
- - Time can be:
1103
-
1104
- | Time | Seconds |
1105
- |-------|----------------|
1106
- | 24h | 86.400 |
1107
- | 7d | 604.800 |
1108
- | 30d | 2.592.000 |
1109
-
1110
- ```javascript
1111
- await sock.sendMessage(
1112
- jid,
1113
- {
1114
- pin: {
1115
- type: 1, // 0 to remove
1116
- time: 86400
1117
- key: message.key
1118
- }
1119
- }
1120
- )
1121
- ```
1122
-
1123
- <a id="handling-events"></a>
1124
- #### 🗳️ Pesan Poll
1125
- ```javascript
1126
- await sock.sendMessage(
1127
- jid,
1128
- {
1129
- poll: {
1130
- name: 'My Poll',
1131
- values: ['Option 1', 'Option 2', ...],
1132
- selectableCount: 1,
1133
- toAnnouncementGroup: false // or true
1134
- }
1135
- }
1136
- )
1137
- ```
1138
-
1139
- <a id="handling-events"></a>
1140
- ### 💬 Mengirim Pesan with Link Previews
1141
-
1142
- 1. By default, wa does not have link generation when sent from the web
1143
- 2. Baileys has a function to generate the content for these link previews
1144
- 3. To enable this function's usage, add `link-preview-js` as a dependency to your project with `yarn add link-preview-js`
1145
- 4. Send a link:
1146
- ```javascript
1147
- await sock.sendMessage(
1148
- jid,
1149
- {
1150
- text: 'Hi, this was sent using https://github.com/whiskeysockets/baileys'
1151
- }
1152
- )
1153
- ```
1154
-
1155
- ### 🎞️ Pesan Media
1156
-
1157
- Sending media (video, stickers, images) is easier & more efficient than ever.
1158
-
1159
- > [!NOTE]
1160
- > In media messages, you can pass `{ stream: Stream }` or `{ url: Url }` or `Buffer` directly, you can see more [here](https://baileys.whiskeysockets.io/types/WAMediaUpload.html)
1161
-
1162
- - When specifying a media url, Baileys never loads the entire buffer into memory; it even encrypts the media as a readable stream.
1163
-
1164
- > [!TIP]
1165
- > It's recommended to use Stream or Url to save memory
1166
-
1167
- <a id="handling-events"></a>
1168
- #### 🎬 Pesan GIF
1169
- - Whatsapp doesn't support `.gif` files, that's why we send gifs as common `.mp4` video with `gifPlayback` flag
1170
- ```javascript
1171
- await sock.sendMessage(
1172
- jid,
1173
- {
1174
- video: fs.readFileSync('Media/ma_gif.mp4'),
1175
- caption: 'hello word',
1176
- gifPlayback: true
1177
- }
1178
- )
1179
- ```
1180
-
1181
- <a id="handling-events"></a>
1182
- #### 📹 Pesan Video
1183
- ```javascript
1184
- await sock.sendMessage(
1185
- id,
1186
- {
1187
- video: {
1188
- url: './Media/ma_gif.mp4'
1189
- },
1190
- caption: 'hello word',
1191
- ptv: false // if set to true, will send as a `video note`
1192
- }
1193
- )
1194
- ```
1195
-
1196
- <a id="handling-events"></a>
1197
- #### 🔊 Pesan Audio
1198
- - To audio message work in all devices you need to convert with some tool like `ffmpeg` with this flags:
1199
- ```bash
1200
- codec: libopus //ogg file
1201
- ac: 1 //one channel
1202
- avoid_negative_ts
1203
- make_zero
1204
- ```
1205
- - Example:
1206
- ```bash
1207
- ffmpeg -i input.mp4 -avoid_negative_ts make_zero -ac 1 output.ogg
1208
- ```
1209
- ```javascript
1210
- await sock.sendMessage(
1211
- jid,
1212
- {
1213
- audio: {
1214
- url: './Media/audio.mp3'
1215
- },
1216
- mimetype: 'audio/mp4'
1217
- }
1218
- )
1219
- ```
1220
-
1221
- <a id="handling-events"></a>
1222
- #### 🖼️ Pesan Gambar
1223
- ```javascript
1224
- await sock.sendMessage(
1225
- id,
1226
- {
1227
- image: {
1228
- url: './Media/ma_img.png'
1229
- },
1230
- caption: 'hello word'
1231
- }
1232
- )
1233
- ```
1234
-
1235
- <a id="handling-events"></a>
1236
- #### 👁️ View Once (Sekali Lihat)
1237
-
1238
- - You can send all messages above as `viewOnce`, you only need to pass `viewOnce: true` in content object
1239
-
1240
- ```javascript
1241
- await sock.sendMessage(
1242
- id,
1243
- {
1244
- image: {
1245
- url: './Media/ma_img.png'
1246
- },
1247
- viewOnce: true, //works with video, audio too
1248
- caption: 'hello word'
1249
- }
1250
- )
1251
- ```
1252
-
1253
- <a id="handling-events"></a>
1254
- ## ✏️ Memodifikasi Pesan
1255
-
1256
- <a id="handling-events"></a>
1257
- ### 🗑️ Menghapus Pesan (untuk semua)
1258
-
1259
- ```javascript
1260
- const msg = await sock.sendMessage(jid, { text: 'hello word' })
1261
- await sock.sendMessage(jid, { delete: msg.key })
1262
- ```
1263
-
1264
- **Note:** deleting for oneself is supported via `chatModify`, see in [this section](#modifying-chats)
1265
-
1266
- <a id="handling-events"></a>
1267
- ### 🖊️ Mengedit Pesan
1268
-
1269
- - You can pass all editable contents here
1270
- ```javascript
1271
- await sock.sendMessage(jid, {
1272
- text: 'updated text goes here',
1273
- edit: response.key,
1274
- });
1275
- ```
1276
-
1277
- <a id="handling-events"></a>
1278
- ## 🛠️ Manipulasi Pesan Media
1279
-
1280
- <a id="handling-events"></a>
1281
- ### 🖼️ Thumbnail pada Pesan Media
1282
- - For media messages, the thumbnail can be generated automatically for images & stickers provided you add `jimp` or `sharp` as a dependency in your project using `yarn add jimp` or `yarn add sharp`.
1283
- - Thumbnails for videos can also be generated automatically, though, you need to have `ffmpeg` installed on your system.
1284
-
1285
- <a id="handling-events"></a>
1286
- ### ⬇️ Mengunduh Pesan Media
1287
-
1288
- If you want to save the media you received
1289
- ```javascript
1290
- const { createWriteStream } = require('fs');
1291
- const { downloadMediaMessage, getContentType } = require("astrabail");
1292
-
1293
- sock.ev.on('messages.upsert', async ({ [m] }) => {
1294
- if (!m.message) return // if there is no text or media message
1295
- const messageType = getContentType(m) // get what type of message it is (text, image, video...)
1296
-
1297
- // if the message is an image
1298
- if (messageType === 'imageMessage') {
1299
- // download the message
1300
- const stream = await downloadMediaMessage(
1301
- m,
1302
- 'stream', // can be 'buffer' too
1303
- { },
1304
- {
1305
- logger,
1306
- // pass this so that baileys can request a reupload of media
1307
- // that has been deleted
1308
- reuploadRequest: sock.updateMediaMessage
1309
- }
1310
- )
1311
- // save to file
1312
- const writeStream = createWriteStream('./my-download.jpeg')
1313
- stream.pipe(writeStream)
1314
- }
1315
- }
1316
- ```
1317
-
1318
- <a id="handling-events"></a>
1319
- ### 🔁 Mengunggah Ulang Pesan Media ke WhatsApp
1320
-
1321
- - WhatsApp automatically removes old media from their servers. For the device to access said media -- a re-upload is required by another device that has it. This can be accomplished using:
1322
- ```javascript
1323
- await sock.updateMediaMessage(msg)
1324
- ```
1325
-
1326
- <a id="handling-events"></a>
1327
- ## 🚫 Menolak Panggilan
1328
-
1329
- - You can obtain `callId` and `callFrom` from `call` event
1330
-
1331
- ```javascript
1332
- await sock.rejectCall(callId, callFrom)
1333
- ```
1334
-
1335
- <a id="handling-events"></a>
1336
- ## 📡 Status Pengiriman di Chat
1337
-
1338
- <a id="handling-events"></a>
1339
- ### 📖 Membaca Pesan
1340
- - A set of message [keys](https://baileys.whiskeysockets.io/types/WAMessageKey.html) must be explicitly marked read now.
1341
- - You cannot mark an entire 'chat' read as it were with Baileys Web.
1342
- This means you have to keep track of unread messages.
1343
-
1344
- ```javascript
1345
- const key: WAMessageKey
1346
- // can pass multiple keys to read multiple messages as well
1347
- await sock.readMessages([key])
1348
- ```
1349
-
1350
- The message ID is the unique identifier of the message that you are marking as read.
1351
- On a `WAMessage`, the `messageID` can be accessed using ```messageID = message.key.id```.
1352
-
1353
- <a id="handling-events"></a>
1354
- ### 🟢 Memperbarui Presence
1355
-
1356
- - ``` presence ``` can be one of [these](https://baileys.whiskeysockets.io/types/WAPresence.html)
1357
- - The presence expires after about 10 seconds.
1358
- - This lets the person/group with `jid` know whether you're online, offline, typing etc.
1359
-
1360
- ```javascript
1361
- await sock.sendPresenceUpdate('available', jid)
1362
- ```
1363
-
1364
- > [!NOTE]
1365
- > If a desktop client is active, WA doesn't send push notifications to the device. If you would like to receive said notifications -- mark your Baileys client offline using `sock.sendPresenceUpdate('unavailable')`
1366
-
1367
- <a id="handling-events"></a>
1368
- ## 🗂️ Memodifikasi Chat
1369
-
1370
- WA uses an encrypted form of communication to send chat/app updates. This has been implemented mostly and you can send the following updates:
1371
-
1372
- > [!IMPORTANT]
1373
- > If you mess up one of your updates, WA can log you out of all your devices and you'll have to log in again.
1374
-
1375
- <a id="handling-events"></a>
1376
- ### 🗃️ Arsipkan Chat
1377
- ```javascript
1378
- const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
1379
- await sock.chatModify({ archive: true, lastMessages: [lastMsgInChat] }, jid)
1380
- ```
1381
-
1382
- <a id="handling-events"></a>
1383
- ### 🔕 Mute/Unmute Chat
1384
-
1385
- - Supported times:
1386
-
1387
- | Time | Miliseconds |
1388
- |-------|-----------------|
1389
- | Remove | null |
1390
- | 8h | 86.400.000 |
1391
- | 7d | 604.800.000 |
1392
-
1393
- ```javascript
1394
- // mute for 8 hours
1395
- await sock.chatModify({ mute: 8 * 60 * 60 * 1000 }, jid)
1396
- // unmute
1397
- await sock.chatModify({ mute: null }, jid)
1398
- ```
1399
-
1400
- <a id="handling-events"></a>
1401
- ### ✅ Tandai Chat Baca/Belum Baca
1402
- ```javascript
1403
- const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
1404
- // mark it unread
1405
- await sock.chatModify({ markRead: false, lastMessages: [lastMsgInChat] }, jid)
1406
- ```
1407
-
1408
- <a id="handling-events"></a>
1409
- ### 🧹 Hapus Pesan untuk Saya
1410
- ```javascript
1411
- await sock.chatModify(
1412
- {
1413
- clear: {
1414
- messages: [
1415
- {
1416
- id: 'ATWYHDNNWU81732J',
1417
- fromMe: true,
1418
- timestamp: '1654823909'
1419
- }
1420
- ]
1421
- }
1422
- },
1423
- jid
1424
- )
1425
-
1426
- ```
1427
-
1428
- <a id="handling-events"></a>
1429
- ### ❌ Hapus Chat
1430
- ```javascript
1431
- const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
1432
- await sock.chatModify({
1433
- delete: true,
1434
- lastMessages: [
1435
- {
1436
- key: lastMsgInChat.key,
1437
- messageTimestamp: lastMsgInChat.messageTimestamp
1438
- }
1439
- ]
1440
- },
1441
- jid
1442
- )
1443
- ```
1444
-
1445
- <a id="handling-events"></a>
1446
- ### 📌 Pin/Unpin Chat
1447
- ```javascript
1448
- await sock.chatModify({
1449
- pin: true // or `false` to unpin
1450
- },
1451
- jid
1452
- )
1453
- ```
1454
-
1455
- <a id="handling-events"></a>
1456
- ### ⭐ Star/Unstar Pesan
1457
- ```javascript
1458
- await sock.chatModify({
1459
- star: {
1460
- messages: [
1461
- {
1462
- id: 'messageID',
1463
- fromMe: true // or `false`
1464
- }
1465
- ],
1466
- star: true // - true: Star Message; false: Unstar Message
1467
- }
1468
- },
1469
- jid
1470
- )
1471
- ```
1472
-
1473
- <a id="handling-events"></a>
1474
- ### 🕒 Pesan yang Menghilang (Disappearing)
1475
-
1476
- - Ephemeral can be:
1477
-
1478
- | Time | Seconds |
1479
- |-------|----------------|
1480
- | Remove | 0 |
1481
- | 24h | 86.400 |
1482
- | 7d | 604.800 |
1483
- | 90d | 7.776.000 |
1484
-
1485
- - You need to pass in **Seconds**, default is 7 days
1486
-
1487
- ```javascript
1488
- // turn on disappearing messages
1489
- await sock.sendMessage(
1490
- jid,
1491
- // this is 1 week in seconds -- how long you want messages to appear for
1492
- { disappearingMessagesInChat: WA_DEFAULT_EPHEMERAL }
1493
- )
1494
-
1495
- // will send as a disappearing message
1496
- await sock.sendMessage(jid, { text: 'hello' }, { ephemeralExpiration: WA_DEFAULT_EPHEMERAL })
1497
-
1498
- // turn off disappearing messages
1499
- await sock.sendMessage(
1500
- jid,
1501
- { disappearingMessagesInChat: false }
1502
- )
1503
- ```
1504
-
1505
- <a id="handling-events"></a>
1506
- ## 🔎 Query Pengguna
1507
-
1508
- <a id="handling-events"></a>
1509
- ### 🔍 Cek Jika ID Ada di WhatsApp
1510
- ```javascript
1511
- const [result] = await sock.onWhatsApp(jid)
1512
- if (result.exists) console.log (`${jid} exists on WhatsApp, as jid: ${result.jid}`)
1513
- ```
1514
-
1515
- <a id="handling-events"></a>
1516
- ### 📜 Query Riwayat Chat (termasuk grup)
1517
-
1518
- - You need to have oldest message in chat
1519
- ```javascript
1520
- const msg = await getOldestMessageInChat(jid)
1521
- await sock.fetchMessageHistory(
1522
- 50, //quantity (max: 50 per query)
1523
- msg.key,
1524
- msg.messageTimestamp
1525
- )
1526
- ```
1527
- - Messages will be received in `messaging.history-set` event
1528
-
1529
- <a id="handling-events"></a>
1530
- ### 📣 Ambil Status
1531
- ```javascript
1532
- const status = await sock.fetchStatus(jid)
1533
- console.log('status: ' + status)
1534
- ```
1535
-
1536
- <a id="handling-events"></a>
1537
- ### 🖼️ Ambil Foto Profil (termasuk grup)
1538
- - To get the display picture of some person/group
1539
- ```javascript
1540
- // for low res picture
1541
- const ppUrl = await sock.profilePictureUrl(jid)
1542
- console.log(ppUrl)
1543
-
1544
- // for high res picture
1545
- const ppUrl = await sock.profilePictureUrl(jid, 'image')
1546
- ```
1547
-
1548
- <a id="handling-events"></a>
1549
- ### 🏷️ Ambil Profil Bisnis (deskripsi/kategori)
1550
- ```javascript
1551
- const profile = await sock.getBusinessProfile(jid)
1552
- console.log('business description: ' + profile.description + ', category: ' + profile.category)
1553
- ```
1554
-
1555
- <a id="handling-events"></a>
1556
- ### 👀 Ambil Presence Seseorang (sedang mengetik/online)
1557
- ```javascript
1558
- // the presence update is fetched and called here
1559
- sock.ev.on('presence.update', console.log)
1560
-
1561
- // request updates for a chat
1562
- await sock.presenceSubscribe(jid)
1563
- ```
1564
-
1565
- <a id="handling-events"></a>
1566
- ## 🧑‍💼 Mengubah Profil
1567
-
1568
- <a id="handling-events"></a>
1569
- ### 🧑‍💼 Mengubah Profil Status
1570
- ```javascript
1571
- await sock.updateProfileStatus('Hello World!')
1572
- ```
1573
- <a id="handling-events"></a>
1574
- ### 🧑‍💼 Mengubah Profil Name
1575
- ```javascript
1576
- await sock.updateProfileName('My name')
1577
- ```
1578
- <a id="handling-events"></a>
1579
- ### 🖼️ Ubah Foto Profil (termasuk grup)
1580
- - To change your display picture or a group's
1581
-
1582
- > [!NOTE]
1583
- > Like media messages, you can pass `{ stream: Stream }` or `{ url: Url }` or `Buffer` directly, you can see more [here](https://baileys.whiskeysockets.io/types/WAMediaUpload.html)
1584
-
1585
- ```javascript
1586
- await sock.updateProfilePicture(jid, { url: './new-profile-picture.jpeg' })
1587
- ```
1588
- <a id="handling-events"></a>
1589
- ### 🗑️ Hapus Foto Profil (termasuk grup)
1590
- ```javascript
1591
- await sock.removeProfilePicture(jid)
1592
- ```
1593
-
1594
- <a id="handling-events"></a>
1595
- ## 👥 Grup
1596
-
1597
- - To change group properties you need to be admin
1598
-
1599
- <a id="handling-events"></a>
1600
- ### ➕ Buat Grup
1601
- ```javascript
1602
- // title & participants
1603
- const group = await sock.groupCreate('My Fab Group', ['1234@s.whatsapp.net', '4564@s.whatsapp.net'])
1604
- console.log('created group with id: ' + group.gid)
1605
- await sock.sendMessage(group.id, { text: 'hello there' }) // say hello to everyone on the group
1606
- ```
1607
- <a id="handling-events"></a>
1608
- ### ➕/➖ Tambah/Hapus atau Turunkan/Naikkan Status
1609
- ```javascript
1610
- // id & people to add to the group (will throw error if it fails)
1611
- await sock.groupParticipantsUpdate(
1612
- jid,
1613
- ['abcd@s.whatsapp.net', 'efgh@s.whatsapp.net'],
1614
- 'add' // replace this parameter with 'remove' or 'demote' or 'promote'
1615
- )
1616
- ```
1617
- <a id="handling-events"></a>
1618
- ### ✏️ Ubah Subjek (Nama)
1619
- ```javascript
1620
- await sock.groupUpdateSubject(jid, 'New Subject!')
1621
- ```
1622
- <a id="handling-events"></a>
1623
- ### 📝 Ubah Deskripsi
1624
- ```javascript
1625
- await sock.groupUpdateDescription(jid, 'New Description!')
1626
- ```
1627
- <a id="handling-events"></a>
1628
- ### ⚙️ Ubah Pengaturan
1629
- ```javascript
1630
- // only allow admins to send messages
1631
- await sock.groupSettingUpdate(jid, 'announcement')
1632
- // allow everyone to send messages
1633
- await sock.groupSettingUpdate(jid, 'not_announcement')
1634
- // allow everyone to modify the group's settings -- like display picture etc.
1635
- await sock.groupSettingUpdate(jid, 'unlocked')
1636
- // only allow admins to modify the group's settings
1637
- await sock.groupSettingUpdate(jid, 'locked')
1638
- ```
1639
- <a id="handling-events"></a>
1640
- ### 🚪 Keluar Grup
1641
- ```javascript
1642
- // will throw error if it fails
1643
- await sock.groupLeave(jid)
1644
- ```
1645
- <a id="handling-events"></a>
1646
- ### 🔐 Dapatkan Kode Undangan
1647
- - To create link with code use `'https://chat.whatsapp.com/' + code`
1648
- ```javascript
1649
- const code = await sock.groupInviteCode(jid)
1650
- console.log('group code: ' + code)
1651
- ```
1652
- <a id="handling-events"></a>
1653
- ### 🔄 Cabut Kode Undangan
1654
- ```javascript
1655
- const code = await sock.groupRevokeInvite(jid)
1656
- console.log('New group code: ' + code)
1657
- ```
1658
- <a id="handling-events"></a>
1659
- ### ➿ Bergabung Menggunakan Kode Undangan
1660
- - Code can't have `https://chat.whatsapp.com/`, only code
1661
- ```javascript
1662
- const response = await sock.groupAcceptInvite(code)
1663
- console.log('joined to: ' + response)
1664
- ```
1665
- <a id="handling-events"></a>
1666
- ### ℹ️ Dapatkan Info Grup lewat Kode Undangan
1667
- ```javascript
1668
- const response = await sock.groupGetInviteInfo(code)
1669
- console.log('group information: ' + response)
1670
- ```
1671
- <a id="handling-events"></a>
1672
- ### 🔎 Query Metadata (peserta, nama, deskripsi...)
1673
- ```javascript
1674
- const metadata = await sock.groupMetadata(jid)
1675
- console.log(metadata.id + ', title: ' + metadata.subject + ', description: ' + metadata.desc)
1676
- ```
1677
- <a id="handling-events"></a>
1678
- ### Join using `groupInviteMessage`
1679
- ```javascript
1680
- const response = await sock.groupAcceptInviteV4(jid, groupInviteMessage)
1681
- console.log('joined to: ' + response)
1682
- ```
1683
- <a id="handling-events"></a>
1684
- ### 📥 Dapatkan Daftar Permintaan Bergabung
1685
- ```javascript
1686
- const response = await sock.groupRequestParticipantsList(jid)
1687
- console.log(response)
1688
- ```
1689
- <a id="handling-events"></a>
1690
- ### ✅/❌ Setuju/Tolak Permintaan Bergabung
1691
- ```javascript
1692
- const response = await sock.groupRequestParticipantsUpdate(
1693
- jid, // group id
1694
- ['abcd@s.whatsapp.net', 'efgh@s.whatsapp.net'],
1695
- 'approve' // or 'reject'
1696
- )
1697
- console.log(response)
1698
- ```
1699
- <a id="handling-events"></a>
1700
- ### 📚 Dapatkan Semua Metadata Grup yang Diikuti
1701
- ```javascript
1702
- const response = await sock.groupFetchAllParticipating()
1703
- console.log(response)
1704
- ```
1705
- <a id="handling-events"></a>
1706
- ### ⏳ Toggle Ephemeral
1707
-
1708
- - Ephemeral can be:
1709
-
1710
- | Time | Seconds |
1711
- |-------|----------------|
1712
- | Remove | 0 |
1713
- | 24h | 86.400 |
1714
- | 7d | 604.800 |
1715
- | 90d | 7.776.000 |
1716
-
1717
- ```javascript
1718
- await sock.groupToggleEphemeral(jid, 86400)
1719
- ```
1720
-
1721
- <a id="handling-events"></a>
1722
- ### 🔐 Ubah Mode Penambahan
1723
- ```javascript
1724
- await sock.groupMemberAddMode(
1725
- jid,
1726
- 'all_member_add' // or 'admin_add'
1727
- )
1728
- ```
1729
-
1730
- <a id="handling-events"></a>
1731
- ## 🔒 Privasi
1732
-
1733
- <a id="handling-events"></a>
1734
- ### ⛔/✅ Blokir/Buka Blokir Pengguna
1735
- ```javascript
1736
- await sock.updateBlockStatus(jid, 'block') // Block user
1737
- await sock.updateBlockStatus(jid, 'unblock') // Unblock user
1738
- ```
1739
- <a id="handling-events"></a>
1740
- ### ⚙️ Dapatkan Pengaturan Privasi
1741
- ```javascript
1742
- const privacySettings = await sock.fetchPrivacySettings(true)
1743
- console.log('privacy settings: ' + privacySettings)
1744
- ```
1745
- <a id="handling-events"></a>
1746
- ### 📛 Dapatkan Daftar Blokir
1747
- ```javascript
1748
- const response = await sock.fetchBlocklist()
1749
- console.log(response)
1750
- ```
1751
- <a id="handling-events"></a>
1752
- ### 👀 Update Privasi LastSeen
1753
- ```javascript
1754
- const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
1755
- await sock.updateLastSeenPrivacy(value)
1756
- ```
1757
- <a id="handling-events"></a>
1758
- ### 🟢 Update Privasi Online
1759
- ```javascript
1760
- const value = 'all' // 'match_last_seen'
1761
- await sock.updateOnlinePrivacy(value)
1762
- ```
1763
- <a id="handling-events"></a>
1764
- ### 🖼️ Update Privasi Foto Profil
1765
- ```javascript
1766
- const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
1767
- await sock.updateProfilePicturePrivacy(value)
1768
- ```
1769
- <a id="handling-events"></a>
1770
- ### 📣 Update Privasi Status
1771
- ```javascript
1772
- const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
1773
- await sock.updateStatusPrivacy(value)
1774
- ```
1775
- <a id="handling-events"></a>
1776
- ### ✅ Update Privasi Read Receipts
1777
- ```javascript
1778
- const value = 'all' // 'none'
1779
- await sock.updateReadReceiptsPrivacy(value)
1780
- ```
1781
- <a id="handling-events"></a>
1782
- ### 👥 Update Privasi Tambah Grup
1783
- ```javascript
1784
- const value = 'all' // 'contacts' | 'contact_blacklist'
1785
- await sock.updateGroupsAddPrivacy(value)
1786
- ```
1787
- <a id="handling-events"></a>
1788
- ### 🕒 Update Mode Default Disappearing
1789
-
1790
- - Like [this](#disappearing-messages), ephemeral can be:
1791
-
1792
- | Time | Seconds |
1793
- |-------|----------------|
1794
- | Remove | 0 |
1795
- | 24h | 86.400 |
1796
- | 7d | 604.800 |
1797
- | 90d | 7.776.000 |
1798
-
1799
- ```javascript
1800
- const ephemeral = 86400
1801
- await sock.updateDefaultDisappearingMode(ephemeral)
1802
- ```
1803
-
1804
- <a id="handling-events"></a>
1805
- ## 📢 Broadcast & Story
1806
-
1807
- <a id="handling-events"></a>
1808
- ### 📤 Kirim Broadcast & Story
1809
- - Messages can be sent to broadcasts & stories. You need to add the following message options in sendMessage, like this:
1810
- ```javascript
1811
- await sock.sendMessage(
1812
- jid,
1813
- {
1814
- image: {
1815
- url: url
1816
- },
1817
- caption: caption
1818
- },
1819
- {
1820
- backgroundColor: backgroundColor,
1821
- font: font,
1822
- statusJidList: statusJidList,
1823
- broadcast: true
1824
- }
1825
- )
1826
- ```
1827
- - Message body can be a `extendedTextMessage` or `imageMessage` or `videoMessage` or `voiceMessage`, see [here](https://baileys.whiskeysockets.io/types/AnyRegularMessageContent.html)
1828
- - You can add `backgroundColor` and other options in the message options, see [here](https://baileys.whiskeysockets.io/types/MiscMessageGenerationOptions.html)
1829
- - `broadcast: true` enables broadcast mode
1830
- - `statusJidList`: a list of people that you can get which you need to provide, which are the people who will get this status message.
1831
-
1832
- - You can send messages to broadcast lists the same way you send messages to groups & individual chats.
1833
- - Right now, WA Web does not support creating broadcast lists, but you can still delete them.
1834
- - Broadcast IDs are in the format `12345678@broadcast`
1835
- <a id="handling-events"></a>
1836
- ### 🔎 Query Penerima & Nama Broadcast List
1837
- ```javascript
1838
- const bList = await sock.getBroadcastListInfo('1234@broadcast')
1839
- console.log (`list name: ${bList.name}, recps: ${bList.recipients}`)
1840
- ```
1841
-
1842
- <a id="handling-events"></a>
1843
- ## ✍️ Menulis Fungsionalitas Kustom
1844
- Baileys is written with custom functionality in mind. Instead of forking the project & re-writing the internals, you can simply write your own extensions.
1845
-
1846
- <a id="handling-events"></a>
1847
- ### 🐛 Mengaktifkan Level Debug di Log Baileys
1848
- First, enable the logging of unhandled messages from WhatsApp by setting:
1849
- ```javascript
1850
- const sock = makeWASocket({
1851
- logger: P({ level: 'debug' }),
1852
- })
1853
- ```
1854
- This will enable you to see all sorts of messages WhatsApp sends in the console.
1855
-
1856
- <a id="handling-events"></a>
1857
- ### 🔬 Bagaimana WhatsApp Berkomunikasi dengan Kita
1858
-
1859
- > [!TIP]
1860
- > If you want to learn whatsapp protocol, we recommend to study about Libsignal Protocol and Noise Protocol
1861
-
1862
- - **Example:** Functionality to track the battery percentage of your phone. You enable logging and you'll see a message about your battery pop up in the console:
1863
- ```
1864
- {
1865
- "level": 10,
1866
- "fromMe": false,
1867
- "frame": {
1868
- "tag": "ib",
1869
- "attrs": {
1870
- "from": "@s.whatsapp.net"
1871
- },
1872
- "content": [
1873
- {
1874
- "tag": "edge_routing",
1875
- "attrs": {},
1876
- "content": [
1877
- {
1878
- "tag": "routing_info",
1879
- "attrs": {},
1880
- "content": {
1881
- "type": "Buffer",
1882
- "data": [8,2,8,5]
1883
- }
1884
- }
1885
- ]
1886
- }
1887
- ]
1888
- },
1889
- "msg":"communication"
1890
- }
1891
- ```
1892
-
1893
- The `'frame'` is what the message received is, it has three components:
1894
- - `tag` -- what this frame is about (eg. message will have 'message')
1895
- - `attrs` -- a string key-value pair with some metadata (contains ID of the message usually)
1896
- - `content` -- the actual data (eg. a message node will have the actual message content in it)
1897
- - read more about this format [here](/src/WABinary/readme.md)
1898
-
1899
- <a id="handling-events"></a>
1900
- ### 🔁 Mendaftarkan Callback untuk Event Websocket
1901
-
1902
- > [!TIP]
1903
- > Recommended to see `onMessageReceived` function in `socket.ts` file to understand how websockets events are fired
1904
-
1905
- ```javascript
1906
- // for any message with tag 'edge_routing'
1907
- sock.ws.on('CB:edge_routing', (node: BinaryNode) => { })
1908
-
1909
- // for any message with tag 'edge_routing' and id attribute = abcd
1910
- sock.ws.on('CB:edge_routing,id:abcd', (node: BinaryNode) => { })
1911
-
1912
- // for any message with tag 'edge_routing', id attribute = abcd & first content node routing_info
1913
- sock.ws.on('CB:edge_routing,id:abcd,routing_info', (node: BinaryNode) => { })
1914
- ```
1915
-
1916
- > [!NOTE]
1917
- > Also, this repo is now licenced under GPL 3 since it uses [libsignal-node](https://git.questbook.io/backend/service-coderunner/-/merge_requests/1)
1918
-
1919
-
1920
- <a id="handling-events"></a>
1921
- ## ⚠️ Catatan
1922
-
1923
- Proyek ini **tidak berafiliasi dengan WhatsApp Inc.**
1924
- Gunakan secara bertanggung jawab dan hindari aktivitas ilegal atau penyalahgunaan.
1925
-
1926
- ---
1927
-
1928
- <a id="handling-events"></a>
1929
- ## Lisensi
1930
-
1931
- 📘 *Documentation powered by AstraBail*
1932
- 🧑‍💻 **Modified and Presented by AstraBail**
1933
-
1934
- <a id="kirim-sticker-pack"></a>
1935
- ## Sticker Pack Message
1936
-
1937
- Gunakan field `stickerPack` pada `sendMessage` untuk mengirim satu paket sticker sekaligus.
1938
-
1939
- Catatan penting: `stickerPack` sekarang bisa menerima campuran sticker statis dan video/animated (`webp/png/jpg/jpeg/gif/webm/mp4`) lalu mengonversinya ke WebP otomatis saat proses kirim, selama `ffmpeg` tersedia di server. Format `tgs`/Lottie tetap butuh preview/konverter tambahan di luar runtime ini.
1940
-
1941
- ```javascript
1942
- await sock.sendMessage(jid, {
1943
- stickerPack: {
1944
- name: 'Nama Pack',
1945
- publisher: 'Nama Publisher',
1946
- description: 'Deskripsi singkat',
1947
- cover: { url: './cover.png' },
1948
- stickers: [
1949
- { sticker: { url: './1.webp' }, emojis: ['🙂'] },
1950
- { sticker: { url: './2.png' }, emojis: ['🎉'] }
1951
- ]
1952
- }
1953
- })
1954
- ```
1955
-
1956
- `cover` dan setiap item `sticker` menerima format media yang sama seperti pengiriman media biasa: path lokal, URL, Buffer, atau stream.
1
+ <div align="center">
2
+
3
+ <h1>
4
+ <img src="https://img.shields.io/badge/⚡-AstraBail-0f0f0f?style=for-the-badge&labelColor=0f0f0f&color=6c63ff" height="45" alt="AstraBail" />
5
+ </h1>
6
+
7
+ <p align="center">
8
+ <strong>Professional WhatsApp Web API Library — Built for the Next Generation of Bots</strong><br/>
9
+ <sub>Fork-optimized from AstraBail · Maintained by <a href="https://github.com/Danimaru-ze">Danimaru-ze</a></sub>
10
+ </p>
11
+
12
+ <p align="center">
13
+ <a href="https://www.npmjs.com/package/astrabail">
14
+ <img src="https://img.shields.io/npm/v/astrabail.svg?style=flat-square&label=npm&color=6c63ff&logo=npm&logoColor=white" alt="npm version" />
15
+ </a>
16
+ <a href="https://www.npmjs.com/package/astrabail">
17
+ <img src="https://img.shields.io/npm/dw/astrabail.svg?style=flat-square&label=downloads&color=38bdf8&logo=npm&logoColor=white" alt="downloads" />
18
+ </a>
19
+ <a href="https://github.com/Danimaru-ze/AstraBail/blob/main/LICENSE">
20
+ <img src="https://img.shields.io/npm/l/astrabail.svg?style=flat-square&label=license&color=22c55e" alt="license" />
21
+ </a>
22
+ <a href="https://github.com/Danimaru-ze/AstraBail">
23
+ <img src="https://img.shields.io/badge/GitHub-AstraBail-181717?style=flat-square&logo=github" alt="github" />
24
+ </a>
25
+ <a href="https://whatsapp.com/channel/0029Vazo6KM8kyyJ4eWh3A25">
26
+ <img src="https://img.shields.io/badge/WhatsApp-Channel-25D366?style=flat-square&logo=whatsapp&logoColor=white" alt="WhatsApp Channel" />
27
+ </a>
28
+ </p>
29
+
30
+ </div>
31
+
32
+ ---
33
+
34
+ ## ✨ Tentang AstraBail
35
+
36
+ **AstraBail** adalah library WhatsApp Web API profesional yang dioptimalkan dari basis *AstraBail*. Dikelola oleh **Danimaru-ze**, library ini dirancang untuk performa tinggi, stabilitas maksimal, dan kemudahan integrasi ke berbagai proyek bot WhatsApp modern.
37
+
38
+ ### 🚀 Fitur Unggulan
39
+
40
+ | Fitur | Keterangan |
41
+ |-------|-----------|
42
+ | 🔀 **Multi-Device** | Dukungan penuh sistem multi-device WhatsApp terbaru |
43
+ | 🔐 **End-to-End Encryption** | Enkripsi pesan standar industri |
44
+ | ⚡ **Turbo Handshake** | Inisialisasi koneksi yang sangat cepat |
45
+ | 🧠 **Memory Optimized** | Penggunaan RAM yang ringan dan efisien |
46
+ | 📦 **Semua Jenis Pesan** | Teks, Media, Button, Poll, Sticker, dan lainnya |
47
+ | 🆔 **LID & JID Mapping** | Pemetaan `@lid` dan `@jid` lengkap |
48
+
49
+ ---
50
+
51
+ ## 📦 Instalasi
52
+
53
+ ```bash
54
+ npm install astrabail
55
+ # atau
56
+ yarn add astrabail
57
+ ```
58
+
59
+ ---
60
+
61
+ ## ⚡ Mulai Cepat
62
+
63
+ ### Instalasi & Koneksi Dasar
64
+
65
+ ```javascript
66
+ const { default: makeWASocket, useMultiFileAuthState } = require("astrabail")
67
+
68
+ async function startBot() {
69
+ const { state, saveCreds } = await useMultiFileAuthState('./session')
70
+
71
+ const sock = makeWASocket({
72
+ auth: state,
73
+ printQRInTerminal: true
74
+ })
75
+
76
+ sock.ev.on('creds.update', saveCreds)
77
+
78
+ sock.ev.on('connection.update', ({ connection }) => {
79
+ if (connection === 'open') console.log('✅ AstraBail: Bot Connected!')
80
+ })
81
+ }
82
+
83
+ startBot()
84
+ ```
85
+
86
+
87
+
88
+ ## Kirim Sticker Pack
89
+
90
+ ```javascript
91
+ await sock.sendMessage('6281234567890@s.whatsapp.net', {
92
+ stickerPack: {
93
+ name: 'AstraBail Sticker',
94
+ publisher: 'AstraBail',
95
+ description: 'Sticker pack custom dari AstraBail',
96
+ cover: { url: './assets/cover.png' },
97
+ stickers: [
98
+ { sticker: { url: './assets/sticker-1.webp' }, emojis: ['😀'] },
99
+ { sticker: { url: './assets/sticker-2.webp' }, emojis: ['🔥'] },
100
+ { sticker: { url: './assets/sticker-3.png' }, emojis: ['🚀'] }
101
+ ]
102
+ }
103
+ })
104
+ ```
105
+
106
+ ### Format object `stickerPack`
107
+
108
+ - `name`: nama pack sticker
109
+ - `publisher`: nama author/publisher
110
+ - `description`: deskripsi pack
111
+ - `cover`: cover/tray icon, bisa file path, buffer, stream, atau URL
112
+ - `stickers`: array isi sticker, minimal 1 maksimal 60
113
+ - `sticker`: media tiap sticker, bisa WebP/PNG/JPG. Jika bukan WebP akan dicoba dikonversi otomatis
114
+ - `emojis`: emoji untuk sticker terkait
115
+ - `accessibilityLabel`: label opsional
116
+ - `packId`: opsional, jika tidak diisi akan dibuat otomatis
117
+
118
+ ### Catatan
119
+
120
+ - Sangat disarankan install `sharp` agar konversi gambar ke WebP lebih stabil.
121
+ - Jika `sharp` tidak ada, library akan mencoba memakai `jimp`.
122
+ - Ukuran tiap sticker maksimal 1 MB.
123
+ - Jumlah sticker maksimal 60 per pack.
124
+
125
+ ---
126
+
127
+ # Documentation
128
+
129
+ - [Connecting Account](#connecting-account)
130
+ - [Connect with QR-CODE](#starting-socket-with-qr-code)
131
+ - [Connect with Pairing Code](#starting-socket-with-pairing-code)
132
+ - [Receive Full History](#receive-full-history)
133
+ - [Important Notes About Socket Config](#important-notes-about-socket-config)
134
+ - [Caching Group Metadata (Recommended)](#caching-group-metadata-recommended)
135
+ - [Improve Retry System & Decrypt Poll Votes](#improve-retry-system--decrypt-poll-votes)
136
+ - [Receive Notifications in Whatsapp App](#receive-notifications-in-whatsapp-app)
137
+
138
+ - [Save Auth Info](#saving--restoring-sessions)
139
+ - [Handling Events](#handling-events)
140
+ - [Example to Start](#example-to-start)
141
+ - [Decrypt Poll Votes](#decrypt-poll-votes)
142
+ - [Summary of Events on First Connection](#summary-of-events-on-first-connection)
143
+ - [Implementing a Data Store](#implementing-a-data-store)
144
+ - [Whatsapp IDs Explain](#whatsapp-ids-explain)
145
+ - [Utility Functions](#utility-functions)
146
+ - [Broadcast Lists & Stories](#broadcast-lists--stories)
147
+ - [Send Broadcast & Stories](#send-broadcast--stories)
148
+ - [Send Global Channel (upswgc)](#send-global-channel-upswgc)
149
+ - [Query a Broadcast List's Recipients & Name](#query-a-broadcast-lists-recipients--name)
150
+ - [Sending Messages](#sending-messages)
151
+ - [Non-Media Messages](#non-media-messages)
152
+ - [Buttons Message](#buttons-message)
153
+ - [Buttons Flow](#buttons-flow)
154
+ - [Interactive Message](#interactive-message)
155
+ - [Text Message](#text-message)
156
+ - [Quote Message](#quote-message-works-with-all-types)
157
+ - [Mention User](#mention-user-works-with-most-types)
158
+ - [Mention Status](#mention-status)
159
+ - [Result Poll From Newsletter](#result-poll-from-newsletter)
160
+ - [SendAlbumMessage](#send-album-message)
161
+ - [Interactive Response](#interactive-response)
162
+ - [Request Payment](#request-payment)
163
+ - [Event Message](#event-message)
164
+ - [Interactive](#interactive)
165
+ - [Forward Messages](#forward-messages)
166
+ - [Location Message](#location-message)
167
+ - [Contact Message](#contact-message)
168
+ - [Reaction Message](#reaction-message)
169
+ - [Pin Message](#pin-message)
170
+ - [Poll Message](#poll-message)
171
+ - [Sending with Link Preview](#sending-messages-with-link-previews)
172
+ - [Media Messages](#media-messages)
173
+ - [Gif Message](#gif-message)
174
+ - [Video Message](#video-message)
175
+ - [Audio Message](#audio-message)
176
+ - [Image Message](#image-message)
177
+ - [ViewOnce Message](#view-once-message)
178
+ - [Sticker Pack Message](#kirim-sticker-pack)
179
+ - [Modify Messages](#modify-messages)
180
+ - [Delete Messages (for everyone)](#deleting-messages-for-everyone)
181
+ - [Edit Messages](#editing-messages)
182
+ - [Manipulating Media Messages](#manipulating-media-messages)
183
+ - [Thumbnail in Media Messages](#thumbnail-in-media-messages)
184
+ - [Downloading Media Messages](#downloading-media-messages)
185
+ - [Re-upload Media Message to Whatsapp](#re-upload-media-message-to-whatsapp)
186
+ - [Reject Call](#reject-call)
187
+ - [Send States in Chat](#send-states-in-chat)
188
+ - [Reading Messages](#reading-messages)
189
+ - [Update Presence](#update-presence)
190
+ - [Modifying Chats](#modifying-chats)
191
+ - [Archive a Chat](#archive-a-chat)
192
+ - [Mute/Unmute a Chat](#muteunmute-a-chat)
193
+ - [Mark a Chat Read/Unread](#mark-a-chat-readunread)
194
+ - [Delete a Message for Me](#delete-a-message-for-me)
195
+ - [Delete a Chat](#delete-a-chat)
196
+ - [Star/Unstar a Message](#starunstar-a-message)
197
+ - [Disappearing Messages](#disappearing-messages)
198
+ - [User Querys](#user-querys)
199
+ - [Check If ID Exists in Whatsapp](#check-if-id-exists-in-whatsapp)
200
+ - [Query Chat History (groups too)](#query-chat-history-groups-too)
201
+ - [Fetch Status](#fetch-status)
202
+ - [Fetch Profile Picture (groups too)](#fetch-profile-picture-groups-too)
203
+ - [Fetch Bussines Profile (such as description or category)](#fetch-bussines-profile-such-as-description-or-category)
204
+ - [Fetch Someone's Presence (if they're typing or online)](#fetch-someones-presence-if-theyre-typing-or-online)
205
+ - [Change Profile](#change-profile)
206
+ - [Change Profile Status](#change-profile-status)
207
+ - [Change Profile Name](#change-profile-name)
208
+ - [Change Display Picture (groups too)](#change-display-picture-groups-too)
209
+ - [Remove display picture (groups too)](#remove-display-picture-groups-too)
210
+ - [Groups](#groups)
211
+ - [Create a Group](#create-a-group)
212
+ - [Add/Remove or Demote/Promote](#addremove-or-demotepromote)
213
+ - [Change Subject (name)](#change-subject-name)
214
+ - [Change Description](#change-description)
215
+ - [Change Settings](#change-settings)
216
+ - [Leave a Group](#leave-a-group)
217
+ - [Get Invite Code](#get-invite-code)
218
+ - [Revoke Invite Code](#revoke-invite-code)
219
+ - [Join Using Invitation Code](#join-using-invitation-code)
220
+ - [Get Group Info by Invite Code](#get-group-info-by-invite-code)
221
+ - [Query Metadata (participants, name, description...)](#query-metadata-participants-name-description)
222
+ - [Join using groupInviteMessage](#join-using-groupinvitemessage)
223
+ - [Get Request Join List](#get-request-join-list)
224
+ - [Approve/Reject Request Join](#approvereject-request-join)
225
+ - [Get All Participating Groups Metadata](#get-all-participating-groups-metadata)
226
+ - [Toggle Ephemeral](#toggle-ephemeral)
227
+ - [Change Add Mode](#change-add-mode)
228
+ - [Privacy](#privacy)
229
+ - [Block/Unblock User](#blockunblock-user)
230
+ - [Get Privacy Settings](#get-privacy-settings)
231
+ - [Get BlockList](#get-blocklist)
232
+ - [Update LastSeen Privacy](#update-lastseen-privacy)
233
+ - [Update Online Privacy](#update-online-privacy)
234
+ - [Update Profile Picture Privacy](#update-profile-picture-privacy)
235
+ - [Update Status Privacy](#update-status-privacy)
236
+ - [Update Read Receipts Privacy](#update-read-receipts-privacy)
237
+ - [Update Groups Add Privacy](#update-groups-add-privacy)
238
+ - [Update Default Disappearing Mode](#update-default-disappearing-mode)
239
+ - [Broadcast Lists & Stories](#broadcast-lists--stories)
240
+ - [Send Broadcast & Stories](#send-broadcast--stories)
241
+ - [Query a Broadcast List's Recipients & Name](#query-a-broadcast-lists-recipients--name)
242
+ - [Writing Custom Functionality](#writing-custom-functionality)
243
+ - [Enabling Debug Level in AstraBail Logs](#enabling-debug-level-in-AstraBail-logs)
244
+ - [How Whatsapp Communicate With Us](#how-whatsapp-communicate-with-us)
245
+ - [Register a Callback for Websocket Events](#register-a-callback-for-websocket-events)
246
+
247
+ <a id="connecting-account"></a>
248
+ ## 🔗 Menghubungkan Akun
249
+
250
+ WhatsApp provides a multi-device API that allows AstraBail to be authenticated as a second WhatsApp client by scanning a **QR code** or **Pairing Code** with WhatsApp on your phone.
251
+
252
+ <a id="starting-socket-with-qr-code"></a>
253
+ ### 🔹 Memulai Socket dengan Kode QR
254
+
255
+ > [!TIP]
256
+ > You can customize browser name if you connect with **QR-CODE**, with `Browser` constant, we have some browsers config, **see [here](https://AstraBail.whiskeysockets.io/types/BrowsersMap.html)**
257
+
258
+ ```javascript
259
+ const { default: makeWASocket } = require("astrabail")
260
+
261
+
262
+ const sock = makeWASocket({
263
+ // can provide additional config here
264
+ browser: Browsers.ubuntu('My App'),
265
+ printQRInTerminal: true
266
+ })
267
+ ```
268
+
269
+ If the connection is successful, you will see a QR code printed on your terminal screen, scan it with WhatsApp on your phone and you'll be logged in!
270
+
271
+ <a id="starting-socket-with-pairing-code"></a>
272
+ ### 🔹 Memulai Socket dengan **Kode Pairing**
273
+
274
+
275
+ > [!IMPORTANT]
276
+ > Pairing Code isn't Mobile API, it's a method to connect Whatsapp Web without QR-CODE, you can connect only with one device, see [here](https://faq.whatsapp.com/1324084875126592/?cms_platform=web)
277
+
278
+ The phone number can't have `+` or `()` or `-`, only numbers, you must provide country code
279
+
280
+ ```javascript
281
+ const { default: makeWASocket } = require("astrabail")
282
+
283
+ const sock = makeWASocket({
284
+ // can provide additional config here
285
+ printQRInTerminal: false //need to be false
286
+ })
287
+
288
+ - Normal Pairing
289
+ if (!sock.authState.creds.registered) {
290
+ const number = 'XXXXXXXXXXX'
291
+ const code = await sock.requestPairingCode(number)
292
+ console.log(code)
293
+ }
294
+
295
+ - Costum Pairing
296
+ if (!sock.authState.creds.registered) {
297
+ const pair = "12345678" // only 8 digit numbers or letters (no more or less)
298
+ const number = 'XXXXXXXXXXX'
299
+ const code = await sock.requestPairingCode(number, pair)
300
+ console.log(code)
301
+ }
302
+ ```
303
+
304
+ <a id="receive-full-history"></a>
305
+ ### 🔹 Menerima Riwayat Penuh
306
+
307
+ 1. Set `syncFullHistory` as `true`
308
+ 2. AstraBail, by default, use chrome browser config
309
+ - If you'd like to emulate a desktop connection (and receive more message history), this browser setting to your Socket config:
310
+
311
+ ```javascript
312
+ const sock = makeWASocket({
313
+ ...otherOpts,
314
+ // can use Windows, Ubuntu here too
315
+ browser: Browsers.macOS('Desktop'),
316
+ syncFullHistory: true
317
+ })
318
+ ```
319
+
320
+ <a id="important-notes-about-socket-config"></a>
321
+ ## ⚙️ Catatan Penting tentang Konfigurasi Socket
322
+
323
+ <a id="caching-group-metadata-recommended"></a>
324
+ ### 🧠 Caching Metadata Grup (Direkomendasikan)
325
+ - If you use AstraBail for groups, we recommend you to set `cachedGroupMetadata` in socket config, you need to implement a cache like this:
326
+
327
+ ```javascript
328
+ const groupCache = new NodeCache({stdTTL: 5 * 60, useClones: false})
329
+
330
+ const sock = makeWASocket({
331
+ cachedGroupMetadata: async (jid) => groupCache.get(jid)
332
+ })
333
+
334
+ sock.ev.on('groups.update', async ([event]) => {
335
+ const metadata = await sock.groupMetadata(event.id)
336
+ groupCache.set(event.id, metadata)
337
+ })
338
+
339
+ sock.ev.on('group-participants.update', async (event) => {
340
+ const metadata = await sock.groupMetadata(event.id)
341
+ groupCache.set(event.id, metadata)
342
+ })
343
+ ```
344
+
345
+ <a id="handling-events"></a>
346
+ ### 🔁 Perbaiki Sistem Retry & Dekripsi Polling
347
+ - If you want to improve sending message, retrying when error occurs and decrypt poll votes, you need to have a store and set `getMessage` config in socket like this:
348
+ ```javascript
349
+ const sock = makeWASocket({
350
+ getMessage: async (key) => await getMessageFromStore(key)
351
+ })
352
+ ```
353
+ <a id="handling-events"></a>
354
+ ### 🔔 Menerima Notifikasi di Aplikasi WhatsApp
355
+ - If you want to receive notifications in whatsapp app, set `markOnlineOnConnect` to `false`
356
+ ```javascript
357
+ const sock = makeWASocket({
358
+ markOnlineOnConnect: false
359
+ })
360
+ ```
361
+ <a id="handling-events"></a>
362
+ ## 📦 Menyimpan & Mengembalikan Sesi
363
+
364
+ You obviously don't want to keep scanning the QR code every time you want to connect.
365
+
366
+ So, you can load the credentials to log back in:
367
+ ```javascript
368
+ const makeWASocket = require("astrabail").default;
369
+ const { useMultiFileAuthState } = require("astrabail");
370
+
371
+ const { state, saveCreds } = await useMultiFileAuthState('auth_info_AstraBail')
372
+
373
+ // will use the given state to connect
374
+ // so if valid credentials are available -- it'll connect without QR
375
+ const sock = makeWASocket({ auth: state })
376
+
377
+ // this will be called as soon as the credentials are updated
378
+ sock.ev.on('creds.update', saveCreds)
379
+ ```
380
+
381
+ > [!IMPORTANT]
382
+ > `useMultiFileAuthState` is a utility function to help save the auth state in a single folder, this function serves as a good guide to help write auth & key states for SQL/no-SQL databases, which I would recommend in any production grade system.
383
+
384
+ > [!NOTE]
385
+ > When a message is received/sent, due to signal sessions needing updating, the auth keys (`authState.keys`) will update. Whenever that happens, you must save the updated keys (`authState.keys.set()` is called). Not doing so will prevent your messages from reaching the recipient & cause other unexpected consequences. The `useMultiFileAuthState` function automatically takes care of that, but for any other serious implementation -- you will need to be very careful with the key state management.
386
+
387
+ <a id="handling-events"></a>
388
+ ## 📡 Penanganan Event
389
+
390
+ - AstraBail uses the EventEmitter syntax for events.
391
+ They're all nicely typed up, so you shouldn't have any issues with an Intellisense editor like VS Code.
392
+
393
+ > [!IMPORTANT]
394
+ > **The events are [these](https://AstraBail.whiskeysockets.io/types/AstraBailEventMap.html)**, it's important you see all events
395
+
396
+ You can listen to these events like this:
397
+ ```javascript
398
+ const sock = makeWASocket()
399
+ sock.ev.on('messages.upsert', ({ messages }) => {
400
+ console.log('got messages', messages)
401
+ })
402
+ ```
403
+
404
+ <a id="handling-events"></a>
405
+ ### 🛠️ Contoh Awal
406
+
407
+ > [!NOTE]
408
+ > This example includes basic auth storage too
409
+
410
+ ```javascript
411
+ const makeWASocket = require("astrabail").default;
412
+ const { DisconnectReason, useMultiFileAuthState } = require("astrabail");
413
+ const Boom = require('@hapi/boom');
414
+
415
+ async function connectToWhatsApp () {
416
+ const { state, saveCreds } = await useMultiFileAuthState('auth_info_AstraBail')
417
+ const sock = makeWASocket({
418
+ // can provide additional config here
419
+ auth: state,
420
+ printQRInTerminal: true
421
+ })
422
+ sock.ev.on('connection.update', (update) => {
423
+ const { connection, lastDisconnect } = update
424
+ if(connection === 'close') {
425
+ const shouldReconnect = (lastDisconnect.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut
426
+ console.log('connection closed due to ', lastDisconnect.error, ', reconnecting ', shouldReconnect)
427
+ // reconnect if not logged out
428
+ if(shouldReconnect) {
429
+ connectToWhatsApp()
430
+ }
431
+ } else if(connection === 'open') {
432
+ console.log('opened connection')
433
+ }
434
+ })
435
+ sock.ev.on('messages.upsert', event => {
436
+ for (const m of event.messages) {
437
+ console.log(JSON.stringify(m, undefined, 2))
438
+
439
+ console.log('replying to', m.key.remoteJid)
440
+ await sock.sendMessage(m.key.remoteJid!, { text: 'Hello Word' })
441
+ }
442
+ })
443
+
444
+ // to storage creds (session info) when it updates
445
+ sock.ev.on('creds.update', saveCreds)
446
+ }
447
+ // run in main file
448
+ connectToWhatsApp()
449
+ ```
450
+
451
+ > [!IMPORTANT]
452
+ > In `messages.upsert` it's recommended to use a loop like `for (const message of event.messages)` to handle all messages in array
453
+
454
+ <a id="handling-events"></a>
455
+ ### 🔐 Dekripsi Pilihan Polling
456
+
457
+ - By default poll votes are encrypted and handled in `messages.update`
458
+ - That's a simple example
459
+ ```javascript
460
+ sock.ev.on('messages.update', event => {
461
+ for(const { key, update } of event) {
462
+ if(update.pollUpdates) {
463
+ const pollCreation = await getMessage(key)
464
+ if(pollCreation) {
465
+ console.log(
466
+ 'got poll update, aggregation: ',
467
+ getAggregateVotesInPollMessage({
468
+ message: pollCreation,
469
+ pollUpdates: update.pollUpdates,
470
+ })
471
+ )
472
+ }
473
+ }
474
+ }
475
+ })
476
+ ```
477
+
478
+ - `getMessage` is a [store](#implementing-a-data-store) implementation (in your end)
479
+
480
+ <a id="handling-events"></a>
481
+ ### 🔎 Ringkasan Event pada Koneksi Pertama
482
+
483
+ 1. When you connect first time, `connection.update` will be fired requesting you to restart sock
484
+ 2. Then, history messages will be received in `messaging.history-set`
485
+
486
+ <a id="handling-events"></a>
487
+ ## 💾 Mengimplementasikan Data Store
488
+
489
+ - AstraBail does not come with a defacto storage for chats, contacts, or messages. However, a simple in-memory implementation has been provided. The store listens for chat updates, new messages, message updates, etc., to always have an up-to-date version of the data.
490
+
491
+ > [!IMPORTANT]
492
+ > I highly recommend building your own data store, as storing someone's entire chat history in memory is a terrible waste of RAM.
493
+
494
+ It can be used as follows:
495
+
496
+ ```javascript
497
+ const makeWASocket = require("astrabail").default;
498
+ const { makeInMemoryStore } = require("astrabail");
499
+ // the store maintains the data of the WA connection in memory
500
+ // can be written out to a file & read from it
501
+ const store = makeInMemoryStore({ })
502
+ // can be read from a file
503
+ store.readFromFile('./AstraBail_store.json')
504
+ // saves the state to a file every 10s
505
+ setInterval(() => {
506
+ store.writeToFile('./AstraBail_store.json')
507
+ }, 10_000)
508
+
509
+ const sock = makeWASocket({ })
510
+ // will listen from this socket
511
+ // the store can listen from a new socket once the current socket outlives its lifetime
512
+ store.bind(sock.ev)
513
+
514
+ sock.ev.on('chats.upsert', () => {
515
+ // can use 'store.chats' however you want, even after the socket dies out
516
+ // 'chats' => a KeyedDB instance
517
+ console.log('got chats', store.chats.all())
518
+ })
519
+
520
+ sock.ev.on('contacts.upsert', () => {
521
+ console.log('got contacts', Object.values(store.contacts))
522
+ })
523
+
524
+ ```
525
+
526
+ The store also provides some simple functions such as `loadMessages` that utilize the store to speed up data retrieval.
527
+
528
+ <a id="handling-events"></a>
529
+ ## 🆔 Penjelasan ID WhatsApp
530
+
531
+ - `id` is the WhatsApp ID, called `jid` too, of the person or group you're sending the message to.
532
+ - It must be in the format ```[country code][phone number]@s.whatsapp.net```
533
+ - Example for people: ```+19999999999@s.whatsapp.net```.
534
+ - For groups, it must be in the format ``` 123456789-123345@g.us ```.
535
+ - For broadcast lists, it's `[timestamp of creation]@broadcast`.
536
+ - For stories, the ID is `status@broadcast`.
537
+
538
+ <a id="handling-events"></a>
539
+ ## 🧰 Fungsi Utilitas
540
+
541
+ - `getContentType`, returns the content type for any message
542
+ - `getDevice`, returns the device from message
543
+ - `makeCacheableSignalKeyStore`, make auth store more fast
544
+ - `downloadContentFromMessage`, download content from any message
545
+
546
+
547
+ ---
548
+ <a id="broadcast-lists--stories"></a>
549
+ ## 💫 Status Mention Grup (upswgc)
550
+
551
+ Digunakan untuk mengirim status WhatsApp (story) Grup baik berupa teks maupun media ke status@broadcast.
552
+
553
+ `
554
+ [!NOTE]
555
+ Fungsi ini sudah otomatis mendeteksi tipe konten (teks, gambar, video, audio).
556
+ Jika teks dan media digabung, hanya satu yang akan dikirim tergantung prioritas konten.
557
+ `
558
+
559
+ ### Kirim teks ke status WhatsApp
560
+ ```javascript
561
+ await conn.upswgc(m.chat, { text: "Halo dari upswgc versi final!" })
562
+ ```
563
+
564
+ ### Kirim gambar ke status WhatsApp
565
+ ```javascript
566
+ await conn.upswgc(m.chat, {
567
+ image: { url: "https://m.media-amazon.com/images/S/pv-target-images/f75db71efd62ea2eff81bd7cc01c44a9344b4ac18615ab71a80f58459ddf8791.jpg" },
568
+ caption : "apasi"
569
+       });
570
+
571
+ ```
572
+ ### Kirim video ke status WhatsApp
573
+ ```javascript
574
+ await conn.upswgc(m.chat, {
575
+ video: { url: "https://m.media-amazon.com/images/S/pv-target-images/f75db71efd62ea2eff81bd7cc01c44a9344b4ac18615ab71a80f58459ddf8791.jpg" },
576
+ caption : "apasi"
577
+       });
578
+ ```
579
+ ### Kirim audio (voice note) ke status WhatsApp
580
+ ```javascript
581
+ await conn.upswgc(m.chat, {
582
+ audio: { url: "https://raw.githubusercontent.com/Danimaru-ze/AstraBail/main/assets/sample.opus" },
583
+ caption : "apasi"
584
+       });
585
+ ```
586
+
587
+ `[!TIP]
588
+ Jika kamu ingin mengirim ke story + broadcast sekaligus, gunakan fungsi sendMessage()
589
+ dengan broadcast: true seperti dijelaskan pada bagian sebelumnya.`
590
+
591
+ ---
592
+
593
+ <a id="handling-events"></a>
594
+ ## 💬 Mengirim Pesan
595
+
596
+ - Send all types of messages with a single function
597
+ - **[Here](https://AstraBail.whiskeysockets.io/types/AnyMessageContent.html) you can see all message contents supported, like text message**
598
+ - **[Here](https://AstraBail.whiskeysockets.io/types/MiscMessageGenerationOptions.html) you can see all options supported, like quote message**
599
+
600
+ ```javascript
601
+ const jid: string
602
+ const content: AnyMessageContent
603
+ const options: MiscMessageGenerationOptions
604
+
605
+ sock.sendMessage(jid, content, options)
606
+ ```
607
+
608
+ <a id="handling-events"></a>
609
+ ### ✉️ Pesan Non-Media
610
+
611
+ <a id="handling-events"></a>
612
+ #### 🔘 Pesan Tombol (Buttons)
613
+ ```javascript
614
+ // send a buttons message!
615
+ sock.sendMessage(jid, {
616
+ text: "Hello World !",
617
+ footer: "AstraBail - 2026",
618
+ buttons: [
619
+ {
620
+ buttonId: `🚀`,
621
+ buttonText: {
622
+ displayText: '🗿'
623
+ },
624
+ type: 1
625
+ }
626
+ ],
627
+ headerType: 1,
628
+ viewOnce: true
629
+ },{ quoted: null })
630
+ ```
631
+
632
+ <a id="handling-events"></a>
633
+ #### 🔁 Alur Tombol
634
+ ```javascript
635
+ sock.sendMessage(jid, {
636
+ text: "Hello Wolrd !;",
637
+ footer: "© Danimaru-ze Dev",
638
+ buttons: [
639
+ {
640
+ buttonId: '.tes',
641
+ buttonText: {
642
+ displayText: 'TESTING BOT'
643
+ },
644
+ type: 1,
645
+ },
646
+ {
647
+ buttonId: ' ',
648
+ buttonText: {
649
+ displayText: 'PRIVATE SCRIPT'
650
+ },
651
+ type: 1,
652
+ },
653
+ {
654
+ buttonId: 'action',
655
+ buttonText: {
656
+ displayText: 'ini pesan interactiveMeta'
657
+ },
658
+ type: 4,
659
+ nativeFlowInfo: {
660
+ name: 'single_select',
661
+ paramsJson: JSON.stringify({
662
+ title: 'message',
663
+ sections: [
664
+ {
665
+ title: 'AstraBail - 2026',
666
+ highlight_label: '😜',
667
+ rows: [
668
+ {
669
+ header: 'HEADER',
670
+ title: 'TITLE',
671
+ description: 'DESCRIPTION',
672
+ id: 'YOUR ID',
673
+ },
674
+ {
675
+ header: 'HEADER',
676
+ title: 'TITLE',
677
+ description: 'DESCRIPTION',
678
+ id: 'YOUR ID',
679
+ },
680
+ ],
681
+ },
682
+ ],
683
+ }),
684
+ },
685
+ },
686
+ ],
687
+ headerType: 1,
688
+ viewOnce: true
689
+ }, { quoted: m });
690
+ ```
691
+
692
+ <a id="handling-events"></a>
693
+ #### 🧩 Pesan Interaktif
694
+ ```javascript
695
+ let msg = generateWAMessageFromContent(m.chat, {
696
+ viewOnceMessage: {
697
+ message: {
698
+ "messageContextInfo": {
699
+ "deviceListMetadata": {},
700
+ "deviceListMetadataVersion": 2
701
+ },
702
+ interactiveMessage: proto.Message.InteractiveMessage.create({
703
+ body: proto.Message.InteractiveMessage.Body.create({
704
+ text: "Danimaru-ze"
705
+ }),
706
+ footer: proto.Message.InteractiveMessage.Footer.create({
707
+ text: "Bot"
708
+ }),
709
+ header: proto.Message.InteractiveMessage.Header.create({
710
+ title: "Igna",
711
+ subtitle: "test",
712
+ hasMediaAttachment: false
713
+ }),
714
+ nativeFlowMessage: proto.Message.InteractiveMessage.NativeFlowMessage.create({
715
+ buttons: [
716
+ {
717
+ "name": "single_select",
718
+ "buttonParamsJson": "{\"title\":\"title\",\"sections\":[{\".menu\":\".play dj webito\",\"highlight_label\":\"label\",\"rows\":[{\"header\":\"header\",\"title\":\"title\",\"description\":\"description\",\"id\":\"id\"},{\"header\":\"header\",\"title\":\"title\",\"description\":\"description\",\"id\":\"id\"}]}]}"
719
+ },
720
+ {
721
+ "name": "cta_reply",
722
+ "buttonParamsJson": "{\"display_text\":\"quick_reply\",\"id\":\"message\"}"
723
+ },
724
+ {
725
+ "name": "cta_url",
726
+ "buttonParamsJson": "{\"display_text\":\"url\",\"url\":\"https://www.google.com\",\"merchant_url\":\"https://www.google.com\"}"
727
+ },
728
+ {
729
+ "name": "cta_call",
730
+ "buttonParamsJson": "{\"display_text\":\"call\",\"id\":\"message\"}"
731
+ },
732
+ {
733
+ "name": "cta_copy",
734
+ "buttonParamsJson": "{\"display_text\":\"copy\",\"id\":\"123456789\",\"copy_code\":\"message\"}"
735
+ },
736
+ {
737
+ "name": "cta_reminder",
738
+ "buttonParamsJson": "{\"display_text\":\"Recordatorio\",\"id\":\"message\"}"
739
+ },
740
+ {
741
+ "name": "cta_cancel_reminder",
742
+ "buttonParamsJson": "{\"display_text\":\"cta_cancel_reminder\",\"id\":\"message\"}"
743
+ },
744
+ {
745
+ "name": "address_message",
746
+ "buttonParamsJson": "{\"display_text\":\"address_message\",\"id\":\"message\"}"
747
+ },
748
+ {
749
+ "name": "send_location",
750
+ "buttonParamsJson": ""
751
+ }
752
+ ],
753
+ })
754
+ })
755
+ }
756
+ }
757
+ }, {})
758
+
759
+ return sock.relayMessage(msg.key.remoteJid, msg.message, { messageId: msg.key.id })
760
+ ```
761
+
762
+ <a id="handling-events"></a>
763
+ #### 📝 Pesan Teks
764
+ ```javascript
765
+ await sock.sendMessage(jid, { text: 'hello word' })
766
+ ```
767
+
768
+ <a id="handling-events"></a>
769
+ #### ❝ Pesan Quote (bekerja untuk semua tipe)
770
+ ```javascript
771
+ await sock.sendMessage(jid, { text: 'hello word' }, { quoted: message })
772
+ ```
773
+
774
+ <a id="handling-events"></a>
775
+ #### 🏷️ Mention Pengguna (bekerja di kebanyakan tipe)
776
+ - @number is to mention in text, it's optional
777
+ ```javascript
778
+ await sock.sendMessage(
779
+ jid,
780
+ {
781
+ text: '@12345678901',
782
+ mentions: ['12345678901@s.whatsapp.net']
783
+ }
784
+ )
785
+ ```
786
+
787
+ <a id="handling-events"></a>
788
+ #### 📣 Mention Status
789
+ - [ jid ] If the Jid Group and Jid Private Chat are included in the JID list, try to make the JID group first starting from the Jid Private Chat or Jid Private Chat in the middle between the group Jid
790
+ ```javascript
791
+ await sock.StatusMentions(
792
+ {
793
+ text: "Hello", // or image / video / audio ( url or buffer )
794
+ },
795
+ [
796
+ "123456789123456789@g.us",
797
+ "123456789@s.whatsapp.net",
798
+ // Enter jid chat here
799
+ ]
800
+ )
801
+ ```
802
+
803
+ <a id="handling-events"></a>
804
+ #### 📊 Hasil Poll dari Newsletter
805
+ ```javascript
806
+ await client.sendMessage(
807
+ jid,
808
+ {
809
+ pollResult: {
810
+ name: "Text poll",
811
+ votes: [["Options 1", 10], ["Options 2", 10]], // 10 For Fake Polling Count Results
812
+ }
813
+ }, { quoted : message }
814
+ )
815
+ ```
816
+
817
+ <a id="handling-events"></a>
818
+ #### 🖼️ Mengirim Pesan Album
819
+ - url or buffer ( image or video )
820
+ ```javascript
821
+ await sock.sendAlbumMessage(
822
+ jid,
823
+ [
824
+ {
825
+ image: { url: "https://example.jpg" }, // or buffer
826
+ caption: "Hello World",
827
+ },
828
+ {
829
+ video: { url: "https://example.mp4" }, // or buffer
830
+ caption: "Hello World",
831
+ },
832
+ ],
833
+ {
834
+ quoted : message,
835
+ delay : 2000 // number in seconds
836
+ }
837
+ )
838
+
839
+ ```
840
+
841
+ <a id="handling-events"></a>
842
+ #### 🔔 Respon Interaktif
843
+ ```javascript
844
+ await client.sendMessage(
845
+ jid,
846
+ {
847
+ buttonReply: {
848
+ text: 'Text',
849
+ nativeFlow: {
850
+ version: 3,
851
+ },
852
+ },
853
+ type: 'interactive',
854
+ ephemeral: true,
855
+ }
856
+ )
857
+
858
+ ```
859
+
860
+ <a id="handling-events"></a>
861
+ #### 💳 Permintaan Pembayaran
862
+ ```javascript
863
+ - Example non media sticker
864
+ await client.sendMessage(
865
+ jid,
866
+ {
867
+ requestPayment: {
868
+ currency: "IDR",
869
+ amount: "10000000",
870
+ from: "123456@s.whatsapp.net",
871
+ note: "Hai Guys",
872
+ background: { ...background of the message }
873
+ }
874
+ },
875
+ { quoted : message }
876
+ )
877
+
878
+ - with media sticker buffer
879
+ await client.sendMessage(
880
+ jid,
881
+ {
882
+ requestPayment: {
883
+ currency: "IDR",
884
+ amount: "10000000",
885
+ from: "123456@s.whatsapp.net",
886
+ sticker: Buffer,
887
+ background: { ...background of the message }
888
+ }
889
+ },
890
+ { quoted : message }
891
+ )
892
+
893
+ - with media sticker url
894
+ await client.sendMessage(
895
+ jid,
896
+ {
897
+ requestPayment: {
898
+ currency: "IDR",
899
+ amount: "10000000",
900
+ from: "123456@s.whatsapp.net",
901
+ sticker: { url: Sticker Url },
902
+ background: { ...background of the message }
903
+ }
904
+ },
905
+ { quoted : message }
906
+ )
907
+ ```
908
+
909
+ <a id="handling-events"></a>
910
+ #### 📆 Pesan Event
911
+ ```javascript
912
+ await client.sendMessage(
913
+ jid,
914
+ {
915
+ event: {
916
+ isCanceled: false, // or true for cancel event
917
+ name: "Name Event",
918
+ description: "Description Event",
919
+ location: {
920
+ degressLatitude: -0,
921
+ degressLongitude: - 0
922
+ },
923
+ link: Call Link,
924
+ startTime: m.messageTimestamp.low,
925
+ endTime: m.messageTimestamp.low + 86400, // 86400 is day in seconds
926
+ extraGuestsAllowed: true // or false
927
+ }
928
+ },
929
+ { quoted : message }
930
+ )
931
+ ```
932
+
933
+ <a id="handling-events"></a>
934
+ #### 🔗 Interaktif
935
+ ```javascript
936
+ - Example non header media
937
+ await client.sendMessage(
938
+ jid,
939
+ {
940
+ text: "Description Of Messages", //Additional information
941
+ title: "Title Of Messages",
942
+ subtitle: "Subtitle Message",
943
+ footer: "Footer Messages",
944
+ interactiveButtons: [
945
+ {
946
+ name: "quick_reply",
947
+ buttonParamsJson: JSON.stringify({
948
+ display_text: "Display Button",
949
+ id: "ID"
950
+ })
951
+ },
952
+ {
953
+ name: "cta_url",
954
+ buttonParamsJson: JSON.stringify({
955
+ display_text: "Display Button",
956
+ url: "https://www.example.com"
957
+ })
958
+ }
959
+ ]
960
+ },
961
+ {
962
+ quoted : message
963
+ }
964
+ )
965
+
966
+ - Example with media
967
+ await client.sendMessage(
968
+ jid,
969
+ {
970
+ image: { url : "https://example.jpg" }, // Can buffer
971
+ caption: "Description Of Messages", //Additional information
972
+ title: "Title Of Messages",
973
+ subtitle: "Subtile Message",
974
+ footer: "Footer Messages",
975
+ media: true,
976
+ interactiveButtons: [
977
+ {
978
+ name: "quick_reply",
979
+ buttonParamsJson: JSON.stringify({
980
+ display_text: "Display Button",
981
+ id: "ID"
982
+ })
983
+ },
984
+ {
985
+ name: "cta_url",
986
+ buttonParamsJson: JSON.stringify({
987
+ display_text: "Display Button",
988
+ url: "https://www.example.com"
989
+ })
990
+ }
991
+ ]
992
+ },
993
+ {
994
+ quoted : message
995
+ }
996
+ )
997
+
998
+ - Example with header product
999
+ await client.sendMessage(
1000
+ jid,
1001
+ {
1002
+ product: {
1003
+ productImage: { url: "https://example.jpg }, //or buffer
1004
+ productImageCount: 1,
1005
+ title: "Title Product",
1006
+ description: "Description Product",
1007
+ priceAmount1000: 20000 * 1000,
1008
+ currencyCode: "IDR",
1009
+ retailerId: "Retail",
1010
+ url: "https://example.com",
1011
+ },
1012
+ businessOwnerJid: "1234@s.whatsapp.net",
1013
+ caption: "Description Of Messages", //Additional information
1014
+ title: "Title Of Messages",
1015
+ footer: "Footer Messages",
1016
+ media: true,
1017
+ interactiveButtons: [
1018
+ {
1019
+ name: "quick_reply",
1020
+ buttonParamsJson: JSON.stringify({
1021
+ display_text: "Display Button",
1022
+ id: "ID"
1023
+ })
1024
+ },
1025
+ {
1026
+ name: "cta_url",
1027
+ buttonParamsJson: JSON.stringify({
1028
+ display_text: "Display Button",
1029
+ url: "https://www.example.com"
1030
+ })
1031
+ }
1032
+ ]
1033
+ },
1034
+ {
1035
+ quoted : message
1036
+ }
1037
+ )
1038
+ ```
1039
+
1040
+ <a id="handling-events"></a>
1041
+ #### 📤 Meneruskan Pesan
1042
+ - You need to have message object, can be retrieved from [store](#implementing-a-data-store) or use a [message](https://AstraBail.whiskeysockets.io/types/WAMessage.html) object
1043
+ ```javascript
1044
+ const msg = getMessageFromStore() // implement this on your end
1045
+ await sock.sendMessage(jid, { forward: msg }) // WA forward the message!
1046
+ ```
1047
+
1048
+ <a id="handling-events"></a>
1049
+ #### 📍 Pesan Lokasi
1050
+ ```javascript
1051
+ await sock.sendMessage(
1052
+ jid,
1053
+ {
1054
+ location: {
1055
+ degreesLatitude: 24.121231,
1056
+ degreesLongitude: 55.1121221
1057
+ }
1058
+ }
1059
+ )
1060
+ ```
1061
+
1062
+ <a id="handling-events"></a>
1063
+ #### 👤 Pesan Kontak
1064
+ ```javascript
1065
+ const vcard = 'BEGIN:VCARD\n' // metadata of the contact card
1066
+ + 'VERSION:3.0\n'
1067
+ + 'FN:Jeff Singh\n' // full name
1068
+ + 'ORG:Ashoka Uni;\n' // the organization of the contact
1069
+ + 'TEL;type=CELL;type=VOICE;waid=911234567890:+91 12345 67890\n' // WhatsApp ID + phone number
1070
+ + 'END:VCARD'
1071
+
1072
+ await sock.sendMessage(
1073
+ id,
1074
+ {
1075
+ contacts: {
1076
+ displayName: 'Jeff',
1077
+ contacts: [{ vcard }]
1078
+ }
1079
+ }
1080
+ )
1081
+ ```
1082
+
1083
+ <a id="handling-events"></a>
1084
+ #### ❤️ Pesan Reaksi
1085
+ - You need to pass the key of message, you can retrieve from [store](#implementing-a-data-store) or use a [key](https://AstraBail.whiskeysockets.io/types/WAMessageKey.html) object
1086
+ ```javascript
1087
+ await sock.sendMessage(
1088
+ jid,
1089
+ {
1090
+ react: {
1091
+ text: '💖', // use an empty string to remove the reaction
1092
+ key: message.key
1093
+ }
1094
+ }
1095
+ )
1096
+ ```
1097
+
1098
+ <a id="handling-events"></a>
1099
+ #### 📌 Pesan Pin
1100
+ - You need to pass the key of message, you can retrieve from [store](#implementing-a-data-store) or use a [key](https://AstraBail.whiskeysockets.io/types/WAMessageKey.html) object
1101
+
1102
+ - Time can be:
1103
+
1104
+ | Time | Seconds |
1105
+ |-------|----------------|
1106
+ | 24h | 86.400 |
1107
+ | 7d | 604.800 |
1108
+ | 30d | 2.592.000 |
1109
+
1110
+ ```javascript
1111
+ await sock.sendMessage(
1112
+ jid,
1113
+ {
1114
+ pin: {
1115
+ type: 1, // 0 to remove
1116
+ time: 86400
1117
+ key: message.key
1118
+ }
1119
+ }
1120
+ )
1121
+ ```
1122
+
1123
+ <a id="handling-events"></a>
1124
+ #### 🗳️ Pesan Poll
1125
+ ```javascript
1126
+ await sock.sendMessage(
1127
+ jid,
1128
+ {
1129
+ poll: {
1130
+ name: 'My Poll',
1131
+ values: ['Option 1', 'Option 2', ...],
1132
+ selectableCount: 1,
1133
+ toAnnouncementGroup: false // or true
1134
+ }
1135
+ }
1136
+ )
1137
+ ```
1138
+
1139
+ <a id="handling-events"></a>
1140
+ ### 💬 Mengirim Pesan with Link Previews
1141
+
1142
+ 1. By default, wa does not have link generation when sent from the web
1143
+ 2. AstraBail has a function to generate the content for these link previews
1144
+ 3. To enable this function's usage, add `link-preview-js` as a dependency to your project with `yarn add link-preview-js`
1145
+ 4. Send a link:
1146
+ ```javascript
1147
+ await sock.sendMessage(
1148
+ jid,
1149
+ {
1150
+ text: 'Hi, this was sent using https://github.com/whiskeysockets/AstraBail'
1151
+ }
1152
+ )
1153
+ ```
1154
+
1155
+ ### 🎞️ Pesan Media
1156
+
1157
+ Sending media (video, stickers, images) is easier & more efficient than ever.
1158
+
1159
+ > [!NOTE]
1160
+ > In media messages, you can pass `{ stream: Stream }` or `{ url: Url }` or `Buffer` directly, you can see more [here](https://AstraBail.whiskeysockets.io/types/WAMediaUpload.html)
1161
+
1162
+ - When specifying a media url, AstraBail never loads the entire buffer into memory; it even encrypts the media as a readable stream.
1163
+
1164
+ > [!TIP]
1165
+ > It's recommended to use Stream or Url to save memory
1166
+
1167
+ <a id="handling-events"></a>
1168
+ #### 🎬 Pesan GIF
1169
+ - Whatsapp doesn't support `.gif` files, that's why we send gifs as common `.mp4` video with `gifPlayback` flag
1170
+ ```javascript
1171
+ await sock.sendMessage(
1172
+ jid,
1173
+ {
1174
+ video: fs.readFileSync('Media/ma_gif.mp4'),
1175
+ caption: 'hello word',
1176
+ gifPlayback: true
1177
+ }
1178
+ )
1179
+ ```
1180
+
1181
+ <a id="handling-events"></a>
1182
+ #### 📹 Pesan Video
1183
+ ```javascript
1184
+ await sock.sendMessage(
1185
+ id,
1186
+ {
1187
+ video: {
1188
+ url: './Media/ma_gif.mp4'
1189
+ },
1190
+ caption: 'hello word',
1191
+ ptv: false // if set to true, will send as a `video note`
1192
+ }
1193
+ )
1194
+ ```
1195
+
1196
+ <a id="handling-events"></a>
1197
+ #### 🔊 Pesan Audio
1198
+ - To audio message work in all devices you need to convert with some tool like `ffmpeg` with this flags:
1199
+ ```bash
1200
+ codec: libopus //ogg file
1201
+ ac: 1 //one channel
1202
+ avoid_negative_ts
1203
+ make_zero
1204
+ ```
1205
+ - Example:
1206
+ ```bash
1207
+ ffmpeg -i input.mp4 -avoid_negative_ts make_zero -ac 1 output.ogg
1208
+ ```
1209
+ ```javascript
1210
+ await sock.sendMessage(
1211
+ jid,
1212
+ {
1213
+ audio: {
1214
+ url: './Media/audio.mp3'
1215
+ },
1216
+ mimetype: 'audio/mp4'
1217
+ }
1218
+ )
1219
+ ```
1220
+
1221
+ <a id="handling-events"></a>
1222
+ #### 🖼️ Pesan Gambar
1223
+ ```javascript
1224
+ await sock.sendMessage(
1225
+ id,
1226
+ {
1227
+ image: {
1228
+ url: './Media/ma_img.png'
1229
+ },
1230
+ caption: 'hello word'
1231
+ }
1232
+ )
1233
+ ```
1234
+
1235
+ <a id="handling-events"></a>
1236
+ #### 👁️ View Once (Sekali Lihat)
1237
+
1238
+ - You can send all messages above as `viewOnce`, you only need to pass `viewOnce: true` in content object
1239
+
1240
+ ```javascript
1241
+ await sock.sendMessage(
1242
+ id,
1243
+ {
1244
+ image: {
1245
+ url: './Media/ma_img.png'
1246
+ },
1247
+ viewOnce: true, //works with video, audio too
1248
+ caption: 'hello word'
1249
+ }
1250
+ )
1251
+ ```
1252
+
1253
+ <a id="handling-events"></a>
1254
+ ## ✏️ Memodifikasi Pesan
1255
+
1256
+ <a id="handling-events"></a>
1257
+ ### 🗑️ Menghapus Pesan (untuk semua)
1258
+
1259
+ ```javascript
1260
+ const msg = await sock.sendMessage(jid, { text: 'hello word' })
1261
+ await sock.sendMessage(jid, { delete: msg.key })
1262
+ ```
1263
+
1264
+ **Note:** deleting for oneself is supported via `chatModify`, see in [this section](#modifying-chats)
1265
+
1266
+ <a id="handling-events"></a>
1267
+ ### 🖊️ Mengedit Pesan
1268
+
1269
+ - You can pass all editable contents here
1270
+ ```javascript
1271
+ await sock.sendMessage(jid, {
1272
+ text: 'updated text goes here',
1273
+ edit: response.key,
1274
+ });
1275
+ ```
1276
+
1277
+ <a id="handling-events"></a>
1278
+ ## 🛠️ Manipulasi Pesan Media
1279
+
1280
+ <a id="handling-events"></a>
1281
+ ### 🖼️ Thumbnail pada Pesan Media
1282
+ - For media messages, the thumbnail can be generated automatically for images & stickers provided you add `jimp` or `sharp` as a dependency in your project using `yarn add jimp` or `yarn add sharp`.
1283
+ - Thumbnails for videos can also be generated automatically, though, you need to have `ffmpeg` installed on your system.
1284
+
1285
+ <a id="handling-events"></a>
1286
+ ### ⬇️ Mengunduh Pesan Media
1287
+
1288
+ If you want to save the media you received
1289
+ ```javascript
1290
+ const { createWriteStream } = require('fs');
1291
+ const { downloadMediaMessage, getContentType } = require("astrabail");
1292
+
1293
+ sock.ev.on('messages.upsert', async ({ [m] }) => {
1294
+ if (!m.message) return // if there is no text or media message
1295
+ const messageType = getContentType(m) // get what type of message it is (text, image, video...)
1296
+
1297
+ // if the message is an image
1298
+ if (messageType === 'imageMessage') {
1299
+ // download the message
1300
+ const stream = await downloadMediaMessage(
1301
+ m,
1302
+ 'stream', // can be 'buffer' too
1303
+ { },
1304
+ {
1305
+ logger,
1306
+ // pass this so that AstraBail can request a reupload of media
1307
+ // that has been deleted
1308
+ reuploadRequest: sock.updateMediaMessage
1309
+ }
1310
+ )
1311
+ // save to file
1312
+ const writeStream = createWriteStream('./my-download.jpeg')
1313
+ stream.pipe(writeStream)
1314
+ }
1315
+ }
1316
+ ```
1317
+
1318
+ <a id="handling-events"></a>
1319
+ ### 🔁 Mengunggah Ulang Pesan Media ke WhatsApp
1320
+
1321
+ - WhatsApp automatically removes old media from their servers. For the device to access said media -- a re-upload is required by another device that has it. This can be accomplished using:
1322
+ ```javascript
1323
+ await sock.updateMediaMessage(msg)
1324
+ ```
1325
+
1326
+ <a id="handling-events"></a>
1327
+ ## 🚫 Menolak Panggilan
1328
+
1329
+ - You can obtain `callId` and `callFrom` from `call` event
1330
+
1331
+ ```javascript
1332
+ await sock.rejectCall(callId, callFrom)
1333
+ ```
1334
+
1335
+ <a id="handling-events"></a>
1336
+ ## 📡 Status Pengiriman di Chat
1337
+
1338
+ <a id="handling-events"></a>
1339
+ ### 📖 Membaca Pesan
1340
+ - A set of message [keys](https://AstraBail.whiskeysockets.io/types/WAMessageKey.html) must be explicitly marked read now.
1341
+ - You cannot mark an entire 'chat' read as it were with AstraBail Web.
1342
+ This means you have to keep track of unread messages.
1343
+
1344
+ ```javascript
1345
+ const key: WAMessageKey
1346
+ // can pass multiple keys to read multiple messages as well
1347
+ await sock.readMessages([key])
1348
+ ```
1349
+
1350
+ The message ID is the unique identifier of the message that you are marking as read.
1351
+ On a `WAMessage`, the `messageID` can be accessed using ```messageID = message.key.id```.
1352
+
1353
+ <a id="handling-events"></a>
1354
+ ### 🟢 Memperbarui Presence
1355
+
1356
+ - ``` presence ``` can be one of [these](https://AstraBail.whiskeysockets.io/types/WAPresence.html)
1357
+ - The presence expires after about 10 seconds.
1358
+ - This lets the person/group with `jid` know whether you're online, offline, typing etc.
1359
+
1360
+ ```javascript
1361
+ await sock.sendPresenceUpdate('available', jid)
1362
+ ```
1363
+
1364
+ > [!NOTE]
1365
+ > If a desktop client is active, WA doesn't send push notifications to the device. If you would like to receive said notifications -- mark your AstraBail client offline using `sock.sendPresenceUpdate('unavailable')`
1366
+
1367
+ <a id="handling-events"></a>
1368
+ ## 🗂️ Memodifikasi Chat
1369
+
1370
+ WA uses an encrypted form of communication to send chat/app updates. This has been implemented mostly and you can send the following updates:
1371
+
1372
+ > [!IMPORTANT]
1373
+ > If you mess up one of your updates, WA can log you out of all your devices and you'll have to log in again.
1374
+
1375
+ <a id="handling-events"></a>
1376
+ ### 🗃️ Arsipkan Chat
1377
+ ```javascript
1378
+ const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
1379
+ await sock.chatModify({ archive: true, lastMessages: [lastMsgInChat] }, jid)
1380
+ ```
1381
+
1382
+ <a id="handling-events"></a>
1383
+ ### 🔕 Mute/Unmute Chat
1384
+
1385
+ - Supported times:
1386
+
1387
+ | Time | Miliseconds |
1388
+ |-------|-----------------|
1389
+ | Remove | null |
1390
+ | 8h | 86.400.000 |
1391
+ | 7d | 604.800.000 |
1392
+
1393
+ ```javascript
1394
+ // mute for 8 hours
1395
+ await sock.chatModify({ mute: 8 * 60 * 60 * 1000 }, jid)
1396
+ // unmute
1397
+ await sock.chatModify({ mute: null }, jid)
1398
+ ```
1399
+
1400
+ <a id="handling-events"></a>
1401
+ ### ✅ Tandai Chat Baca/Belum Baca
1402
+ ```javascript
1403
+ const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
1404
+ // mark it unread
1405
+ await sock.chatModify({ markRead: false, lastMessages: [lastMsgInChat] }, jid)
1406
+ ```
1407
+
1408
+ <a id="handling-events"></a>
1409
+ ### 🧹 Hapus Pesan untuk Saya
1410
+ ```javascript
1411
+ await sock.chatModify(
1412
+ {
1413
+ clear: {
1414
+ messages: [
1415
+ {
1416
+ id: 'ATWYHDNNWU81732J',
1417
+ fromMe: true,
1418
+ timestamp: '1654823909'
1419
+ }
1420
+ ]
1421
+ }
1422
+ },
1423
+ jid
1424
+ )
1425
+
1426
+ ```
1427
+
1428
+ <a id="handling-events"></a>
1429
+ ### ❌ Hapus Chat
1430
+ ```javascript
1431
+ const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
1432
+ await sock.chatModify({
1433
+ delete: true,
1434
+ lastMessages: [
1435
+ {
1436
+ key: lastMsgInChat.key,
1437
+ messageTimestamp: lastMsgInChat.messageTimestamp
1438
+ }
1439
+ ]
1440
+ },
1441
+ jid
1442
+ )
1443
+ ```
1444
+
1445
+ <a id="handling-events"></a>
1446
+ ### 📌 Pin/Unpin Chat
1447
+ ```javascript
1448
+ await sock.chatModify({
1449
+ pin: true // or `false` to unpin
1450
+ },
1451
+ jid
1452
+ )
1453
+ ```
1454
+
1455
+ <a id="handling-events"></a>
1456
+ ### ⭐ Star/Unstar Pesan
1457
+ ```javascript
1458
+ await sock.chatModify({
1459
+ star: {
1460
+ messages: [
1461
+ {
1462
+ id: 'messageID',
1463
+ fromMe: true // or `false`
1464
+ }
1465
+ ],
1466
+ star: true // - true: Star Message; false: Unstar Message
1467
+ }
1468
+ },
1469
+ jid
1470
+ )
1471
+ ```
1472
+
1473
+ <a id="handling-events"></a>
1474
+ ### 🕒 Pesan yang Menghilang (Disappearing)
1475
+
1476
+ - Ephemeral can be:
1477
+
1478
+ | Time | Seconds |
1479
+ |-------|----------------|
1480
+ | Remove | 0 |
1481
+ | 24h | 86.400 |
1482
+ | 7d | 604.800 |
1483
+ | 90d | 7.776.000 |
1484
+
1485
+ - You need to pass in **Seconds**, default is 7 days
1486
+
1487
+ ```javascript
1488
+ // turn on disappearing messages
1489
+ await sock.sendMessage(
1490
+ jid,
1491
+ // this is 1 week in seconds -- how long you want messages to appear for
1492
+ { disappearingMessagesInChat: WA_DEFAULT_EPHEMERAL }
1493
+ )
1494
+
1495
+ // will send as a disappearing message
1496
+ await sock.sendMessage(jid, { text: 'hello' }, { ephemeralExpiration: WA_DEFAULT_EPHEMERAL })
1497
+
1498
+ // turn off disappearing messages
1499
+ await sock.sendMessage(
1500
+ jid,
1501
+ { disappearingMessagesInChat: false }
1502
+ )
1503
+ ```
1504
+
1505
+ <a id="handling-events"></a>
1506
+ ## 🔎 Query Pengguna
1507
+
1508
+ <a id="handling-events"></a>
1509
+ ### 🔍 Cek Jika ID Ada di WhatsApp
1510
+ ```javascript
1511
+ const [result] = await sock.onWhatsApp(jid)
1512
+ if (result.exists) console.log (`${jid} exists on WhatsApp, as jid: ${result.jid}`)
1513
+ ```
1514
+
1515
+ <a id="handling-events"></a>
1516
+ ### 📜 Query Riwayat Chat (termasuk grup)
1517
+
1518
+ - You need to have oldest message in chat
1519
+ ```javascript
1520
+ const msg = await getOldestMessageInChat(jid)
1521
+ await sock.fetchMessageHistory(
1522
+ 50, //quantity (max: 50 per query)
1523
+ msg.key,
1524
+ msg.messageTimestamp
1525
+ )
1526
+ ```
1527
+ - Messages will be received in `messaging.history-set` event
1528
+
1529
+ <a id="handling-events"></a>
1530
+ ### 📣 Ambil Status
1531
+ ```javascript
1532
+ const status = await sock.fetchStatus(jid)
1533
+ console.log('status: ' + status)
1534
+ ```
1535
+
1536
+ <a id="handling-events"></a>
1537
+ ### 🖼️ Ambil Foto Profil (termasuk grup)
1538
+ - To get the display picture of some person/group
1539
+ ```javascript
1540
+ // for low res picture
1541
+ const ppUrl = await sock.profilePictureUrl(jid)
1542
+ console.log(ppUrl)
1543
+
1544
+ // for high res picture
1545
+ const ppUrl = await sock.profilePictureUrl(jid, 'image')
1546
+ ```
1547
+
1548
+ <a id="handling-events"></a>
1549
+ ### 🏷️ Ambil Profil Bisnis (deskripsi/kategori)
1550
+ ```javascript
1551
+ const profile = await sock.getBusinessProfile(jid)
1552
+ console.log('business description: ' + profile.description + ', category: ' + profile.category)
1553
+ ```
1554
+
1555
+ <a id="handling-events"></a>
1556
+ ### 👀 Ambil Presence Seseorang (sedang mengetik/online)
1557
+ ```javascript
1558
+ // the presence update is fetched and called here
1559
+ sock.ev.on('presence.update', console.log)
1560
+
1561
+ // request updates for a chat
1562
+ await sock.presenceSubscribe(jid)
1563
+ ```
1564
+
1565
+ <a id="handling-events"></a>
1566
+ ## 🧑‍💼 Mengubah Profil
1567
+
1568
+ <a id="handling-events"></a>
1569
+ ### 🧑‍💼 Mengubah Profil Status
1570
+ ```javascript
1571
+ await sock.updateProfileStatus('Hello World!')
1572
+ ```
1573
+ <a id="handling-events"></a>
1574
+ ### 🧑‍💼 Mengubah Profil Name
1575
+ ```javascript
1576
+ await sock.updateProfileName('My name')
1577
+ ```
1578
+ <a id="handling-events"></a>
1579
+ ### 🖼️ Ubah Foto Profil (termasuk grup)
1580
+ - To change your display picture or a group's
1581
+
1582
+ > [!NOTE]
1583
+ > Like media messages, you can pass `{ stream: Stream }` or `{ url: Url }` or `Buffer` directly, you can see more [here](https://AstraBail.whiskeysockets.io/types/WAMediaUpload.html)
1584
+
1585
+ ```javascript
1586
+ await sock.updateProfilePicture(jid, { url: './new-profile-picture.jpeg' })
1587
+ ```
1588
+ <a id="handling-events"></a>
1589
+ ### 🗑️ Hapus Foto Profil (termasuk grup)
1590
+ ```javascript
1591
+ await sock.removeProfilePicture(jid)
1592
+ ```
1593
+
1594
+ <a id="handling-events"></a>
1595
+ ## 👥 Grup
1596
+
1597
+ - To change group properties you need to be admin
1598
+
1599
+ <a id="handling-events"></a>
1600
+ ### ➕ Buat Grup
1601
+ ```javascript
1602
+ // title & participants
1603
+ const group = await sock.groupCreate('My Fab Group', ['1234@s.whatsapp.net', '4564@s.whatsapp.net'])
1604
+ console.log('created group with id: ' + group.gid)
1605
+ await sock.sendMessage(group.id, { text: 'hello there' }) // say hello to everyone on the group
1606
+ ```
1607
+ <a id="handling-events"></a>
1608
+ ### ➕/➖ Tambah/Hapus atau Turunkan/Naikkan Status
1609
+ ```javascript
1610
+ // id & people to add to the group (will throw error if it fails)
1611
+ await sock.groupParticipantsUpdate(
1612
+ jid,
1613
+ ['abcd@s.whatsapp.net', 'efgh@s.whatsapp.net'],
1614
+ 'add' // replace this parameter with 'remove' or 'demote' or 'promote'
1615
+ )
1616
+ ```
1617
+ <a id="handling-events"></a>
1618
+ ### ✏️ Ubah Subjek (Nama)
1619
+ ```javascript
1620
+ await sock.groupUpdateSubject(jid, 'New Subject!')
1621
+ ```
1622
+ <a id="handling-events"></a>
1623
+ ### 📝 Ubah Deskripsi
1624
+ ```javascript
1625
+ await sock.groupUpdateDescription(jid, 'New Description!')
1626
+ ```
1627
+ <a id="handling-events"></a>
1628
+ ### ⚙️ Ubah Pengaturan
1629
+ ```javascript
1630
+ // only allow admins to send messages
1631
+ await sock.groupSettingUpdate(jid, 'announcement')
1632
+ // allow everyone to send messages
1633
+ await sock.groupSettingUpdate(jid, 'not_announcement')
1634
+ // allow everyone to modify the group's settings -- like display picture etc.
1635
+ await sock.groupSettingUpdate(jid, 'unlocked')
1636
+ // only allow admins to modify the group's settings
1637
+ await sock.groupSettingUpdate(jid, 'locked')
1638
+ ```
1639
+ <a id="handling-events"></a>
1640
+ ### 🚪 Keluar Grup
1641
+ ```javascript
1642
+ // will throw error if it fails
1643
+ await sock.groupLeave(jid)
1644
+ ```
1645
+ <a id="handling-events"></a>
1646
+ ### 🔐 Dapatkan Kode Undangan
1647
+ - To create link with code use `'https://chat.whatsapp.com/' + code`
1648
+ ```javascript
1649
+ const code = await sock.groupInviteCode(jid)
1650
+ console.log('group code: ' + code)
1651
+ ```
1652
+ <a id="handling-events"></a>
1653
+ ### 🔄 Cabut Kode Undangan
1654
+ ```javascript
1655
+ const code = await sock.groupRevokeInvite(jid)
1656
+ console.log('New group code: ' + code)
1657
+ ```
1658
+ <a id="handling-events"></a>
1659
+ ### ➿ Bergabung Menggunakan Kode Undangan
1660
+ - Code can't have `https://chat.whatsapp.com/`, only code
1661
+ ```javascript
1662
+ const response = await sock.groupAcceptInvite(code)
1663
+ console.log('joined to: ' + response)
1664
+ ```
1665
+ <a id="handling-events"></a>
1666
+ ### ℹ️ Dapatkan Info Grup lewat Kode Undangan
1667
+ ```javascript
1668
+ const response = await sock.groupGetInviteInfo(code)
1669
+ console.log('group information: ' + response)
1670
+ ```
1671
+ <a id="handling-events"></a>
1672
+ ### 🔎 Query Metadata (peserta, nama, deskripsi...)
1673
+ ```javascript
1674
+ const metadata = await sock.groupMetadata(jid)
1675
+ console.log(metadata.id + ', title: ' + metadata.subject + ', description: ' + metadata.desc)
1676
+ ```
1677
+ <a id="handling-events"></a>
1678
+ ### Join using `groupInviteMessage`
1679
+ ```javascript
1680
+ const response = await sock.groupAcceptInviteV4(jid, groupInviteMessage)
1681
+ console.log('joined to: ' + response)
1682
+ ```
1683
+ <a id="handling-events"></a>
1684
+ ### 📥 Dapatkan Daftar Permintaan Bergabung
1685
+ ```javascript
1686
+ const response = await sock.groupRequestParticipantsList(jid)
1687
+ console.log(response)
1688
+ ```
1689
+ <a id="handling-events"></a>
1690
+ ### ✅/❌ Setuju/Tolak Permintaan Bergabung
1691
+ ```javascript
1692
+ const response = await sock.groupRequestParticipantsUpdate(
1693
+ jid, // group id
1694
+ ['abcd@s.whatsapp.net', 'efgh@s.whatsapp.net'],
1695
+ 'approve' // or 'reject'
1696
+ )
1697
+ console.log(response)
1698
+ ```
1699
+ <a id="handling-events"></a>
1700
+ ### 📚 Dapatkan Semua Metadata Grup yang Diikuti
1701
+ ```javascript
1702
+ const response = await sock.groupFetchAllParticipating()
1703
+ console.log(response)
1704
+ ```
1705
+ <a id="handling-events"></a>
1706
+ ### ⏳ Toggle Ephemeral
1707
+
1708
+ - Ephemeral can be:
1709
+
1710
+ | Time | Seconds |
1711
+ |-------|----------------|
1712
+ | Remove | 0 |
1713
+ | 24h | 86.400 |
1714
+ | 7d | 604.800 |
1715
+ | 90d | 7.776.000 |
1716
+
1717
+ ```javascript
1718
+ await sock.groupToggleEphemeral(jid, 86400)
1719
+ ```
1720
+
1721
+ <a id="handling-events"></a>
1722
+ ### 🔐 Ubah Mode Penambahan
1723
+ ```javascript
1724
+ await sock.groupMemberAddMode(
1725
+ jid,
1726
+ 'all_member_add' // or 'admin_add'
1727
+ )
1728
+ ```
1729
+
1730
+ <a id="handling-events"></a>
1731
+ ## 🔒 Privasi
1732
+
1733
+ <a id="handling-events"></a>
1734
+ ### ⛔/✅ Blokir/Buka Blokir Pengguna
1735
+ ```javascript
1736
+ await sock.updateBlockStatus(jid, 'block') // Block user
1737
+ await sock.updateBlockStatus(jid, 'unblock') // Unblock user
1738
+ ```
1739
+ <a id="handling-events"></a>
1740
+ ### ⚙️ Dapatkan Pengaturan Privasi
1741
+ ```javascript
1742
+ const privacySettings = await sock.fetchPrivacySettings(true)
1743
+ console.log('privacy settings: ' + privacySettings)
1744
+ ```
1745
+ <a id="handling-events"></a>
1746
+ ### 📛 Dapatkan Daftar Blokir
1747
+ ```javascript
1748
+ const response = await sock.fetchBlocklist()
1749
+ console.log(response)
1750
+ ```
1751
+ <a id="handling-events"></a>
1752
+ ### 👀 Update Privasi LastSeen
1753
+ ```javascript
1754
+ const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
1755
+ await sock.updateLastSeenPrivacy(value)
1756
+ ```
1757
+ <a id="handling-events"></a>
1758
+ ### 🟢 Update Privasi Online
1759
+ ```javascript
1760
+ const value = 'all' // 'match_last_seen'
1761
+ await sock.updateOnlinePrivacy(value)
1762
+ ```
1763
+ <a id="handling-events"></a>
1764
+ ### 🖼️ Update Privasi Foto Profil
1765
+ ```javascript
1766
+ const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
1767
+ await sock.updateProfilePicturePrivacy(value)
1768
+ ```
1769
+ <a id="handling-events"></a>
1770
+ ### 📣 Update Privasi Status
1771
+ ```javascript
1772
+ const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
1773
+ await sock.updateStatusPrivacy(value)
1774
+ ```
1775
+ <a id="handling-events"></a>
1776
+ ### ✅ Update Privasi Read Receipts
1777
+ ```javascript
1778
+ const value = 'all' // 'none'
1779
+ await sock.updateReadReceiptsPrivacy(value)
1780
+ ```
1781
+ <a id="handling-events"></a>
1782
+ ### 👥 Update Privasi Tambah Grup
1783
+ ```javascript
1784
+ const value = 'all' // 'contacts' | 'contact_blacklist'
1785
+ await sock.updateGroupsAddPrivacy(value)
1786
+ ```
1787
+ <a id="handling-events"></a>
1788
+ ### 🕒 Update Mode Default Disappearing
1789
+
1790
+ - Like [this](#disappearing-messages), ephemeral can be:
1791
+
1792
+ | Time | Seconds |
1793
+ |-------|----------------|
1794
+ | Remove | 0 |
1795
+ | 24h | 86.400 |
1796
+ | 7d | 604.800 |
1797
+ | 90d | 7.776.000 |
1798
+
1799
+ ```javascript
1800
+ const ephemeral = 86400
1801
+ await sock.updateDefaultDisappearingMode(ephemeral)
1802
+ ```
1803
+
1804
+ <a id="handling-events"></a>
1805
+ ## 📢 Broadcast & Story
1806
+
1807
+ <a id="handling-events"></a>
1808
+ ### 📤 Kirim Broadcast & Story
1809
+ - Messages can be sent to broadcasts & stories. You need to add the following message options in sendMessage, like this:
1810
+ ```javascript
1811
+ await sock.sendMessage(
1812
+ jid,
1813
+ {
1814
+ image: {
1815
+ url: url
1816
+ },
1817
+ caption: caption
1818
+ },
1819
+ {
1820
+ backgroundColor: backgroundColor,
1821
+ font: font,
1822
+ statusJidList: statusJidList,
1823
+ broadcast: true
1824
+ }
1825
+ )
1826
+ ```
1827
+ - Message body can be a `extendedTextMessage` or `imageMessage` or `videoMessage` or `voiceMessage`, see [here](https://AstraBail.whiskeysockets.io/types/AnyRegularMessageContent.html)
1828
+ - You can add `backgroundColor` and other options in the message options, see [here](https://AstraBail.whiskeysockets.io/types/MiscMessageGenerationOptions.html)
1829
+ - `broadcast: true` enables broadcast mode
1830
+ - `statusJidList`: a list of people that you can get which you need to provide, which are the people who will get this status message.
1831
+
1832
+ - You can send messages to broadcast lists the same way you send messages to groups & individual chats.
1833
+ - Right now, WA Web does not support creating broadcast lists, but you can still delete them.
1834
+ - Broadcast IDs are in the format `12345678@broadcast`
1835
+ <a id="handling-events"></a>
1836
+ ### 🔎 Query Penerima & Nama Broadcast List
1837
+ ```javascript
1838
+ const bList = await sock.getBroadcastListInfo('1234@broadcast')
1839
+ console.log (`list name: ${bList.name}, recps: ${bList.recipients}`)
1840
+ ```
1841
+
1842
+ <a id="handling-events"></a>
1843
+ ## ✍️ Menulis Fungsionalitas Kustom
1844
+ AstraBail is written with custom functionality in mind. Instead of forking the project & re-writing the internals, you can simply write your own extensions.
1845
+
1846
+ <a id="handling-events"></a>
1847
+ ### 🐛 Mengaktifkan Level Debug di Log AstraBail
1848
+ First, enable the logging of unhandled messages from WhatsApp by setting:
1849
+ ```javascript
1850
+ const sock = makeWASocket({
1851
+ logger: P({ level: 'debug' }),
1852
+ })
1853
+ ```
1854
+ This will enable you to see all sorts of messages WhatsApp sends in the console.
1855
+
1856
+ <a id="handling-events"></a>
1857
+ ### 🔬 Bagaimana WhatsApp Berkomunikasi dengan Kita
1858
+
1859
+ > [!TIP]
1860
+ > If you want to learn whatsapp protocol, we recommend to study about Libsignal Protocol and Noise Protocol
1861
+
1862
+ - **Example:** Functionality to track the battery percentage of your phone. You enable logging and you'll see a message about your battery pop up in the console:
1863
+ ```
1864
+ {
1865
+ "level": 10,
1866
+ "fromMe": false,
1867
+ "frame": {
1868
+ "tag": "ib",
1869
+ "attrs": {
1870
+ "from": "@s.whatsapp.net"
1871
+ },
1872
+ "content": [
1873
+ {
1874
+ "tag": "edge_routing",
1875
+ "attrs": {},
1876
+ "content": [
1877
+ {
1878
+ "tag": "routing_info",
1879
+ "attrs": {},
1880
+ "content": {
1881
+ "type": "Buffer",
1882
+ "data": [8,2,8,5]
1883
+ }
1884
+ }
1885
+ ]
1886
+ }
1887
+ ]
1888
+ },
1889
+ "msg":"communication"
1890
+ }
1891
+ ```
1892
+
1893
+ The `'frame'` is what the message received is, it has three components:
1894
+ - `tag` -- what this frame is about (eg. message will have 'message')
1895
+ - `attrs` -- a string key-value pair with some metadata (contains ID of the message usually)
1896
+ - `content` -- the actual data (eg. a message node will have the actual message content in it)
1897
+ - read more about this format [here](/src/WABinary/readme.md)
1898
+
1899
+ <a id="handling-events"></a>
1900
+ ### 🔁 Mendaftarkan Callback untuk Event Websocket
1901
+
1902
+ > [!TIP]
1903
+ > Recommended to see `onMessageReceived` function in `socket.ts` file to understand how websockets events are fired
1904
+
1905
+ ```javascript
1906
+ // for any message with tag 'edge_routing'
1907
+ sock.ws.on('CB:edge_routing', (node: BinaryNode) => { })
1908
+
1909
+ // for any message with tag 'edge_routing' and id attribute = abcd
1910
+ sock.ws.on('CB:edge_routing,id:abcd', (node: BinaryNode) => { })
1911
+
1912
+ // for any message with tag 'edge_routing', id attribute = abcd & first content node routing_info
1913
+ sock.ws.on('CB:edge_routing,id:abcd,routing_info', (node: BinaryNode) => { })
1914
+ ```
1915
+
1916
+ > [!NOTE]
1917
+ > Also, this repo is now licenced under GPL 3 since it uses [libsignal-node](https://git.questbook.io/backend/service-coderunner/-/merge_requests/1)
1918
+
1919
+
1920
+ <a id="handling-events"></a>
1921
+ ## ⚠️ Catatan
1922
+
1923
+ Proyek ini **tidak berafiliasi dengan WhatsApp Inc.**
1924
+ Gunakan secara bertanggung jawab dan hindari aktivitas ilegal atau penyalahgunaan.
1925
+
1926
+ ---
1927
+
1928
+ <a id="handling-events"></a>
1929
+ ## Lisensi
1930
+
1931
+ 📘 *Documentation powered by AstraBail*
1932
+ 🧑‍💻 **Modified and Presented by AstraBail**
1933
+
1934
+ <a id="kirim-sticker-pack"></a>
1935
+ ## Sticker Pack Message
1936
+
1937
+ Gunakan field `stickerPack` pada `sendMessage` untuk mengirim satu paket sticker sekaligus.
1938
+
1939
+ Catatan penting: `stickerPack` sekarang bisa menerima campuran sticker statis dan video/animated (`webp/png/jpg/jpeg/gif/webm/mp4`) lalu mengonversinya ke WebP otomatis saat proses kirim, selama `ffmpeg` tersedia di server. Format `tgs`/Lottie tetap butuh preview/konverter tambahan di luar runtime ini.
1940
+
1941
+ ```javascript
1942
+ await sock.sendMessage(jid, {
1943
+ stickerPack: {
1944
+ name: 'Nama Pack',
1945
+ publisher: 'Nama Publisher',
1946
+ description: 'Deskripsi singkat',
1947
+ cover: { url: './cover.png' },
1948
+ stickers: [
1949
+ { sticker: { url: './1.webp' }, emojis: ['🙂'] },
1950
+ { sticker: { url: './2.png' }, emojis: ['🎉'] }
1951
+ ]
1952
+ }
1953
+ })
1954
+ ```
1955
+
1956
+ `cover` dan setiap item `sticker` menerima format media yang sama seperti pengiriman media biasa: path lokal, URL, Buffer, atau stream.