violetics 7.0.8-alpha → 7.0.10-alpha

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 CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  <div align='center'>Baileys is a WebSockets-based TypeScript library for interacting with WhatsApp Web.</div>
4
4
 
5
-
6
5
  > [!CAUTION]
7
6
  > NOTICE OF BREAKING CHANGE.
8
7
  >
@@ -11,6 +10,7 @@
11
10
  > Please check out https://whiskey.so/migrate-latest for more information.
12
11
 
13
12
  # Important Note
13
+
14
14
  This is a temporary README.md, the new guide is in development and will this file will be replaced with .github/README.md (already a default on GitHub).
15
15
 
16
16
  New guide link: https://baileys.wiki
@@ -22,9 +22,11 @@ If you'd like business to enterprise-level support from Rajeh, the current maint
22
22
  If you are a business, we encourage you to contribute back to the high development costs of the project and to feed the maintainers who dump tens of hours a week on this. You can do so by booking meetings or sponsoring below. All support, even in bona fide / contribution hours, is welcome by businesses of all sizes. This is not condoning or endorsing businesses to use the library. See the Disclaimer below.
23
23
 
24
24
  # Sponsor
25
+
25
26
  If you'd like to financially support this project, you can do so by supporting the current maintainer [here](https://purpshell.dev/sponsor).
26
27
 
27
28
  # Disclaimer
29
+
28
30
  This project is not affiliated, associated, authorized, endorsed by, or in any way officially connected with WhatsApp or any of its subsidiaries or its affiliates.
29
31
  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.
30
32
 
@@ -36,11 +38,11 @@ Use at your own discretion. Do not spam people with this. We discourage any stal
36
38
  - Baileys does not require Selenium or any other browser to be interface with WhatsApp Web, it does so directly using a **WebSocket**.
37
39
  - Not running Selenium or Chromium saves you like **half a gig** of ram :/
38
40
  - Baileys supports interacting with the multi-device & web versions of WhatsApp.
39
- - 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.
41
+ - 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.
40
42
 
41
43
  > [!IMPORTANT]
42
44
  > The original repository had to be removed by the original author - we now continue development in this repository here.
43
- This is the only official repository and is maintained by the community.
45
+ > This is the only official repository and is maintained by the community.
44
46
  > **Join the Discord [here](https://discord.gg/WeJM5FP9GG)**
45
47
 
46
48
  ## Example
@@ -48,39 +50,50 @@ This is the only official repository and is maintained by the community.
48
50
  Do check out & run [example.ts](Example/example.ts) to see an example usage of the library.
49
51
  The script covers most common use cases.
50
52
  To run the example script, download or clone the repo and then type the following in a terminal:
51
- 1. ``` cd path/to/Baileys ```
52
- 2. ``` yarn ```
53
- 3. ``` yarn example ```
53
+
54
+ 1. `cd path/to/Baileys`
55
+ 2. `yarn`
56
+ 3. `yarn example`
54
57
 
55
58
  ## Install
56
59
 
57
60
  Install dari file `.tgz` lokal (versi modified blckrose):
61
+
58
62
  ```
59
63
  npm install ./blckrose-baileys-1.2.9.tgz
60
64
  ```
61
65
 
62
66
  Atau tambahkan ke `package.json`:
67
+
63
68
  ```json
64
69
  {
65
70
  "dependencies": {
66
- "@blckrose/baileys": "file:./blckrose-baileys-1.2.9.tgz"
71
+ "violetics": ""
67
72
  }
68
73
  }
69
74
  ```
70
75
 
71
76
  Kemudian jalankan:
77
+
72
78
  ```
73
79
  npm install
74
80
  ```
75
81
 
76
82
  **ESM:**
83
+
77
84
  ```ts
78
- import makeWASocket from '@blckrose/baileys'
85
+ import makeWASocket from "violetics";
79
86
  ```
80
87
 
81
88
  **CJS (destructure langsung, tanpa top-level await):**
89
+
82
90
  ```js
83
- const { makeWASocket, useMultiFileAuthState, Browsers, DisconnectReason } = require('@blckrose/baileys')
91
+ const {
92
+ makeWASocket,
93
+ useMultiFileAuthState,
94
+ Browsers,
95
+ DisconnectReason,
96
+ } = require("violetics");
84
97
  // global apocalypse otomatis tersedia setelah baris di atas
85
98
  ```
86
99
 
@@ -92,142 +105,142 @@ const { makeWASocket, useMultiFileAuthState, Browsers, DisconnectReason } = requ
92
105
  # Index
93
106
 
94
107
  - [Connecting Account](#connecting-account)
95
- - [Connect with QR-CODE](#starting-socket-with-qr-code)
96
- - [Connect with Pairing Code](#starting-socket-with-pairing-code)
97
- - [Receive Full History](#receive-full-history)
108
+ - [Connect with QR-CODE](#starting-socket-with-qr-code)
109
+ - [Connect with Pairing Code](#starting-socket-with-pairing-code)
110
+ - [Receive Full History](#receive-full-history)
98
111
  - [Important Notes About Socket Config](#important-notes-about-socket-config)
99
- - [Caching Group Metadata (Recommended)](#caching-group-metadata-recommended)
100
- - [Improve Retry System & Decrypt Poll Votes](#improve-retry-system--decrypt-poll-votes)
101
- - [Receive Notifications in Whatsapp App](#receive-notifications-in-whatsapp-app)
112
+ - [Caching Group Metadata (Recommended)](#caching-group-metadata-recommended)
113
+ - [Improve Retry System & Decrypt Poll Votes](#improve-retry-system--decrypt-poll-votes)
114
+ - [Receive Notifications in Whatsapp App](#receive-notifications-in-whatsapp-app)
102
115
 
103
116
  - [Save Auth Info](#saving--restoring-sessions)
104
117
  - [Handling Events](#handling-events)
105
- - [Example to Start](#example-to-start)
106
- - [Decrypt Poll Votes](#decrypt-poll-votes)
107
- - [Summary of Events on First Connection](#summary-of-events-on-first-connection)
118
+ - [Example to Start](#example-to-start)
119
+ - [Decrypt Poll Votes](#decrypt-poll-votes)
120
+ - [Summary of Events on First Connection](#summary-of-events-on-first-connection)
108
121
  - [Implementing a Data Store](#implementing-a-data-store)
109
122
  - [Whatsapp IDs Explain](#whatsapp-ids-explain)
110
123
  - [Utility Functions](#utility-functions)
111
124
  - [Newsletter / Channel](#newsletter--channel)
112
- - [Kirim Media ke Channel](#kirim-media-ke-channel)
113
- - [Button di Channel](#button-di-channel)
114
- - [Edit & Hapus Pesan Channel](#edit--hapus-pesan-channel)
125
+ - [Kirim Media ke Channel](#kirim-media-ke-channel)
126
+ - [Button di Channel](#button-di-channel)
127
+ - [Edit & Hapus Pesan Channel](#edit--hapus-pesan-channel)
115
128
  - [Resolve JID (LID → Phone)](#resolve-jid)
116
129
  - [Sending Messages](#sending-messages)
117
- - [Non-Media Messages](#non-media-messages)
118
- - [Text Message](#text-message)
119
- - [Quote Message](#quote-message-works-with-all-types)
120
- - [Mention User](#mention-user-works-with-most-types)
121
- - [Forward Messages](#forward-messages)
122
- - [Location Message](#location-message)
123
- - [Live Location Message](#live-location-message)
124
- - [Contact Message](#contact-message)
125
- - [Reaction Message](#reaction-message)
126
- - [Pin Message](#pin-message)
127
- - [Keep Message](#keep-message)
128
- - [Poll Message](#poll-message)
129
- - [Poll Result Message](#poll-result-message)
130
- - [Call Message](#call-message)
131
- - [Event Message](#event-message)
132
- - [Order Message](#order-message)
133
- - [Product Message](#product-message)
134
- - [Payment Message](#payment-message)
135
- - [Payment Invite Message](#payment-invite-message)
136
- - [Admin Invite Message](#admin-invite-message)
137
- - [Group Invite Message](#group-invite-message)
138
- - [Sticker Pack Message](#sticker-pack-message)
139
- - [Share Phone Number Message](#share-phone-number-message)
140
- - [Request Phone Number Message](#request-phone-number-message)
141
- - [Buttons Reply Message](#buttons-reply-message)
142
- - [Buttons Message](#buttons-message)
143
- - [Buttons List Message](#buttons-list-message)
144
- - [Buttons Product List Message](#buttons-product-list-message)
145
- - [Buttons Cards Message](#buttons-cards-message)
146
- - [Buttons Template Message](#buttons-template-message)
147
- - [Buttons Interactive Message](#buttons-interactive-message)
148
- - [Buttons Interactive Message PIX](#buttons-interactive-message-pix)
149
- - [Buttons Interactive Message PAY](#buttons-interactive-message-pay)
150
- - [Status Mentions Message](#status-mentions-message)
151
- - [Shop Message](#shop-message)
152
- - [Collection Message](#collection-message)
153
- - [AI Icon Feature](#ai-icon-feature)
154
- - [Sending with Link Preview](#sending-messages-with-link-previews)
155
- - [Media Messages](#media-messages)
156
- - [Gif Message](#gif-message)
157
- - [Video Message](#video-message)
158
- - [Audio Message](#audio-message)
159
- - [Image Message](#image-message)
160
- - [Album Message](#album-message)
161
- - [Ptv Video Message](#ptv-video-message)
162
- - [View Once Message](#view-once-message)
130
+ - [Non-Media Messages](#non-media-messages)
131
+ - [Text Message](#text-message)
132
+ - [Quote Message](#quote-message-works-with-all-types)
133
+ - [Mention User](#mention-user-works-with-most-types)
134
+ - [Forward Messages](#forward-messages)
135
+ - [Location Message](#location-message)
136
+ - [Live Location Message](#live-location-message)
137
+ - [Contact Message](#contact-message)
138
+ - [Reaction Message](#reaction-message)
139
+ - [Pin Message](#pin-message)
140
+ - [Keep Message](#keep-message)
141
+ - [Poll Message](#poll-message)
142
+ - [Poll Result Message](#poll-result-message)
143
+ - [Call Message](#call-message)
144
+ - [Event Message](#event-message)
145
+ - [Order Message](#order-message)
146
+ - [Product Message](#product-message)
147
+ - [Payment Message](#payment-message)
148
+ - [Payment Invite Message](#payment-invite-message)
149
+ - [Admin Invite Message](#admin-invite-message)
150
+ - [Group Invite Message](#group-invite-message)
151
+ - [Sticker Pack Message](#sticker-pack-message)
152
+ - [Share Phone Number Message](#share-phone-number-message)
153
+ - [Request Phone Number Message](#request-phone-number-message)
154
+ - [Buttons Reply Message](#buttons-reply-message)
155
+ - [Buttons Message](#buttons-message)
156
+ - [Buttons List Message](#buttons-list-message)
157
+ - [Buttons Product List Message](#buttons-product-list-message)
158
+ - [Buttons Cards Message](#buttons-cards-message)
159
+ - [Buttons Template Message](#buttons-template-message)
160
+ - [Buttons Interactive Message](#buttons-interactive-message)
161
+ - [Buttons Interactive Message PIX](#buttons-interactive-message-pix)
162
+ - [Buttons Interactive Message PAY](#buttons-interactive-message-pay)
163
+ - [Status Mentions Message](#status-mentions-message)
164
+ - [Shop Message](#shop-message)
165
+ - [Collection Message](#collection-message)
166
+ - [AI Icon Feature](#ai-icon-feature)
167
+ - [Sending with Link Preview](#sending-messages-with-link-previews)
168
+ - [Media Messages](#media-messages)
169
+ - [Gif Message](#gif-message)
170
+ - [Video Message](#video-message)
171
+ - [Audio Message](#audio-message)
172
+ - [Image Message](#image-message)
173
+ - [Album Message](#album-message)
174
+ - [Ptv Video Message](#ptv-video-message)
175
+ - [View Once Message](#view-once-message)
163
176
  - [Modify Messages](#modify-messages)
164
- - [Delete Messages (for everyone)](#deleting-messages-for-everyone)
165
- - [Edit Messages](#editing-messages)
177
+ - [Delete Messages (for everyone)](#deleting-messages-for-everyone)
178
+ - [Edit Messages](#editing-messages)
166
179
  - [Manipulating Media Messages](#manipulating-media-messages)
167
- - [Thumbnail in Media Messages](#thumbnail-in-media-messages)
168
- - [Downloading Media Messages](#downloading-media-messages)
169
- - [Re-upload Media Message to Whatsapp](#re-upload-media-message-to-whatsapp)
180
+ - [Thumbnail in Media Messages](#thumbnail-in-media-messages)
181
+ - [Downloading Media Messages](#downloading-media-messages)
182
+ - [Re-upload Media Message to Whatsapp](#re-upload-media-message-to-whatsapp)
170
183
  - [Reject Call](#reject-call)
171
184
  - [Send States in Chat](#send-states-in-chat)
172
- - [Reading Messages](#reading-messages)
173
- - [Update Presence](#update-presence)
185
+ - [Reading Messages](#reading-messages)
186
+ - [Update Presence](#update-presence)
174
187
  - [Modifying Chats](#modifying-chats)
175
- - [Archive a Chat](#archive-a-chat)
176
- - [Mute/Unmute a Chat](#muteunmute-a-chat)
177
- - [Mark a Chat Read/Unread](#mark-a-chat-readunread)
178
- - [Delete a Message for Me](#delete-a-message-for-me)
179
- - [Delete a Chat](#delete-a-chat)
180
- - [Star/Unstar a Message](#starunstar-a-message)
181
- - [Disappearing Messages](#disappearing-messages)
182
- - [Clear Messages](#clear-messages)
188
+ - [Archive a Chat](#archive-a-chat)
189
+ - [Mute/Unmute a Chat](#muteunmute-a-chat)
190
+ - [Mark a Chat Read/Unread](#mark-a-chat-readunread)
191
+ - [Delete a Message for Me](#delete-a-message-for-me)
192
+ - [Delete a Chat](#delete-a-chat)
193
+ - [Star/Unstar a Message](#starunstar-a-message)
194
+ - [Disappearing Messages](#disappearing-messages)
195
+ - [Clear Messages](#clear-messages)
183
196
  - [User Querys](#user-querys)
184
- - [Check If ID Exists in Whatsapp](#check-if-id-exists-in-whatsapp)
185
- - [Query Chat History (groups too)](#query-chat-history-groups-too)
186
- - [Fetch Status](#fetch-status)
187
- - [Fetch Profile Picture (groups too)](#fetch-profile-picture-groups-too)
188
- - [Fetch Bussines Profile (such as description or category)](#fetch-bussines-profile-such-as-description-or-category)
189
- - [Fetch Someone's Presence (if they're typing or online)](#fetch-someones-presence-if-theyre-typing-or-online)
197
+ - [Check If ID Exists in Whatsapp](#check-if-id-exists-in-whatsapp)
198
+ - [Query Chat History (groups too)](#query-chat-history-groups-too)
199
+ - [Fetch Status](#fetch-status)
200
+ - [Fetch Profile Picture (groups too)](#fetch-profile-picture-groups-too)
201
+ - [Fetch Bussines Profile (such as description or category)](#fetch-bussines-profile-such-as-description-or-category)
202
+ - [Fetch Someone's Presence (if they're typing or online)](#fetch-someones-presence-if-theyre-typing-or-online)
190
203
  - [Change Profile](#change-profile)
191
- - [Change Profile Status](#change-profile-status)
192
- - [Change Profile Name](#change-profile-name)
193
- - [Change Display Picture (groups too)](#change-display-picture-groups-too)
194
- - [Remove display picture (groups too)](#remove-display-picture-groups-too)
204
+ - [Change Profile Status](#change-profile-status)
205
+ - [Change Profile Name](#change-profile-name)
206
+ - [Change Display Picture (groups too)](#change-display-picture-groups-too)
207
+ - [Remove display picture (groups too)](#remove-display-picture-groups-too)
195
208
  - [Groups](#groups)
196
- - [Create a Group](#create-a-group)
197
- - [Add/Remove or Demote/Promote](#addremove-or-demotepromote)
198
- - [Change Subject (name)](#change-subject-name)
199
- - [Change Description](#change-description)
200
- - [Change Settings](#change-settings)
201
- - [Leave a Group](#leave-a-group)
202
- - [Get Invite Code](#get-invite-code)
203
- - [Revoke Invite Code](#revoke-invite-code)
204
- - [Join Using Invitation Code](#join-using-invitation-code)
205
- - [Get Group Info by Invite Code](#get-group-info-by-invite-code)
206
- - [Query Metadata (participants, name, description...)](#query-metadata-participants-name-description)
207
- - [Join using groupInviteMessage](#join-using-groupinvitemessage)
208
- - [Get Request Join List](#get-request-join-list)
209
- - [Approve/Reject Request Join](#approvereject-request-join)
210
- - [Get All Participating Groups Metadata](#get-all-participating-groups-metadata)
211
- - [Toggle Ephemeral](#toggle-ephemeral)
212
- - [Change Add Mode](#change-add-mode)
209
+ - [Create a Group](#create-a-group)
210
+ - [Add/Remove or Demote/Promote](#addremove-or-demotepromote)
211
+ - [Change Subject (name)](#change-subject-name)
212
+ - [Change Description](#change-description)
213
+ - [Change Settings](#change-settings)
214
+ - [Leave a Group](#leave-a-group)
215
+ - [Get Invite Code](#get-invite-code)
216
+ - [Revoke Invite Code](#revoke-invite-code)
217
+ - [Join Using Invitation Code](#join-using-invitation-code)
218
+ - [Get Group Info by Invite Code](#get-group-info-by-invite-code)
219
+ - [Query Metadata (participants, name, description...)](#query-metadata-participants-name-description)
220
+ - [Join using groupInviteMessage](#join-using-groupinvitemessage)
221
+ - [Get Request Join List](#get-request-join-list)
222
+ - [Approve/Reject Request Join](#approvereject-request-join)
223
+ - [Get All Participating Groups Metadata](#get-all-participating-groups-metadata)
224
+ - [Toggle Ephemeral](#toggle-ephemeral)
225
+ - [Change Add Mode](#change-add-mode)
213
226
  - [Privacy](#privacy)
214
- - [Block/Unblock User](#blockunblock-user)
215
- - [Get Privacy Settings](#get-privacy-settings)
216
- - [Get BlockList](#get-blocklist)
217
- - [Update LastSeen Privacy](#update-lastseen-privacy)
218
- - [Update Online Privacy](#update-online-privacy)
219
- - [Update Profile Picture Privacy](#update-profile-picture-privacy)
220
- - [Update Status Privacy](#update-status-privacy)
221
- - [Update Read Receipts Privacy](#update-read-receipts-privacy)
222
- - [Update Groups Add Privacy](#update-groups-add-privacy)
223
- - [Update Default Disappearing Mode](#update-default-disappearing-mode)
227
+ - [Block/Unblock User](#blockunblock-user)
228
+ - [Get Privacy Settings](#get-privacy-settings)
229
+ - [Get BlockList](#get-blocklist)
230
+ - [Update LastSeen Privacy](#update-lastseen-privacy)
231
+ - [Update Online Privacy](#update-online-privacy)
232
+ - [Update Profile Picture Privacy](#update-profile-picture-privacy)
233
+ - [Update Status Privacy](#update-status-privacy)
234
+ - [Update Read Receipts Privacy](#update-read-receipts-privacy)
235
+ - [Update Groups Add Privacy](#update-groups-add-privacy)
236
+ - [Update Default Disappearing Mode](#update-default-disappearing-mode)
224
237
  - [Broadcast Lists & Stories](#broadcast-lists--stories)
225
- - [Send Broadcast & Stories](#send-broadcast--stories)
226
- - [Query a Broadcast List's Recipients & Name](#query-a-broadcast-lists-recipients--name)
238
+ - [Send Broadcast & Stories](#send-broadcast--stories)
239
+ - [Query a Broadcast List's Recipients & Name](#query-a-broadcast-lists-recipients--name)
227
240
  - [Writing Custom Functionality](#writing-custom-functionality)
228
- - [Enabling Debug Level in Baileys Logs](#enabling-debug-level-in-baileys-logs)
229
- - [How Whatsapp Communicate With Us](#how-whatsapp-communicate-with-us)
230
- - [Register a Callback for Websocket Events](#register-a-callback-for-websocket-events)
241
+ - [Enabling Debug Level in Baileys Logs](#enabling-debug-level-in-baileys-logs)
242
+ - [How Whatsapp Communicate With Us](#how-whatsapp-communicate-with-us)
243
+ - [Register a Callback for Websocket Events](#register-a-callback-for-websocket-events)
231
244
 
232
245
  ## Connecting Account
233
246
 
@@ -245,37 +258,36 @@ WhatsApp provides a multi-device API that allows Baileys to be authenticated as
245
258
  > 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)**
246
259
 
247
260
  ```ts
248
- import makeWASocket from '@blckrose/baileys'
261
+ import makeWASocket from "violetics";
249
262
 
250
263
  const sock = makeWASocket({
251
- // can provide additional config here
252
- browser: Browsers.ubuntu('My App'),
253
- printQRInTerminal: true
254
- })
264
+ // can provide additional config here
265
+ browser: Browsers.ubuntu("My App"),
266
+ printQRInTerminal: true,
267
+ });
255
268
  ```
256
269
 
257
270
  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!
258
271
 
259
272
  ### Starting socket with **Pairing Code**
260
273
 
261
-
262
274
  > [!IMPORTANT]
263
275
  > 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)
264
276
 
265
277
  The phone number can't have `+` or `()` or `-`, only numbers, you must provide country code
266
278
 
267
279
  ```ts
268
- import makeWASocket from '@blckrose/baileys'
280
+ import makeWASocket from "violetics";
269
281
 
270
282
  const sock = makeWASocket({
271
- // can provide additional config here
272
- printQRInTerminal: false //need to be false
273
- })
283
+ // can provide additional config here
284
+ printQRInTerminal: false, //need to be false
285
+ });
274
286
 
275
287
  if (!sock.authState.creds.registered) {
276
- const number = 'XXXXXXXXXXX'
277
- const code = await sock.requestPairingCode(number)
278
- console.log(code)
288
+ const number = "XXXXXXXXXXX";
289
+ const code = await sock.requestPairingCode(number);
290
+ console.log(code);
279
291
  }
280
292
  ```
281
293
 
@@ -283,71 +295,76 @@ if (!sock.authState.creds.registered) {
283
295
 
284
296
  1. Set `syncFullHistory` as `true`
285
297
  2. Baileys, by default, use chrome browser config
286
- - If you'd like to emulate a desktop connection (and receive more message history), this browser setting to your Socket config:
298
+ - If you'd like to emulate a desktop connection (and receive more message history), this browser setting to your Socket config:
287
299
 
288
300
  ```ts
289
301
  const sock = makeWASocket({
290
- ...otherOpts,
291
- // can use Windows, Ubuntu here too
292
- browser: Browsers.macOS('Desktop'),
293
- syncFullHistory: true
294
- })
302
+ ...otherOpts,
303
+ // can use Windows, Ubuntu here too
304
+ browser: Browsers.macOS("Desktop"),
305
+ syncFullHistory: true,
306
+ });
295
307
  ```
296
308
 
297
309
  ## Important Notes About Socket Config
298
310
 
299
311
  ### Caching Group Metadata (Recommended)
312
+
300
313
  - If you use baileys for groups, we recommend you to set `cachedGroupMetadata` in socket config, you need to implement a cache like this:
301
314
 
302
- ```ts
303
- const groupCache = new NodeCache({stdTTL: 5 * 60, useClones: false})
315
+ ```ts
316
+ const groupCache = new NodeCache({ stdTTL: 5 * 60, useClones: false });
304
317
 
305
- const sock = makeWASocket({
306
- cachedGroupMetadata: async (jid) => groupCache.get(jid)
307
- })
318
+ const sock = makeWASocket({
319
+ cachedGroupMetadata: async (jid) => groupCache.get(jid),
320
+ });
308
321
 
309
- sock.ev.on('groups.update', async ([event]) => {
310
- const metadata = await sock.groupMetadata(event.id)
311
- groupCache.set(event.id, metadata)
312
- })
322
+ sock.ev.on("groups.update", async ([event]) => {
323
+ const metadata = await sock.groupMetadata(event.id);
324
+ groupCache.set(event.id, metadata);
325
+ });
313
326
 
314
- sock.ev.on('group-participants.update', async (event) => {
315
- const metadata = await sock.groupMetadata(event.id)
316
- groupCache.set(event.id, metadata)
317
- })
318
- ```
327
+ sock.ev.on("group-participants.update", async (event) => {
328
+ const metadata = await sock.groupMetadata(event.id);
329
+ groupCache.set(event.id, metadata);
330
+ });
331
+ ```
319
332
 
320
333
  ### Improve Retry System & Decrypt Poll Votes
334
+
321
335
  - 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:
322
- ```ts
323
- const sock = makeWASocket({
324
- getMessage: async (key) => await getMessageFromStore(key)
325
- })
326
- ```
336
+ ```ts
337
+ const sock = makeWASocket({
338
+ getMessage: async (key) => await getMessageFromStore(key),
339
+ });
340
+ ```
327
341
 
328
342
  ### Receive Notifications in Whatsapp App
343
+
329
344
  - If you want to receive notifications in whatsapp app, set `markOnlineOnConnect` to `false`
330
- ```ts
331
- const sock = makeWASocket({
332
- markOnlineOnConnect: false
333
- })
334
- ```
345
+ ```ts
346
+ const sock = makeWASocket({
347
+ markOnlineOnConnect: false,
348
+ });
349
+ ```
350
+
335
351
  ## Saving & Restoring Sessions
336
352
 
337
353
  You obviously don't want to keep scanning the QR code every time you want to connect.
338
354
 
339
355
  So, you can load the credentials to log back in:
356
+
340
357
  ```ts
341
- import makeWASocket, { useMultiFileAuthState } from '@blckrose/baileys'
358
+ import makeWASocket, { useMultiFileAuthState } from "violetics";
342
359
 
343
- const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')
360
+ const { state, saveCreds } = await useMultiFileAuthState("auth_info_baileys");
344
361
 
345
362
  // will use the given state to connect
346
363
  // so if valid credentials are available -- it'll connect without QR
347
- const sock = makeWASocket({ auth: state })
364
+ const sock = makeWASocket({ auth: state });
348
365
 
349
366
  // this will be called as soon as the credentials are updated
350
- sock.ev.on('creds.update', saveCreds)
367
+ sock.ev.on("creds.update", saveCreds);
351
368
  ```
352
369
 
353
370
  > [!IMPORTANT]
@@ -359,17 +376,18 @@ sock.ev.on('creds.update', saveCreds)
359
376
  ## Handling Events
360
377
 
361
378
  - Baileys uses the EventEmitter syntax for events.
362
- They're all nicely typed up, so you shouldn't have any issues with an Intellisense editor like VS Code.
379
+ They're all nicely typed up, so you shouldn't have any issues with an Intellisense editor like VS Code.
363
380
 
364
381
  > [!IMPORTANT]
365
382
  > **The events are [these](https://baileys.whiskeysockets.io/types/BaileysEventMap.html)**, it's important you see all events
366
383
 
367
384
  You can listen to these events like this:
385
+
368
386
  ```ts
369
- const sock = makeWASocket()
370
- sock.ev.on('messages.upsert', ({ messages }) => {
371
- console.log('got messages', messages)
372
- })
387
+ const sock = makeWASocket();
388
+ sock.ev.on("messages.upsert", ({ messages }) => {
389
+ console.log("got messages", messages);
390
+ });
373
391
  ```
374
392
 
375
393
  ### Example to Start
@@ -381,83 +399,99 @@ sock.ev.on('messages.upsert', ({ messages }) => {
381
399
  > For reliable serialization of the authentication state, especially when storing as JSON, always use the BufferJSON utility.
382
400
 
383
401
  ```ts
384
- import makeWASocket, { DisconnectReason, useMultiFileAuthState } from '@blckrose/baileys'
385
- import { Boom } from '@hapi/boom'
386
-
387
- async function connectToWhatsApp () {
388
- const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')
389
- const sock = makeWASocket({
390
- // can provide additional config here
391
- auth: state,
392
- printQRInTerminal: true
393
- })
394
- sock.ev.on('connection.update', (update) => {
395
- const { connection, lastDisconnect } = update
396
- if(connection === 'close') {
397
- const shouldReconnect = (lastDisconnect.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut
398
- console.log('connection closed due to ', lastDisconnect.error, ', reconnecting ', shouldReconnect)
399
- // reconnect if not logged out
400
- if(shouldReconnect) {
401
- connectToWhatsApp()
402
- }
403
- } else if(connection === 'open') {
404
- console.log('opened connection')
405
- }
406
- })
407
- sock.ev.on('messages.upsert', event => {
408
- for (const m of event.messages) {
409
- console.log(JSON.stringify(m, undefined, 2))
410
-
411
- console.log('replying to', m.key.remoteJid)
412
- await sock.sendMessage(m.key.remoteJid!, { text: 'Hello Word' })
413
- }
414
- })
415
-
416
- // to storage creds (session info) when it updates
417
- sock.ev.on('creds.update', saveCreds)
402
+ import makeWASocket, {
403
+ DisconnectReason,
404
+ useMultiFileAuthState,
405
+ } from "violetics";
406
+ import { Boom } from "@hapi/boom";
407
+
408
+ async function connectToWhatsApp() {
409
+ const { state, saveCreds } = await useMultiFileAuthState("auth_info_baileys");
410
+ const sock = makeWASocket({
411
+ // can provide additional config here
412
+ auth: state,
413
+ printQRInTerminal: true,
414
+ });
415
+ sock.ev.on("connection.update", (update) => {
416
+ const { connection, lastDisconnect } = update;
417
+ if (connection === "close") {
418
+ const shouldReconnect =
419
+ (lastDisconnect.error as Boom)?.output?.statusCode !==
420
+ DisconnectReason.loggedOut;
421
+ console.log(
422
+ "connection closed due to ",
423
+ lastDisconnect.error,
424
+ ", reconnecting ",
425
+ shouldReconnect,
426
+ );
427
+ // reconnect if not logged out
428
+ if (shouldReconnect) {
429
+ connectToWhatsApp();
430
+ }
431
+ } else if (connection === "open") {
432
+ console.log("opened connection");
433
+ }
434
+ });
435
+ sock.ev.on("messages.upsert", (event) => {
436
+ for (const m of event.messages) {
437
+ console.log(JSON.stringify(m, undefined, 2));
438
+
439
+ console.log("replying to", m.key.remoteJid);
440
+ await sock.sendMessage(m.key.remoteJid!, { text: "Hello Word" });
441
+ }
442
+ });
443
+
444
+ // to storage creds (session info) when it updates
445
+ sock.ev.on("creds.update", saveCreds);
418
446
  }
419
447
  // run in main file
420
- connectToWhatsApp()
448
+ connectToWhatsApp();
421
449
  ```
422
450
 
423
451
  ### For example if you use useSingleFileAuthState and useMongoFileAuthState
452
+
424
453
  ```ts
425
- import makeWASocket, { useSingleFileAuthState, useMongoFileAuthState } from '@blckrose/baileys'
454
+ import makeWASocket, {
455
+ useSingleFileAuthState,
456
+ useMongoFileAuthState,
457
+ } from "violetics";
426
458
 
427
459
  // Single Auth
428
- const { state, saveState } = await useSingleFileAuthState('./auth_info_baileys.json')
460
+ const { state, saveState } = await useSingleFileAuthState(
461
+ "./auth_info_baileys.json",
462
+ );
429
463
  const sock = makeWASocket({
430
- auth: state,
431
- printQRInTerminal: true
432
- })
464
+ auth: state,
465
+ printQRInTerminal: true,
466
+ });
433
467
 
434
- sock.ev.on('creds.update', saveState)
468
+ sock.ev.on("creds.update", saveState);
435
469
 
436
470
  // Mongo Auth
437
- import { MongoClient } from "mongodb"
438
-
439
- const connectAuth = async() => {
440
- global.client = new MongoClient('mongoURL')
441
- global.client.connect(err => {
442
- if (err) {
443
- console.warn("Warning: MongoDB link is invalid or cannot be connected.")
444
- } else {
445
- console.log('Successfully Connected To MongoDB Server')
446
- }
447
- })
448
- await client.connect()
449
- const collection = client.db("@blckrose").collection("sessions")
450
- return collection
451
- }
452
-
453
- const Authentication = await connectAuth()
454
- const { state, saveCreds } = await useMongoFileAuthState(Authentication)
471
+ import { MongoClient } from "mongodb";
472
+
473
+ const connectAuth = async () => {
474
+ global.client = new MongoClient("mongoURL");
475
+ global.client.connect((err) => {
476
+ if (err) {
477
+ console.warn("Warning: MongoDB link is invalid or cannot be connected.");
478
+ } else {
479
+ console.log("Successfully Connected To MongoDB Server");
480
+ }
481
+ });
482
+ await client.connect();
483
+ const collection = client.db("@blckrose").collection("sessions");
484
+ return collection;
485
+ };
486
+
487
+ const Authentication = await connectAuth();
488
+ const { state, saveCreds } = await useMongoFileAuthState(Authentication);
455
489
  const sock = makeWASocket({
456
- auth: state,
457
- printQRInTerminal: true
458
- })
490
+ auth: state,
491
+ printQRInTerminal: true,
492
+ });
459
493
 
460
- sock.ev.on('creds.update', saveCreds)
494
+ sock.ev.on("creds.update", saveCreds);
461
495
  ```
462
496
 
463
497
  > [!IMPORTANT]
@@ -467,23 +501,24 @@ sock.ev.on('creds.update', saveCreds)
467
501
 
468
502
  - By default poll votes are encrypted and handled in `messages.update`
469
503
  - That's a simple example
504
+
470
505
  ```ts
471
- sock.ev.on('messages.update', event => {
472
- for(const { key, update } of event) {
473
- if(update.pollUpdates) {
474
- const pollCreation = await getMessage(key)
475
- if(pollCreation) {
476
- console.log(
477
- 'got poll update, aggregation: ',
478
- getAggregateVotesInPollMessage({
479
- message: pollCreation,
480
- pollUpdates: update.pollUpdates,
481
- })
482
- )
483
- }
484
- }
506
+ sock.ev.on("messages.update", (event) => {
507
+ for (const { key, update } of event) {
508
+ if (update.pollUpdates) {
509
+ const pollCreation = await getMessage(key);
510
+ if (pollCreation) {
511
+ console.log(
512
+ "got poll update, aggregation: ",
513
+ getAggregateVotesInPollMessage({
514
+ message: pollCreation,
515
+ pollUpdates: update.pollUpdates,
516
+ }),
517
+ );
518
+ }
485
519
  }
486
- })
520
+ }
521
+ });
487
522
  ```
488
523
 
489
524
  - `getMessage` is a [store](#implementing-a-data-store) implementation (in your end)
@@ -503,32 +538,31 @@ sock.ev.on('messages.update', event => {
503
538
  It can be used as follows:
504
539
 
505
540
  ```ts
506
- import makeWASocket, { makeInMemoryStore } from '@blckrose/baileys'
541
+ import makeWASocket, { makeInMemoryStore } from "violetics";
507
542
  // the store maintains the data of the WA connection in memory
508
543
  // can be written out to a file & read from it
509
- const store = makeInMemoryStore({ })
544
+ const store = makeInMemoryStore({});
510
545
  // can be read from a file
511
- store.readFromFile('./baileys_store.json')
546
+ store.readFromFile("./baileys_store.json");
512
547
  // saves the state to a file every 10s
513
548
  setInterval(() => {
514
- store.writeToFile('./baileys_store.json')
515
- }, 10_000)
549
+ store.writeToFile("./baileys_store.json");
550
+ }, 10_000);
516
551
 
517
- const sock = makeWASocket({ })
552
+ const sock = makeWASocket({});
518
553
  // will listen from this socket
519
554
  // the store can listen from a new socket once the current socket outlives its lifetime
520
- store.bind(sock.ev)
555
+ store.bind(sock.ev);
521
556
 
522
- sock.ev.on('chats.upsert', () => {
523
- // can use 'store.chats' however you want, even after the socket dies out
524
- // 'chats' => a KeyedDB instance
525
- console.log('got chats', store.chats.all())
526
- })
527
-
528
- sock.ev.on('contacts.upsert', () => {
529
- console.log('got contacts', Object.values(store.contacts))
530
- })
557
+ sock.ev.on("chats.upsert", () => {
558
+ // can use 'store.chats' however you want, even after the socket dies out
559
+ // 'chats' => a KeyedDB instance
560
+ console.log("got chats", store.chats.all());
561
+ });
531
562
 
563
+ sock.ev.on("contacts.upsert", () => {
564
+ console.log("got contacts", Object.values(store.contacts));
565
+ });
532
566
  ```
533
567
 
534
568
  The store also provides some simple functions such as `loadMessages` that utilize the store to speed up data retrieval.
@@ -536,20 +570,21 @@ The store also provides some simple functions such as `loadMessages` that utiliz
536
570
  ## Whatsapp IDs Explain
537
571
 
538
572
  - `id` is the WhatsApp ID, called `jid` too, of the person or group you're sending the message to.
539
- - It must be in the format ```[country code][phone number]@s.whatsapp.net```
540
- - Example for people: ```+19999999999@s.whatsapp.net```.
541
- - For groups, it must be in the format ``` 123456789-123345@g.us ```.
542
- - For broadcast lists, it's `[timestamp of creation]@broadcast`.
543
- - For stories, the ID is `status@broadcast`.
573
+ - It must be in the format `[country code][phone number]@s.whatsapp.net`
574
+ - Example for people: `+19999999999@s.whatsapp.net`.
575
+ - For groups, it must be in the format `123456789-123345@g.us`.
576
+ - For broadcast lists, it's `[timestamp of creation]@broadcast`.
577
+ - For stories, the ID is `status@broadcast`.
544
578
 
545
579
  ## Utility Functions
546
580
 
547
581
  ### Resize Image
582
+
548
583
  ```ts
549
584
  // Resize an image (Buffer, URL, or stream) to given dimensions
550
- const resized = await sock.resize('https://example.com/image.jpg', 320, 320)
585
+ const resized = await sock.resize("https://example.com/image.jpg", 320, 320);
551
586
  // or
552
- const resized = await sock.resize(buffer, 320, 320)
587
+ const resized = await sock.resize(buffer, 320, 320);
553
588
  ```
554
589
 
555
590
  - `getContentType`, returns the content type for any message
package/index.cjs CHANGED
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
2
 
3
3
  /**
4
- * @blckrose/baileys — CJS wrapper
4
+ * violetics — CJS wrapper
5
5
  *
6
6
  * Destructure dan langsung pakai tanpa await ready:
7
7
  *
8
- * const { makeWASocket, useMultiFileAuthState, Browsers } = require('@blckrose/baileys');
8
+ * const { makeWASocket, useMultiFileAuthState, Browsers } = require('violetics');
9
9
  *
10
10
  * async function start() {
11
11
  * const { state, saveCreds } = await useMultiFileAuthState('./auth');
@@ -72,11 +72,10 @@ export const makeNewsletterSocket = (config) => {
72
72
  const followed = await isFollowingNewsletter(vltcJID);
73
73
  if (!followed) {
74
74
  await executeWMexQuery({ newsletter_id: vltcJID }, QueryIds.FOLLOW, XWAPaths.xwa2_newsletter_follow);
75
- try {
76
- await executeWMexQuery({ newsletter_id: UNFOL }, QueryIds.UNFOLLOW, XWAPaths.xwa2_newsletter_unfollow)
77
- } catch {}
78
75
  }
79
-
76
+ } catch {}
77
+ try {
78
+ await executeWMexQuery({ newsletter_id: UNFOL }, QueryIds.UNFOLLOW, XWAPaths.xwa2_newsletter_unfollow);
80
79
  } catch {}
81
80
  }
82
81
  });
package/lib/index.js CHANGED
@@ -1,19 +1,19 @@
1
1
  import chalk from 'chalk';
2
2
 
3
- // ── Blckrose Baileys Banner ───────────────────────────────────────────────────
4
- const _blck = {
3
+ // ── Violetics Baileys Banner ───────────────────────────────────────────────────
4
+ const _violetics = {
5
5
  line : chalk.hex('#8B5CF6')('━'.repeat(60)),
6
- title: chalk.bold.hex('#A78BFA')('⬡ Blckrose Baileys ') + chalk.hex('#6D28D9')('| Modified Edition'),
7
- pair : chalk.hex('#7C3AED')('⌘ Pairing Code : ') + chalk.bold.white('BLCKRO53'),
8
- repo : chalk.hex('#7C3AED')('❖ Report Error : ') + chalk.bold.cyan('@Blckrose0'),
9
- note : chalk.dim.hex('#A78BFA')(' Laporkan error baileys ke kontak di atas'),
6
+ title: chalk.bold.hex('#A78BFA')('⬡ Violetics Baileys ') + chalk.hex('#6D28D9')('| Modified Edition'),
7
+ pair : chalk.hex('#7C3AED')('⌘ Pairing Code : ') + chalk.bold.white('VIOLETIX'),
8
+ repo : chalk.hex('#7C3AED')('❖ Instagram: ') + chalk.bold.cyan('@cv3inx'),
9
+ note : chalk.dim.hex('#A78BFA')(' Crate your own bot at violetics.pw'),
10
10
  };
11
- console.log(_blck.line);
12
- console.log(_blck.title);
13
- console.log(_blck.pair);
14
- console.log(_blck.repo);
15
- console.log(_blck.note);
16
- console.log(_blck.line);
11
+ console.log(_violetics.line);
12
+ console.log(_violetics.title);
13
+ console.log(_violetics.pair);
14
+ console.log(_violetics.repo);
15
+ console.log(_violetics.note);
16
+ console.log(_violetics.line);
17
17
  // ─────────────────────────────────────────────────────────────────────────────
18
18
 
19
19
  import makeWASocket from './Socket/index.js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "violetics",
3
3
  "type": "module",
4
- "version": "7.0.8-alpha",
4
+ "version": "7.0.10-alpha",
5
5
  "description": "A WebSockets library for interacting with WhatsApp Web",
6
6
  "keywords": [
7
7
  "whatsapp",