angularsockets 1.0.3 → 1.4.1
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/LICENSE +21 -0
- package/README.MD +170 -0
- package/README.md +163 -1813
- package/WAProto/GenerateStatics.sh +4 -0
- package/WAProto/WAProto.proto +4775 -0
- package/WAProto/index.d.ts +4798 -124
- package/WAProto/index.js +14270 -302
- package/WAProto/index.ts.ts +53473 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +4 -6
- package/lib/Defaults/index.js +4 -6
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.d.ts +14 -0
- package/lib/Signal/Group/group-session-builder.js +64 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +96 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +57 -0
- package/lib/Signal/Group/keyhelper.d.ts +10 -0
- package/lib/Signal/Group/keyhelper.js +55 -0
- package/lib/Signal/Group/queue-job.d.ts +1 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-chain-key.js +34 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-message.js +69 -0
- package/lib/Signal/Group/sender-key-name.d.ts +17 -0
- package/lib/Signal/Group/sender-key-name.js +51 -0
- package/lib/Signal/Group/sender-key-record.d.ts +30 -0
- package/lib/Signal/Group/sender-key-record.js +53 -0
- package/lib/Signal/Group/sender-key-state.d.ts +38 -0
- package/lib/Signal/Group/sender-key-state.js +99 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +6 -16
- package/lib/Signal/libsignal.js +51 -29
- package/lib/Socket/Client/index.d.ts +2 -3
- package/lib/Socket/Client/index.js +2 -3
- package/lib/Socket/Client/{abstract-socket-client.d.ts → types.d.ts} +1 -2
- package/lib/Socket/Client/{web-socket-client.d.ts → websocket.d.ts} +2 -1
- package/lib/Socket/Client/{web-socket-client.js → websocket.js} +54 -5
- package/lib/Socket/RHandler.d.ts +416 -0
- package/lib/Socket/RHandler.js +530 -0
- package/lib/Socket/business.d.ts +39 -37
- package/lib/Socket/chats.d.ts +36 -23
- package/lib/Socket/chats.js +74 -116
- package/lib/Socket/groups.d.ts +42 -33
- package/lib/Socket/groups.js +26 -9
- package/lib/Socket/index.d.ts +39 -39
- package/lib/Socket/index.js +2 -2
- package/lib/Socket/messages-recv.d.ts +37 -34
- package/lib/Socket/messages-recv.js +111 -29
- package/lib/Socket/messages-send.d.ts +50 -53
- package/lib/Socket/messages-send.js +213 -397
- package/lib/Socket/newsletter.d.ts +25 -21
- package/lib/Socket/newsletter.js +92 -25
- package/lib/Socket/socket.d.ts +10 -11
- package/lib/Socket/socket.js +34 -23
- package/lib/Socket/usync.d.ts +11 -12
- package/lib/Store/index.d.ts +1 -2
- package/lib/Store/index.js +1 -3
- package/lib/Store/make-in-memory-store.d.ts +22 -22
- package/lib/Store/make-in-memory-store.js +21 -13
- package/lib/Store/make-ordered-dictionary.d.ts +1 -1
- package/lib/Types/Auth.d.ts +0 -6
- package/lib/Types/Chat.d.ts +6 -4
- package/lib/Types/Contact.d.ts +5 -1
- package/lib/Types/Events.d.ts +27 -0
- package/lib/Types/GroupMetadata.d.ts +8 -0
- package/lib/Types/Label.d.ts +0 -11
- package/lib/Types/Message.d.ts +59 -90
- package/lib/Types/Message.js +0 -2
- package/lib/Types/Newsletter.d.ts +97 -86
- package/lib/Types/Newsletter.js +38 -32
- package/lib/Types/Socket.d.ts +10 -7
- package/lib/Types/index.d.ts +1 -3
- package/lib/Types/index.js +1 -1
- package/lib/Utils/audioToBuffer.js +29 -0
- package/lib/Utils/auth-utils.d.ts +3 -3
- package/lib/Utils/auth-utils.js +13 -41
- package/lib/Utils/business.d.ts +1 -1
- package/lib/Utils/chat-utils.d.ts +12 -12
- package/lib/Utils/chat-utils.js +4 -19
- package/lib/Utils/crypto.d.ts +15 -15
- package/lib/Utils/crypto.js +6 -12
- package/lib/Utils/decode-wa-message.d.ts +5 -6
- package/lib/Utils/decode-wa-message.js +28 -55
- package/lib/Utils/event-buffer.d.ts +2 -2
- package/lib/Utils/event-buffer.js +2 -1
- package/lib/Utils/generics.d.ts +12 -11
- package/lib/Utils/generics.js +64 -38
- package/lib/Utils/history.d.ts +2 -2
- package/lib/Utils/history.js +1 -1
- package/lib/Utils/index.d.ts +2 -0
- package/lib/Utils/index.js +3 -0
- package/lib/Utils/link-preview.d.ts +2 -2
- package/lib/Utils/link-preview.js +34 -1
- package/lib/Utils/logger.d.ts +10 -1
- package/lib/Utils/lt-hash.d.ts +2 -2
- package/lib/Utils/lt-hash.js +6 -6
- package/lib/Utils/messages-media.d.ts +40 -29
- package/lib/Utils/messages-media.js +276 -110
- package/lib/Utils/messages.d.ts +8 -10
- package/lib/Utils/messages.js +126 -317
- package/lib/Utils/noise-handler.d.ts +10 -11
- package/lib/Utils/noise-handler.js +3 -13
- package/lib/Utils/process-message.d.ts +3 -2
- package/lib/Utils/process-message.js +17 -5
- package/lib/Utils/signal.js +2 -8
- package/lib/Utils/streamToBuffer.js +15 -0
- package/lib/Utils/use-multi-file-auth-state.js +72 -242
- package/lib/Utils/validate-connection.d.ts +2 -3
- package/lib/Utils/validate-connection.js +19 -51
- package/lib/WABinary/constants.d.ts +4 -4
- package/lib/WABinary/constants.js +1276 -13
- package/lib/WABinary/decode.d.ts +2 -2
- package/lib/WABinary/decode.js +3 -2
- package/lib/WABinary/encode.js +5 -7
- package/lib/WABinary/generic-utils.d.ts +2 -2
- package/lib/WABinary/jid-utils.d.ts +9 -4
- package/lib/WABinary/jid-utils.js +26 -5
- package/lib/WABinary/jid-utils.js.bak +83 -0
- package/lib/WAM/encode.d.ts +1 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +3 -3
- package/lib/WAUSync/USyncUser.d.ts +2 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.js +48 -4
- package/lib/index.js.bak +56 -0
- package/package.json +43 -35
- package/WASignalGroup/GroupProtocol.js +0 -1697
- package/WASignalGroup/ciphertext_message.js +0 -16
- package/WASignalGroup/group_cipher.js +0 -120
- package/WASignalGroup/group_session_builder.js +0 -46
- package/WASignalGroup/index.js +0 -5
- package/WASignalGroup/keyhelper.js +0 -21
- package/WASignalGroup/protobufs.js +0 -3
- package/WASignalGroup/queue_job.js +0 -69
- package/WASignalGroup/sender_chain_key.js +0 -50
- package/WASignalGroup/sender_key_distribution_message.js +0 -78
- package/WASignalGroup/sender_key_message.js +0 -92
- package/WASignalGroup/sender_key_name.js +0 -70
- package/WASignalGroup/sender_key_record.js +0 -56
- package/WASignalGroup/sender_key_state.js +0 -129
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/registration.d.ts +0 -264
- package/lib/Socket/registration.js +0 -166
- package/lib/Store/make-cache-manager-store.d.ts +0 -14
- package/lib/Store/make-cache-manager-store.js +0 -83
- package/lib/Utils/use-single-file-auth-state.d.ts +0 -12
- package/lib/Utils/use-single-file-auth-state.js +0 -75
- /package/lib/Socket/Client/{abstract-socket-client.js → types.js} +0 -0
package/README.md
CHANGED
|
@@ -1,1900 +1,250 @@
|
|
|
1
|
-
# <div align='center'>Angular Sockets |WhatsApp Web API</div>
|
|
2
|
-
|
|
3
|
-
<div align='center'>
|
|
4
|
-
|
|
5
|
-

|
|
6
1
|
|
|
2
|
+
<div align="center">
|
|
3
|
+
<h1>✨ angularsockets</h1>
|
|
4
|
+
<p><em>Custom WhatsApp library built upon Baileys — enhanced, modernized, and elegant ✨</em></p>
|
|
5
|
+
|
|
6
|
+
<img src="https://files.catbox.moe/dmz2fn.jpg" width="300" alt="Elaina Bail Banner" />
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
<p>
|
|
11
|
+
<a href="https://www.npmjs.com/package/angularsockets">
|
|
12
|
+
<img src="https://img.shields.io/npm/v/angularsockets?color=blueviolet&label=version&logo=npm" alt="npm version" />
|
|
13
|
+
</a>
|
|
14
|
+
<a href="https://www.npmjs.com/package/angularsockets">
|
|
15
|
+
<img src="https://img.shields.io/npm/dt/angularsockets?color=blueviolet&label=downloads&logo=npm" alt="npm downloads" />
|
|
16
|
+
</a>
|
|
17
|
+
<a href="https://whatsapp.com/channel/0029VapYyKEGufIpsd3Rja2C">
|
|
18
|
+
<img src="https://img.shields.io/badge/Join-WhatsApp%20Channel-25D366?logo=whatsapp&logoColor=white" alt="WhatsApp Channel" />
|
|
19
|
+
</a>
|
|
20
|
+
</p>
|
|
7
21
|
</div>
|
|
8
22
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
This modified version of Baileys was created with the intention of empowering developers, but it **must be used responsibly**. The maintainers **strongly discourage** any usage that goes against WhatsApp’s [Terms of Service](https://www.whatsapp.com/legal/terms-of-service). This includes—but is not limited to—spamming, bulk or automated messaging, stalking, scraping user data, or deploying it in any way that violates privacy, consent, or platform integrity.
|
|
16
|
-
|
|
17
|
-
This project is provided **as-is** and should be used with **extreme caution**.
|
|
18
|
-
**You are solely responsible** for how you choose to use this library. Always ensure your use case is ethical, legal, and respects the rights and privacy of others.
|
|
19
|
-
|
|
20
|
-
**Use at your own discretion.** Respect platform rules, user boundaries, and stay within legal and moral lines.
|
|
21
|
-
|
|
22
|
-
## Example
|
|
23
|
-
|
|
24
|
-
Here is an example you can use: [example.ts](Example/example.ts) or here is a tutorial for running the Baileys WhatsApp API code
|
|
25
|
-
1. ``` cd path/to/Angularsockets ```
|
|
26
|
-
2. ``` npm install```
|
|
27
|
-
3. ``` node example.js```
|
|
28
|
-
|
|
29
|
-
## Install
|
|
30
|
-
|
|
31
|
-
Use the stable version:
|
|
32
|
-
```bash
|
|
33
|
-
npm install angularsockets
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
Use the edge version (no guarantee of stability, but latest fixes + features)
|
|
37
|
-
```bash
|
|
38
|
-
yarn add angularsockets@latest
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
Then import your code using:
|
|
42
|
-
```javascript
|
|
43
|
-
const { default: makeWASocket } = require("angularsockets")
|
|
44
|
-
```
|
|
45
|
-
# Links
|
|
46
|
-
|
|
47
|
-
#### Official
|
|
48
|
-
- [Discord](https://discord.gg/WeJM5FP9GG)
|
|
49
|
-
- [Docs](https://guide.whiskeysockets.io/)
|
|
50
|
-
|
|
51
|
-
#### AngularSockets
|
|
52
|
-
- [WhatsApp](https://whatsapp.com/channel/0029Vb89ifxH5JM0fh2VvM2U)
|
|
53
|
-
|
|
54
|
-
# Index
|
|
55
|
-
|
|
56
|
-
- [Connecting Account](#connecting-account)
|
|
57
|
-
- [Connect with QR-CODE](#starting-socket-with-qr-code)
|
|
58
|
-
- [Connect with Pairing Code](#starting-socket-with-pairing-code)
|
|
59
|
-
- [Receive Full History](#receive-full-history)
|
|
60
|
-
- [Important Notes About Socket Config](#important-notes-about-socket-config)
|
|
61
|
-
- [Caching Group Metadata (Recommended)](#caching-group-metadata-recommended)
|
|
62
|
-
- [Improve Retry System & Decrypt Poll Votes](#improve-retry-system--decrypt-poll-votes)
|
|
63
|
-
- [Receive Notifications in Whatsapp App](#receive-notifications-in-whatsapp-app)
|
|
64
|
-
- [Custom generateMessageID Function](#custom-generatemessageid-function)
|
|
65
|
-
- [Save Auth Info](#saving--restoring-sessions)
|
|
66
|
-
- [Handling Events](#handling-events)
|
|
67
|
-
- [Example to Start](#example-to-start)
|
|
68
|
-
- [Decrypt Poll Votes](#decrypt-poll-votes)
|
|
69
|
-
- [Summary of Events on First Connection](#summary-of-events-on-first-connection)
|
|
70
|
-
- [Implementing a Data Store](#implementing-a-data-store)
|
|
71
|
-
- [Whatsapp IDs Explain](#whatsapp-ids-explain)
|
|
72
|
-
- [Utility Functions](#utility-functions)
|
|
73
|
-
- [Sending Messages](#sending-messages)
|
|
74
|
-
- [Non-Media Messages](#non-media-messages)
|
|
75
|
-
- [Buttons Message](#buttons-message)
|
|
76
|
-
- [Buttons Flow](#buttons-flow)
|
|
77
|
-
- [Interactive Message](#interactive-message)
|
|
78
|
-
- [Text Message](#text-message)
|
|
79
|
-
- [Quote Message](#quote-message-works-with-all-types)
|
|
80
|
-
- [Mention User](#mention-user-works-with-most-types)
|
|
81
|
-
- [Mention Status](#mention-status)
|
|
82
|
-
- [Result Poll From Newsletter](#result-poll-from-newsletter)
|
|
83
|
-
- [SendAlbumMessage](#send-album-message)
|
|
84
|
-
- [List Message](#list-message)
|
|
85
|
-
- [Carousel Message](#carousel-message)
|
|
86
|
-
- [Interactive Response](#interactive-response)
|
|
87
|
-
- [Request Payment](#request-payment)
|
|
88
|
-
- [Event Message](#event-message)
|
|
89
|
-
- [Interactive](#interactive)
|
|
90
|
-
- [Forward Messages](#forward-messages)
|
|
91
|
-
- [Location Message](#location-message)
|
|
92
|
-
- [Contact Message](#contact-message)
|
|
93
|
-
- [Reaction Message](#reaction-message)
|
|
94
|
-
- [Pin Message](#pin-message)
|
|
95
|
-
- [Poll Message](#poll-message)
|
|
96
|
-
- [Sending with Link Preview](#sending-messages-with-link-previews)
|
|
97
|
-
- [Media Messages](#media-messages)
|
|
98
|
-
- [Gif Message](#gif-message)
|
|
99
|
-
- [Video Message](#video-message)
|
|
100
|
-
- [Audio Message](#audio-message)
|
|
101
|
-
- [Image Message](#image-message)
|
|
102
|
-
- [ViewOnce Message](#view-once-message)
|
|
103
|
-
- [Modify Messages](#modify-messages)
|
|
104
|
-
- [Delete Messages (for everyone)](#deleting-messages-for-everyone)
|
|
105
|
-
- [Edit Messages](#editing-messages)
|
|
106
|
-
- [Manipulating Media Messages](#manipulating-media-messages)
|
|
107
|
-
- [Thumbnail in Media Messages](#thumbnail-in-media-messages)
|
|
108
|
-
- [Downloading Media Messages](#downloading-media-messages)
|
|
109
|
-
- [Re-upload Media Message to Whatsapp](#re-upload-media-message-to-whatsapp)
|
|
110
|
-
- [Reject Call](#reject-call)
|
|
111
|
-
- [Send States in Chat](#send-states-in-chat)
|
|
112
|
-
- [Reading Messages](#reading-messages)
|
|
113
|
-
- [Update Presence](#update-presence)
|
|
114
|
-
- [Modifying Chats](#modifying-chats)
|
|
115
|
-
- [Archive a Chat](#archive-a-chat)
|
|
116
|
-
- [Mute/Unmute a Chat](#muteunmute-a-chat)
|
|
117
|
-
- [Mark a Chat Read/Unread](#mark-a-chat-readunread)
|
|
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
|
-
- [Newsletter](#newsletter)
|
|
153
|
-
- [Subscribe to Newsletter Updates](#subscribe-to-newsletter-updates)
|
|
154
|
-
- [Update Reaction Mode](#update-reaction-mode)
|
|
155
|
-
- [Update Newsletter Description](#update-newsletter-description)
|
|
156
|
-
- [Update Newsletter Name](#update-newsletter-name)
|
|
157
|
-
- [Update Newsletter Picture](#update-newsletter-picture)
|
|
158
|
-
- [Remove Newsletter Picture](#remove-newsletter-picture)
|
|
159
|
-
- [Follow a Newsletter](#follow-a-newsletter)
|
|
160
|
-
- [Unfollow a Newsletter](#unfollow-a-newsletter)
|
|
161
|
-
- [Mute a Newsletter](#mute-a-newsletter)
|
|
162
|
-
- [Unmute a Newsletter](#unmute-a-newsletter)
|
|
163
|
-
- [Perform a Newsletter Action (Generic)](#perform-a-newsletter-action-generic)
|
|
164
|
-
- [Create a Newsletter](#create-a-newsletter)
|
|
165
|
-
- [Fetch Newsletter Metadata](#fetch-newsletter-metadata)
|
|
166
|
-
- [Get Admin Count](#get-admin-count)
|
|
167
|
-
- [Change Newsletter Owner](#change-newsletter-owner)
|
|
168
|
-
- [Demote Newsletter Admin](#demote-newsletter-admin)
|
|
169
|
-
- [Delete Newsletter](#delete-newsletter)
|
|
170
|
-
- [React to a Message in Newsletter](#react-to-a-message-in-newsletter)
|
|
171
|
-
- [Fetch Messages in Newsletter](#fetch-messages-in-newsletter)
|
|
172
|
-
- [Fetch Updates in Newsletter](#fetch-updates-in-newsletter)
|
|
173
|
-
- [Privacy](#privacy)
|
|
174
|
-
- [Block/Unblock User](#blockunblock-user)
|
|
175
|
-
- [Get Privacy Settings](#get-privacy-settings)
|
|
176
|
-
- [Get BlockList](#get-blocklist)
|
|
177
|
-
- [Update LastSeen Privacy](#update-lastseen-privacy)
|
|
178
|
-
- [Update Online Privacy](#update-online-privacy)
|
|
179
|
-
- [Update Profile Picture Privacy](#update-profile-picture-privacy)
|
|
180
|
-
- [Update Status Privacy](#update-status-privacy)
|
|
181
|
-
- [Update Read Receipts Privacy](#update-read-receipts-privacy)
|
|
182
|
-
- [Update Groups Add Privacy](#update-groups-add-privacy)
|
|
183
|
-
- [Update Default Disappearing Mode](#update-default-disappearing-mode)
|
|
184
|
-
- [Broadcast Lists & Stories](#broadcast-lists--stories)
|
|
185
|
-
- [Send Broadcast & Stories](#send-broadcast--stories)
|
|
186
|
-
- [Query a Broadcast List's Recipients & Name](#query-a-broadcast-lists-recipients--name)
|
|
187
|
-
- [Writing Custom Functionality](#writing-custom-functionality)
|
|
188
|
-
- [Enabling Debug Level in Baileys Logs](#enabling-debug-level-in-baileys-logs)
|
|
189
|
-
- [How Whatsapp Communicate With Us](#how-whatsapp-communicate-with-us)
|
|
190
|
-
- [Register a Callback for Websocket Events](#register-a-callback-for-websocket-events)
|
|
191
|
-
|
|
192
|
-
## Connecting Account
|
|
193
|
-
|
|
194
|
-
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.
|
|
195
|
-
|
|
196
|
-
### Starting socket with **QR-CODE**
|
|
197
|
-
|
|
198
|
-
> [!TIP]
|
|
199
|
-
> 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)**
|
|
200
|
-
|
|
201
|
-
```javascript
|
|
202
|
-
const { default: makeWASocket } = require("baileys-pro")
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
const sock = makeWASocket({
|
|
206
|
-
// can provide additional config here
|
|
207
|
-
browser: Browsers.ubuntu('My App'),
|
|
208
|
-
printQRInTerminal: true
|
|
209
|
-
})
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
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!
|
|
213
|
-
|
|
214
|
-
### Starting socket with **Pairing Code**
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
> [!IMPORTANT]
|
|
218
|
-
> 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)
|
|
219
|
-
|
|
220
|
-
The phone number can't have `+` or `()` or `-`, only numbers, you must provide country code
|
|
221
|
-
|
|
222
|
-
```javascript
|
|
223
|
-
const { default: makeWASocket } = require("baileys-pro")
|
|
224
|
-
|
|
225
|
-
const sock = makeWASocket({
|
|
226
|
-
// can provide additional config here
|
|
227
|
-
printQRInTerminal: false //need to be false
|
|
228
|
-
})
|
|
229
|
-
|
|
230
|
-
- Normal Pairing
|
|
231
|
-
if (!sock.authState.creds.registered) {
|
|
232
|
-
const number = 'XXXXXXXXXXX'
|
|
233
|
-
const code = await sock.requestPairingCode(number)
|
|
234
|
-
console.log(code)
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
- Costum Pairing
|
|
238
|
-
if (!sock.authState.creds.registered) {
|
|
239
|
-
const pair = "AB123C4D" // only 8 alphanumeric (no more or less)
|
|
240
|
-
const number = 'XXXXXXXXXXX'
|
|
241
|
-
const code = await sock.requestPairingCode(number, pair)
|
|
242
|
-
console.log(code)
|
|
243
|
-
}
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
### Receive Full History
|
|
247
|
-
|
|
248
|
-
1. Set `syncFullHistory` as `true`
|
|
249
|
-
2. Baileys, by default, use chrome browser config
|
|
250
|
-
- If you'd like to emulate a desktop connection (and receive more message history), this browser setting to your Socket config:
|
|
251
|
-
|
|
252
|
-
```javascript
|
|
253
|
-
const sock = makeWASocket({
|
|
254
|
-
...otherOpts,
|
|
255
|
-
// can use Windows, Ubuntu here too
|
|
256
|
-
browser: Browsers.macOS('Desktop'),
|
|
257
|
-
syncFullHistory: true
|
|
258
|
-
})
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
## Important Notes About Socket Config
|
|
262
|
-
|
|
263
|
-
### Caching Group Metadata (Recommended)
|
|
264
|
-
- If you use baileys for groups, we recommend you to set `cachedGroupMetadata` in socket config, you need to implement a cache like this:
|
|
265
|
-
|
|
266
|
-
```javascript
|
|
267
|
-
const groupCache = new NodeCache({stdTTL: 5 * 60, useClones: false})
|
|
268
|
-
|
|
269
|
-
const sock = makeWASocket({
|
|
270
|
-
cachedGroupMetadata: async (jid) => groupCache.get(jid)
|
|
271
|
-
})
|
|
272
|
-
|
|
273
|
-
sock.ev.on('groups.update', async ([event]) => {
|
|
274
|
-
const metadata = await sock.groupMetadata(event.id)
|
|
275
|
-
groupCache.set(event.id, metadata)
|
|
276
|
-
})
|
|
277
|
-
|
|
278
|
-
sock.ev.on('group-participants.update', async (event) => {
|
|
279
|
-
const metadata = await sock.groupMetadata(event.id)
|
|
280
|
-
groupCache.set(event.id, metadata)
|
|
281
|
-
})
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
### Improve Retry System & Decrypt Poll Votes
|
|
285
|
-
- 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:
|
|
286
|
-
```javascript
|
|
287
|
-
const sock = makeWASocket({
|
|
288
|
-
getMessage: async (key) => await getMessageFromStore(key)
|
|
289
|
-
})
|
|
290
|
-
```
|
|
291
|
-
|
|
292
|
-
### Receive Notifications in Whatsapp App
|
|
293
|
-
- If you want to receive notifications in whatsapp app, set `markOnlineOnConnect` to `false`
|
|
294
|
-
```javascript
|
|
295
|
-
const sock = makeWASocket({
|
|
296
|
-
markOnlineOnConnect: false
|
|
297
|
-
})
|
|
298
|
-
```
|
|
299
|
-
|
|
300
|
-
### Custom generateMessageID Function
|
|
301
|
-
- you can modify the messageId generator function against the socket
|
|
302
|
-
```javascript
|
|
303
|
-
const sock = makeWASocket({
|
|
304
|
-
generateMessageID: () => crypto.randomBytes(11).toString('hex').toUpperCase(),
|
|
305
|
-
generateMessageIDV2: (userId) => {
|
|
306
|
-
const hash = crypto.createHash('sha256').update(userId).digest('hex').toUpperCase();
|
|
307
|
-
const randomPart = crypto.randomBytes(11).toString('hex').toUpperCase();
|
|
308
|
-
const combined = hash + randomPart;
|
|
309
|
-
let result = '';
|
|
310
|
-
for (let i = 0; i < 22; i++) {
|
|
311
|
-
const randomIndex = crypto.randomBytes(1)[0] % combined.length;
|
|
312
|
-
result += combined[randomIndex];
|
|
313
|
-
}
|
|
314
|
-
return result;
|
|
315
|
-
}
|
|
316
|
-
})
|
|
317
|
-
```
|
|
318
|
-
## Saving & Restoring Sessions
|
|
319
|
-
|
|
320
|
-
You obviously don't want to keep scanning the QR code every time you want to connect.
|
|
321
|
-
|
|
322
|
-
So, you can load the credentials to log back in:
|
|
323
|
-
```javascript
|
|
324
|
-
const makeWASocket = require("baileys-pro").default;
|
|
325
|
-
const { useMultiFileAuthState } = require("baileys-pro");
|
|
326
|
-
|
|
327
|
-
// enable authDebug to display session logs
|
|
328
|
-
const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys', { authDebug: true })
|
|
329
|
-
|
|
330
|
-
// will use the given state to connect
|
|
331
|
-
// so if valid credentials are available -- it'll connect without QR
|
|
332
|
-
const sock = makeWASocket({ auth: state })
|
|
333
|
-
|
|
334
|
-
// this will be called as soon as the credentials are updated
|
|
335
|
-
sock.ev.on('creds.update', saveCreds)
|
|
336
|
-
```
|
|
337
|
-
|
|
338
|
-
You can sync cache on MultiFileAuthState
|
|
339
|
-
```javascript
|
|
340
|
-
const { state, saveCreds, cache: authCache } = await useMultiFileAuthState('auth_info_baileys', { syncCache: true })
|
|
341
|
-
|
|
342
|
-
const sock = makeWASocket({
|
|
343
|
-
auth: {
|
|
344
|
-
creds: state.creds,
|
|
345
|
-
keys: makeCacheableSignalKeyStore(
|
|
346
|
-
state.keys,
|
|
347
|
-
pino().child({ level: "silent", stream: "store" }),
|
|
348
|
-
authCache
|
|
349
|
-
)
|
|
350
|
-
}
|
|
351
|
-
})
|
|
352
|
-
|
|
353
|
-
sock.ev.on('creds.update', saveCreds)
|
|
354
|
-
```
|
|
355
|
-
|
|
356
|
-
> [!IMPORTANT]
|
|
357
|
-
> `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.
|
|
358
|
-
|
|
359
|
-
> [!NOTE]
|
|
360
|
-
> 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.
|
|
361
|
-
|
|
362
|
-
## Handling Events
|
|
363
|
-
|
|
364
|
-
- Baileys uses the EventEmitter syntax for events.
|
|
365
|
-
They're all nicely typed up, so you shouldn't have any issues with an Intellisense editor like VS Code.
|
|
366
|
-
|
|
367
|
-
> [!IMPORTANT]
|
|
368
|
-
> **The events are [these](https://baileys.whiskeysockets.io/types/BaileysEventMap.html)**, it's important you see all events
|
|
369
|
-
|
|
370
|
-
You can listen to these events like this:
|
|
371
|
-
```javascript
|
|
372
|
-
const sock = makeWASocket()
|
|
373
|
-
sock.ev.on('messages.upsert', ({ messages }) => {
|
|
374
|
-
console.log('got messages', messages)
|
|
375
|
-
})
|
|
376
|
-
```
|
|
377
|
-
|
|
378
|
-
### Example to Start
|
|
379
|
-
|
|
380
|
-
> [!NOTE]
|
|
381
|
-
> This example includes basic auth storage too
|
|
382
|
-
|
|
383
|
-
```javascript
|
|
384
|
-
const makeWASocket = require("baileys-pro").default;
|
|
385
|
-
const { DisconnectReason, useMultiFileAuthState } = require("baileys-pro");
|
|
386
|
-
const Boom = require('@hapi/boom');
|
|
387
|
-
|
|
388
|
-
async function connectToWhatsApp () {
|
|
389
|
-
const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')
|
|
390
|
-
const sock = makeWASocket({
|
|
391
|
-
// can provide additional config here
|
|
392
|
-
auth: state,
|
|
393
|
-
printQRInTerminal: true
|
|
394
|
-
})
|
|
395
|
-
sock.ev.on('connection.update', (update) => {
|
|
396
|
-
const { connection, lastDisconnect } = update
|
|
397
|
-
if(connection === 'close') {
|
|
398
|
-
const shouldReconnect = (lastDisconnect.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut
|
|
399
|
-
console.log('connection closed due to ', lastDisconnect.error, ', reconnecting ', shouldReconnect)
|
|
400
|
-
// reconnect if not logged out
|
|
401
|
-
if(shouldReconnect) {
|
|
402
|
-
connectToWhatsApp()
|
|
403
|
-
}
|
|
404
|
-
} else if(connection === 'open') {
|
|
405
|
-
console.log('opened connection')
|
|
406
|
-
}
|
|
407
|
-
})
|
|
408
|
-
sock.ev.on('messages.upsert', event => {
|
|
409
|
-
for (const m of event.messages) {
|
|
410
|
-
console.log(JSON.stringify(m, undefined, 2))
|
|
411
|
-
|
|
412
|
-
console.log('replying to', m.key.remoteJid)
|
|
413
|
-
await sock.sendMessage(m.key.remoteJid!, { text: 'Hello Word' })
|
|
414
|
-
}
|
|
415
|
-
})
|
|
416
|
-
|
|
417
|
-
// to storage creds (session info) when it updates
|
|
418
|
-
sock.ev.on('creds.update', saveCreds)
|
|
419
|
-
}
|
|
420
|
-
// run in main file
|
|
421
|
-
connectToWhatsApp()
|
|
422
|
-
```
|
|
423
|
-
|
|
424
|
-
> [!IMPORTANT]
|
|
425
|
-
> In `messages.upsert` it's recommended to use a loop like `for (const message of event.messages)` to handle all messages in array
|
|
426
|
-
|
|
427
|
-
### Decrypt Poll Votes
|
|
428
|
-
|
|
429
|
-
- By default poll votes are encrypted and handled in `messages.update`
|
|
430
|
-
- That's a simple example
|
|
431
|
-
```javascript
|
|
432
|
-
sock.ev.on('messages.update', event => {
|
|
433
|
-
for(const { key, update } of event) {
|
|
434
|
-
if(update.pollUpdates) {
|
|
435
|
-
const pollCreation = await getMessage(key)
|
|
436
|
-
if(pollCreation) {
|
|
437
|
-
console.log(
|
|
438
|
-
'got poll update, aggregation: ',
|
|
439
|
-
getAggregateVotesInPollMessage({
|
|
440
|
-
message: pollCreation,
|
|
441
|
-
pollUpdates: update.pollUpdates,
|
|
442
|
-
})
|
|
443
|
-
)
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
})
|
|
448
|
-
```
|
|
449
|
-
|
|
450
|
-
- `getMessage` is a [store](#implementing-a-data-store) implementation (in your end)
|
|
451
|
-
|
|
452
|
-
### Summary of Events on First Connection
|
|
453
|
-
|
|
454
|
-
1. When you connect first time, `connection.update` will be fired requesting you to restart sock
|
|
455
|
-
2. Then, history messages will be received in `messaging.history-set`
|
|
456
|
-
|
|
457
|
-
## Implementing a Data Store
|
|
458
|
-
|
|
459
|
-
- 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.
|
|
460
|
-
|
|
461
|
-
> [!IMPORTANT]
|
|
462
|
-
> I highly recommend building your own data store, as storing someone's entire chat history in memory is a terrible waste of RAM.
|
|
463
|
-
|
|
464
|
-
It can be used as follows:
|
|
465
|
-
|
|
466
|
-
```javascript
|
|
467
|
-
const makeWASocket = require("baileys-pro").default;
|
|
468
|
-
const { makeInMemoryStore } = require("baileys-pro");
|
|
469
|
-
// the store maintains the data of the WA connection in memory
|
|
470
|
-
// can be written out to a file & read from it
|
|
471
|
-
const store = makeInMemoryStore({ })
|
|
472
|
-
// can be read from a file
|
|
473
|
-
store.readFromFile('./baileys_store.json')
|
|
474
|
-
// saves the state to a file every 10s
|
|
475
|
-
setInterval(() => {
|
|
476
|
-
store.writeToFile('./baileys_store.json')
|
|
477
|
-
}, 10_000)
|
|
478
|
-
|
|
479
|
-
const sock = makeWASocket({ })
|
|
480
|
-
// will listen from this socket
|
|
481
|
-
// the store can listen from a new socket once the current socket outlives its lifetime
|
|
482
|
-
store.bind(sock.ev)
|
|
483
|
-
|
|
484
|
-
sock.ev.on('chats.upsert', () => {
|
|
485
|
-
// can use 'store.chats' however you want, even after the socket dies out
|
|
486
|
-
// 'chats' => a KeyedDB instance
|
|
487
|
-
console.log('got chats', store.chats.all())
|
|
488
|
-
})
|
|
489
|
-
|
|
490
|
-
sock.ev.on('contacts.upsert', () => {
|
|
491
|
-
console.log('got contacts', Object.values(store.contacts))
|
|
492
|
-
})
|
|
493
|
-
|
|
494
|
-
```
|
|
495
|
-
|
|
496
|
-
The store also provides some simple functions such as `loadMessages` that utilize the store to speed up data retrieval.
|
|
497
|
-
|
|
498
|
-
## Whatsapp IDs Explain
|
|
499
|
-
|
|
500
|
-
- `id` is the WhatsApp ID, called `jid` too, of the person or group you're sending the message to.
|
|
501
|
-
- It must be in the format ```[country code][phone number]@s.whatsapp.net```
|
|
502
|
-
- Example for people: ```+19999999999@s.whatsapp.net```.
|
|
503
|
-
- For groups, it must be in the format ``` 123456789-123345@g.us ```.
|
|
504
|
-
- For broadcast lists, it's `[timestamp of creation]@broadcast`.
|
|
505
|
-
- For stories, the ID is `status@broadcast`.
|
|
506
|
-
|
|
507
|
-
## Utility Functions
|
|
508
|
-
|
|
509
|
-
- `getContentType`, returns the content type for any message
|
|
510
|
-
- `getDevice`, returns the device from message
|
|
511
|
-
- `makeCacheableSignalKeyStore`, make auth store more fast
|
|
512
|
-
- `downloadContentFromMessage`, download content from any message
|
|
513
|
-
|
|
514
|
-
## Sending Messages
|
|
515
|
-
|
|
516
|
-
- Send all types of messages with a single function
|
|
517
|
-
- **[Here](https://baileys.whiskeysockets.io/types/AnyMessageContent.html) you can see all message contents supported, like text message**
|
|
518
|
-
- **[Here](https://baileys.whiskeysockets.io/types/MiscMessageGenerationOptions.html) you can see all options supported, like quote message**
|
|
519
|
-
|
|
520
|
-
```javascript
|
|
521
|
-
const jid: string
|
|
522
|
-
const content: AnyMessageContent
|
|
523
|
-
const options: MiscMessageGenerationOptions
|
|
524
|
-
|
|
525
|
-
sock.sendMessage(jid, content, options)
|
|
526
|
-
```
|
|
23
|
+
<p align="center">
|
|
24
|
+
<a href="https://elaina-bail.vercel.app">
|
|
25
|
+
<img src="https://img.shields.io/badge/Documentation-Baileys-blue?style=for-the-badge&logo=readthedocs&logoColor=white" alt="View Documentation">
|
|
26
|
+
</a>
|
|
27
|
+
</p>
|
|
527
28
|
|
|
528
|
-
|
|
29
|
+
---
|
|
529
30
|
|
|
530
|
-
|
|
531
|
-
```javascript
|
|
532
|
-
// send a buttons message!
|
|
533
|
-
sock.sendMessage(jid, {
|
|
534
|
-
text: "Hello World !",
|
|
535
|
-
footer: "Baileys - 2025",
|
|
536
|
-
buttons: [
|
|
537
|
-
{
|
|
538
|
-
buttonId: `🚀`,
|
|
539
|
-
buttonText: {
|
|
540
|
-
displayText: '🗿'
|
|
541
|
-
},
|
|
542
|
-
type: 1
|
|
543
|
-
}
|
|
544
|
-
],
|
|
545
|
-
headerType: 1,
|
|
546
|
-
viewOnce: true
|
|
547
|
-
},{ quoted: null })
|
|
548
|
-
```
|
|
31
|
+
## 📌 Overview
|
|
549
32
|
|
|
550
|
-
|
|
551
|
-
```javascript
|
|
552
|
-
sock.sendMessage(jid, {
|
|
553
|
-
text: "Hello Wolrd !;",
|
|
554
|
-
footer: "© Baileys Pro",
|
|
555
|
-
buttons: [
|
|
556
|
-
{
|
|
557
|
-
buttonId: '.tes',
|
|
558
|
-
buttonText: {
|
|
559
|
-
displayText: 'TESTING BOT'
|
|
560
|
-
},
|
|
561
|
-
type: 1,
|
|
562
|
-
},
|
|
563
|
-
{
|
|
564
|
-
buttonId: ' ',
|
|
565
|
-
buttonText: {
|
|
566
|
-
displayText: 'PRIVATE SCRIPT'
|
|
567
|
-
},
|
|
568
|
-
type: 1,
|
|
569
|
-
},
|
|
570
|
-
{
|
|
571
|
-
buttonId: 'action',
|
|
572
|
-
buttonText: {
|
|
573
|
-
displayText: 'ini pesan interactiveMeta'
|
|
574
|
-
},
|
|
575
|
-
type: 4,
|
|
576
|
-
nativeFlowInfo: {
|
|
577
|
-
name: 'single_select',
|
|
578
|
-
paramsJson: JSON.stringify({
|
|
579
|
-
title: 'message',
|
|
580
|
-
sections: [
|
|
581
|
-
{
|
|
582
|
-
title: 'Baileys - 2025',
|
|
583
|
-
highlight_label: '😜',
|
|
584
|
-
rows: [
|
|
585
|
-
{
|
|
586
|
-
header: 'HEADER',
|
|
587
|
-
title: 'TITLE',
|
|
588
|
-
description: 'DESCRIPTION',
|
|
589
|
-
id: 'YOUR ID',
|
|
590
|
-
},
|
|
591
|
-
{
|
|
592
|
-
header: 'HEADER',
|
|
593
|
-
title: 'TITLE',
|
|
594
|
-
description: 'DESCRIPTION',
|
|
595
|
-
id: 'YOUR ID',
|
|
596
|
-
},
|
|
597
|
-
],
|
|
598
|
-
},
|
|
599
|
-
],
|
|
600
|
-
}),
|
|
601
|
-
},
|
|
602
|
-
},
|
|
603
|
-
],
|
|
604
|
-
headerType: 1,
|
|
605
|
-
viewOnce: true
|
|
606
|
-
}, { quoted: m });
|
|
607
|
-
```
|
|
33
|
+
> **angularsockets** is a refined version of the Baileys library with cleaner API usage, exclusive features like album messaging, newsletter controls, and full-size profile uploads — tailored for modern WhatsApp automation needs.
|
|
608
34
|
|
|
609
|
-
|
|
610
|
-
```javascript
|
|
611
|
-
let msg = generateWAMessageFromContent(m.chat, {
|
|
612
|
-
viewOnceMessage: {
|
|
613
|
-
message: {
|
|
614
|
-
"messageContextInfo": {
|
|
615
|
-
"deviceListMetadata": {},
|
|
616
|
-
"deviceListMetadataVersion": 2
|
|
617
|
-
},
|
|
618
|
-
interactiveMessage: proto.Message.InteractiveMessage.create({
|
|
619
|
-
body: proto.Message.InteractiveMessage.Body.create({
|
|
620
|
-
text: "Baileys Pro"
|
|
621
|
-
}),
|
|
622
|
-
footer: proto.Message.InteractiveMessage.Footer.create({
|
|
623
|
-
text: "Bot"
|
|
624
|
-
}),
|
|
625
|
-
header: proto.Message.InteractiveMessage.Header.create({
|
|
626
|
-
title: "Igna",
|
|
627
|
-
subtitle: "test",
|
|
628
|
-
hasMediaAttachment: false
|
|
629
|
-
}),
|
|
630
|
-
nativeFlowMessage: proto.Message.InteractiveMessage.NativeFlowMessage.create({
|
|
631
|
-
buttons: [
|
|
632
|
-
{
|
|
633
|
-
"name": "single_select",
|
|
634
|
-
"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\"}]}]}"
|
|
635
|
-
},
|
|
636
|
-
{
|
|
637
|
-
"name": "cta_reply",
|
|
638
|
-
"buttonParamsJson": "{\"display_text\":\"quick_reply\",\"id\":\"message\"}"
|
|
639
|
-
},
|
|
640
|
-
{
|
|
641
|
-
"name": "cta_url",
|
|
642
|
-
"buttonParamsJson": "{\"display_text\":\"url\",\"url\":\"https://www.google.com\",\"merchant_url\":\"https://www.google.com\"}"
|
|
643
|
-
},
|
|
644
|
-
{
|
|
645
|
-
"name": "cta_call",
|
|
646
|
-
"buttonParamsJson": "{\"display_text\":\"call\",\"id\":\"message\"}"
|
|
647
|
-
},
|
|
648
|
-
{
|
|
649
|
-
"name": "cta_copy",
|
|
650
|
-
"buttonParamsJson": "{\"display_text\":\"copy\",\"id\":\"123456789\",\"copy_code\":\"message\"}"
|
|
651
|
-
},
|
|
652
|
-
{
|
|
653
|
-
"name": "cta_reminder",
|
|
654
|
-
"buttonParamsJson": "{\"display_text\":\"Recordatorio\",\"id\":\"message\"}"
|
|
655
|
-
},
|
|
656
|
-
{
|
|
657
|
-
"name": "cta_cancel_reminder",
|
|
658
|
-
"buttonParamsJson": "{\"display_text\":\"cta_cancel_reminder\",\"id\":\"message\"}"
|
|
659
|
-
},
|
|
660
|
-
{
|
|
661
|
-
"name": "address_message",
|
|
662
|
-
"buttonParamsJson": "{\"display_text\":\"address_message\",\"id\":\"message\"}"
|
|
663
|
-
},
|
|
664
|
-
{
|
|
665
|
-
"name": "send_location",
|
|
666
|
-
"buttonParamsJson": ""
|
|
667
|
-
}
|
|
668
|
-
],
|
|
669
|
-
})
|
|
670
|
-
})
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
}, {})
|
|
674
|
-
|
|
675
|
-
return sock.relayMessage(msg.key.remoteJid, msg.message, { messageId: msg.key.id })
|
|
676
|
-
```
|
|
35
|
+
### Current Version: **1.4.0**
|
|
677
36
|
|
|
678
|
-
|
|
679
|
-
```javascript
|
|
680
|
-
await sock.sendMessage(jid, { text: 'hello word' })
|
|
681
|
-
```
|
|
37
|
+
> **Update Information**
|
|
682
38
|
|
|
683
|
-
|
|
684
|
-
```javascript
|
|
685
|
-
await sock.sendMessage(jid, { text: 'hello word' }, { quoted: message })
|
|
686
|
-
```
|
|
39
|
+
All update information is now redirected to the WhatsApp channel:
|
|
687
40
|
|
|
688
|
-
|
|
689
|
-
-
|
|
690
|
-
|
|
691
|
-
await sock.sendMessage(
|
|
692
|
-
jid,
|
|
693
|
-
{
|
|
694
|
-
text: '@12345678901',
|
|
695
|
-
mentions: ['12345678901@s.whatsapp.net']
|
|
696
|
-
}
|
|
697
|
-
)
|
|
698
|
-
```
|
|
41
|
+
<a href="https://whatsapp.com/channel/0029VapYyKEGufIpsd3Rja2C">
|
|
42
|
+
<img src="https://img.shields.io/badge/Join-WhatsApp%20Channel-25D366?logo=whatsapp&logoColor=white" alt="WhatsApp Channel" />
|
|
43
|
+
</a>
|
|
699
44
|
|
|
700
|
-
|
|
701
|
-
- [ 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
|
|
702
|
-
```javascript
|
|
703
|
-
await sock.sendStatusMentions(
|
|
704
|
-
{
|
|
705
|
-
text: "Hello", // or image / video / audio ( url or buffer )
|
|
706
|
-
},
|
|
707
|
-
[
|
|
708
|
-
"123456789123456789@g.us",
|
|
709
|
-
"123456789@s.whatsapp.net",
|
|
710
|
-
// Enter jid chat here
|
|
711
|
-
]
|
|
712
|
-
)
|
|
713
|
-
```
|
|
45
|
+
---
|
|
714
46
|
|
|
715
|
-
|
|
716
|
-
```javascript
|
|
717
|
-
await sock.sendMessage(
|
|
718
|
-
jid,
|
|
719
|
-
{
|
|
720
|
-
pollResult: {
|
|
721
|
-
name: "Text poll",
|
|
722
|
-
votes: [["Options 1", 10], ["Options 2", 10]], // 10 For Fake Polling Count Results
|
|
723
|
-
}
|
|
724
|
-
}, { quoted : message }
|
|
725
|
-
)
|
|
726
|
-
```
|
|
47
|
+
## 📦 Installation
|
|
727
48
|
|
|
728
|
-
|
|
729
|
-
- url or buffer ( image or video )
|
|
730
|
-
```javascript
|
|
731
|
-
await sock.sendAlbumMessage(
|
|
732
|
-
jid,
|
|
733
|
-
[
|
|
734
|
-
{
|
|
735
|
-
image: { url: "https://example.jpg" }, // or buffer
|
|
736
|
-
caption: "Hello World",
|
|
737
|
-
},
|
|
738
|
-
{
|
|
739
|
-
video: { url: "https://example.mp4" }, // or buffer
|
|
740
|
-
caption: "Hello World",
|
|
741
|
-
},
|
|
742
|
-
],
|
|
743
|
-
{
|
|
744
|
-
quoted : message,
|
|
745
|
-
delay : 2000 // number in seconds
|
|
746
|
-
}
|
|
747
|
-
)
|
|
49
|
+
### Via package.json Fork Baileys (NPM)
|
|
748
50
|
|
|
749
|
-
|
|
51
|
+
**@whiskeysockets/baileys**
|
|
750
52
|
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
{
|
|
755
|
-
title: "Section 1",
|
|
756
|
-
rows: [
|
|
757
|
-
{title: "Option 1", rowId: "option1"},
|
|
758
|
-
{title: "Option 2", rowId: "option2", description: "This is a description"}
|
|
759
|
-
]
|
|
760
|
-
},
|
|
761
|
-
{
|
|
762
|
-
title: "Section 2",
|
|
763
|
-
rows: [
|
|
764
|
-
{title: "Option 3", rowId: "option3"},
|
|
765
|
-
{title: "Option 4", rowId: "option4", description: "This is a description V2"}
|
|
766
|
-
]
|
|
767
|
-
},
|
|
768
|
-
]
|
|
769
|
-
|
|
770
|
-
const listMessage = {
|
|
771
|
-
text: "This is a list",
|
|
772
|
-
footer: "nice footer, link: https://google.com",
|
|
773
|
-
title: "Amazing boldfaced list title",
|
|
774
|
-
buttonText: "Required, text on the button to view the list",
|
|
775
|
-
sections
|
|
53
|
+
```json
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"@whiskeysockets/baileys": "npm:angularsockets"
|
|
776
56
|
}
|
|
777
|
-
|
|
778
|
-
await sock.sendMessage(jid, listMessage)
|
|
779
|
-
```
|
|
780
|
-
|
|
781
|
-
#### Carousel Message
|
|
782
|
-
```javascript
|
|
783
|
-
sock.sendMessage(jid, {
|
|
784
|
-
text: 'hah',
|
|
785
|
-
footer: 'ya',
|
|
786
|
-
cards: [
|
|
787
|
-
{
|
|
788
|
-
title: 'oke',
|
|
789
|
-
image: { url: 'https://example.com/image.jpeg' },
|
|
790
|
-
caption: 'tes'
|
|
791
|
-
},
|
|
792
|
-
{
|
|
793
|
-
title: 'oke',
|
|
794
|
-
image: { url: 'https://example.com/image.jpeg' },
|
|
795
|
-
caption: 'tes'
|
|
796
|
-
}
|
|
797
|
-
],
|
|
798
|
-
viewOnce: true
|
|
799
|
-
})
|
|
800
|
-
```
|
|
801
|
-
|
|
802
|
-
#### Interactive Response
|
|
803
|
-
```javascript
|
|
804
|
-
await sock.sendMessage(
|
|
805
|
-
jid,
|
|
806
|
-
{
|
|
807
|
-
buttonReply: {
|
|
808
|
-
text: 'Text',
|
|
809
|
-
nativeFlow: {
|
|
810
|
-
version: 3,
|
|
811
|
-
},
|
|
812
|
-
},
|
|
813
|
-
type: 'interactive',
|
|
814
|
-
ephemeral: true,
|
|
815
|
-
}
|
|
816
|
-
)
|
|
817
|
-
|
|
818
|
-
```
|
|
819
|
-
|
|
820
|
-
#### Request Payment
|
|
821
|
-
```javascript
|
|
822
|
-
- Example non media sticker
|
|
823
|
-
await sock.sendMessage(
|
|
824
|
-
jid,
|
|
825
|
-
{
|
|
826
|
-
requestPayment: {
|
|
827
|
-
currency: "IDR",
|
|
828
|
-
amount: "10000000",
|
|
829
|
-
from: "123456@s.whatsapp.net",
|
|
830
|
-
note: "Hai Guys",
|
|
831
|
-
background: { ...background of the message }
|
|
832
|
-
}
|
|
833
|
-
},
|
|
834
|
-
{ quoted : message }
|
|
835
|
-
)
|
|
836
|
-
|
|
837
|
-
- with media sticker buffer
|
|
838
|
-
await sock.sendMessage(
|
|
839
|
-
jid,
|
|
840
|
-
{
|
|
841
|
-
requestPayment: {
|
|
842
|
-
currency: "IDR",
|
|
843
|
-
amount: "10000000",
|
|
844
|
-
from: "123456@s.whatsapp.net",
|
|
845
|
-
sticker: Buffer,
|
|
846
|
-
background: { ...background of the message }
|
|
847
|
-
}
|
|
848
|
-
},
|
|
849
|
-
{ quoted : message }
|
|
850
|
-
)
|
|
851
|
-
|
|
852
|
-
- with media sticker url
|
|
853
|
-
await sock.sendMessage(
|
|
854
|
-
jid,
|
|
855
|
-
{
|
|
856
|
-
requestPayment: {
|
|
857
|
-
currency: "IDR",
|
|
858
|
-
amount: "10000000",
|
|
859
|
-
from: "123456@s.whatsapp.net",
|
|
860
|
-
sticker: { url: Sticker Url },
|
|
861
|
-
background: { ...background of the message }
|
|
862
|
-
}
|
|
863
|
-
},
|
|
864
|
-
{ quoted : message }
|
|
865
|
-
)
|
|
866
|
-
```
|
|
867
|
-
|
|
868
|
-
#### Event Message
|
|
869
|
-
```javascript
|
|
870
|
-
await sock.sendMessage(
|
|
871
|
-
jid,
|
|
872
|
-
{
|
|
873
|
-
event: {
|
|
874
|
-
isCanceled: false, // or true for cancel event
|
|
875
|
-
name: "Name Event",
|
|
876
|
-
description: "Description Event",
|
|
877
|
-
location: {
|
|
878
|
-
degressLatitude: -0,
|
|
879
|
-
degressLongitude: - 0
|
|
880
|
-
},
|
|
881
|
-
link: Call Link,
|
|
882
|
-
startTime: m.messageTimestamp.low,
|
|
883
|
-
endTime: m.messageTimestamp.low + 86400, // 86400 is day in seconds
|
|
884
|
-
extraGuestsAllowed: true // or false
|
|
885
|
-
}
|
|
886
|
-
},
|
|
887
|
-
{ quoted : message }
|
|
888
|
-
)
|
|
889
|
-
```
|
|
890
|
-
|
|
891
|
-
#### Interactive
|
|
892
|
-
```javascript
|
|
893
|
-
- Example non header media
|
|
894
|
-
await sock.sendMessage(
|
|
895
|
-
jid,
|
|
896
|
-
{
|
|
897
|
-
text: "Description Of Messages", //Additional information
|
|
898
|
-
title: "Title Of Messages",
|
|
899
|
-
subtitle: "Subtitle Message",
|
|
900
|
-
footer: "Footer Messages",
|
|
901
|
-
interactiveButtons: [
|
|
902
|
-
{
|
|
903
|
-
name: "quick_reply",
|
|
904
|
-
buttonParamsJson: JSON.stringify({
|
|
905
|
-
display_text: "Display Button",
|
|
906
|
-
id: "ID"
|
|
907
|
-
})
|
|
908
|
-
},
|
|
909
|
-
{
|
|
910
|
-
name: "cta_url",
|
|
911
|
-
buttonParamsJson: JSON.stringify({
|
|
912
|
-
display_text: "Display Button",
|
|
913
|
-
url: "https://www.example.com"
|
|
914
|
-
})
|
|
915
|
-
}
|
|
916
|
-
]
|
|
917
|
-
},
|
|
918
|
-
{
|
|
919
|
-
quoted : message
|
|
920
|
-
}
|
|
921
|
-
)
|
|
922
|
-
|
|
923
|
-
// Example with media
|
|
924
|
-
await sock.sendMessage(
|
|
925
|
-
jid,
|
|
926
|
-
{
|
|
927
|
-
image: { url : "https://example.jpg" }, // Can buffer
|
|
928
|
-
caption: "Description Of Messages", //Additional information
|
|
929
|
-
title: "Title Of Messages",
|
|
930
|
-
subtitle: "Subtile Message",
|
|
931
|
-
footer: "Footer Messages",
|
|
932
|
-
media: true,
|
|
933
|
-
interactiveButtons: [
|
|
934
|
-
{
|
|
935
|
-
name: "quick_reply",
|
|
936
|
-
buttonParamsJson: JSON.stringify({
|
|
937
|
-
display_text: "Display Button",
|
|
938
|
-
id: "ID"
|
|
939
|
-
})
|
|
940
|
-
},
|
|
941
|
-
{
|
|
942
|
-
name: "cta_url",
|
|
943
|
-
buttonParamsJson: JSON.stringify({
|
|
944
|
-
display_text: "Display Button",
|
|
945
|
-
url: "https://www.example.com"
|
|
946
|
-
})
|
|
947
|
-
}
|
|
948
|
-
]
|
|
949
|
-
},
|
|
950
|
-
{
|
|
951
|
-
quoted : message
|
|
952
|
-
}
|
|
953
|
-
)
|
|
954
|
-
|
|
955
|
-
// Example with header product
|
|
956
|
-
await sock.sendMessage(
|
|
957
|
-
jid,
|
|
958
|
-
{
|
|
959
|
-
product: {
|
|
960
|
-
productImage: { url: "https://example.jpg }, //or buffer
|
|
961
|
-
productImageCount: 1,
|
|
962
|
-
title: "Title Product",
|
|
963
|
-
description: "Description Product",
|
|
964
|
-
priceAmount1000: 20000 * 1000,
|
|
965
|
-
currencyCode: "IDR",
|
|
966
|
-
retailerId: "Retail",
|
|
967
|
-
url: "https://example.com",
|
|
968
|
-
},
|
|
969
|
-
businessOwnerJid: "1234@s.whatsapp.net",
|
|
970
|
-
caption: "Description Of Messages", //Additional information
|
|
971
|
-
title: "Title Of Messages",
|
|
972
|
-
footer: "Footer Messages",
|
|
973
|
-
media: true,
|
|
974
|
-
interactiveButtons: [
|
|
975
|
-
{
|
|
976
|
-
name: "quick_reply",
|
|
977
|
-
buttonParamsJson: JSON.stringify({
|
|
978
|
-
display_text: "Display Button",
|
|
979
|
-
id: "ID"
|
|
980
|
-
})
|
|
981
|
-
},
|
|
982
|
-
{
|
|
983
|
-
name: "cta_url",
|
|
984
|
-
buttonParamsJson: JSON.stringify({
|
|
985
|
-
display_text: "Display Button",
|
|
986
|
-
url: "https://www.example.com"
|
|
987
|
-
})
|
|
988
|
-
}
|
|
989
|
-
]
|
|
990
|
-
},
|
|
991
|
-
{
|
|
992
|
-
quoted : message
|
|
993
|
-
}
|
|
994
|
-
)
|
|
995
|
-
```
|
|
996
|
-
|
|
997
|
-
#### Forward Messages
|
|
998
|
-
- 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
|
|
999
|
-
```javascript
|
|
1000
|
-
const msg = getMessageFromStore() // implement this on your end
|
|
1001
|
-
await sock.sendMessage(jid, { forward: msg }) // WA forward the message!
|
|
1002
|
-
```
|
|
1003
|
-
|
|
1004
|
-
#### Location Message
|
|
1005
|
-
```javascript
|
|
1006
|
-
await sock.sendMessage(
|
|
1007
|
-
jid,
|
|
1008
|
-
{
|
|
1009
|
-
location: {
|
|
1010
|
-
degreesLatitude: 24.121231,
|
|
1011
|
-
degreesLongitude: 55.1121221
|
|
1012
|
-
}
|
|
1013
|
-
}
|
|
1014
|
-
)
|
|
1015
|
-
```
|
|
1016
|
-
#### Contact Message
|
|
1017
|
-
```javascript
|
|
1018
|
-
const vcard = 'BEGIN:VCARD\n' // metadata of the contact card
|
|
1019
|
-
+ 'VERSION:3.0\n'
|
|
1020
|
-
+ 'FN:Jeff Singh\n' // full name
|
|
1021
|
-
+ 'ORG:Ashoka Uni;\n' // the organization of the contact
|
|
1022
|
-
+ 'TEL;type=CELL;type=VOICE;waid=911234567890:+91 12345 67890\n' // WhatsApp ID + phone number
|
|
1023
|
-
+ 'END:VCARD'
|
|
1024
|
-
|
|
1025
|
-
await sock.sendMessage(
|
|
1026
|
-
id,
|
|
1027
|
-
{
|
|
1028
|
-
contacts: {
|
|
1029
|
-
displayName: 'Jeff',
|
|
1030
|
-
contacts: [{ vcard }]
|
|
1031
|
-
}
|
|
1032
|
-
}
|
|
1033
|
-
)
|
|
1034
|
-
```
|
|
1035
|
-
|
|
1036
|
-
#### Reaction Message
|
|
1037
|
-
- 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
|
|
1038
|
-
```javascript
|
|
1039
|
-
await sock.sendMessage(
|
|
1040
|
-
jid,
|
|
1041
|
-
{
|
|
1042
|
-
react: {
|
|
1043
|
-
text: '💖', // use an empty string to remove the reaction
|
|
1044
|
-
key: message.key
|
|
1045
|
-
}
|
|
1046
|
-
}
|
|
1047
|
-
)
|
|
1048
|
-
```
|
|
1049
|
-
|
|
1050
|
-
#### Pin Message
|
|
1051
|
-
- 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
|
|
1052
|
-
|
|
1053
|
-
- Time can be:
|
|
1054
|
-
|
|
1055
|
-
| Time | Seconds |
|
|
1056
|
-
|-------|----------------|
|
|
1057
|
-
| 24h | 86.400 |
|
|
1058
|
-
| 7d | 604.800 |
|
|
1059
|
-
| 30d | 2.592.000 |
|
|
1060
|
-
|
|
1061
|
-
```javascript
|
|
1062
|
-
await sock.sendMessage(
|
|
1063
|
-
jid,
|
|
1064
|
-
{
|
|
1065
|
-
pin: {
|
|
1066
|
-
type: 1, // 0 to remove
|
|
1067
|
-
time: 86400
|
|
1068
|
-
key: message.key
|
|
1069
|
-
}
|
|
1070
|
-
}
|
|
1071
|
-
)
|
|
1072
|
-
```
|
|
1073
|
-
|
|
1074
|
-
#### Poll Message
|
|
1075
|
-
```javascript
|
|
1076
|
-
await sock.sendMessage(
|
|
1077
|
-
jid,
|
|
1078
|
-
{
|
|
1079
|
-
poll: {
|
|
1080
|
-
name: 'My Poll',
|
|
1081
|
-
values: ['Option 1', 'Option 2', ...],
|
|
1082
|
-
selectableCount: 1,
|
|
1083
|
-
toAnnouncementGroup: false // or true
|
|
1084
|
-
}
|
|
1085
|
-
}
|
|
1086
|
-
)
|
|
1087
|
-
```
|
|
1088
|
-
|
|
1089
|
-
### Sending Messages with Link Previews
|
|
1090
|
-
|
|
1091
|
-
1. By default, wa does not have link generation when sent from the web
|
|
1092
|
-
2. Baileys has a function to generate the content for these link previews
|
|
1093
|
-
3. To enable this function's usage, add `link-preview-js` as a dependency to your project with `yarn add link-preview-js`
|
|
1094
|
-
4. Send a link:
|
|
1095
|
-
```javascript
|
|
1096
|
-
await sock.sendMessage(
|
|
1097
|
-
jid,
|
|
1098
|
-
{
|
|
1099
|
-
text: 'Hi, this was sent using https://github.com/whiskeysockets/baileys'
|
|
1100
|
-
}
|
|
1101
|
-
)
|
|
1102
|
-
```
|
|
1103
|
-
|
|
1104
|
-
### Media Messages
|
|
1105
|
-
|
|
1106
|
-
Sending media (video, stickers, images) is easier & more efficient than ever.
|
|
1107
|
-
|
|
1108
|
-
> [!NOTE]
|
|
1109
|
-
> 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)
|
|
1110
|
-
|
|
1111
|
-
- When specifying a media url, Baileys never loads the entire buffer into memory; it even encrypts the media as a readable stream.
|
|
1112
|
-
|
|
1113
|
-
> [!TIP]
|
|
1114
|
-
> It's recommended to use Stream or Url to save memory
|
|
1115
|
-
|
|
1116
|
-
#### Gif Message
|
|
1117
|
-
- Whatsapp doesn't support `.gif` files, that's why we send gifs as common `.mp4` video with `gifPlayback` flag
|
|
1118
|
-
```javascript
|
|
1119
|
-
await sock.sendMessage(
|
|
1120
|
-
jid,
|
|
1121
|
-
{
|
|
1122
|
-
video: fs.readFileSync('Media/ma_gif.mp4'),
|
|
1123
|
-
caption: 'hello word',
|
|
1124
|
-
gifPlayback: true
|
|
1125
|
-
}
|
|
1126
|
-
)
|
|
1127
|
-
```
|
|
1128
|
-
|
|
1129
|
-
#### Video Message
|
|
1130
|
-
```javascript
|
|
1131
|
-
await sock.sendMessage(
|
|
1132
|
-
id,
|
|
1133
|
-
{
|
|
1134
|
-
video: {
|
|
1135
|
-
url: './Media/ma_gif.mp4'
|
|
1136
|
-
},
|
|
1137
|
-
caption: 'hello word',
|
|
1138
|
-
ptv: false // if set to true, will send as a `video note`
|
|
1139
|
-
}
|
|
1140
|
-
)
|
|
1141
|
-
```
|
|
1142
|
-
|
|
1143
|
-
#### Audio Message
|
|
1144
|
-
- To audio message work in all devices you need to convert with some tool like `ffmpeg` with this flags:
|
|
1145
|
-
```bash
|
|
1146
|
-
codec: libopus //ogg file
|
|
1147
|
-
ac: 1 //one channel
|
|
1148
|
-
avoid_negative_ts
|
|
1149
|
-
make_zero
|
|
1150
|
-
```
|
|
1151
|
-
- Example:
|
|
1152
|
-
```bash
|
|
1153
|
-
ffmpeg -i input.mp4 -avoid_negative_ts make_zero -ac 1 output.ogg
|
|
1154
|
-
```
|
|
1155
|
-
```javascript
|
|
1156
|
-
await sock.sendMessage(
|
|
1157
|
-
jid,
|
|
1158
|
-
{
|
|
1159
|
-
audio: {
|
|
1160
|
-
url: './Media/audio.mp3'
|
|
1161
|
-
},
|
|
1162
|
-
mimetype: 'audio/mp4'
|
|
1163
|
-
}
|
|
1164
|
-
)
|
|
1165
|
-
```
|
|
1166
|
-
|
|
1167
|
-
#### Image Message
|
|
1168
|
-
```javascript
|
|
1169
|
-
await sock.sendMessage(
|
|
1170
|
-
id,
|
|
1171
|
-
{
|
|
1172
|
-
image: {
|
|
1173
|
-
url: './Media/ma_img.png'
|
|
1174
|
-
},
|
|
1175
|
-
caption: 'hello word'
|
|
1176
|
-
}
|
|
1177
|
-
)
|
|
1178
|
-
```
|
|
1179
|
-
|
|
1180
|
-
#### View Once Message
|
|
1181
|
-
|
|
1182
|
-
- You can send all messages above as `viewOnce`, you only need to pass `viewOnce: true` in content object
|
|
1183
|
-
|
|
1184
|
-
```javascript
|
|
1185
|
-
await sock.sendMessage(
|
|
1186
|
-
id,
|
|
1187
|
-
{
|
|
1188
|
-
image: {
|
|
1189
|
-
url: './Media/ma_img.png'
|
|
1190
|
-
},
|
|
1191
|
-
viewOnce: true, //works with video, audio too
|
|
1192
|
-
caption: 'hello word'
|
|
1193
|
-
}
|
|
1194
|
-
)
|
|
1195
|
-
```
|
|
1196
|
-
|
|
1197
|
-
## Modify Messages
|
|
1198
|
-
|
|
1199
|
-
### Deleting Messages (for everyone)
|
|
1200
|
-
|
|
1201
|
-
```javascript
|
|
1202
|
-
const msg = await sock.sendMessage(jid, { text: 'hello word' })
|
|
1203
|
-
await sock.sendMessage(jid, { delete: msg.key })
|
|
1204
57
|
```
|
|
1205
58
|
|
|
1206
|
-
**
|
|
59
|
+
**@adiwajsing/baileys**
|
|
1207
60
|
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
```javascript
|
|
1212
|
-
await sock.sendMessage(jid, {
|
|
1213
|
-
text: 'updated text goes here',
|
|
1214
|
-
edit: response.key,
|
|
1215
|
-
});
|
|
1216
|
-
```
|
|
1217
|
-
|
|
1218
|
-
## Manipulating Media Messages
|
|
1219
|
-
|
|
1220
|
-
### Thumbnail in Media Messages
|
|
1221
|
-
- 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`.
|
|
1222
|
-
- Thumbnails for videos can also be generated automatically, though, you need to have `ffmpeg` installed on your system.
|
|
1223
|
-
|
|
1224
|
-
### Downloading Media Messages
|
|
1225
|
-
|
|
1226
|
-
If you want to save the media you received
|
|
1227
|
-
```javascript
|
|
1228
|
-
const { createWriteStream } = require('fs');
|
|
1229
|
-
const { downloadMediaMessage, getContentType } = require("baileys-pro");
|
|
1230
|
-
|
|
1231
|
-
sock.ev.on('messages.upsert', async ({ [m] }) => {
|
|
1232
|
-
if (!m.message) return // if there is no text or media message
|
|
1233
|
-
const messageType = getContentType(m) // get what type of message it is (text, image, video...)
|
|
1234
|
-
|
|
1235
|
-
// if the message is an image
|
|
1236
|
-
if (messageType === 'imageMessage') {
|
|
1237
|
-
// download the message
|
|
1238
|
-
const stream = await downloadMediaMessage(
|
|
1239
|
-
m,
|
|
1240
|
-
'stream', // can be 'buffer' too
|
|
1241
|
-
{ },
|
|
1242
|
-
{
|
|
1243
|
-
logger,
|
|
1244
|
-
// pass this so that baileys can request a reupload of media
|
|
1245
|
-
// that has been deleted
|
|
1246
|
-
reuploadRequest: sock.updateMediaMessage
|
|
1247
|
-
}
|
|
1248
|
-
)
|
|
1249
|
-
// save to file
|
|
1250
|
-
const writeStream = createWriteStream('./my-download.jpeg')
|
|
1251
|
-
stream.pipe(writeStream)
|
|
1252
|
-
}
|
|
61
|
+
```json
|
|
62
|
+
"dependencies": {
|
|
63
|
+
"@adiwajshing/baileys": "npm:angularsockets"
|
|
1253
64
|
}
|
|
1254
65
|
```
|
|
1255
66
|
|
|
1256
|
-
###
|
|
1257
|
-
|
|
1258
|
-
- 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:
|
|
1259
|
-
```javascript
|
|
1260
|
-
await sock.updateMediaMessage(msg)
|
|
1261
|
-
```
|
|
1262
|
-
|
|
1263
|
-
## Reject Call
|
|
1264
|
-
|
|
1265
|
-
- You can obtain `callId` and `callFrom` from `call` event
|
|
1266
|
-
|
|
1267
|
-
```javascript
|
|
1268
|
-
await sock.rejectCall(callId, callFrom)
|
|
1269
|
-
```
|
|
1270
|
-
|
|
1271
|
-
## Send States in Chat
|
|
1272
|
-
|
|
1273
|
-
### Reading Messages
|
|
1274
|
-
- A set of message [keys](https://baileys.whiskeysockets.io/types/WAMessageKey.html) must be explicitly marked read now.
|
|
1275
|
-
- You cannot mark an entire 'chat' read as it were with Baileys Web.
|
|
1276
|
-
This means you have to keep track of unread messages.
|
|
1277
|
-
|
|
1278
|
-
```javascript
|
|
1279
|
-
const key: WAMessageKey
|
|
1280
|
-
// can pass multiple keys to read multiple messages as well
|
|
1281
|
-
await sock.readMessages([key])
|
|
1282
|
-
```
|
|
1283
|
-
|
|
1284
|
-
The message ID is the unique identifier of the message that you are marking as read.
|
|
1285
|
-
On a `WAMessage`, the `messageID` can be accessed using ```messageID = message.key.id```.
|
|
67
|
+
### Or via terminal
|
|
1286
68
|
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
- ``` presence ``` can be one of [these](https://baileys.whiskeysockets.io/types/WAPresence.html)
|
|
1290
|
-
- The presence expires after about 10 seconds.
|
|
1291
|
-
- This lets the person/group with `jid` know whether you're online, offline, typing etc.
|
|
1292
|
-
|
|
1293
|
-
```javascript
|
|
1294
|
-
await sock.sendPresenceUpdate('available', jid)
|
|
1295
|
-
```
|
|
1296
|
-
|
|
1297
|
-
> [!NOTE]
|
|
1298
|
-
> 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')`
|
|
1299
|
-
|
|
1300
|
-
## Modifying Chats
|
|
1301
|
-
|
|
1302
|
-
WA uses an encrypted form of communication to send chat/app updates. This has been implemented mostly and you can send the following updates:
|
|
1303
|
-
|
|
1304
|
-
> [!IMPORTANT]
|
|
1305
|
-
> 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.
|
|
1306
|
-
|
|
1307
|
-
### Archive a Chat
|
|
1308
|
-
```javascript
|
|
1309
|
-
const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
|
|
1310
|
-
await sock.chatModify({ archive: true, lastMessages: [lastMsgInChat] }, jid)
|
|
1311
|
-
```
|
|
1312
|
-
### Mute/Unmute a Chat
|
|
1313
|
-
|
|
1314
|
-
- Supported times:
|
|
1315
|
-
|
|
1316
|
-
| Time | Miliseconds |
|
|
1317
|
-
|-------|-----------------|
|
|
1318
|
-
| Remove | null |
|
|
1319
|
-
| 8h | 86.400.000 |
|
|
1320
|
-
| 7d | 604.800.000 |
|
|
1321
|
-
|
|
1322
|
-
```javascript
|
|
1323
|
-
// mute for 8 hours
|
|
1324
|
-
await sock.chatModify({ mute: 8 * 60 * 60 * 1000 }, jid)
|
|
1325
|
-
// unmute
|
|
1326
|
-
await sock.chatModify({ mute: null }, jid)
|
|
1327
|
-
```
|
|
1328
|
-
### Mark a Chat Read/Unread
|
|
1329
|
-
```javascript
|
|
1330
|
-
const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
|
|
1331
|
-
// mark it unread
|
|
1332
|
-
await sock.chatModify({ markRead: false, lastMessages: [lastMsgInChat] }, jid)
|
|
1333
|
-
```
|
|
1334
|
-
|
|
1335
|
-
### Delete a Message for Me
|
|
1336
|
-
```javascript
|
|
1337
|
-
await sock.chatModify(
|
|
1338
|
-
{
|
|
1339
|
-
clear: {
|
|
1340
|
-
messages: [
|
|
1341
|
-
{
|
|
1342
|
-
id: 'ATWYHDNNWU81732J',
|
|
1343
|
-
fromMe: true,
|
|
1344
|
-
timestamp: '1654823909'
|
|
1345
|
-
}
|
|
1346
|
-
]
|
|
1347
|
-
}
|
|
1348
|
-
},
|
|
1349
|
-
jid
|
|
1350
|
-
)
|
|
1351
|
-
|
|
1352
|
-
```
|
|
1353
|
-
### Delete a Chat
|
|
1354
|
-
```javascript
|
|
1355
|
-
const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
|
|
1356
|
-
await sock.chatModify({
|
|
1357
|
-
delete: true,
|
|
1358
|
-
lastMessages: [
|
|
1359
|
-
{
|
|
1360
|
-
key: lastMsgInChat.key,
|
|
1361
|
-
messageTimestamp: lastMsgInChat.messageTimestamp
|
|
1362
|
-
}
|
|
1363
|
-
]
|
|
1364
|
-
},
|
|
1365
|
-
jid
|
|
1366
|
-
)
|
|
1367
|
-
```
|
|
1368
|
-
### Pin/Unpin a Chat
|
|
1369
|
-
```javascript
|
|
1370
|
-
await sock.chatModify({
|
|
1371
|
-
pin: true // or `false` to unpin
|
|
1372
|
-
},
|
|
1373
|
-
jid
|
|
1374
|
-
)
|
|
1375
|
-
```
|
|
1376
|
-
### Star/Unstar a Message
|
|
1377
|
-
```javascript
|
|
1378
|
-
await sock.chatModify({
|
|
1379
|
-
star: {
|
|
1380
|
-
messages: [
|
|
1381
|
-
{
|
|
1382
|
-
id: 'messageID',
|
|
1383
|
-
fromMe: true // or `false`
|
|
1384
|
-
}
|
|
1385
|
-
],
|
|
1386
|
-
star: true // - true: Star Message; false: Unstar Message
|
|
1387
|
-
}
|
|
1388
|
-
},
|
|
1389
|
-
jid
|
|
1390
|
-
)
|
|
1391
|
-
```
|
|
1392
|
-
|
|
1393
|
-
### Disappearing Messages
|
|
1394
|
-
|
|
1395
|
-
- Ephemeral can be:
|
|
1396
|
-
|
|
1397
|
-
| Time | Seconds |
|
|
1398
|
-
|-------|----------------|
|
|
1399
|
-
| Remove | 0 |
|
|
1400
|
-
| 24h | 86.400 |
|
|
1401
|
-
| 7d | 604.800 |
|
|
1402
|
-
| 90d | 7.776.000 |
|
|
1403
|
-
|
|
1404
|
-
- You need to pass in **Seconds**, default is 7 days
|
|
1405
|
-
|
|
1406
|
-
```javascript
|
|
1407
|
-
// turn on disappearing messages
|
|
1408
|
-
await sock.sendMessage(
|
|
1409
|
-
jid,
|
|
1410
|
-
// this is 1 week in seconds -- how long you want messages to appear for
|
|
1411
|
-
{ disappearingMessagesInChat: WA_DEFAULT_EPHEMERAL }
|
|
1412
|
-
)
|
|
1413
|
-
|
|
1414
|
-
// will send as a disappearing message
|
|
1415
|
-
await sock.sendMessage(jid, { text: 'hello' }, { ephemeralExpiration: WA_DEFAULT_EPHEMERAL })
|
|
1416
|
-
|
|
1417
|
-
// turn off disappearing messages
|
|
1418
|
-
await sock.sendMessage(
|
|
1419
|
-
jid,
|
|
1420
|
-
{ disappearingMessagesInChat: false }
|
|
1421
|
-
)
|
|
1422
|
-
```
|
|
1423
|
-
|
|
1424
|
-
## User Querys
|
|
1425
|
-
|
|
1426
|
-
### Check If ID Exists in Whatsapp
|
|
1427
|
-
```javascript
|
|
1428
|
-
const [result] = await sock.onWhatsApp(jid)
|
|
1429
|
-
if (result.exists) console.log (`${jid} exists on WhatsApp, as jid: ${result.jid}`)
|
|
1430
|
-
```
|
|
1431
|
-
|
|
1432
|
-
### Query Chat History (groups too)
|
|
1433
|
-
|
|
1434
|
-
- You need to have oldest message in chat
|
|
1435
|
-
```javascript
|
|
1436
|
-
const msg = await getOldestMessageInChat(jid)
|
|
1437
|
-
await sock.fetchMessageHistory(
|
|
1438
|
-
50, //quantity (max: 50 per query)
|
|
1439
|
-
msg.key,
|
|
1440
|
-
msg.messageTimestamp
|
|
1441
|
-
)
|
|
1442
|
-
```
|
|
1443
|
-
- Messages will be received in `messaging.history-set` event
|
|
1444
|
-
|
|
1445
|
-
### Fetch Status
|
|
1446
|
-
```javascript
|
|
1447
|
-
const status = await sock.fetchStatus(jid)
|
|
1448
|
-
console.log('status: ' + status)
|
|
69
|
+
```bash
|
|
70
|
+
npm install baileys@npm:angularsockets
|
|
1449
71
|
```
|
|
1450
72
|
|
|
1451
|
-
###
|
|
1452
|
-
- To get the display picture of some person/group
|
|
1453
|
-
```javascript
|
|
1454
|
-
// for low res picture
|
|
1455
|
-
const ppUrl = await sock.profilePictureUrl(jid)
|
|
1456
|
-
console.log(ppUrl)
|
|
73
|
+
### Importing (for those who don't fork another repository)
|
|
1457
74
|
|
|
1458
|
-
|
|
1459
|
-
const ppUrl = await sock.profilePictureUrl(jid, 'image')
|
|
1460
|
-
```
|
|
75
|
+
**ESM**
|
|
1461
76
|
|
|
1462
|
-
### Fetch Bussines Profile (such as description or category)
|
|
1463
77
|
```javascript
|
|
1464
|
-
|
|
1465
|
-
console.log('business description: ' + profile.description + ', category: ' + profile.category)
|
|
78
|
+
import makeWASocket from 'angularsockets'
|
|
1466
79
|
```
|
|
1467
80
|
|
|
1468
|
-
|
|
1469
|
-
```javascript
|
|
1470
|
-
// the presence update is fetched and called here
|
|
1471
|
-
sock.ev.on('presence.update', console.log)
|
|
81
|
+
**CJS**
|
|
1472
82
|
|
|
1473
|
-
// request updates for a chat
|
|
1474
|
-
await sock.presenceSubscribe(jid)
|
|
1475
|
-
```
|
|
1476
|
-
|
|
1477
|
-
## Change Profile
|
|
1478
|
-
|
|
1479
|
-
### Change Profile Status
|
|
1480
83
|
```javascript
|
|
1481
|
-
|
|
84
|
+
const { default: makeWASocket } = require('angularsockets')
|
|
1482
85
|
```
|
|
1483
|
-
### Change Profile Name
|
|
1484
|
-
```javascript
|
|
1485
|
-
await sock.updateProfileName('My name')
|
|
1486
|
-
```
|
|
1487
|
-
### Change Display Picture (groups too)
|
|
1488
|
-
- To change your display picture or a group's
|
|
1489
86
|
|
|
1490
|
-
|
|
1491
|
-
> 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)
|
|
87
|
+
---
|
|
1492
88
|
|
|
1493
|
-
|
|
1494
|
-
await sock.updateProfilePicture(jid, { url: './new-profile-picture.jpeg' })
|
|
1495
|
-
```
|
|
1496
|
-
### Remove display picture (groups too)
|
|
1497
|
-
```javascript
|
|
1498
|
-
await sock.removeProfilePicture(jid)
|
|
1499
|
-
```
|
|
1500
|
-
|
|
1501
|
-
## Groups
|
|
1502
|
-
|
|
1503
|
-
- To change group properties you need to be admin
|
|
89
|
+
## 🌟 Key Features
|
|
1504
90
|
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
await sock.groupParticipantsUpdate(
|
|
1516
|
-
jid,
|
|
1517
|
-
['abcd@s.whatsapp.net', 'efgh@s.whatsapp.net'],
|
|
1518
|
-
'add' // replace this parameter with 'remove' or 'demote' or 'promote'
|
|
1519
|
-
)
|
|
1520
|
-
```
|
|
1521
|
-
### Change Subject (name)
|
|
1522
|
-
```javascript
|
|
1523
|
-
await sock.groupUpdateSubject(jid, 'New Subject!')
|
|
1524
|
-
```
|
|
1525
|
-
### Change Description
|
|
1526
|
-
```javascript
|
|
1527
|
-
await sock.groupUpdateDescription(jid, 'New Description!')
|
|
1528
|
-
```
|
|
1529
|
-
### Change Settings
|
|
1530
|
-
```javascript
|
|
1531
|
-
// only allow admins to send messages
|
|
1532
|
-
await sock.groupSettingUpdate(jid, 'announcement')
|
|
1533
|
-
// allow everyone to send messages
|
|
1534
|
-
await sock.groupSettingUpdate(jid, 'not_announcement')
|
|
1535
|
-
// allow everyone to modify the group's settings -- like display picture etc.
|
|
1536
|
-
await sock.groupSettingUpdate(jid, 'unlocked')
|
|
1537
|
-
// only allow admins to modify the group's settings
|
|
1538
|
-
await sock.groupSettingUpdate(jid, 'locked')
|
|
1539
|
-
```
|
|
1540
|
-
### Leave a Group
|
|
1541
|
-
```javascript
|
|
1542
|
-
// will throw error if it fails
|
|
1543
|
-
await sock.groupLeave(jid)
|
|
1544
|
-
```
|
|
1545
|
-
### Get Invite Code
|
|
1546
|
-
- To create link with code use `'https://chat.whatsapp.com/' + code`
|
|
1547
|
-
```javascript
|
|
1548
|
-
const code = await sock.groupInviteCode(jid)
|
|
1549
|
-
console.log('group code: ' + code)
|
|
1550
|
-
```
|
|
1551
|
-
### Revoke Invite Code
|
|
1552
|
-
```javascript
|
|
1553
|
-
const code = await sock.groupRevokeInvite(jid)
|
|
1554
|
-
console.log('New group code: ' + code)
|
|
1555
|
-
```
|
|
1556
|
-
### Join Using Invitation Code
|
|
1557
|
-
- Code can't have `https://chat.whatsapp.com/`, only code
|
|
1558
|
-
```javascript
|
|
1559
|
-
const response = await sock.groupAcceptInvite(code)
|
|
1560
|
-
console.log('joined to: ' + response)
|
|
1561
|
-
```
|
|
1562
|
-
### Get Group Info by Invite Code
|
|
1563
|
-
```javascript
|
|
1564
|
-
const response = await sock.groupGetInviteInfo(code)
|
|
1565
|
-
console.log('group information: ' + response)
|
|
1566
|
-
```
|
|
1567
|
-
### Query Metadata (participants, name, description...)
|
|
1568
|
-
```javascript
|
|
1569
|
-
const metadata = await sock.groupMetadata(jid)
|
|
1570
|
-
console.log(metadata.id + ', title: ' + metadata.subject + ', description: ' + metadata.desc)
|
|
1571
|
-
```
|
|
1572
|
-
### Join using `groupInviteMessage`
|
|
1573
|
-
```javascript
|
|
1574
|
-
const response = await sock.groupAcceptInviteV4(jid, groupInviteMessage)
|
|
1575
|
-
console.log('joined to: ' + response)
|
|
1576
|
-
```
|
|
1577
|
-
### Get Request Join List
|
|
1578
|
-
```javascript
|
|
1579
|
-
const response = await sock.groupRequestParticipantsList(jid)
|
|
1580
|
-
console.log(response)
|
|
1581
|
-
```
|
|
1582
|
-
### Approve/Reject Request Join
|
|
1583
|
-
```javascript
|
|
1584
|
-
const response = await sock.groupRequestParticipantsUpdate(
|
|
1585
|
-
jid, // group id
|
|
1586
|
-
['abcd@s.whatsapp.net', 'efgh@s.whatsapp.net'],
|
|
1587
|
-
'approve' // or 'reject'
|
|
1588
|
-
)
|
|
1589
|
-
console.log(response)
|
|
1590
|
-
```
|
|
1591
|
-
### Get All Participating Groups Metadata
|
|
1592
|
-
```javascript
|
|
1593
|
-
const response = await sock.groupFetchAllParticipating()
|
|
1594
|
-
console.log(response)
|
|
1595
|
-
```
|
|
1596
|
-
### Toggle Ephemeral
|
|
91
|
+
| Category | Description |
|
|
92
|
+
|----------|-------------|
|
|
93
|
+
| 📢 Channels | Seamlessly send messages to WhatsApp Channels |
|
|
94
|
+
| 🖱️ Buttons | Create interactive messages with button options and quick replies |
|
|
95
|
+
| 🖼️ Albums | Send grouped images or videos as an album (carousel-like format) |
|
|
96
|
+
| 👤 LID Grouping | Handle group operations using the latest @lid addressing style |
|
|
97
|
+
| 🤖 AI Message Style | Add a stylized "AI" icon to messages |
|
|
98
|
+
| 📷 HD Profile Pics | Upload full-size profile pictures without cropping |
|
|
99
|
+
| 🔐 Pairing Code | Generate custom alphanumeric pairing codes |
|
|
100
|
+
| 🛠️ Dev Experience | Reduced noise from logs with optimized libsignal printouts |
|
|
1597
101
|
|
|
1598
|
-
|
|
102
|
+
---
|
|
1599
103
|
|
|
1600
|
-
|
|
1601
|
-
|-------|----------------|
|
|
1602
|
-
| Remove | 0 |
|
|
1603
|
-
| 24h | 86.400 |
|
|
1604
|
-
| 7d | 604.800 |
|
|
1605
|
-
| 90d | 7.776.000 |
|
|
104
|
+
## 💡 Use Case Examples
|
|
1606
105
|
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
```
|
|
106
|
+
<details>
|
|
107
|
+
<summary><strong>📬 Newsletter Control</strong></summary>
|
|
1610
108
|
|
|
1611
|
-
### Change Add Mode
|
|
1612
109
|
```javascript
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
110
|
+
// Create a newsletter
|
|
111
|
+
await sock.newsletterCreate("Elaina Updates");
|
|
112
|
+
|
|
113
|
+
// Change description
|
|
114
|
+
await sock.newsletterUpdateDescription("elaina@newsletter", "Fresh updates weekly");
|
|
115
|
+
|
|
116
|
+
// Send a reaction to a channel message
|
|
117
|
+
await sock.newsletterReactMessage("elaina@newsletter", "175", "🔥");
|
|
1617
118
|
```
|
|
1618
119
|
|
|
1619
|
-
|
|
120
|
+
</details>
|
|
1620
121
|
|
|
1621
|
-
|
|
122
|
+
<details>
|
|
123
|
+
<summary><strong>📌 Interactive Messaging</strong></summary>
|
|
1622
124
|
|
|
1623
|
-
### Subscribe to Newsletter Updates
|
|
1624
125
|
```javascript
|
|
1625
|
-
|
|
126
|
+
const buttons = [
|
|
127
|
+
{ buttonId: 'btn1', buttonText: { displayText: 'Click Me' }, type: 1 },
|
|
128
|
+
{ buttonId: 'btn2', buttonText: { displayText: 'Visit Site' }, type: 1 }
|
|
129
|
+
];
|
|
130
|
+
|
|
131
|
+
const msg = {
|
|
132
|
+
text: "Choose one:",
|
|
133
|
+
footer: "From Elaina with love 💜",
|
|
134
|
+
buttons,
|
|
135
|
+
headerType: 1
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
await sock.sendMessage(id, msg, { quoted: null });
|
|
1626
139
|
```
|
|
1627
140
|
|
|
1628
|
-
|
|
1629
|
-
```javascript
|
|
1630
|
-
await sock.newsletterReactionMode(jid, mode) // e.g., 'enabled', 'disabled'
|
|
1631
|
-
```
|
|
141
|
+
</details>
|
|
1632
142
|
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
await sock.newsletterUpdateDescription(jid, 'Your new description')
|
|
1636
|
-
```
|
|
143
|
+
<details>
|
|
144
|
+
<summary><strong>🖼️ Send Album</strong></summary>
|
|
1637
145
|
|
|
1638
|
-
### Update Newsletter Name
|
|
1639
146
|
```javascript
|
|
1640
|
-
|
|
147
|
+
const media = [
|
|
148
|
+
{ image: { url: "https://example.com/pic1.jpg" } },
|
|
149
|
+
{ video: { url: "https://example.com/clip.mp4" } }
|
|
150
|
+
];
|
|
151
|
+
|
|
152
|
+
await sock.sendMessage(id, { album: media, caption: "Memories 💫" }, { quoted: null });
|
|
1641
153
|
```
|
|
1642
154
|
|
|
1643
|
-
|
|
1644
|
-
```javascript
|
|
1645
|
-
await sock.newsletterUpdatePicture(jid, content)
|
|
1646
|
-
```
|
|
155
|
+
</details>
|
|
1647
156
|
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
await sock.newsletterRemovePicture(jid)
|
|
1651
|
-
```
|
|
157
|
+
<details>
|
|
158
|
+
<summary><strong>🔐 Pairing with Custom Code</strong></summary>
|
|
1652
159
|
|
|
1653
|
-
### Follow a Newsletter
|
|
1654
160
|
```javascript
|
|
1655
|
-
await sock.
|
|
161
|
+
const code = await sock.requestPairingCode("62xxxxxxxxxx", "ELAINA01");
|
|
162
|
+
console.log("Your Pairing Code:", code);
|
|
1656
163
|
```
|
|
1657
164
|
|
|
1658
|
-
|
|
1659
|
-
```javascript
|
|
1660
|
-
await sock.newsletterUnfollow(jid)
|
|
1661
|
-
```
|
|
165
|
+
</details>
|
|
1662
166
|
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
await sock.newsletterMute(jid)
|
|
1666
|
-
```
|
|
167
|
+
<details>
|
|
168
|
+
<summary><strong>📊 Poll Creation</strong></summary>
|
|
1667
169
|
|
|
1668
|
-
### Unmute a Newsletter
|
|
1669
170
|
```javascript
|
|
1670
|
-
|
|
171
|
+
const pollMessage = {
|
|
172
|
+
name: "Favorite Color?",
|
|
173
|
+
values: ["Red", "Blue", "Green"],
|
|
174
|
+
selectableCount: 1
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
await sock.sendMessage(id, { poll: pollMessage });
|
|
1671
178
|
```
|
|
1672
179
|
|
|
1673
|
-
|
|
1674
|
-
```javascript
|
|
1675
|
-
await sock.newsletterAction(jid, 'mute' | 'unmute' | 'follow' | 'unfollow')
|
|
1676
|
-
```
|
|
180
|
+
</details>
|
|
1677
181
|
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
const newsletter = await sock.newsletterCreate('Newsletter Name', 'Newsletter Description')
|
|
1681
|
-
console.log(newsletter)
|
|
1682
|
-
```
|
|
182
|
+
<details>
|
|
183
|
+
<summary><strong>📍 Location Sharing</strong></summary>
|
|
1683
184
|
|
|
1684
|
-
### Fetch Newsletter Metadata
|
|
1685
185
|
```javascript
|
|
1686
|
-
|
|
1687
|
-
|
|
186
|
+
const locationMessage = {
|
|
187
|
+
degreesLatitude: 37.422,
|
|
188
|
+
degreesLongitude: -122.084,
|
|
189
|
+
name: "Googleplex",
|
|
190
|
+
address: "1600 Amphitheatre Pkwy, Mountain View, CA 94043"
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
await sock.sendMessage(id, { location: locationMessage });
|
|
1688
194
|
```
|
|
1689
195
|
|
|
1690
|
-
|
|
1691
|
-
```javascript
|
|
1692
|
-
const count = await sock.newsletterAdminCount(jid)
|
|
1693
|
-
```
|
|
196
|
+
</details>
|
|
1694
197
|
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
/**user is Lid, not Jid */
|
|
1698
|
-
await sock.newsletterChangeOwner(jid, userLid)
|
|
1699
|
-
```
|
|
198
|
+
<details>
|
|
199
|
+
<summary><strong>👥 Group Management</strong></summary>
|
|
1700
200
|
|
|
1701
|
-
### Demote Newsletter Admin
|
|
1702
201
|
```javascript
|
|
1703
|
-
|
|
1704
|
-
await sock.
|
|
202
|
+
// Create group
|
|
203
|
+
const group = await sock.groupCreate("My New Group", [number1, number2]);
|
|
204
|
+
|
|
205
|
+
// Add participants
|
|
206
|
+
await sock.groupAdd(group.id, [number3, number4]);
|
|
207
|
+
|
|
208
|
+
// Change group description
|
|
209
|
+
await sock.groupUpdateDescription(group.id, "This is our awesome group!");
|
|
1705
210
|
```
|
|
1706
211
|
|
|
1707
|
-
|
|
1708
|
-
```javascript
|
|
1709
|
-
await sock.newsletterDelete(jid)
|
|
1710
|
-
```
|
|
212
|
+
</details>
|
|
1711
213
|
|
|
1712
|
-
|
|
1713
|
-
```javascript
|
|
1714
|
-
// Copying the message link in the Newsletter will get
|
|
1715
|
-
// https://whatsapp.com/channel/XXXXXXXXX/$serverId
|
|
214
|
+
---
|
|
1716
215
|
|
|
1717
|
-
|
|
1718
|
-
// pass null or empty to remove reaction
|
|
1719
|
-
```
|
|
216
|
+
**Note:** Replace `id` with the actual recipient ID and `sock` with your WhatsApp socket connection variable.
|
|
1720
217
|
|
|
1721
|
-
|
|
1722
|
-
```javascript
|
|
1723
|
-
const messages = await sock.newsletterFetchMessages('direct' | 'invite', key, count, after)
|
|
1724
|
-
```
|
|
218
|
+
---
|
|
1725
219
|
|
|
1726
|
-
|
|
1727
|
-
```javascript
|
|
1728
|
-
const updates = await sock.newsletterFetchUpdates(jid, count, after, since)
|
|
1729
|
-
```
|
|
220
|
+
## 🐞 Found a Bug?
|
|
1730
221
|
|
|
1731
|
-
|
|
222
|
+
Please contact the maintainer directly via WhatsApp:
|
|
1732
223
|
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
### Get Privacy Settings
|
|
1739
|
-
```javascript
|
|
1740
|
-
const privacySettings = await sock.fetchPrivacySettings(true)
|
|
1741
|
-
console.log('privacy settings: ' + privacySettings)
|
|
1742
|
-
```
|
|
1743
|
-
### Get BlockList
|
|
1744
|
-
```javascript
|
|
1745
|
-
const response = await sock.fetchBlocklist()
|
|
1746
|
-
console.log(response)
|
|
1747
|
-
```
|
|
1748
|
-
### Update LastSeen Privacy
|
|
1749
|
-
```javascript
|
|
1750
|
-
const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
|
|
1751
|
-
await sock.updateLastSeenPrivacy(value)
|
|
1752
|
-
```
|
|
1753
|
-
### Update Online Privacy
|
|
1754
|
-
```javascript
|
|
1755
|
-
const value = 'all' // 'match_last_seen'
|
|
1756
|
-
await sock.updateOnlinePrivacy(value)
|
|
1757
|
-
```
|
|
1758
|
-
### Update Profile Picture Privacy
|
|
1759
|
-
```javascript
|
|
1760
|
-
const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
|
|
1761
|
-
await sock.updateProfilePicturePrivacy(value)
|
|
1762
|
-
```
|
|
1763
|
-
### Update Status Privacy
|
|
1764
|
-
```javascript
|
|
1765
|
-
const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
|
|
1766
|
-
await sock.updateStatusPrivacy(value)
|
|
1767
|
-
```
|
|
1768
|
-
### Update Read Receipts Privacy
|
|
1769
|
-
```javascript
|
|
1770
|
-
const value = 'all' // 'none'
|
|
1771
|
-
await sock.updateReadReceiptsPrivacy(value)
|
|
1772
|
-
```
|
|
1773
|
-
### Update Groups Add Privacy
|
|
1774
|
-
```javascript
|
|
1775
|
-
const value = 'all' // 'contacts' | 'contact_blacklist'
|
|
1776
|
-
await sock.updateGroupsAddPrivacy(value)
|
|
1777
|
-
```
|
|
1778
|
-
### Update Default Disappearing Mode
|
|
224
|
+
<p align="center">
|
|
225
|
+
<a href="https://wa.me/263719647303" target="_blank">
|
|
226
|
+
<img alt="WhatsApp" src="https://img.shields.io/badge/Chat%20on%20WhatsApp-25D366?style=for-the-badge&logo=whatsapp&logoColor=white">
|
|
227
|
+
</a>
|
|
228
|
+
</p>
|
|
1779
229
|
|
|
1780
|
-
|
|
230
|
+
---
|
|
1781
231
|
|
|
1782
|
-
|
|
1783
|
-
|-------|----------------|
|
|
1784
|
-
| Remove | 0 |
|
|
1785
|
-
| 24h | 86.400 |
|
|
1786
|
-
| 7d | 604.800 |
|
|
1787
|
-
| 90d | 7.776.000 |
|
|
232
|
+
## 🙏 Credits
|
|
1788
233
|
|
|
1789
|
-
|
|
1790
|
-
const ephemeral = 86400
|
|
1791
|
-
await sock.updateDefaultDisappearingMode(ephemeral)
|
|
1792
|
-
```
|
|
234
|
+
**Creator:** MR FRANK OFC
|
|
1793
235
|
|
|
1794
|
-
|
|
236
|
+
- 🌐 Website: [mrfrankofc.gleeze.com](https://mrfrankofc.gleeze.com)
|
|
237
|
+
- 💻 GitHub: [@mrfr8nk](https://github.com/mrfr8nk)
|
|
1795
238
|
|
|
1796
|
-
|
|
1797
|
-
-
|
|
1798
|
-
|
|
1799
|
-
await sock.sendMessage(
|
|
1800
|
-
jid,
|
|
1801
|
-
{
|
|
1802
|
-
image: {
|
|
1803
|
-
url: url
|
|
1804
|
-
},
|
|
1805
|
-
caption: caption
|
|
1806
|
-
},
|
|
1807
|
-
{
|
|
1808
|
-
backgroundColor: backgroundColor,
|
|
1809
|
-
font: font,
|
|
1810
|
-
statusJidList: statusJidList,
|
|
1811
|
-
broadcast: true
|
|
1812
|
-
}
|
|
1813
|
-
)
|
|
1814
|
-
```
|
|
1815
|
-
- Message body can be a `extendedTextMessage` or `imageMessage` or `videoMessage` or `voiceMessage`, see [here](https://baileys.whiskeysockets.io/types/AnyRegularMessageContent.html)
|
|
1816
|
-
- You can add `backgroundColor` and other options in the message options, see [here](https://baileys.whiskeysockets.io/types/MiscMessageGenerationOptions.html)
|
|
1817
|
-
- `broadcast: true` enables broadcast mode
|
|
1818
|
-
- `statusJidList`: a list of people that you can get which you need to provide, which are the people who will get this status message.
|
|
1819
|
-
|
|
1820
|
-
- You can send messages to broadcast lists the same way you send messages to groups & individual chats.
|
|
1821
|
-
- Right now, WA Web does not support creating broadcast lists, but you can still delete them.
|
|
1822
|
-
- Broadcast IDs are in the format `12345678@broadcast`
|
|
1823
|
-
### Query a Broadcast List's Recipients & Name
|
|
1824
|
-
```javascript
|
|
1825
|
-
const bList = await sock.getBroadcastListInfo('1234@broadcast')
|
|
1826
|
-
console.log (`list name: ${bList.name}, recps: ${bList.recipients}`)
|
|
1827
|
-
```
|
|
1828
|
-
|
|
1829
|
-
## Writing Custom Functionality
|
|
1830
|
-
Baileys is written with custom functionality in mind. Instead of forking the project & re-writing the internals, you can simply write your own extensions.
|
|
1831
|
-
|
|
1832
|
-
### Enabling Debug Level in Baileys Logs
|
|
1833
|
-
First, enable the logging of unhandled messages from WhatsApp by setting:
|
|
1834
|
-
```javascript
|
|
1835
|
-
const sock = makeWASocket({
|
|
1836
|
-
logger: P({ level: 'debug' }),
|
|
1837
|
-
})
|
|
1838
|
-
```
|
|
1839
|
-
This will enable you to see all sorts of messages WhatsApp sends in the console.
|
|
1840
|
-
|
|
1841
|
-
### How Whatsapp Communicate With Us
|
|
1842
|
-
|
|
1843
|
-
> [!TIP]
|
|
1844
|
-
> If you want to learn whatsapp protocol, we recommend to study about Libsignal Protocol and Noise Protocol
|
|
1845
|
-
|
|
1846
|
-
- **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:
|
|
1847
|
-
```json
|
|
1848
|
-
{
|
|
1849
|
-
"level": 10,
|
|
1850
|
-
"fromMe": false,
|
|
1851
|
-
"frame": {
|
|
1852
|
-
"tag": "ib",
|
|
1853
|
-
"attrs": {
|
|
1854
|
-
"from": "@s.whatsapp.net"
|
|
1855
|
-
},
|
|
1856
|
-
"content": [
|
|
1857
|
-
{
|
|
1858
|
-
"tag": "edge_routing",
|
|
1859
|
-
"attrs": {},
|
|
1860
|
-
"content": [
|
|
1861
|
-
{
|
|
1862
|
-
"tag": "routing_info",
|
|
1863
|
-
"attrs": {},
|
|
1864
|
-
"content": {
|
|
1865
|
-
"type": "Buffer",
|
|
1866
|
-
"data": [8,2,8,5]
|
|
1867
|
-
}
|
|
1868
|
-
}
|
|
1869
|
-
]
|
|
1870
|
-
}
|
|
1871
|
-
]
|
|
1872
|
-
},
|
|
1873
|
-
"msg":"communication"
|
|
1874
|
-
}
|
|
1875
|
-
```
|
|
1876
|
-
|
|
1877
|
-
The `'frame'` is what the message received is, it has three components:
|
|
1878
|
-
- `tag` -- what this frame is about (eg. message will have 'message')
|
|
1879
|
-
- `attrs` -- a string key-value pair with some metadata (contains ID of the message usually)
|
|
1880
|
-
- `content` -- the actual data (eg. a message node will have the actual message content in it)
|
|
1881
|
-
- read more about this format [here](/src/WABinary/readme.md)
|
|
1882
|
-
|
|
1883
|
-
### Register a Callback for Websocket Events
|
|
1884
|
-
|
|
1885
|
-
> [!TIP]
|
|
1886
|
-
> Recommended to see `onMessageReceived` function in `socket.ts` file to understand how websockets events are fired
|
|
239
|
+
**Special Thanks:**
|
|
240
|
+
- RexyHayanais
|
|
241
|
+
- Nystar
|
|
1887
242
|
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
sock.ws.on('CB:edge_routing', (node: BinaryNode) => { })
|
|
243
|
+
> [!CAUTION]
|
|
244
|
+
> Built on top of the WhiskeySockets/Baileys project. All original core logic credits go to their team. angularsockets extends it with thoughtful UX and DX improvements.
|
|
1891
245
|
|
|
1892
|
-
|
|
1893
|
-
sock.ws.on('CB:edge_routing,id:abcd', (node: BinaryNode) => { })
|
|
246
|
+
---
|
|
1894
247
|
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
> [!NOTE]
|
|
1900
|
-
> Also, this repo is now licenced under GPL 3 since it uses [libsignal-node](https://git.questbook.io/backend/service-coderunner/-/merge_requests/1)
|
|
248
|
+
<div align="center">
|
|
249
|
+
<p>Made with 💜 by MR FRANK OFC</p>
|
|
250
|
+
</div>
|