@queenanya/baileys 9.2.4 → 9.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +329 -1237
- package/WAProto/fix-imports.js +22 -18
- package/WAProto/index.js +22 -18
- package/lib/Defaults/index.d.ts +17 -0
- package/lib/Defaults/index.d.ts.map +1 -1
- package/lib/Defaults/index.js +29 -3
- package/lib/Defaults/index.js.map +1 -1
- package/lib/Signal/libsignal.d.ts.map +1 -1
- package/lib/Signal/libsignal.js +61 -2
- package/lib/Signal/libsignal.js.map +1 -1
- package/lib/Signal/lid-mapping.d.ts +5 -9
- package/lib/Signal/lid-mapping.d.ts.map +1 -1
- package/lib/Signal/lid-mapping.js +170 -70
- package/lib/Signal/lid-mapping.js.map +1 -1
- package/lib/Socket/business.d.ts +114 -2
- package/lib/Socket/business.d.ts.map +1 -1
- package/lib/Socket/chats.d.ts +14 -1
- package/lib/Socket/chats.d.ts.map +1 -1
- package/lib/Socket/chats.js +253 -38
- package/lib/Socket/chats.js.map +1 -1
- package/lib/Socket/communities.d.ts +114 -2
- package/lib/Socket/communities.d.ts.map +1 -1
- package/lib/Socket/groups.d.ts +9 -0
- package/lib/Socket/groups.d.ts.map +1 -1
- package/lib/Socket/groups.js +6 -0
- package/lib/Socket/groups.js.map +1 -1
- package/lib/Socket/index.d.ts +114 -2
- package/lib/Socket/index.d.ts.map +1 -1
- package/lib/Socket/index.js +0 -6
- package/lib/Socket/index.js.map +1 -1
- package/lib/Socket/messages-recv.d.ts +115 -3
- package/lib/Socket/messages-recv.d.ts.map +1 -1
- package/lib/Socket/messages-recv.js +739 -150
- package/lib/Socket/messages-recv.js.map +1 -1
- package/lib/Socket/messages-send.d.ts +118 -4
- package/lib/Socket/messages-send.d.ts.map +1 -1
- package/lib/Socket/messages-send.js +328 -86
- package/lib/Socket/messages-send.js.map +1 -1
- package/lib/Socket/newsletter.d.ts +9 -0
- package/lib/Socket/newsletter.d.ts.map +1 -1
- package/lib/Socket/newsletter.js +2 -2
- package/lib/Socket/newsletter.js.map +1 -1
- package/lib/Socket/socket.d.ts +2 -0
- package/lib/Socket/socket.d.ts.map +1 -1
- package/lib/Socket/socket.js +143 -17
- package/lib/Socket/socket.js.map +1 -1
- package/lib/Types/Auth.d.ts +2 -0
- package/lib/Types/Auth.d.ts.map +1 -1
- package/lib/Types/Call.d.ts +10 -1
- package/lib/Types/Call.d.ts.map +1 -1
- package/lib/Types/Contact.d.ts +2 -0
- package/lib/Types/Contact.d.ts.map +1 -1
- package/lib/Types/Events.d.ts +21 -1
- package/lib/Types/Events.d.ts.map +1 -1
- package/lib/Types/GroupMetadata.d.ts +4 -0
- package/lib/Types/GroupMetadata.d.ts.map +1 -1
- package/lib/Types/Message.d.ts +530 -16
- package/lib/Types/Message.d.ts.map +1 -1
- package/lib/Types/Message.js.map +1 -1
- package/lib/Types/Newsletter.d.ts +37 -31
- package/lib/Types/Newsletter.d.ts.map +1 -1
- package/lib/Types/Newsletter.js +27 -23
- package/lib/Types/Newsletter.js.map +1 -1
- package/lib/Types/State.d.ts +54 -0
- package/lib/Types/State.d.ts.map +1 -1
- package/lib/Types/State.js +42 -0
- package/lib/Types/State.js.map +1 -1
- package/lib/Types/index.d.ts +9 -0
- package/lib/Types/index.d.ts.map +1 -1
- package/lib/Types/index.js.map +1 -1
- package/lib/Utils/browser-utils.d.ts +13 -0
- package/lib/Utils/browser-utils.d.ts.map +1 -1
- package/lib/Utils/browser-utils.js +90 -10
- package/lib/Utils/browser-utils.js.map +1 -1
- package/lib/Utils/chat-utils.d.ts +30 -0
- package/lib/Utils/chat-utils.d.ts.map +1 -1
- package/lib/Utils/chat-utils.js +81 -52
- package/lib/Utils/chat-utils.js.map +1 -1
- package/lib/Utils/companion-reg-client-utils.d.ts +17 -0
- package/lib/Utils/companion-reg-client-utils.d.ts.map +1 -0
- package/lib/Utils/companion-reg-client-utils.js +34 -0
- package/lib/Utils/companion-reg-client-utils.js.map +1 -0
- package/lib/Utils/crypto.d.ts +4 -8
- package/lib/Utils/crypto.d.ts.map +1 -1
- package/lib/Utils/crypto.js +2 -26
- package/lib/Utils/crypto.js.map +1 -1
- package/lib/Utils/decode-wa-message.d.ts +12 -0
- package/lib/Utils/decode-wa-message.d.ts.map +1 -1
- package/lib/Utils/decode-wa-message.js +16 -0
- package/lib/Utils/decode-wa-message.js.map +1 -1
- package/lib/Utils/event-buffer.js +10 -1
- package/lib/Utils/event-buffer.js.map +1 -1
- package/lib/Utils/generics.d.ts +3 -1
- package/lib/Utils/generics.d.ts.map +1 -1
- package/lib/Utils/generics.js +16 -3
- package/lib/Utils/generics.js.map +1 -1
- package/lib/Utils/history.d.ts +5 -2
- package/lib/Utils/history.d.ts.map +1 -1
- package/lib/Utils/history.js +53 -17
- package/lib/Utils/history.js.map +1 -1
- package/lib/Utils/identity-change-handler.d.ts +44 -0
- package/lib/Utils/identity-change-handler.d.ts.map +1 -0
- package/lib/Utils/identity-change-handler.js +50 -0
- package/lib/Utils/identity-change-handler.js.map +1 -0
- package/lib/Utils/index.d.ts +6 -0
- package/lib/Utils/index.d.ts.map +1 -1
- package/lib/Utils/index.js +6 -0
- package/lib/Utils/index.js.map +1 -1
- package/lib/Utils/interactive-message.d.ts +201 -0
- package/lib/Utils/interactive-message.d.ts.map +1 -0
- package/lib/Utils/interactive-message.js +256 -0
- package/lib/Utils/interactive-message.js.map +1 -0
- package/lib/Utils/lt-hash.d.ts +7 -12
- package/lib/Utils/lt-hash.d.ts.map +1 -1
- package/lib/Utils/lt-hash.js +2 -42
- package/lib/Utils/lt-hash.js.map +1 -1
- package/lib/Utils/message-composer.d.ts +5 -0
- package/lib/Utils/message-composer.d.ts.map +1 -0
- package/lib/Utils/message-composer.js +5 -0
- package/lib/Utils/message-composer.js.map +1 -0
- package/lib/Utils/message-retry-manager.d.ts +30 -2
- package/lib/Utils/message-retry-manager.d.ts.map +1 -1
- package/lib/Utils/message-retry-manager.js +59 -2
- package/lib/Utils/message-retry-manager.js.map +1 -1
- package/lib/Utils/messages-media.d.ts +19 -5
- package/lib/Utils/messages-media.d.ts.map +1 -1
- package/lib/Utils/messages-media.js +26 -17
- package/lib/Utils/messages-media.js.map +1 -1
- package/lib/Utils/messages.d.ts.map +1 -1
- package/lib/Utils/messages.js +433 -13
- package/lib/Utils/messages.js.map +1 -1
- package/lib/Utils/noise-handler.d.ts +2 -2
- package/lib/Utils/noise-handler.d.ts.map +1 -1
- package/lib/Utils/noise-handler.js +10 -10
- package/lib/Utils/noise-handler.js.map +1 -1
- package/lib/Utils/offline-node-processor.d.ts +17 -0
- package/lib/Utils/offline-node-processor.d.ts.map +1 -0
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/offline-node-processor.js.map +1 -0
- package/lib/Utils/process-message.d.ts.map +1 -1
- package/lib/Utils/process-message.js +96 -16
- package/lib/Utils/process-message.js.map +1 -1
- package/lib/Utils/reporting-utils.js +2 -2
- package/lib/Utils/reporting-utils.js.map +1 -1
- package/lib/Utils/stanza-ack.d.ts +11 -0
- package/lib/Utils/stanza-ack.d.ts.map +1 -0
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/stanza-ack.js.map +1 -0
- package/lib/Utils/sync-action-utils.d.ts.map +1 -1
- package/lib/Utils/sync-action-utils.js +2 -1
- package/lib/Utils/sync-action-utils.js.map +1 -1
- package/lib/Utils/tc-token-utils.d.ts +26 -1
- package/lib/Utils/tc-token-utils.d.ts.map +1 -1
- package/lib/Utils/tc-token-utils.js +149 -4
- package/lib/Utils/tc-token-utils.js.map +1 -1
- package/lib/Utils/use-mongo-file-auth-state.d.ts +16 -0
- package/lib/Utils/use-mongo-file-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-mongo-file-auth-state.js +60 -0
- package/lib/Utils/use-mongo-file-auth-state.js.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +1 -1
- package/lib/Utils/use-multi-file-auth-state.js.map +1 -1
- package/lib/Utils/validate-connection.d.ts.map +1 -1
- package/lib/Utils/validate-connection.js +11 -1
- package/lib/Utils/validate-connection.js.map +1 -1
- package/lib/WABinary/generic-utils.d.ts +9 -0
- package/lib/WABinary/generic-utils.d.ts.map +1 -1
- package/lib/WABinary/generic-utils.js +23 -0
- package/lib/WABinary/generic-utils.js.map +1 -1
- package/lib/WABinary/jid-utils.js.map +1 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +26 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -1
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/index.d.ts +1 -0
- package/lib/WAUSync/Protocols/index.d.ts.map +1 -1
- package/lib/WAUSync/Protocols/index.js +1 -0
- package/lib/WAUSync/Protocols/index.js.map +1 -1
- package/lib/WAUSync/USyncQuery.d.ts +1 -0
- package/lib/WAUSync/USyncQuery.d.ts.map +1 -1
- package/lib/WAUSync/USyncQuery.js +5 -1
- package/lib/WAUSync/USyncQuery.js.map +1 -1
- package/lib/WAUSync/USyncUser.d.ts +4 -0
- package/lib/WAUSync/USyncUser.d.ts.map +1 -1
- package/lib/WAUSync/USyncUser.js +8 -0
- package/lib/WAUSync/USyncUser.js.map +1 -1
- package/lib/addons/anti-delete.d.ts +72 -0
- package/lib/addons/anti-delete.d.ts.map +1 -0
- package/lib/addons/anti-delete.js +165 -0
- package/lib/addons/anti-delete.js.map +1 -0
- package/lib/addons/auto-reply.d.ts +67 -0
- package/lib/addons/auto-reply.d.ts.map +1 -0
- package/lib/addons/auto-reply.js +145 -0
- package/lib/addons/auto-reply.js.map +1 -0
- package/lib/addons/browser-presets.d.ts +16 -0
- package/lib/addons/browser-presets.d.ts.map +1 -0
- package/lib/addons/browser-presets.js +24 -0
- package/lib/addons/browser-presets.js.map +1 -0
- package/lib/addons/button-sender.d.ts +260 -0
- package/lib/addons/button-sender.d.ts.map +1 -0
- package/lib/addons/button-sender.js +771 -0
- package/lib/addons/button-sender.js.map +1 -0
- package/lib/addons/call-handler.d.ts +79 -0
- package/lib/addons/call-handler.d.ts.map +1 -0
- package/lib/addons/call-handler.js +342 -0
- package/lib/addons/call-handler.js.map +1 -0
- package/lib/addons/from-chats.d.ts +30 -0
- package/lib/addons/from-chats.d.ts.map +1 -0
- package/lib/addons/from-chats.js +38 -0
- package/lib/addons/from-chats.js.map +1 -0
- package/lib/addons/from-messages-recv.d.ts +59 -0
- package/lib/addons/from-messages-recv.d.ts.map +1 -0
- package/lib/addons/from-messages-recv.js +326 -0
- package/lib/addons/from-messages-recv.js.map +1 -0
- package/lib/addons/from-messages-send.d.ts +50 -0
- package/lib/addons/from-messages-send.d.ts.map +1 -0
- package/lib/addons/from-messages-send.js +148 -0
- package/lib/addons/from-messages-send.js.map +1 -0
- package/lib/addons/from-messages.d.ts +52 -0
- package/lib/addons/from-messages.d.ts.map +1 -0
- package/lib/addons/from-messages.js +304 -0
- package/lib/addons/from-messages.js.map +1 -0
- package/lib/addons/index.d.ts +67 -0
- package/lib/addons/index.d.ts.map +1 -0
- package/lib/addons/index.js +86 -0
- package/lib/addons/index.js.map +1 -0
- package/lib/addons/interactive-message.d.ts +201 -0
- package/lib/addons/interactive-message.d.ts.map +1 -0
- package/lib/addons/interactive-message.js +256 -0
- package/lib/addons/interactive-message.js.map +1 -0
- package/lib/addons/jid-plot.d.ts +49 -0
- package/lib/addons/jid-plot.d.ts.map +1 -0
- package/lib/addons/jid-plot.js +84 -0
- package/lib/addons/jid-plot.js.map +1 -0
- package/lib/addons/jid-plotting.d.ts +54 -0
- package/lib/addons/jid-plotting.d.ts.map +1 -0
- package/lib/addons/jid-plotting.js +150 -0
- package/lib/addons/jid-plotting.js.map +1 -0
- package/lib/addons/lid-support.d.ts +41 -0
- package/lib/addons/lid-support.d.ts.map +1 -0
- package/lib/addons/lid-support.js +42 -0
- package/lib/addons/lid-support.js.map +1 -0
- package/lib/addons/message-composer.d.ts +142 -0
- package/lib/addons/message-composer.d.ts.map +1 -0
- package/lib/addons/message-composer.js +377 -0
- package/lib/addons/message-composer.js.map +1 -0
- package/lib/addons/message-scheduler.d.ts +77 -0
- package/lib/addons/message-scheduler.d.ts.map +1 -0
- package/lib/addons/message-scheduler.js +108 -0
- package/lib/addons/message-scheduler.js.map +1 -0
- package/lib/addons/message-search.d.ts +51 -0
- package/lib/addons/message-search.d.ts.map +1 -0
- package/lib/addons/message-search.js +171 -0
- package/lib/addons/message-search.js.map +1 -0
- package/lib/addons/message-utils.d.ts +88 -0
- package/lib/addons/message-utils.d.ts.map +1 -0
- package/lib/addons/message-utils.js +292 -0
- package/lib/addons/message-utils.js.map +1 -0
- package/lib/addons/outgoing-calls.d.ts +64 -0
- package/lib/addons/outgoing-calls.d.ts.map +1 -0
- package/lib/addons/outgoing-calls.js +139 -0
- package/lib/addons/outgoing-calls.js.map +1 -0
- package/lib/addons/pairing-fix.d.ts +31 -0
- package/lib/addons/pairing-fix.d.ts.map +1 -0
- package/lib/addons/pairing-fix.js +74 -0
- package/lib/addons/pairing-fix.js.map +1 -0
- package/lib/addons/past-participants.d.ts +42 -0
- package/lib/addons/past-participants.d.ts.map +1 -0
- package/lib/addons/past-participants.js +41 -0
- package/lib/addons/past-participants.js.map +1 -0
- package/lib/addons/rich-response.d.ts +111 -0
- package/lib/addons/rich-response.d.ts.map +1 -0
- package/lib/addons/rich-response.js +152 -0
- package/lib/addons/rich-response.js.map +1 -0
- package/lib/addons/scheduling.d.ts +41 -0
- package/lib/addons/scheduling.d.ts.map +1 -0
- package/lib/addons/scheduling.js +110 -0
- package/lib/addons/scheduling.js.map +1 -0
- package/lib/addons/status-posting.d.ts +177 -0
- package/lib/addons/status-posting.d.ts.map +1 -0
- package/lib/addons/status-posting.js +240 -0
- package/lib/addons/status-posting.js.map +1 -0
- package/lib/addons/stickerpack.d.ts +37 -0
- package/lib/addons/stickerpack.d.ts.map +1 -0
- package/lib/addons/stickerpack.js +39 -0
- package/lib/addons/stickerpack.js.map +1 -0
- package/lib/addons/templates.d.ts +72 -0
- package/lib/addons/templates.d.ts.map +1 -0
- package/lib/addons/templates.js +145 -0
- package/lib/addons/templates.js.map +1 -0
- package/lib/addons/vcard.d.ts +59 -0
- package/lib/addons/vcard.d.ts.map +1 -0
- package/lib/addons/vcard.js +88 -0
- package/lib/addons/vcard.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -1,1392 +1,484 @@
|
|
|
1
|
-
<h1 align='center'
|
|
1
|
+
<h1 align='center'>
|
|
2
|
+
<img alt="anya-bail logo" src="https://raw.githubusercontent.com/WhiskeySockets/Baileys/refs/heads/master/Media/logo.png" height="75"/>
|
|
3
|
+
</h1>
|
|
2
4
|
|
|
3
|
-
<div align='center'>
|
|
5
|
+
<div align='center'>
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
**anya-bail** — A heavily extended fork of [WhiskeySockets/Baileys](https://github.com/WhiskeySockets/Baileys), the WhatsApp Web API library.
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
Maintained for [@queenanya/baileys](https://github.com/QueenAnya/ANYA-MD) | Last updated: **April 2026**
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
[](#) [](#)
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
</div>
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
The official WhatsApp website can be found at whatsapp.com. "WhatsApp" as well as related names, marks, emblems and images are registered trademarks of their respective owners.
|
|
15
|
+
---
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
Use at your own discretion. Do not spam people with this. We discourage any stalkerware, bulk or automated messaging usage.
|
|
17
|
+
## What's Different from Upstream
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
| Feature | Upstream Baileys | anya-bail |
|
|
20
|
+
| ------------------------------------- | ---------------- | ----------------------------------------- |
|
|
21
|
+
| Interactive / button messages | ❌ | ✅ Full support |
|
|
22
|
+
| Template messages | ❌ | ✅ |
|
|
23
|
+
| List messages | ❌ | ✅ |
|
|
24
|
+
| Cards / Carousel messages | ❌ | ✅ |
|
|
25
|
+
| Album messages | ❌ | ✅ |
|
|
26
|
+
| Sticker pack messages | ❌ | ✅ |
|
|
27
|
+
| Share / Request phone number | ❌ | ✅ |
|
|
28
|
+
| AI icon on messages | ❌ | ✅ |
|
|
29
|
+
| Rich response / Meta AI messages | ❌ | ✅ |
|
|
30
|
+
| Outgoing call API | ❌ | ✅ |
|
|
31
|
+
| Full MEX notification dispatcher | Partial | ✅ |
|
|
32
|
+
| `messaging-history.status` event | ❌ | ✅ |
|
|
33
|
+
| `message-capping.update` event | ❌ | ✅ |
|
|
34
|
+
| Reachout timelock event | ❌ | ✅ |
|
|
35
|
+
| MongoDB auth state | ❌ | ✅ |
|
|
36
|
+
| Single-file auth state | ❌ | ✅ |
|
|
37
|
+
| iOS / Android / KaiOS browser support | Limited | ✅ Extended |
|
|
38
|
+
| Pairing race-condition fix | ❌ | ✅ |
|
|
39
|
+
| Username in contacts / groups | ❌ | ✅ |
|
|
40
|
+
| `authorUsername` in group events | ❌ | ✅ |
|
|
41
|
+
| `chunkOrder` in history sync | ❌ | ✅ |
|
|
42
|
+
| tctoken prune on reconnect | ❌ | ✅ |
|
|
43
|
+
| App state sync resilience | Partial | ✅ `forceSnapshot` + `blockedCollections` |
|
|
44
|
+
| Message ID prefix | `3EB0` | `4NY4W3B` |
|
|
45
|
+
| Addons layer | ❌ | ✅ 18 addon files |
|
|
20
46
|
|
|
21
|
-
|
|
22
|
-
- Not running Selenium or Chromium saves you like **half a gig** of ram :/
|
|
23
|
-
- Baileys supports interacting with the multi-device & web versions of WhatsApp.
|
|
24
|
-
- Thank you to [@pokearaujo](https://github.com/pokearaujo/multidevice) for writing his observations on the workings of WhatsApp Multi-Device. Also, thank you to [@Sigalor](https://github.com/sigalor/whatsapp-web-reveng) for writing his observations on the workings of WhatsApp Web and thanks to [@Rhymen](https://github.com/Rhymen/go-whatsapp/) for the **go** implementation.
|
|
47
|
+
---
|
|
25
48
|
|
|
26
|
-
|
|
27
|
-
> The original repository had to be removed by the original author - we now continue development in this repository here.
|
|
28
|
-
> This is the only official repository and is maintained by the community.
|
|
29
|
-
> **Join the Discord [here](https://discord.gg/WeJM5FP9GG)**
|
|
49
|
+
## Installation
|
|
30
50
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
To run the example script, download or clone the repo and then type the following in a terminal:
|
|
36
|
-
|
|
37
|
-
1. `cd path/to/Baileys`
|
|
38
|
-
2. `yarn`
|
|
39
|
-
3. `yarn example`
|
|
40
|
-
|
|
41
|
-
## Install
|
|
42
|
-
|
|
43
|
-
Use the stable version:
|
|
44
|
-
|
|
45
|
-
```
|
|
46
|
-
yarn add @whiskeysockets/baileys
|
|
51
|
+
```bash
|
|
52
|
+
npm install anya-bail
|
|
53
|
+
# or
|
|
54
|
+
yarn add anya-bail
|
|
47
55
|
```
|
|
48
56
|
|
|
49
|
-
|
|
57
|
+
---
|
|
50
58
|
|
|
51
|
-
|
|
52
|
-
yarn add github:WhiskeySockets/Baileys
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
Then import your code using:
|
|
56
|
-
|
|
57
|
-
```ts
|
|
58
|
-
import makeWASocket from '@whiskeysockets/baileys'
|
|
59
|
-
```
|
|
59
|
+
## Table of Contents
|
|
60
60
|
|
|
61
|
-
#
|
|
62
|
-
|
|
63
|
-
- [Discord](https://discord.gg/WeJM5FP9GG)
|
|
64
|
-
- [Docs](https://guide.whiskeysockets.io/)
|
|
65
|
-
|
|
66
|
-
# Index
|
|
67
|
-
|
|
68
|
-
- [Connecting Account](#connecting-account)
|
|
69
|
-
- [Connect with QR-CODE](#starting-socket-with-qr-code)
|
|
70
|
-
- [Connect with Pairing Code](#starting-socket-with-pairing-code)
|
|
71
|
-
- [Receive Full History](#receive-full-history)
|
|
72
|
-
- [Important Notes About Socket Config](#important-notes-about-socket-config)
|
|
73
|
-
- [Caching Group Metadata (Recommended)](#caching-group-metadata-recommended)
|
|
74
|
-
- [Improve Retry System & Decrypt Poll Votes](#improve-retry-system--decrypt-poll-votes)
|
|
75
|
-
- [Receive Notifications in Whatsapp App](#receive-notifications-in-whatsapp-app)
|
|
76
|
-
|
|
77
|
-
- [Save Auth Info](#saving--restoring-sessions)
|
|
78
|
-
- [Handling Events](#handling-events)
|
|
79
|
-
- [Example to Start](#example-to-start)
|
|
80
|
-
- [Decrypt Poll Votes](#decrypt-poll-votes)
|
|
81
|
-
- [Summary of Events on First Connection](#summary-of-events-on-first-connection)
|
|
82
|
-
- [Implementing a Data Store](#implementing-a-data-store)
|
|
83
|
-
- [Whatsapp IDs Explain](#whatsapp-ids-explain)
|
|
84
|
-
- [Utility Functions](#utility-functions)
|
|
61
|
+
- [Connecting](#connecting)
|
|
85
62
|
- [Sending Messages](#sending-messages)
|
|
86
|
-
- [
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
- [
|
|
97
|
-
|
|
98
|
-
- [
|
|
99
|
-
- [
|
|
100
|
-
- [
|
|
101
|
-
- [
|
|
102
|
-
- [
|
|
103
|
-
- [
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
- [
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
- [Delete a Message for Me](#delete-a-message-for-me)
|
|
119
|
-
- [Delete a Chat](#delete-a-chat)
|
|
120
|
-
- [Star/Unstar a Message](#starunstar-a-message)
|
|
121
|
-
- [Disappearing Messages](#disappearing-messages)
|
|
122
|
-
- [User Querys](#user-querys)
|
|
123
|
-
- [Check If ID Exists in Whatsapp](#check-if-id-exists-in-whatsapp)
|
|
124
|
-
- [Query Chat History (groups too)](#query-chat-history-groups-too)
|
|
125
|
-
- [Fetch Status](#fetch-status)
|
|
126
|
-
- [Fetch Profile Picture (groups too)](#fetch-profile-picture-groups-too)
|
|
127
|
-
- [Fetch Bussines Profile (such as description or category)](#fetch-bussines-profile-such-as-description-or-category)
|
|
128
|
-
- [Fetch Someone's Presence (if they're typing or online)](#fetch-someones-presence-if-theyre-typing-or-online)
|
|
129
|
-
- [Change Profile](#change-profile)
|
|
130
|
-
- [Change Profile Status](#change-profile-status)
|
|
131
|
-
- [Change Profile Name](#change-profile-name)
|
|
132
|
-
- [Change Display Picture (groups too)](#change-display-picture-groups-too)
|
|
133
|
-
- [Remove display picture (groups too)](#remove-display-picture-groups-too)
|
|
134
|
-
- [Groups](#groups)
|
|
135
|
-
- [Create a Group](#create-a-group)
|
|
136
|
-
- [Add/Remove or Demote/Promote](#addremove-or-demotepromote)
|
|
137
|
-
- [Change Subject (name)](#change-subject-name)
|
|
138
|
-
- [Change Description](#change-description)
|
|
139
|
-
- [Change Settings](#change-settings)
|
|
140
|
-
- [Leave a Group](#leave-a-group)
|
|
141
|
-
- [Get Invite Code](#get-invite-code)
|
|
142
|
-
- [Revoke Invite Code](#revoke-invite-code)
|
|
143
|
-
- [Join Using Invitation Code](#join-using-invitation-code)
|
|
144
|
-
- [Get Group Info by Invite Code](#get-group-info-by-invite-code)
|
|
145
|
-
- [Query Metadata (participants, name, description...)](#query-metadata-participants-name-description)
|
|
146
|
-
- [Join using groupInviteMessage](#join-using-groupinvitemessage)
|
|
147
|
-
- [Get Request Join List](#get-request-join-list)
|
|
148
|
-
- [Approve/Reject Request Join](#approvereject-request-join)
|
|
149
|
-
- [Get All Participating Groups Metadata](#get-all-participating-groups-metadata)
|
|
150
|
-
- [Toggle Ephemeral](#toggle-ephemeral)
|
|
151
|
-
- [Change Add Mode](#change-add-mode)
|
|
152
|
-
- [Privacy](#privacy)
|
|
153
|
-
- [Block/Unblock User](#blockunblock-user)
|
|
154
|
-
- [Get Privacy Settings](#get-privacy-settings)
|
|
155
|
-
- [Get BlockList](#get-blocklist)
|
|
156
|
-
- [Update LastSeen Privacy](#update-lastseen-privacy)
|
|
157
|
-
- [Update Online Privacy](#update-online-privacy)
|
|
158
|
-
- [Update Profile Picture Privacy](#update-profile-picture-privacy)
|
|
159
|
-
- [Update Status Privacy](#update-status-privacy)
|
|
160
|
-
- [Update Read Receipts Privacy](#update-read-receipts-privacy)
|
|
161
|
-
- [Update Groups Add Privacy](#update-groups-add-privacy)
|
|
162
|
-
- [Update Default Disappearing Mode](#update-default-disappearing-mode)
|
|
163
|
-
- [Broadcast Lists & Stories](#broadcast-lists--stories)
|
|
164
|
-
- [Send Broadcast & Stories](#send-broadcast--stories)
|
|
165
|
-
- [Query a Broadcast List's Recipients & Name](#query-a-broadcast-lists-recipients--name)
|
|
166
|
-
- [Writing Custom Functionality](#writing-custom-functionality)
|
|
167
|
-
- [Enabling Debug Level in Baileys Logs](#enabling-debug-level-in-baileys-logs)
|
|
168
|
-
- [How Whatsapp Communicate With Us](#how-whatsapp-communicate-with-us)
|
|
169
|
-
- [Register a Callback for Websocket Events](#register-a-callback-for-websocket-events)
|
|
170
|
-
|
|
171
|
-
## Connecting Account
|
|
172
|
-
|
|
173
|
-
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.
|
|
174
|
-
|
|
175
|
-
> [!NOTE]
|
|
176
|
-
> **[Here](#example-to-start) is a simple example of event handling**
|
|
177
|
-
|
|
178
|
-
> [!TIP]
|
|
179
|
-
> **You can see all supported socket configs [here](https://baileys.whiskeysockets.io/types/SocketConfig.html) (Recommended)**
|
|
180
|
-
|
|
181
|
-
### Starting socket with **QR-CODE**
|
|
182
|
-
|
|
183
|
-
> [!TIP]
|
|
184
|
-
> 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)**
|
|
63
|
+
- [Text](#text-message)
|
|
64
|
+
- [Media](#image--video--audio--document)
|
|
65
|
+
- [Buttons](#button-message)
|
|
66
|
+
- [Template](#template-message)
|
|
67
|
+
- [Interactive / List](#interactive--list-message)
|
|
68
|
+
- [Album](#album-message)
|
|
69
|
+
- [Sticker Pack](#sticker-pack-message)
|
|
70
|
+
- [Share Phone Number](#share-phone-number-message)
|
|
71
|
+
- [Request Phone Number](#request-phone-number-message)
|
|
72
|
+
- [AI Icon Feature](#ai-icon-feature)
|
|
73
|
+
- [Rich Response / Meta AI Messages](#rich-response-message)
|
|
74
|
+
- [sendTable](#sendtable)
|
|
75
|
+
- [sendList](#sendlist)
|
|
76
|
+
- [sendCodeBlock](#sendcodeblock)
|
|
77
|
+
- [sendLatex](#sendlatex)
|
|
78
|
+
- [sendLatexImage](#sendlateximage)
|
|
79
|
+
- [sendLatexInlineImage](#sendlatexinlineimage)
|
|
80
|
+
- [sendRichMessage](#sendrichmessage)
|
|
81
|
+
- [captureUnifiedResponse / sendUnifiedResponse](#captureunifiedresponse--sendunifiedresponse)
|
|
82
|
+
- [Calls](#calls)
|
|
83
|
+
- [Auth State](#auth-state)
|
|
84
|
+
- [MEX Notifications](#mex-notifications)
|
|
85
|
+
- [Addons](#addons)
|
|
86
|
+
- [Changelog](#changelog)
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## Connecting
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
import makeWASocket, { DisconnectReason, useMultiFileAuthState } from 'anya-bail'
|
|
94
|
+
import { Boom } from '@hapi/boom'
|
|
185
95
|
|
|
186
|
-
|
|
187
|
-
import makeWASocket from '@whiskeysockets/baileys'
|
|
96
|
+
const { state, saveCreds } = await useMultiFileAuthState('./auth_info')
|
|
188
97
|
|
|
189
98
|
const sock = makeWASocket({
|
|
190
|
-
|
|
191
|
-
browser: Browsers.ubuntu('My App'),
|
|
99
|
+
auth: state,
|
|
192
100
|
printQRInTerminal: true
|
|
193
101
|
})
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
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!
|
|
197
|
-
|
|
198
|
-
### Starting socket with **Pairing Code**
|
|
199
|
-
|
|
200
|
-
> [!IMPORTANT]
|
|
201
|
-
> 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)
|
|
202
|
-
|
|
203
|
-
The phone number can't have `+` or `()` or `-`, only numbers, you must provide country code
|
|
204
|
-
|
|
205
|
-
```ts
|
|
206
|
-
import makeWASocket from '@whiskeysockets/baileys'
|
|
207
|
-
|
|
208
|
-
const sock = makeWASocket({
|
|
209
|
-
// can provide additional config here
|
|
210
|
-
printQRInTerminal: false //need to be false
|
|
211
|
-
})
|
|
212
|
-
|
|
213
|
-
if (!sock.authState.creds.registered) {
|
|
214
|
-
const number = 'XXXXXXXXXXX'
|
|
215
|
-
const code = await sock.requestPairingCode(number)
|
|
216
|
-
console.log(code)
|
|
217
|
-
}
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
### Receive Full History
|
|
221
|
-
|
|
222
|
-
1. Set `syncFullHistory` as `true`
|
|
223
|
-
2. Baileys, by default, use chrome browser config
|
|
224
|
-
- If you'd like to emulate a desktop connection (and receive more message history), this browser setting to your Socket config:
|
|
225
|
-
|
|
226
|
-
```ts
|
|
227
|
-
const sock = makeWASocket({
|
|
228
|
-
...otherOpts,
|
|
229
|
-
// can use Windows, Ubuntu here too
|
|
230
|
-
browser: Browsers.macOS('Desktop'),
|
|
231
|
-
syncFullHistory: true
|
|
232
|
-
})
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
## Important Notes About Socket Config
|
|
236
|
-
|
|
237
|
-
### Caching Group Metadata (Recommended)
|
|
238
|
-
|
|
239
|
-
- If you use baileys for groups, we recommend you to set `cachedGroupMetadata` in socket config, you need to implement a cache like this:
|
|
240
|
-
|
|
241
|
-
```ts
|
|
242
|
-
const groupCache = new NodeCache({ stdTTL: 5 * 60, useClones: false })
|
|
243
|
-
|
|
244
|
-
const sock = makeWASocket({
|
|
245
|
-
cachedGroupMetadata: async jid => groupCache.get(jid)
|
|
246
|
-
})
|
|
247
|
-
|
|
248
|
-
sock.ev.on('groups.update', async ([event]) => {
|
|
249
|
-
const metadata = await sock.groupMetadata(event.id)
|
|
250
|
-
groupCache.set(event.id, metadata)
|
|
251
|
-
})
|
|
252
|
-
|
|
253
|
-
sock.ev.on('group-participants.update', async event => {
|
|
254
|
-
const metadata = await sock.groupMetadata(event.id)
|
|
255
|
-
groupCache.set(event.id, metadata)
|
|
256
|
-
})
|
|
257
|
-
```
|
|
258
|
-
|
|
259
|
-
### Improve Retry System & Decrypt Poll Votes
|
|
260
|
-
|
|
261
|
-
- 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:
|
|
262
|
-
```ts
|
|
263
|
-
const sock = makeWASocket({
|
|
264
|
-
getMessage: async key => await getMessageFromStore(key)
|
|
265
|
-
})
|
|
266
|
-
```
|
|
267
|
-
|
|
268
|
-
### Receive Notifications in Whatsapp App
|
|
269
|
-
|
|
270
|
-
- If you want to receive notifications in whatsapp app, set `markOnlineOnConnect` to `false`
|
|
271
|
-
```ts
|
|
272
|
-
const sock = makeWASocket({
|
|
273
|
-
markOnlineOnConnect: false
|
|
274
|
-
})
|
|
275
|
-
```
|
|
276
|
-
|
|
277
|
-
## Saving & Restoring Sessions
|
|
278
|
-
|
|
279
|
-
You obviously don't want to keep scanning the QR code every time you want to connect.
|
|
280
|
-
|
|
281
|
-
So, you can load the credentials to log back in:
|
|
282
|
-
|
|
283
|
-
```ts
|
|
284
|
-
import makeWASocket, { useMultiFileAuthState } from '@whiskeysockets/baileys'
|
|
285
|
-
|
|
286
|
-
const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')
|
|
287
102
|
|
|
288
|
-
// will use the given state to connect
|
|
289
|
-
// so if valid credentials are available -- it'll connect without QR
|
|
290
|
-
const sock = makeWASocket({ auth: state })
|
|
291
|
-
|
|
292
|
-
// this will be called as soon as the credentials are updated
|
|
293
103
|
sock.ev.on('creds.update', saveCreds)
|
|
294
|
-
```
|
|
295
|
-
|
|
296
|
-
> [!IMPORTANT]
|
|
297
|
-
> `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.
|
|
298
|
-
|
|
299
|
-
> [!NOTE]
|
|
300
|
-
> 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.
|
|
301
|
-
|
|
302
|
-
## Handling Events
|
|
303
|
-
|
|
304
|
-
- Baileys uses the EventEmitter syntax for events.
|
|
305
|
-
They're all nicely typed up, so you shouldn't have any issues with an Intellisense editor like VS Code.
|
|
306
|
-
|
|
307
|
-
> [!IMPORTANT]
|
|
308
|
-
> **The events are [these](https://baileys.whiskeysockets.io/types/BaileysEventMap.html)**, it's important you see all events
|
|
309
|
-
|
|
310
|
-
You can listen to these events like this:
|
|
311
|
-
|
|
312
|
-
```ts
|
|
313
|
-
const sock = makeWASocket()
|
|
314
|
-
sock.ev.on('messages.upsert', ({ messages }) => {
|
|
315
|
-
console.log('got messages', messages)
|
|
316
|
-
})
|
|
317
|
-
```
|
|
318
|
-
|
|
319
|
-
### Example to Start
|
|
320
|
-
|
|
321
|
-
> [!NOTE]
|
|
322
|
-
> This example includes basic auth storage too
|
|
323
|
-
|
|
324
|
-
> [!NOTE]
|
|
325
|
-
> For reliable serialization of the authentication state, especially when storing as JSON, always use the BufferJSON utility.
|
|
326
|
-
|
|
327
|
-
```ts
|
|
328
|
-
import makeWASocket, { DisconnectReason, useMultiFileAuthState } from '@whiskeysockets/baileys'
|
|
329
|
-
import { Boom } from '@hapi/boom'
|
|
330
|
-
|
|
331
|
-
async function connectToWhatsApp() {
|
|
332
|
-
const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')
|
|
333
|
-
const sock = makeWASocket({
|
|
334
|
-
// can provide additional config here
|
|
335
|
-
auth: state,
|
|
336
|
-
printQRInTerminal: true
|
|
337
|
-
})
|
|
338
|
-
sock.ev.on('connection.update', update => {
|
|
339
|
-
const { connection, lastDisconnect } = update
|
|
340
|
-
if (connection === 'close') {
|
|
341
|
-
const shouldReconnect = (lastDisconnect.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut
|
|
342
|
-
console.log('connection closed due to ', lastDisconnect.error, ', reconnecting ', shouldReconnect)
|
|
343
|
-
// reconnect if not logged out
|
|
344
|
-
if (shouldReconnect) {
|
|
345
|
-
connectToWhatsApp()
|
|
346
|
-
}
|
|
347
|
-
} else if (connection === 'open') {
|
|
348
|
-
console.log('opened connection')
|
|
349
|
-
}
|
|
350
|
-
})
|
|
351
|
-
sock.ev.on('messages.upsert', event => {
|
|
352
|
-
for (const m of event.messages) {
|
|
353
|
-
console.log(JSON.stringify(m, undefined, 2))
|
|
354
|
-
|
|
355
|
-
console.log('replying to', m.key.remoteJid)
|
|
356
|
-
await sock.sendMessage(m.key.remoteJid!, { text: 'Hello Word' })
|
|
357
|
-
}
|
|
358
|
-
})
|
|
359
|
-
|
|
360
|
-
// to storage creds (session info) when it updates
|
|
361
|
-
sock.ev.on('creds.update', saveCreds)
|
|
362
|
-
}
|
|
363
|
-
// run in main file
|
|
364
|
-
connectToWhatsApp()
|
|
365
|
-
```
|
|
366
104
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
- By default poll votes are encrypted and handled in `messages.update`
|
|
373
|
-
- That's a simple example
|
|
374
|
-
|
|
375
|
-
```ts
|
|
376
|
-
sock.ev.on('messages.update', event => {
|
|
377
|
-
for (const { key, update } of event) {
|
|
378
|
-
if (update.pollUpdates) {
|
|
379
|
-
const pollCreation = await getMessage(key)
|
|
380
|
-
if (pollCreation) {
|
|
381
|
-
console.log(
|
|
382
|
-
'got poll update, aggregation: ',
|
|
383
|
-
getAggregateVotesInPollMessage({
|
|
384
|
-
message: pollCreation,
|
|
385
|
-
pollUpdates: update.pollUpdates
|
|
386
|
-
})
|
|
387
|
-
)
|
|
388
|
-
}
|
|
389
|
-
}
|
|
105
|
+
sock.ev.on('connection.update', update => {
|
|
106
|
+
const { connection, lastDisconnect } = update
|
|
107
|
+
if (connection === 'close') {
|
|
108
|
+
const shouldReconnect = (lastDisconnect?.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut
|
|
109
|
+
if (shouldReconnect) connectToWhatsApp()
|
|
390
110
|
}
|
|
391
111
|
})
|
|
392
112
|
```
|
|
393
113
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
### Summary of Events on First Connection
|
|
397
|
-
|
|
398
|
-
1. When you connect first time, `connection.update` will be fired requesting you to restart sock
|
|
399
|
-
2. Then, history messages will be received in `messaging.history-set`
|
|
400
|
-
|
|
401
|
-
## Implementing a Data Store
|
|
402
|
-
|
|
403
|
-
- 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.
|
|
404
|
-
|
|
405
|
-
> [!IMPORTANT]
|
|
406
|
-
> I highly recommend building your own data store, as storing someone's entire chat history in memory is a terrible waste of RAM.
|
|
407
|
-
|
|
408
|
-
It can be used as follows:
|
|
114
|
+
**Pairing Code (instead of QR):**
|
|
409
115
|
|
|
410
116
|
```ts
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
// can be written out to a file & read from it
|
|
414
|
-
const store = makeInMemoryStore({})
|
|
415
|
-
// can be read from a file
|
|
416
|
-
store.readFromFile('./baileys_store.json')
|
|
417
|
-
// saves the state to a file every 10s
|
|
418
|
-
setInterval(() => {
|
|
419
|
-
store.writeToFile('./baileys_store.json')
|
|
420
|
-
}, 10_000)
|
|
421
|
-
|
|
422
|
-
const sock = makeWASocket({})
|
|
423
|
-
// will listen from this socket
|
|
424
|
-
// the store can listen from a new socket once the current socket outlives its lifetime
|
|
425
|
-
store.bind(sock.ev)
|
|
426
|
-
|
|
427
|
-
sock.ev.on('chats.upsert', () => {
|
|
428
|
-
// can use 'store.chats' however you want, even after the socket dies out
|
|
429
|
-
// 'chats' => a KeyedDB instance
|
|
430
|
-
console.log('got chats', store.chats.all())
|
|
431
|
-
})
|
|
432
|
-
|
|
433
|
-
sock.ev.on('contacts.upsert', () => {
|
|
434
|
-
console.log('got contacts', Object.values(store.contacts))
|
|
435
|
-
})
|
|
117
|
+
const code = await sock.requestPairingCode('+91XXXXXXXXXX')
|
|
118
|
+
console.log('Pairing code:', code)
|
|
436
119
|
```
|
|
437
120
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
## Whatsapp IDs Explain
|
|
441
|
-
|
|
442
|
-
- `id` is the WhatsApp ID, called `jid` too, of the person or group you're sending the message to.
|
|
443
|
-
- It must be in the format `[country code][phone number]@s.whatsapp.net`
|
|
444
|
-
- Example for people: `+19999999999@s.whatsapp.net`.
|
|
445
|
-
- For groups, it must be in the format `123456789-123345@g.us`.
|
|
446
|
-
- For broadcast lists, it's `[timestamp of creation]@broadcast`.
|
|
447
|
-
- For stories, the ID is `status@broadcast`.
|
|
448
|
-
|
|
449
|
-
## Utility Functions
|
|
450
|
-
|
|
451
|
-
- `getContentType`, returns the content type for any message
|
|
452
|
-
- `getDevice`, returns the device from message
|
|
453
|
-
- `makeCacheableSignalKeyStore`, make auth store more fast
|
|
454
|
-
- `downloadContentFromMessage`, download content from any message
|
|
121
|
+
---
|
|
455
122
|
|
|
456
123
|
## Sending Messages
|
|
457
124
|
|
|
458
|
-
|
|
459
|
-
- **[Here](https://baileys.whiskeysockets.io/types/AnyMessageContent.html) you can see all message contents supported, like text message**
|
|
460
|
-
- **[Here](https://baileys.whiskeysockets.io/types/MiscMessageGenerationOptions.html) you can see all options supported, like quote message**
|
|
461
|
-
|
|
462
|
-
```ts
|
|
463
|
-
const jid: string
|
|
464
|
-
const content: AnyMessageContent
|
|
465
|
-
const options: MiscMessageGenerationOptions
|
|
466
|
-
|
|
467
|
-
sock.sendMessage(jid, content, options)
|
|
468
|
-
```
|
|
469
|
-
|
|
470
|
-
### Non-Media Messages
|
|
471
|
-
|
|
472
|
-
#### Text Message
|
|
125
|
+
### Text Message
|
|
473
126
|
|
|
474
127
|
```ts
|
|
475
|
-
await sock.sendMessage(jid, { text: '
|
|
128
|
+
await sock.sendMessage(jid, { text: 'Hello World!' })
|
|
476
129
|
```
|
|
477
130
|
|
|
478
|
-
|
|
131
|
+
### Image / Video / Audio / Document
|
|
479
132
|
|
|
480
133
|
```ts
|
|
481
|
-
|
|
482
|
-
|
|
134
|
+
// Image
|
|
135
|
+
await sock.sendMessage(jid, { image: { url: './image.jpg' }, caption: 'caption' })
|
|
483
136
|
|
|
484
|
-
|
|
137
|
+
// Video
|
|
138
|
+
await sock.sendMessage(jid, { video: { url: './video.mp4' }, caption: 'caption' })
|
|
485
139
|
|
|
486
|
-
|
|
140
|
+
// Audio (PTT)
|
|
141
|
+
await sock.sendMessage(jid, { audio: { url: './audio.mp3' }, mimetype: 'audio/mp4', ptt: true })
|
|
487
142
|
|
|
488
|
-
|
|
489
|
-
await sock.sendMessage(jid, {
|
|
490
|
-
text: '@12345678901',
|
|
491
|
-
mentions: ['12345678901@s.whatsapp.net']
|
|
492
|
-
})
|
|
493
|
-
```
|
|
494
|
-
|
|
495
|
-
#### Forward Messages
|
|
496
|
-
|
|
497
|
-
- 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
|
|
498
|
-
|
|
499
|
-
```ts
|
|
500
|
-
const msg = getMessageFromStore() // implement this on your end
|
|
501
|
-
await sock.sendMessage(jid, { forward: msg }) // WA forward the message!
|
|
143
|
+
// Document
|
|
144
|
+
await sock.sendMessage(jid, { document: { url: './file.pdf' }, mimetype: 'application/pdf', fileName: 'file.pdf' })
|
|
502
145
|
```
|
|
503
146
|
|
|
504
|
-
|
|
147
|
+
### Button Message
|
|
505
148
|
|
|
506
149
|
```ts
|
|
507
150
|
await sock.sendMessage(jid, {
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
151
|
+
buttons: [
|
|
152
|
+
{ buttonId: 'btn1', buttonText: { displayText: 'Option 1' }, type: 1 },
|
|
153
|
+
{ buttonId: 'btn2', buttonText: { displayText: 'Option 2' }, type: 1 }
|
|
154
|
+
],
|
|
155
|
+
text: 'Pick an option:',
|
|
156
|
+
footer: 'Powered by anya-bail'
|
|
512
157
|
})
|
|
513
158
|
```
|
|
514
159
|
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
```ts
|
|
518
|
-
const vcard =
|
|
519
|
-
'BEGIN:VCARD\n' + // metadata of the contact card
|
|
520
|
-
'VERSION:3.0\n' +
|
|
521
|
-
'FN:Jeff Singh\n' + // full name
|
|
522
|
-
'ORG:Ashoka Uni;\n' + // the organization of the contact
|
|
523
|
-
'TEL;type=CELL;type=VOICE;waid=911234567890:+91 12345 67890\n' + // WhatsApp ID + phone number
|
|
524
|
-
'END:VCARD'
|
|
525
|
-
|
|
526
|
-
await sock.sendMessage(id, {
|
|
527
|
-
contacts: {
|
|
528
|
-
displayName: 'Jeff',
|
|
529
|
-
contacts: [{ vcard }]
|
|
530
|
-
}
|
|
531
|
-
})
|
|
532
|
-
```
|
|
533
|
-
|
|
534
|
-
#### Reaction Message
|
|
535
|
-
|
|
536
|
-
- 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
|
|
160
|
+
### Template Message
|
|
537
161
|
|
|
538
162
|
```ts
|
|
539
163
|
await sock.sendMessage(jid, {
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
164
|
+
templateButtons: [
|
|
165
|
+
{ index: 1, urlButton: { displayText: 'Visit', url: 'https://example.com' } },
|
|
166
|
+
{ index: 2, callButton: { displayText: 'Call', phoneNumber: '+91XXXXXXXXXX' } },
|
|
167
|
+
{ index: 3, quickReplyButton: { displayText: 'Reply', id: 'id1' } }
|
|
168
|
+
],
|
|
169
|
+
text: 'Template body',
|
|
170
|
+
footer: 'footer'
|
|
544
171
|
})
|
|
545
172
|
```
|
|
546
173
|
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
- 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
|
|
550
|
-
|
|
551
|
-
- Time can be:
|
|
552
|
-
|
|
553
|
-
| Time | Seconds |
|
|
554
|
-
| ---- | --------- |
|
|
555
|
-
| 24h | 86.400 |
|
|
556
|
-
| 7d | 604.800 |
|
|
557
|
-
| 30d | 2.592.000 |
|
|
558
|
-
|
|
559
|
-
```ts
|
|
560
|
-
await sock.sendMessage(
|
|
561
|
-
jid,
|
|
562
|
-
{
|
|
563
|
-
pin: {
|
|
564
|
-
type: 1, // 0 to remove
|
|
565
|
-
time: 86400
|
|
566
|
-
key: message.key
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
)
|
|
570
|
-
```
|
|
571
|
-
|
|
572
|
-
#### Poll Message
|
|
573
|
-
|
|
574
|
-
```ts
|
|
575
|
-
await sock.sendMessage(
|
|
576
|
-
jid,
|
|
577
|
-
{
|
|
578
|
-
poll: {
|
|
579
|
-
name: 'My Poll',
|
|
580
|
-
values: ['Option 1', 'Option 2', ...],
|
|
581
|
-
selectableCount: 1,
|
|
582
|
-
toAnnouncementGroup: false // or true
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
)
|
|
586
|
-
```
|
|
587
|
-
|
|
588
|
-
### Sending Messages with Link Previews
|
|
589
|
-
|
|
590
|
-
1. By default, wa does not have link generation when sent from the web
|
|
591
|
-
2. Baileys has a function to generate the content for these link previews
|
|
592
|
-
3. To enable this function's usage, add `link-preview-js` as a dependency to your project with `yarn add link-preview-js`
|
|
593
|
-
4. Send a link:
|
|
174
|
+
### Interactive / List Message
|
|
594
175
|
|
|
595
176
|
```ts
|
|
177
|
+
// Interactive buttons
|
|
596
178
|
await sock.sendMessage(jid, {
|
|
597
|
-
|
|
179
|
+
interactiveButtons: [
|
|
180
|
+
{ name: 'quick_reply', buttonParamsJson: JSON.stringify({ display_text: 'Yes', id: 'yes' }) },
|
|
181
|
+
{ name: 'quick_reply', buttonParamsJson: JSON.stringify({ display_text: 'No', id: 'no' }) }
|
|
182
|
+
],
|
|
183
|
+
body: { text: 'Are you sure?' },
|
|
184
|
+
footer: { text: 'anya-bail' }
|
|
598
185
|
})
|
|
599
|
-
```
|
|
600
|
-
|
|
601
|
-
### Media Messages
|
|
602
|
-
|
|
603
|
-
Sending media (video, stickers, images) is easier & more efficient than ever.
|
|
604
|
-
|
|
605
|
-
> [!NOTE]
|
|
606
|
-
> 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)
|
|
607
|
-
|
|
608
|
-
- When specifying a media url, Baileys never loads the entire buffer into memory; it even encrypts the media as a readable stream.
|
|
609
|
-
|
|
610
|
-
> [!TIP]
|
|
611
|
-
> It's recommended to use Stream or Url to save memory
|
|
612
|
-
|
|
613
|
-
#### Gif Message
|
|
614
|
-
|
|
615
|
-
- Whatsapp doesn't support `.gif` files, that's why we send gifs as common `.mp4` video with `gifPlayback` flag
|
|
616
186
|
|
|
617
|
-
|
|
187
|
+
// List message
|
|
618
188
|
await sock.sendMessage(jid, {
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
caption: 'hello word',
|
|
633
|
-
ptv: false // if set to true, will send as a `video note`
|
|
189
|
+
sections: [
|
|
190
|
+
{
|
|
191
|
+
title: 'Section 1',
|
|
192
|
+
rows: [
|
|
193
|
+
{ title: 'Row 1', rowId: 'r1', description: 'Description 1' },
|
|
194
|
+
{ title: 'Row 2', rowId: 'r2', description: 'Description 2' }
|
|
195
|
+
]
|
|
196
|
+
}
|
|
197
|
+
],
|
|
198
|
+
title: 'List Title',
|
|
199
|
+
text: 'List body',
|
|
200
|
+
footer: 'footer',
|
|
201
|
+
buttonText: 'Open List'
|
|
634
202
|
})
|
|
635
203
|
```
|
|
636
204
|
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
- To audio message work in all devices you need to convert with some tool like `ffmpeg` with this flags:
|
|
640
|
-
|
|
641
|
-
```bash
|
|
642
|
-
codec: libopus //ogg file
|
|
643
|
-
ac: 1 //one channel
|
|
644
|
-
avoid_negative_ts
|
|
645
|
-
make_zero
|
|
646
|
-
```
|
|
647
|
-
|
|
648
|
-
- Example:
|
|
649
|
-
|
|
650
|
-
```bash
|
|
651
|
-
ffmpeg -i input.mp4 -avoid_negative_ts make_zero -ac 1 output.ogg
|
|
652
|
-
```
|
|
205
|
+
### Album Message
|
|
653
206
|
|
|
654
207
|
```ts
|
|
655
208
|
await sock.sendMessage(jid, {
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
})
|
|
661
|
-
```
|
|
662
|
-
|
|
663
|
-
#### Image Message
|
|
664
|
-
|
|
665
|
-
```ts
|
|
666
|
-
await sock.sendMessage(id, {
|
|
667
|
-
image: {
|
|
668
|
-
url: './Media/ma_img.png'
|
|
669
|
-
},
|
|
670
|
-
caption: 'hello word'
|
|
671
|
-
})
|
|
672
|
-
```
|
|
673
|
-
|
|
674
|
-
#### View Once Message
|
|
675
|
-
|
|
676
|
-
- You can send all messages above as `viewOnce`, you only need to pass `viewOnce: true` in content object
|
|
677
|
-
|
|
678
|
-
```ts
|
|
679
|
-
await sock.sendMessage(id, {
|
|
680
|
-
image: {
|
|
681
|
-
url: './Media/ma_img.png'
|
|
682
|
-
},
|
|
683
|
-
viewOnce: true, //works with video, audio too
|
|
684
|
-
caption: 'hello word'
|
|
209
|
+
album: {
|
|
210
|
+
expectedImageCount: 2,
|
|
211
|
+
expectedVideoCount: 1
|
|
212
|
+
}
|
|
685
213
|
})
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
## Modify Messages
|
|
689
|
-
|
|
690
|
-
### Deleting Messages (for everyone)
|
|
691
|
-
|
|
692
|
-
```ts
|
|
693
|
-
const msg = await sock.sendMessage(jid, { text: 'hello word' })
|
|
694
|
-
await sock.sendMessage(jid, { delete: msg.key })
|
|
695
|
-
```
|
|
696
|
-
|
|
697
|
-
**Note:** deleting for oneself is supported via `chatModify`, see in [this section](#modifying-chats)
|
|
698
|
-
|
|
699
|
-
### Editing Messages
|
|
700
|
-
|
|
701
|
-
- You can pass all editable contents here
|
|
702
|
-
|
|
703
|
-
```ts
|
|
214
|
+
// Then send each media with albumParentKey
|
|
704
215
|
await sock.sendMessage(jid, {
|
|
705
|
-
|
|
706
|
-
|
|
216
|
+
image: { url: './photo1.jpg' },
|
|
217
|
+
caption: 'First',
|
|
218
|
+
albumParentKey: albumMsg.key
|
|
707
219
|
})
|
|
708
220
|
```
|
|
709
221
|
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
### Thumbnail in Media Messages
|
|
713
|
-
|
|
714
|
-
- 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`.
|
|
715
|
-
- Thumbnails for videos can also be generated automatically, though, you need to have `ffmpeg` installed on your system.
|
|
716
|
-
|
|
717
|
-
### Downloading Media Messages
|
|
718
|
-
|
|
719
|
-
If you want to save the media you received
|
|
720
|
-
|
|
721
|
-
```ts
|
|
722
|
-
import { createWriteStream } from 'fs'
|
|
723
|
-
import { downloadMediaMessage, getContentType } from '@whiskeysockets/baileys'
|
|
724
|
-
|
|
725
|
-
sock.ev.on('messages.upsert', async ({ [m] }) => {
|
|
726
|
-
if (!m.message) return // if there is no text or media message
|
|
727
|
-
const messageType = getContentType(m) // get what type of message it is (text, image, video...)
|
|
728
|
-
|
|
729
|
-
// if the message is an image
|
|
730
|
-
if (messageType === 'imageMessage') {
|
|
731
|
-
// download the message
|
|
732
|
-
const stream = await downloadMediaMessage(
|
|
733
|
-
m,
|
|
734
|
-
'stream', // can be 'buffer' too
|
|
735
|
-
{ },
|
|
736
|
-
{
|
|
737
|
-
logger,
|
|
738
|
-
// pass this so that baileys can request a reupload of media
|
|
739
|
-
// that has been deleted
|
|
740
|
-
reuploadRequest: sock.updateMediaMessage
|
|
741
|
-
}
|
|
742
|
-
)
|
|
743
|
-
// save to file
|
|
744
|
-
const writeStream = createWriteStream('./my-download.jpeg')
|
|
745
|
-
stream.pipe(writeStream)
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
```
|
|
749
|
-
|
|
750
|
-
### Re-upload Media Message to Whatsapp
|
|
751
|
-
|
|
752
|
-
- 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:
|
|
753
|
-
|
|
754
|
-
```ts
|
|
755
|
-
await sock.updateMediaMessage(msg)
|
|
756
|
-
```
|
|
757
|
-
|
|
758
|
-
## Reject Call
|
|
759
|
-
|
|
760
|
-
- You can obtain `callId` and `callFrom` from `call` event
|
|
761
|
-
|
|
762
|
-
```ts
|
|
763
|
-
await sock.rejectCall(callId, callFrom)
|
|
764
|
-
```
|
|
765
|
-
|
|
766
|
-
## Send States in Chat
|
|
767
|
-
|
|
768
|
-
### Reading Messages
|
|
769
|
-
|
|
770
|
-
- A set of message [keys](https://baileys.whiskeysockets.io/types/WAMessageKey.html) must be explicitly marked read now.
|
|
771
|
-
- You cannot mark an entire 'chat' read as it were with Baileys Web.
|
|
772
|
-
This means you have to keep track of unread messages.
|
|
773
|
-
|
|
774
|
-
```ts
|
|
775
|
-
const key: WAMessageKey
|
|
776
|
-
// can pass multiple keys to read multiple messages as well
|
|
777
|
-
await sock.readMessages([key])
|
|
778
|
-
```
|
|
779
|
-
|
|
780
|
-
The message ID is the unique identifier of the message that you are marking as read.
|
|
781
|
-
On a `WAMessage`, the `messageID` can be accessed using `messageID = message.key.id`.
|
|
782
|
-
|
|
783
|
-
### Update Presence
|
|
784
|
-
|
|
785
|
-
- `presence` can be one of [these](https://baileys.whiskeysockets.io/types/WAPresence.html)
|
|
786
|
-
- The presence expires after about 10 seconds.
|
|
787
|
-
- This lets the person/group with `jid` know whether you're online, offline, typing etc.
|
|
222
|
+
### Sticker Pack Message
|
|
788
223
|
|
|
789
224
|
```ts
|
|
790
|
-
await sock.
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
> [!NOTE]
|
|
794
|
-
> 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')`
|
|
795
|
-
|
|
796
|
-
## Modifying Chats
|
|
797
|
-
|
|
798
|
-
WA uses an encrypted form of communication to send chat/app updates. This has been implemented mostly and you can send the following updates:
|
|
799
|
-
|
|
800
|
-
> [!IMPORTANT]
|
|
801
|
-
> 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.
|
|
802
|
-
|
|
803
|
-
### Archive a Chat
|
|
804
|
-
|
|
805
|
-
```ts
|
|
806
|
-
const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
|
|
807
|
-
await sock.chatModify({ archive: true, lastMessages: [lastMsgInChat] }, jid)
|
|
808
|
-
```
|
|
809
|
-
|
|
810
|
-
### Mute/Unmute a Chat
|
|
811
|
-
|
|
812
|
-
- Supported times:
|
|
813
|
-
|
|
814
|
-
| Time | Miliseconds |
|
|
815
|
-
| ------ | ----------- |
|
|
816
|
-
| Remove | null |
|
|
817
|
-
| 8h | 86.400.000 |
|
|
818
|
-
| 7d | 604.800.000 |
|
|
819
|
-
|
|
820
|
-
```ts
|
|
821
|
-
// mute for 8 hours
|
|
822
|
-
await sock.chatModify({ mute: 8 * 60 * 60 * 1000 }, jid)
|
|
823
|
-
// unmute
|
|
824
|
-
await sock.chatModify({ mute: null }, jid)
|
|
825
|
-
```
|
|
826
|
-
|
|
827
|
-
### Mark a Chat Read/Unread
|
|
828
|
-
|
|
829
|
-
```ts
|
|
830
|
-
const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
|
|
831
|
-
// mark it unread
|
|
832
|
-
await sock.chatModify({ markRead: false, lastMessages: [lastMsgInChat] }, jid)
|
|
833
|
-
```
|
|
834
|
-
|
|
835
|
-
### Delete a Message for Me
|
|
836
|
-
|
|
837
|
-
```ts
|
|
838
|
-
await sock.chatModify(
|
|
839
|
-
{
|
|
840
|
-
clear: {
|
|
841
|
-
messages: [
|
|
842
|
-
{
|
|
843
|
-
id: 'ATWYHDNNWU81732J',
|
|
844
|
-
fromMe: true,
|
|
845
|
-
timestamp: '1654823909'
|
|
846
|
-
}
|
|
847
|
-
]
|
|
848
|
-
}
|
|
849
|
-
},
|
|
850
|
-
jid
|
|
851
|
-
)
|
|
852
|
-
```
|
|
853
|
-
|
|
854
|
-
### Delete a Chat
|
|
855
|
-
|
|
856
|
-
```ts
|
|
857
|
-
const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
|
|
858
|
-
await sock.chatModify(
|
|
859
|
-
{
|
|
860
|
-
delete: true,
|
|
861
|
-
lastMessages: [
|
|
225
|
+
await sock.sendMessage(jid, {
|
|
226
|
+
stickerPack: {
|
|
227
|
+
stickers: [
|
|
862
228
|
{
|
|
863
|
-
|
|
864
|
-
|
|
229
|
+
fileSha256: Buffer.from('...'),
|
|
230
|
+
fileEncSha256: Buffer.from('...'),
|
|
231
|
+
mediaKey: Buffer.from('...'),
|
|
232
|
+
directPath: '/v/...',
|
|
233
|
+
fileLength: 12345
|
|
865
234
|
}
|
|
866
235
|
]
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
)
|
|
870
|
-
```
|
|
871
|
-
|
|
872
|
-
### Pin/Unpin a Chat
|
|
873
|
-
|
|
874
|
-
```ts
|
|
875
|
-
await sock.chatModify(
|
|
876
|
-
{
|
|
877
|
-
pin: true // or `false` to unpin
|
|
878
|
-
},
|
|
879
|
-
jid
|
|
880
|
-
)
|
|
881
|
-
```
|
|
882
|
-
|
|
883
|
-
### Star/Unstar a Message
|
|
884
|
-
|
|
885
|
-
```ts
|
|
886
|
-
await sock.chatModify(
|
|
887
|
-
{
|
|
888
|
-
star: {
|
|
889
|
-
messages: [
|
|
890
|
-
{
|
|
891
|
-
id: 'messageID',
|
|
892
|
-
fromMe: true // or `false`
|
|
893
|
-
}
|
|
894
|
-
],
|
|
895
|
-
star: true // - true: Star Message; false: Unstar Message
|
|
896
|
-
}
|
|
897
|
-
},
|
|
898
|
-
jid
|
|
899
|
-
)
|
|
900
|
-
```
|
|
901
|
-
|
|
902
|
-
### Disappearing Messages
|
|
903
|
-
|
|
904
|
-
- Ephemeral can be:
|
|
905
|
-
|
|
906
|
-
| Time | Seconds |
|
|
907
|
-
| ------ | --------- |
|
|
908
|
-
| Remove | 0 |
|
|
909
|
-
| 24h | 86.400 |
|
|
910
|
-
| 7d | 604.800 |
|
|
911
|
-
| 90d | 7.776.000 |
|
|
912
|
-
|
|
913
|
-
- You need to pass in **Seconds**, default is 7 days
|
|
914
|
-
|
|
915
|
-
```ts
|
|
916
|
-
// turn on disappearing messages
|
|
917
|
-
await sock.sendMessage(
|
|
918
|
-
jid,
|
|
919
|
-
// this is 1 week in seconds -- how long you want messages to appear for
|
|
920
|
-
{ disappearingMessagesInChat: WA_DEFAULT_EPHEMERAL }
|
|
921
|
-
)
|
|
922
|
-
|
|
923
|
-
// will send as a disappearing message
|
|
924
|
-
await sock.sendMessage(jid, { text: 'hello' }, { ephemeralExpiration: WA_DEFAULT_EPHEMERAL })
|
|
925
|
-
|
|
926
|
-
// turn off disappearing messages
|
|
927
|
-
await sock.sendMessage(jid, { disappearingMessagesInChat: false })
|
|
928
|
-
```
|
|
929
|
-
|
|
930
|
-
## User Querys
|
|
931
|
-
|
|
932
|
-
### Check If ID Exists in Whatsapp
|
|
933
|
-
|
|
934
|
-
```ts
|
|
935
|
-
const [result] = await sock.onWhatsApp(jid)
|
|
936
|
-
if (result.exists) console.log(`${jid} exists on WhatsApp, as jid: ${result.jid}`)
|
|
937
|
-
```
|
|
938
|
-
|
|
939
|
-
### Query Chat History (groups too)
|
|
940
|
-
|
|
941
|
-
- You need to have oldest message in chat
|
|
942
|
-
|
|
943
|
-
```ts
|
|
944
|
-
const msg = await getOldestMessageInChat(jid) // implement this on your end
|
|
945
|
-
await sock.fetchMessageHistory(
|
|
946
|
-
50, //quantity (max: 50 per query)
|
|
947
|
-
msg.key,
|
|
948
|
-
msg.messageTimestamp
|
|
949
|
-
)
|
|
950
|
-
```
|
|
951
|
-
|
|
952
|
-
- Messages will be received in `messaging.history-set` event
|
|
953
|
-
|
|
954
|
-
### Fetch Status
|
|
955
|
-
|
|
956
|
-
```ts
|
|
957
|
-
const status = await sock.fetchStatus(jid)
|
|
958
|
-
console.log('status: ' + status)
|
|
959
|
-
```
|
|
960
|
-
|
|
961
|
-
### Fetch Profile Picture (groups too)
|
|
962
|
-
|
|
963
|
-
- To get the display picture of some person/group
|
|
964
|
-
|
|
965
|
-
```ts
|
|
966
|
-
// for low res picture
|
|
967
|
-
const ppUrl = await sock.profilePictureUrl(jid)
|
|
968
|
-
console.log(ppUrl)
|
|
969
|
-
|
|
970
|
-
// for high res picture
|
|
971
|
-
const ppUrl = await sock.profilePictureUrl(jid, 'image')
|
|
972
|
-
```
|
|
973
|
-
|
|
974
|
-
### Fetch Bussines Profile (such as description or category)
|
|
975
|
-
|
|
976
|
-
```ts
|
|
977
|
-
const profile = await sock.getBusinessProfile(jid)
|
|
978
|
-
console.log('business description: ' + profile.description + ', category: ' + profile.category)
|
|
979
|
-
```
|
|
980
|
-
|
|
981
|
-
### Fetch Someone's Presence (if they're typing or online)
|
|
982
|
-
|
|
983
|
-
```ts
|
|
984
|
-
// the presence update is fetched and called here
|
|
985
|
-
sock.ev.on('presence.update', console.log)
|
|
986
|
-
|
|
987
|
-
// request updates for a chat
|
|
988
|
-
await sock.presenceSubscribe(jid)
|
|
989
|
-
```
|
|
990
|
-
|
|
991
|
-
## Change Profile
|
|
992
|
-
|
|
993
|
-
### Change Profile Status
|
|
994
|
-
|
|
995
|
-
```ts
|
|
996
|
-
await sock.updateProfileStatus('Hello World!')
|
|
236
|
+
}
|
|
237
|
+
})
|
|
997
238
|
```
|
|
998
239
|
|
|
999
|
-
###
|
|
240
|
+
### Share Phone Number Message
|
|
1000
241
|
|
|
1001
242
|
```ts
|
|
1002
|
-
await sock.
|
|
243
|
+
await sock.sendMessage(jid, { sharePhoneNumber: true })
|
|
1003
244
|
```
|
|
1004
245
|
|
|
1005
|
-
###
|
|
1006
|
-
|
|
1007
|
-
- To change your display picture or a group's
|
|
1008
|
-
|
|
1009
|
-
> [!NOTE]
|
|
1010
|
-
> 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)
|
|
246
|
+
### Request Phone Number Message
|
|
1011
247
|
|
|
1012
248
|
```ts
|
|
1013
|
-
await sock.
|
|
249
|
+
await sock.sendMessage(jid, { requestPhoneNumber: true })
|
|
1014
250
|
```
|
|
1015
251
|
|
|
1016
|
-
###
|
|
252
|
+
### AI Icon Feature
|
|
1017
253
|
|
|
1018
254
|
```ts
|
|
1019
|
-
|
|
255
|
+
// Adds Meta AI bot icon to any message
|
|
256
|
+
await sock.sendMessage(jid, { text: 'I am a bot!' }, { ai: true })
|
|
1020
257
|
```
|
|
1021
258
|
|
|
1022
|
-
|
|
259
|
+
### Rich Response Message
|
|
1023
260
|
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
### Create a Group
|
|
1027
|
-
|
|
1028
|
-
```ts
|
|
1029
|
-
// title & participants
|
|
1030
|
-
const group = await sock.groupCreate('My Fab Group', ['1234@s.whatsapp.net', '4564@s.whatsapp.net'])
|
|
1031
|
-
console.log('created group with id: ' + group.gid)
|
|
1032
|
-
await sock.sendMessage(group.id, { text: 'hello there' }) // say hello to everyone on the group
|
|
1033
|
-
```
|
|
1034
|
-
|
|
1035
|
-
### Add/Remove or Demote/Promote
|
|
261
|
+
#### sendTable
|
|
1036
262
|
|
|
1037
263
|
```ts
|
|
1038
|
-
|
|
1039
|
-
await sock.groupParticipantsUpdate(
|
|
264
|
+
await sock.sendTable(
|
|
1040
265
|
jid,
|
|
1041
|
-
|
|
1042
|
-
'
|
|
266
|
+
'Results',
|
|
267
|
+
['Name', 'Score'],
|
|
268
|
+
[
|
|
269
|
+
['Alice', '98'],
|
|
270
|
+
['Bob', '87']
|
|
271
|
+
],
|
|
272
|
+
quotedMsg,
|
|
273
|
+
{ headerText: 'Leaderboard:', footer: 'Updated now' }
|
|
1043
274
|
)
|
|
1044
275
|
```
|
|
1045
276
|
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
```ts
|
|
1049
|
-
await sock.groupUpdateSubject(jid, 'New Subject!')
|
|
1050
|
-
```
|
|
1051
|
-
|
|
1052
|
-
### Change Description
|
|
1053
|
-
|
|
1054
|
-
```ts
|
|
1055
|
-
await sock.groupUpdateDescription(jid, 'New Description!')
|
|
1056
|
-
```
|
|
1057
|
-
|
|
1058
|
-
### Change Settings
|
|
1059
|
-
|
|
1060
|
-
```ts
|
|
1061
|
-
// only allow admins to send messages
|
|
1062
|
-
await sock.groupSettingUpdate(jid, 'announcement')
|
|
1063
|
-
// allow everyone to send messages
|
|
1064
|
-
await sock.groupSettingUpdate(jid, 'not_announcement')
|
|
1065
|
-
// allow everyone to modify the group's settings -- like display picture etc.
|
|
1066
|
-
await sock.groupSettingUpdate(jid, 'unlocked')
|
|
1067
|
-
// only allow admins to modify the group's settings
|
|
1068
|
-
await sock.groupSettingUpdate(jid, 'locked')
|
|
1069
|
-
```
|
|
1070
|
-
|
|
1071
|
-
### Leave a Group
|
|
1072
|
-
|
|
1073
|
-
```ts
|
|
1074
|
-
// will throw error if it fails
|
|
1075
|
-
await sock.groupLeave(jid)
|
|
1076
|
-
```
|
|
1077
|
-
|
|
1078
|
-
### Get Invite Code
|
|
1079
|
-
|
|
1080
|
-
- To create link with code use `'https://chat.whatsapp.com/' + code`
|
|
1081
|
-
|
|
1082
|
-
```ts
|
|
1083
|
-
const code = await sock.groupInviteCode(jid)
|
|
1084
|
-
console.log('group code: ' + code)
|
|
1085
|
-
```
|
|
1086
|
-
|
|
1087
|
-
### Revoke Invite Code
|
|
1088
|
-
|
|
1089
|
-
```ts
|
|
1090
|
-
const code = await sock.groupRevokeInvite(jid)
|
|
1091
|
-
console.log('New group code: ' + code)
|
|
1092
|
-
```
|
|
1093
|
-
|
|
1094
|
-
### Join Using Invitation Code
|
|
1095
|
-
|
|
1096
|
-
- Code can't have `https://chat.whatsapp.com/`, only code
|
|
1097
|
-
|
|
1098
|
-
```ts
|
|
1099
|
-
const response = await sock.groupAcceptInvite(code)
|
|
1100
|
-
console.log('joined to: ' + response)
|
|
1101
|
-
```
|
|
1102
|
-
|
|
1103
|
-
### Get Group Info by Invite Code
|
|
277
|
+
#### sendList
|
|
1104
278
|
|
|
1105
279
|
```ts
|
|
1106
|
-
|
|
1107
|
-
console.log('group information: ' + response)
|
|
280
|
+
await sock.sendList(jid, 'Todo', ['Buy milk', 'Call mom', 'Push code'], quotedMsg)
|
|
1108
281
|
```
|
|
1109
282
|
|
|
1110
|
-
|
|
283
|
+
#### sendCodeBlock
|
|
1111
284
|
|
|
1112
285
|
```ts
|
|
1113
|
-
const
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
```ts
|
|
1120
|
-
const response = await sock.groupAcceptInviteV4(jid, groupInviteMessage)
|
|
1121
|
-
console.log('joined to: ' + response)
|
|
286
|
+
await sock.sendCodeBlock(jid, `const greet = name => \`Hello \${name}\``, quotedMsg, {
|
|
287
|
+
title: 'Example',
|
|
288
|
+
language: 'javascript'
|
|
289
|
+
})
|
|
290
|
+
// Supported: javascript, typescript, python (js, ts, py)
|
|
1122
291
|
```
|
|
1123
292
|
|
|
1124
|
-
|
|
293
|
+
#### sendLatex
|
|
1125
294
|
|
|
1126
295
|
```ts
|
|
1127
|
-
|
|
1128
|
-
|
|
296
|
+
await sock.sendLatex(jid, quotedMsg, {
|
|
297
|
+
text: 'Quadratic formula:',
|
|
298
|
+
expressions: [{ latexExpression: 'x = \\frac{-b \\pm \\sqrt{b^2-4ac}}{2a}' }]
|
|
299
|
+
})
|
|
1129
300
|
```
|
|
1130
301
|
|
|
1131
|
-
|
|
302
|
+
#### sendLatexImage
|
|
1132
303
|
|
|
1133
304
|
```ts
|
|
1134
|
-
|
|
1135
|
-
jid,
|
|
1136
|
-
|
|
1137
|
-
|
|
305
|
+
await sock.sendLatexImage(
|
|
306
|
+
jid,
|
|
307
|
+
quotedMsg,
|
|
308
|
+
{ expressions: [{ latexExpression: 'e^{i\\pi}+1=0' }] },
|
|
309
|
+
async latex => renderToPng(latex), // → { buffer, width, height }
|
|
310
|
+
async (buf, type) => uploadToWA(buf, type) // → { url?, directPath? }
|
|
1138
311
|
)
|
|
1139
|
-
console.log(response)
|
|
1140
312
|
```
|
|
1141
313
|
|
|
1142
|
-
|
|
314
|
+
#### sendLatexInlineImage
|
|
1143
315
|
|
|
1144
|
-
|
|
1145
|
-
const response = await sock.groupFetchAllParticipating()
|
|
1146
|
-
console.log(response)
|
|
1147
|
-
```
|
|
316
|
+
Same as `sendLatexImage` but each expression renders as its own inline image block.
|
|
1148
317
|
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
- Ephemeral can be:
|
|
1152
|
-
|
|
1153
|
-
| Time | Seconds |
|
|
1154
|
-
| ------ | --------- |
|
|
1155
|
-
| Remove | 0 |
|
|
1156
|
-
| 24h | 86.400 |
|
|
1157
|
-
| 7d | 604.800 |
|
|
1158
|
-
| 90d | 7.776.000 |
|
|
318
|
+
#### sendRichMessage
|
|
1159
319
|
|
|
1160
320
|
```ts
|
|
1161
|
-
|
|
1162
|
-
```
|
|
321
|
+
import { RichSubMessageType } from 'anya-bail'
|
|
1163
322
|
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
```ts
|
|
1167
|
-
await sock.groupMemberAddMode(
|
|
323
|
+
await sock.sendRichMessage(
|
|
1168
324
|
jid,
|
|
1169
|
-
|
|
325
|
+
[
|
|
326
|
+
{ messageType: RichSubMessageType.TEXT, messageText: 'Hello from bot!' },
|
|
327
|
+
{
|
|
328
|
+
messageType: RichSubMessageType.TABLE,
|
|
329
|
+
tableMetadata: {
|
|
330
|
+
title: 'Data',
|
|
331
|
+
rows: [{ items: ['Key', 'Value'], isHeading: true }, { items: ['status', 'ok'] }]
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
],
|
|
335
|
+
quotedMsg
|
|
1170
336
|
)
|
|
1171
337
|
```
|
|
1172
338
|
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
### Block/Unblock User
|
|
1176
|
-
|
|
1177
|
-
```ts
|
|
1178
|
-
await sock.updateBlockStatus(jid, 'block') // Block user
|
|
1179
|
-
await sock.updateBlockStatus(jid, 'unblock') // Unblock user
|
|
1180
|
-
```
|
|
1181
|
-
|
|
1182
|
-
### Get Privacy Settings
|
|
339
|
+
#### captureUnifiedResponse / sendUnifiedResponse
|
|
1183
340
|
|
|
1184
341
|
```ts
|
|
1185
|
-
|
|
1186
|
-
|
|
342
|
+
sock.ev.on('messages.upsert', async ({ messages }) => {
|
|
343
|
+
for (const msg of messages) {
|
|
344
|
+
const captured = sock.captureUnifiedResponse(msg.message)
|
|
345
|
+
if (captured) {
|
|
346
|
+
await sock.sendUnifiedResponse(otherJid, quotedMsg, captured)
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
})
|
|
1187
350
|
```
|
|
1188
351
|
|
|
1189
|
-
|
|
352
|
+
---
|
|
1190
353
|
|
|
1191
|
-
|
|
1192
|
-
const response = await sock.fetchBlocklist()
|
|
1193
|
-
console.log(response)
|
|
1194
|
-
```
|
|
1195
|
-
|
|
1196
|
-
### Update LastSeen Privacy
|
|
354
|
+
## Calls
|
|
1197
355
|
|
|
1198
356
|
```ts
|
|
1199
|
-
|
|
1200
|
-
await sock.
|
|
1201
|
-
|
|
357
|
+
// Outgoing call
|
|
358
|
+
const { callId } = await sock.initiateCall(jid, { isVideo: false })
|
|
359
|
+
await sock.acceptCall(jid, callId)
|
|
360
|
+
await sock.preacceptCall(jid, callId)
|
|
361
|
+
await sock.muteCall(jid, callId, { isMuted: true })
|
|
362
|
+
await sock.terminateCall(jid, callId)
|
|
363
|
+
await sock.cancelCall(jid, callId)
|
|
1202
364
|
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
const value = 'all' // 'match_last_seen'
|
|
1207
|
-
await sock.updateOnlinePrivacy(value)
|
|
365
|
+
// Group call links
|
|
366
|
+
const link = await sock.queryCallLink(callLinkToken)
|
|
367
|
+
await sock.joinCallLink(callLinkToken)
|
|
1208
368
|
```
|
|
1209
369
|
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
```ts
|
|
1213
|
-
const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
|
|
1214
|
-
await sock.updateProfilePicturePrivacy(value)
|
|
1215
|
-
```
|
|
370
|
+
---
|
|
1216
371
|
|
|
1217
|
-
|
|
372
|
+
## Auth State
|
|
1218
373
|
|
|
1219
374
|
```ts
|
|
1220
|
-
|
|
1221
|
-
await
|
|
1222
|
-
```
|
|
375
|
+
// Multi-file (default)
|
|
376
|
+
const { state, saveCreds } = await useMultiFileAuthState('./auth_info')
|
|
1223
377
|
|
|
1224
|
-
|
|
378
|
+
// Single-file
|
|
379
|
+
import { useSingleFileAuthState } from 'anya-bail'
|
|
380
|
+
const { state, saveState } = useSingleFileAuthState('./auth.json')
|
|
1225
381
|
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
await
|
|
1229
|
-
```
|
|
1230
|
-
|
|
1231
|
-
### Update Groups Add Privacy
|
|
1232
|
-
|
|
1233
|
-
```ts
|
|
1234
|
-
const value = 'all' // 'contacts' | 'contact_blacklist'
|
|
1235
|
-
await sock.updateGroupsAddPrivacy(value)
|
|
382
|
+
// MongoDB
|
|
383
|
+
import { useMongoFileAuthState } from 'anya-bail'
|
|
384
|
+
const { state, saveCreds } = await useMongoFileAuthState(mongoCollection)
|
|
1236
385
|
```
|
|
1237
386
|
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
- Like [this](#disappearing-messages), ephemeral can be:
|
|
387
|
+
---
|
|
1241
388
|
|
|
1242
|
-
|
|
1243
|
-
| ------ | --------- |
|
|
1244
|
-
| Remove | 0 |
|
|
1245
|
-
| 24h | 86.400 |
|
|
1246
|
-
| 7d | 604.800 |
|
|
1247
|
-
| 90d | 7.776.000 |
|
|
389
|
+
## MEX Notifications
|
|
1248
390
|
|
|
1249
391
|
```ts
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
## Broadcast Lists & Stories
|
|
392
|
+
// Newsletter
|
|
393
|
+
sock.ev.on('newsletter-settings.update', ({ id, update }) => {})
|
|
394
|
+
sock.ev.on('newsletter-participants.update', ({ id, user, new_role }) => {})
|
|
1255
395
|
|
|
1256
|
-
|
|
396
|
+
// Linked profiles (LID ↔ PN mapping)
|
|
397
|
+
sock.ev.on('lid-mapping.update', ({ lid, pn }) => {})
|
|
1257
398
|
|
|
1258
|
-
|
|
399
|
+
// Message capping quota
|
|
400
|
+
sock.ev.on('message-capping.update', ({ used_quota, total_quota }) => {})
|
|
1259
401
|
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
image: {
|
|
1265
|
-
url: url
|
|
1266
|
-
},
|
|
1267
|
-
caption: caption
|
|
1268
|
-
},
|
|
1269
|
-
{
|
|
1270
|
-
backgroundColor: backgroundColor,
|
|
1271
|
-
font: font,
|
|
1272
|
-
statusJidList: statusJidList,
|
|
1273
|
-
broadcast: true
|
|
402
|
+
// WA Business reachout timelock
|
|
403
|
+
sock.ev.on('connection.update', ({ reachoutTimeLock }) => {
|
|
404
|
+
if (reachoutTimeLock?.isActive) {
|
|
405
|
+
console.log('Restricted until:', reachoutTimeLock.timeEnforcementEnds)
|
|
1274
406
|
}
|
|
1275
|
-
)
|
|
1276
|
-
```
|
|
1277
|
-
|
|
1278
|
-
- Message body can be a `extendedTextMessage` or `imageMessage` or `videoMessage` or `voiceMessage`, see [here](https://baileys.whiskeysockets.io/types/AnyRegularMessageContent.html)
|
|
1279
|
-
- You can add `backgroundColor` and other options in the message options, see [here](https://baileys.whiskeysockets.io/types/MiscMessageGenerationOptions.html)
|
|
1280
|
-
- `broadcast: true` enables broadcast mode
|
|
1281
|
-
- `statusJidList`: a list of people that you can get which you need to provide, which are the people who will get this status message.
|
|
1282
|
-
|
|
1283
|
-
- You can send messages to broadcast lists the same way you send messages to groups & individual chats.
|
|
1284
|
-
- Right now, WA Web does not support creating broadcast lists, but you can still delete them.
|
|
1285
|
-
- Broadcast IDs are in the format `12345678@broadcast`
|
|
1286
|
-
|
|
1287
|
-
### Query a Broadcast List's Recipients & Name
|
|
1288
|
-
|
|
1289
|
-
```ts
|
|
1290
|
-
const bList = await sock.getBroadcastListInfo('1234@broadcast')
|
|
1291
|
-
console.log(`list name: ${bList.name}, recps: ${bList.recipients}`)
|
|
1292
|
-
```
|
|
1293
|
-
|
|
1294
|
-
## Writing Custom Functionality
|
|
1295
|
-
|
|
1296
|
-
Baileys is written with custom functionality in mind. Instead of forking the project & re-writing the internals, you can simply write your own extensions.
|
|
1297
|
-
|
|
1298
|
-
### Enabling Debug Level in Baileys Logs
|
|
1299
|
-
|
|
1300
|
-
First, enable the logging of unhandled messages from WhatsApp by setting:
|
|
1301
|
-
|
|
1302
|
-
```ts
|
|
1303
|
-
const sock = makeWASocket({
|
|
1304
|
-
logger: P({ level: 'debug' })
|
|
1305
407
|
})
|
|
1306
|
-
```
|
|
1307
|
-
|
|
1308
|
-
This will enable you to see all sorts of messages WhatsApp sends in the console.
|
|
1309
|
-
|
|
1310
|
-
### How Whatsapp Communicate With Us
|
|
1311
|
-
|
|
1312
|
-
> [!TIP]
|
|
1313
|
-
> If you want to learn whatsapp protocol, we recommend to study about Libsignal Protocol and Noise Protocol
|
|
1314
|
-
|
|
1315
|
-
- **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:
|
|
1316
|
-
```
|
|
1317
|
-
{
|
|
1318
|
-
"level": 10,
|
|
1319
|
-
"fromMe": false,
|
|
1320
|
-
"frame": {
|
|
1321
|
-
"tag": "ib",
|
|
1322
|
-
"attrs": {
|
|
1323
|
-
"from": "@s.whatsapp.net"
|
|
1324
|
-
},
|
|
1325
|
-
"content": [
|
|
1326
|
-
{
|
|
1327
|
-
"tag": "edge_routing",
|
|
1328
|
-
"attrs": {},
|
|
1329
|
-
"content": [
|
|
1330
|
-
{
|
|
1331
|
-
"tag": "routing_info",
|
|
1332
|
-
"attrs": {},
|
|
1333
|
-
"content": {
|
|
1334
|
-
"type": "Buffer",
|
|
1335
|
-
"data": [8,2,8,5]
|
|
1336
|
-
}
|
|
1337
|
-
}
|
|
1338
|
-
]
|
|
1339
|
-
}
|
|
1340
|
-
]
|
|
1341
|
-
},
|
|
1342
|
-
"msg":"communication"
|
|
1343
|
-
}
|
|
1344
|
-
```
|
|
1345
|
-
|
|
1346
|
-
The `'frame'` is what the message received is, it has three components:
|
|
1347
|
-
|
|
1348
|
-
- `tag` -- what this frame is about (eg. message will have 'message')
|
|
1349
|
-
- `attrs` -- a string key-value pair with some metadata (contains ID of the message usually)
|
|
1350
|
-
- `content` -- the actual data (eg. a message node will have the actual message content in it)
|
|
1351
|
-
- read more about this format [here](/src/WABinary/readme.md)
|
|
1352
|
-
|
|
1353
|
-
### Register a Callback for Websocket Events
|
|
1354
|
-
|
|
1355
|
-
> [!TIP]
|
|
1356
|
-
> Recommended to see `onMessageReceived` function in `socket.ts` file to understand how websockets events are fired
|
|
1357
|
-
|
|
1358
|
-
```ts
|
|
1359
|
-
// for any message with tag 'edge_routing'
|
|
1360
|
-
sock.ws.on('CB:edge_routing', (node: BinaryNode) => {})
|
|
1361
|
-
|
|
1362
|
-
// for any message with tag 'edge_routing' and id attribute = abcd
|
|
1363
|
-
sock.ws.on('CB:edge_routing,id:abcd', (node: BinaryNode) => {})
|
|
1364
408
|
|
|
1365
|
-
//
|
|
1366
|
-
sock.
|
|
409
|
+
// History sync completion / stall
|
|
410
|
+
sock.ev.on('messaging-history.status', ({ syncType, status, explicit }) => {
|
|
411
|
+
console.log(`History sync ${status} (${syncType}) explicit=${explicit}`)
|
|
412
|
+
})
|
|
1367
413
|
```
|
|
1368
414
|
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
415
|
+
---
|
|
416
|
+
|
|
417
|
+
## Addons
|
|
418
|
+
|
|
419
|
+
```ts
|
|
420
|
+
import { buildVCard, AutoReplyEngine, createScheduler, ... } from 'anya-bail'
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
| Addon | Description |
|
|
424
|
+
| --------------------- | ---------------------------------------------------- |
|
|
425
|
+
| `message-composer` | Rich/bot message builders (table, list, code, latex) |
|
|
426
|
+
| `button-sender` | Interactive / native-flow button helpers |
|
|
427
|
+
| `call-handler` | Inbound call handling |
|
|
428
|
+
| `auto-reply` | Rule-based auto-reply engine |
|
|
429
|
+
| `scheduling` | Message queue + scheduled sending |
|
|
430
|
+
| `anti-delete` | Detect and recover deleted messages |
|
|
431
|
+
| `vcard` | Build vCard contact strings |
|
|
432
|
+
| `message-search` | Search messages by type/text/regex |
|
|
433
|
+
| `status-posting` | Broadcast statuses to multiple JIDs |
|
|
434
|
+
| `jid-plotting` | JID resolution + LID/PN mapping helpers |
|
|
435
|
+
| `templates` | Template message variable helpers |
|
|
436
|
+
| `interactive-message` | Interactive message utilities |
|
|
437
|
+
| `from-messages` | Message processing helpers |
|
|
438
|
+
| `from-messages-recv` | Inbound message helpers |
|
|
439
|
+
| `from-messages-send` | Outbound message helpers |
|
|
440
|
+
| `from-chats` | Chat event helpers |
|
|
441
|
+
|
|
442
|
+
---
|
|
443
|
+
|
|
444
|
+
## Changelog
|
|
445
|
+
|
|
446
|
+
### v8.0.0 — April 2026 (anya-bail)
|
|
447
|
+
|
|
448
|
+
**Based on:** WhiskeySockets/Baileys master (April 2026) + InnovatorsSOFT Baileys additions
|
|
449
|
+
|
|
450
|
+
**Added over upstream:**
|
|
451
|
+
|
|
452
|
+
- Full interactive/button/template/list/cards/carousel message system
|
|
453
|
+
- Album messages with `albumParentKey` support
|
|
454
|
+
- Sticker pack messages
|
|
455
|
+
- Share/Request phone number messages
|
|
456
|
+
- AI icon on any message (`options.ai = true`)
|
|
457
|
+
- Rich response / Meta AI messages — `sendTable`, `sendList`, `sendCodeBlock`, `sendLatex`, `sendLatexImage`, `sendLatexInlineImage`, `sendRichMessage`, `captureUnifiedResponse`, `sendUnifiedResponse`
|
|
458
|
+
- Full outgoing call API (`initiateCall`, `acceptCall`, `preacceptCall`, `muteCall`, `terminateCall`, `cancelCall`, `queryCallLink`, `joinCallLink`)
|
|
459
|
+
- Full MEX notification dispatcher — reachout timelock, message capping, linked profiles, newsletter ops
|
|
460
|
+
- `messaging-history.status` event with pause timeout (120s)
|
|
461
|
+
- `message-capping.update` event
|
|
462
|
+
- `authorUsername` in group participant events
|
|
463
|
+
- `chunkOrder` in history sync
|
|
464
|
+
- MongoDB + single-file auth states
|
|
465
|
+
- Extended browser map: iOS, Android, androidCompanion, Linux, KaiOS, ChromeOS
|
|
466
|
+
- `getPlatformDisplayName()` utility
|
|
467
|
+
- Pairing race-condition fix (`sendPairingIQ` + queue)
|
|
468
|
+
- `buildPairingQRData` from companion-reg-client-utils
|
|
469
|
+
- tctoken issuance + prune system (daily cleanup on reconnect)
|
|
470
|
+
- App state sync resilience: `forceSnapshotCollections`, `blockedCollections`
|
|
471
|
+
- `ensureLTHashStateVersion`, `isMissingKeyError`, `isAppStateSyncIrrecoverable`, `MAX_SYNC_ATTEMPTS`
|
|
472
|
+
- `storeTcTokensFromHistorySync` — saves tctokens from history sync chats
|
|
473
|
+
- `SERVER_ERROR_CODES` (463 MissingTcToken, 479 SmaxInvalid)
|
|
474
|
+
- Username fields in Contact, GroupMetadata, GroupParticipant, WAMessageKey
|
|
475
|
+
- `isJidBot`, `isJidMetaAI`, `PSA_WID` exports
|
|
476
|
+
- `onBeforeSessionRefresh` in identity change handler
|
|
477
|
+
- `QueryIdd`, `MexOperations`, `XWAPathsMexUpdates` in Newsletter types
|
|
478
|
+
- 18-file addons layer
|
|
479
|
+
- Message ID prefix: `4NY4W3B`
|
|
480
|
+
- WA version: `2.3000.1037656372`
|
|
481
|
+
|
|
482
|
+
---
|
|
483
|
+
|
|
484
|
+
> Based on [WhiskeySockets/Baileys](https://github.com/WhiskeySockets/Baileys) and [InnovatorsSOFT/Baileys](https://github.com/InnovatorsSOFT/Baileys). Not affiliated with WhatsApp or Meta.
|