@pasqua-dev/baileys 1.0.0 → 2.0.0
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 +65 -46
- package/lib/Defaults/index.js +3 -1
- package/lib/Socket/socket.js +103 -53
- package/lib/Utils/companion-reg-client-utils.js +24 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
5
|
<p align="center">
|
|
6
|
-
<img src="https://img.shields.io/npm/v/@pasqua-
|
|
6
|
+
<img src="https://img.shields.io/npm/v/@pasqua-baileys/baileys?style=for-the-badge&logo=npm&color=dc2626&labelColor=111111" />
|
|
7
7
|
<img src="https://img.shields.io/github/stars/pasquawisdom2007-beep/pasqua-baileys?style=for-the-badge&logo=github&color=dc2626&labelColor=111111" />
|
|
8
8
|
<img src="https://img.shields.io/badge/License-MIT-dc2626?style=for-the-badge&labelColor=111111" />
|
|
9
9
|
<img src="https://img.shields.io/badge/Node.js-%3E%3D20-dc2626?style=for-the-badge&logo=node.js&labelColor=111111" />
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
|
|
67
67
|
## Overview
|
|
68
68
|
|
|
69
|
-
`@pasqua-
|
|
69
|
+
`@pasqua-baileys/baileys` is a powerful, production-ready WhatsApp API wrapper for Node.js, built on top of the Baileys protocol. It extends the core with rich messaging capabilities, Meta AI-style compositing, and a streamlined developer experience.
|
|
70
70
|
|
|
71
71
|
### What Sets It Apart
|
|
72
72
|
|
|
@@ -96,28 +96,47 @@
|
|
|
96
96
|
|
|
97
97
|
```bash
|
|
98
98
|
# NPM
|
|
99
|
-
npm install @pasqua-
|
|
99
|
+
npm install @pasqua-baileys/baileys
|
|
100
100
|
|
|
101
101
|
# GitHub
|
|
102
|
-
npm install github:
|
|
102
|
+
npm install github:pasqua-baileys/baileys
|
|
103
103
|
```
|
|
104
104
|
|
|
105
105
|
Import (ESM & CJS)
|
|
106
106
|
|
|
107
107
|
```javascript
|
|
108
108
|
// ESM
|
|
109
|
-
import { makeWASocket } from '@pasqua-
|
|
109
|
+
import { makeWASocket } from '@pasqua-baileys/baileys'
|
|
110
110
|
|
|
111
111
|
// CJS (Node.js 24+)
|
|
112
|
-
const { makeWASocket } = require('@pasqua-
|
|
112
|
+
const { makeWASocket } = require('@pasqua-baileys/baileys')
|
|
113
113
|
```
|
|
114
114
|
|
|
115
|
+
### Windows support
|
|
116
|
+
|
|
117
|
+
Baileys connects directly through a WebSocket; it does not require Chrome,
|
|
118
|
+
Selenium, or a browser process. The default browser identity now follows the
|
|
119
|
+
host operating system, including Windows. For a stable Windows desktop
|
|
120
|
+
identity, pass the WhiskeySockets-compatible preset explicitly:
|
|
121
|
+
|
|
122
|
+
```javascript
|
|
123
|
+
import { Browsers, makeWASocket } from '@pasqua-dev/baileys'
|
|
124
|
+
|
|
125
|
+
const sock = makeWASocket({
|
|
126
|
+
browser: Browsers.windows('Desktop'),
|
|
127
|
+
auth: state
|
|
128
|
+
})
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Windows deployments require Node.js 20 or newer. Media thumbnail generation
|
|
132
|
+
also requires `ffmpeg` to be installed and available on `PATH`.
|
|
133
|
+
|
|
115
134
|
---
|
|
116
135
|
|
|
117
136
|
## Quick Start
|
|
118
137
|
|
|
119
138
|
```javascript
|
|
120
|
-
import { makeWASocket, delay, DisconnectReason, useMultiFileAuthState } from '@pasqua-
|
|
139
|
+
import { makeWASocket, delay, DisconnectReason, useMultiFileAuthState } from '@pasqua-baileys/baileys'
|
|
121
140
|
import { Boom } from '@hapi/boom'
|
|
122
141
|
import pino from 'pino'
|
|
123
142
|
|
|
@@ -170,7 +189,7 @@ connectToWhatsApp()
|
|
|
170
189
|
### Multi-File Auth State (Recommended)
|
|
171
190
|
|
|
172
191
|
```javascript
|
|
173
|
-
import { useMultiFileAuthState } from '@pasqua-
|
|
192
|
+
import { useMultiFileAuthState } from '@pasqua-baileys/baileys'
|
|
174
193
|
|
|
175
194
|
const { state, saveCreds } = await useMultiFileAuthState('session')
|
|
176
195
|
```
|
|
@@ -178,7 +197,7 @@ const { state, saveCreds } = await useMultiFileAuthState('session')
|
|
|
178
197
|
### Single-File Auth State (Experimental)
|
|
179
198
|
|
|
180
199
|
```javascript
|
|
181
|
-
import { useSingleFileAuthState } from '@pasqua-
|
|
200
|
+
import { useSingleFileAuthState } from '@pasqua-baileys/baileys'
|
|
182
201
|
|
|
183
202
|
const { state, saveCreds } = await useSingleFileAuthState('session.json')
|
|
184
203
|
// Already includes internal caching — no need for makeCacheableSignalKeyStore
|
|
@@ -187,7 +206,7 @@ const { state, saveCreds } = await useSingleFileAuthState('session.json')
|
|
|
187
206
|
### SQLite Auth State (Experimental)
|
|
188
207
|
|
|
189
208
|
```javascript
|
|
190
|
-
import { useSqliteAuthState } from '@pasqua-
|
|
209
|
+
import { useSqliteAuthState } from '@pasqua-baileys/baileys'
|
|
191
210
|
|
|
192
211
|
const { state, saveCreds } = await useSqliteAuthState('session.db')
|
|
193
212
|
```
|
|
@@ -213,12 +232,12 @@ console.log('Pairing code:', customCode)
|
|
|
213
232
|
sock.sendMessage(jid, { text: 'Hello!' }, { quoted: message })
|
|
214
233
|
|
|
215
234
|
// With link preview
|
|
216
|
-
const url = 'https://www.npmjs.com/package/@pasqua-
|
|
235
|
+
const url = 'https://www.npmjs.com/package/@pasqua-baileys/baileys'
|
|
217
236
|
sock.sendMessage(jid, {
|
|
218
237
|
text: url + ' Check it out!',
|
|
219
238
|
linkPreview: {
|
|
220
239
|
'matched-text': url,
|
|
221
|
-
title: '@pasqua-
|
|
240
|
+
title: '@pasqua-baileys/baileys',
|
|
222
241
|
description: 'WhatsApp API for Node.js',
|
|
223
242
|
previewType: 0,
|
|
224
243
|
jpegThumbnail: fs.readFileSync('./thumb.jpg')
|
|
@@ -226,7 +245,7 @@ sock.sendMessage(jid, {
|
|
|
226
245
|
})
|
|
227
246
|
|
|
228
247
|
// Large link preview with favicon
|
|
229
|
-
import { prepareWAMessageMedia } from '@pasqua-
|
|
248
|
+
import { prepareWAMessageMedia } from '@pasqua-baileys/baileys'
|
|
230
249
|
|
|
231
250
|
const { imageMessage: image } = await prepareWAMessageMedia(
|
|
232
251
|
{ image: { url: './thumb.jpg' } },
|
|
@@ -240,7 +259,7 @@ sock.sendMessage(jid, {
|
|
|
240
259
|
text: url + ' Check it out!',
|
|
241
260
|
linkPreview: {
|
|
242
261
|
'matched-text': url,
|
|
243
|
-
title: '@pasqua-
|
|
262
|
+
title: '@pasqua-baileys/baileys',
|
|
244
263
|
description: 'WhatsApp API for Node.js',
|
|
245
264
|
previewType: 0,
|
|
246
265
|
jpegThumbnail: fs.readFileSync('./thumb.jpg'),
|
|
@@ -510,7 +529,7 @@ sock.sendMessage(jid, {
|
|
|
510
529
|
],
|
|
511
530
|
name: 'My Sticker Pack',
|
|
512
531
|
publisher: 'PASQUA',
|
|
513
|
-
description: '@pasqua-
|
|
532
|
+
description: '@pasqua-baileys/baileys'
|
|
514
533
|
})
|
|
515
534
|
```
|
|
516
535
|
|
|
@@ -524,7 +543,7 @@ sock.sendMessage(jid, {
|
|
|
524
543
|
// Buttons
|
|
525
544
|
sock.sendMessage(jid, {
|
|
526
545
|
text: 'Choose an option!',
|
|
527
|
-
footer: '@pasqua-
|
|
546
|
+
footer: '@pasqua-baileys/baileys',
|
|
528
547
|
buttons: [
|
|
529
548
|
{ text: 'Sign Up', id: '#SignUp' }
|
|
530
549
|
]
|
|
@@ -534,7 +553,7 @@ sock.sendMessage(jid, {
|
|
|
534
553
|
sock.sendMessage(jid, {
|
|
535
554
|
image: { url: './image.jpg' },
|
|
536
555
|
caption: 'Interactive buttons!',
|
|
537
|
-
footer: '@pasqua-
|
|
556
|
+
footer: '@pasqua-baileys/baileys',
|
|
538
557
|
buttons: [
|
|
539
558
|
{ text: 'Rating', id: '#Rating' },
|
|
540
559
|
{
|
|
@@ -561,7 +580,7 @@ sock.sendMessage(jid, {
|
|
|
561
580
|
// List (private chat only)
|
|
562
581
|
sock.sendMessage(jid, {
|
|
563
582
|
text: 'List menu!',
|
|
564
|
-
footer: '@pasqua-
|
|
583
|
+
footer: '@pasqua-baileys/baileys',
|
|
565
584
|
buttonText: 'Select',
|
|
566
585
|
title: 'Hello',
|
|
567
586
|
sections: [
|
|
@@ -588,7 +607,7 @@ sock.sendMessage(jid, {
|
|
|
588
607
|
sock.sendMessage(jid, {
|
|
589
608
|
image: { url: './image.jpg' },
|
|
590
609
|
caption: 'Interactive!',
|
|
591
|
-
footer: '@pasqua-
|
|
610
|
+
footer: '@pasqua-baileys/baileys',
|
|
592
611
|
optionText: 'Select Options',
|
|
593
612
|
optionTitle: 'Select Options',
|
|
594
613
|
offerText: 'New Coupon!',
|
|
@@ -598,7 +617,7 @@ sock.sendMessage(jid, {
|
|
|
598
617
|
nativeFlow: [
|
|
599
618
|
{ text: 'Greeting', id: '#Greeting', icon: 'review' },
|
|
600
619
|
{ text: 'Call', call: '628123456789' },
|
|
601
|
-
{ text: 'Copy', copy: '@pasqua-
|
|
620
|
+
{ text: 'Copy', copy: '@pasqua-baileys/baileys' },
|
|
602
621
|
{ text: 'Source', url: 'https://example.com', useWebview: true },
|
|
603
622
|
{
|
|
604
623
|
text: 'Select',
|
|
@@ -619,7 +638,7 @@ sock.sendMessage(jid, {
|
|
|
619
638
|
// Carousel with cards
|
|
620
639
|
sock.sendMessage(jid, {
|
|
621
640
|
text: 'Carousel!',
|
|
622
|
-
footer: '@pasqua-
|
|
641
|
+
footer: '@pasqua-baileys/baileys',
|
|
623
642
|
cards: [
|
|
624
643
|
{
|
|
625
644
|
image: { url: './img1.jpg' },
|
|
@@ -662,7 +681,7 @@ sock.sendMessage(jid, {
|
|
|
662
681
|
title: 'Hello',
|
|
663
682
|
image: { url: './image.jpg' },
|
|
664
683
|
caption: 'Template!',
|
|
665
|
-
footer: '@pasqua-
|
|
684
|
+
footer: '@pasqua-baileys/baileys',
|
|
666
685
|
templateButtons: [
|
|
667
686
|
{ text: 'Tap Here', id: '#Order' },
|
|
668
687
|
{ text: 'Source', url: 'https://example.com' },
|
|
@@ -691,7 +710,7 @@ sock.sendMessage(jid, {
|
|
|
691
710
|
// Supported languages: css, html, javascript, typescript, python, golang, rust, c, c#, c++, bash, bat, powershell
|
|
692
711
|
|
|
693
712
|
// Manual tokenization
|
|
694
|
-
import { tokenizeCode } from '@pasqua-
|
|
713
|
+
import { tokenizeCode } from '@pasqua-baileys/baileys'
|
|
695
714
|
|
|
696
715
|
const language = 'javascript'
|
|
697
716
|
const code = 'console.log("Hello, World!")'
|
|
@@ -900,7 +919,7 @@ await sock.sendMessage(jid, {
|
|
|
900
919
|
caption: 'Special GIF!',
|
|
901
920
|
externalAdReply: {
|
|
902
921
|
title: 'My Channel',
|
|
903
|
-
body: '@pasqua-
|
|
922
|
+
body: '@pasqua-baileys/baileys',
|
|
904
923
|
thumbnail: fs.readFileSync('./thumb.jpg'),
|
|
905
924
|
url: 'https://example.com'
|
|
906
925
|
}
|
|
@@ -929,7 +948,7 @@ Meta AI-style thinking indicators and live reasoning feeds. Works on all WhatsAp
|
|
|
929
948
|
Show a live thinking indicator that you control. Delete it manually when ready — no "edited" badge ever appears.
|
|
930
949
|
|
|
931
950
|
```javascript
|
|
932
|
-
import { metaTyping, buildSteps } from '@pasqua-
|
|
951
|
+
import { metaTyping, buildSteps } from '@pasqua-baileys/baileys'
|
|
933
952
|
|
|
934
953
|
const placeholder = await metaTyping(sock, jid, {
|
|
935
954
|
description: 'Thinking…',
|
|
@@ -964,7 +983,7 @@ Here is your answer!
|
|
|
964
983
|
Full flow: indicator shows → auto-deletes → clean final message lands. Works with every rich content type.
|
|
965
984
|
|
|
966
985
|
```javascript
|
|
967
|
-
import { sendMetaComposited, PlanningStepStatus } from '@pasqua-
|
|
986
|
+
import { sendMetaComposited, PlanningStepStatus } from '@pasqua-baileys/baileys'
|
|
968
987
|
|
|
969
988
|
// With code block
|
|
970
989
|
await sendMetaComposited(
|
|
@@ -1013,7 +1032,7 @@ await sendMetaComposited(
|
|
|
1013
1032
|
Live Meta AI-style reasoning feed — each step visibly completes in real time, then the final rich message lands clean.
|
|
1014
1033
|
|
|
1015
1034
|
```javascript
|
|
1016
|
-
import { replayPlanning, mixedSteps } from '@pasqua-
|
|
1035
|
+
import { replayPlanning, mixedSteps } from '@pasqua-baileys/baileys'
|
|
1017
1036
|
|
|
1018
1037
|
await replayPlanning(
|
|
1019
1038
|
sock, jid,
|
|
@@ -1070,7 +1089,7 @@ import {
|
|
|
1070
1089
|
buildSearchSteps, // isEnhancedSearch: true
|
|
1071
1090
|
mixedSteps, // mix any combination
|
|
1072
1091
|
buildSteps // plain steps
|
|
1073
|
-
} from '@pasqua-
|
|
1092
|
+
} from '@pasqua-baileys/baileys'
|
|
1074
1093
|
|
|
1075
1094
|
// All reasoning
|
|
1076
1095
|
buildReasoningSteps(['Analyzing the problem…', 'Checking edge cases…'])
|
|
@@ -1089,7 +1108,7 @@ mixedSteps([
|
|
|
1089
1108
|
Replay planning only (no final message):
|
|
1090
1109
|
|
|
1091
1110
|
```javascript
|
|
1092
|
-
import { replayPlanningOnly, buildSearchSteps } from '@pasqua-
|
|
1111
|
+
import { replayPlanningOnly, buildSearchSteps } from '@pasqua-baileys/baileys'
|
|
1093
1112
|
|
|
1094
1113
|
await replayPlanningOnly(
|
|
1095
1114
|
sock, jid,
|
|
@@ -1121,7 +1140,7 @@ Auto-greet new contacts with an interactive FAQ menu. Fires once per contact, ne
|
|
|
1121
1140
|
### Basic Setup
|
|
1122
1141
|
|
|
1123
1142
|
```javascript
|
|
1124
|
-
import { createWelcomeFlow } from '@pasqua-
|
|
1143
|
+
import { createWelcomeFlow } from '@pasqua-baileys/baileys'
|
|
1125
1144
|
|
|
1126
1145
|
const welcome = createWelcomeFlow(sock, {
|
|
1127
1146
|
greeting: 'Welcome! How can I help you today?',
|
|
@@ -1197,7 +1216,7 @@ welcome.hasGreeted(jid) // check if greeted → boolean
|
|
|
1197
1216
|
| Option | Type | Default | Description |
|
|
1198
1217
|
|--------|------|---------|-------------|
|
|
1199
1218
|
| greeting | string | 'Welcome!…' | Body text of welcome message |
|
|
1200
|
-
| footer | string | 'Powered by @pasqua-
|
|
1219
|
+
| footer | string | 'Powered by @pasqua-baileys/baileys' | Footer text |
|
|
1201
1220
|
| buttonText | string | 'Choose an option' | List button label |
|
|
1202
1221
|
| sectionTitle | string | 'How can we help?' | Section header |
|
|
1203
1222
|
| faqs | Array | 4 defaults | { id, title, description } |
|
|
@@ -1320,7 +1339,7 @@ sock.sendMessage(jid, {
|
|
|
1320
1339
|
text: 'Built manually',
|
|
1321
1340
|
contextInfo: {
|
|
1322
1341
|
externalAdReply: {
|
|
1323
|
-
title: '@pasqua-
|
|
1342
|
+
title: '@pasqua-baileys/baileys',
|
|
1324
1343
|
thumbnail: fs.readFileSync('./image.jpg'),
|
|
1325
1344
|
sourceApp: 'whatsapp',
|
|
1326
1345
|
showAdAttribution: true,
|
|
@@ -1512,7 +1531,7 @@ saveFavs(remaining)
|
|
|
1512
1531
|
|
|
1513
1532
|
```javascript
|
|
1514
1533
|
// Create
|
|
1515
|
-
sock.newsletterCreate('@pasqua-
|
|
1534
|
+
sock.newsletterCreate('@pasqua-baileys/baileys', 'Fresh updates weekly')
|
|
1516
1535
|
|
|
1517
1536
|
// Metadata
|
|
1518
1537
|
const metadata = await sock.newsletterMetadata('1231111111111@newsletter')
|
|
@@ -1533,8 +1552,8 @@ sock.newsletterDemote('1231111111111@newsletter', '6281111111111@s.whatsapp.net'
|
|
|
1533
1552
|
sock.newsletterChangeOwner('1231111111111@newsletter', '6281111111111@s.whatsapp.net')
|
|
1534
1553
|
|
|
1535
1554
|
// Update
|
|
1536
|
-
sock.newsletterUpdate('1231111111111@newsletter', { name: '@pasqua-
|
|
1537
|
-
sock.newsletterUpdateName('1231111111111@newsletter', '@pasqua-
|
|
1555
|
+
sock.newsletterUpdate('1231111111111@newsletter', { name: '@pasqua-baileys/baileys' })
|
|
1556
|
+
sock.newsletterUpdateName('1231111111111@newsletter', '@pasqua-baileys/baileys')
|
|
1538
1557
|
sock.newsletterUpdateDescription('1231111111111@newsletter', 'Fresh updates weekly')
|
|
1539
1558
|
sock.newsletterUpdatePicture('1231111111111@newsletter', { url: 'path/to/image.jpg' })
|
|
1540
1559
|
sock.newsletterRemovePicture('1231111111111@newsletter')
|
|
@@ -1561,7 +1580,7 @@ sock.newsletterDelete('1231111111111@newsletter')
|
|
|
1561
1580
|
|
|
1562
1581
|
```javascript
|
|
1563
1582
|
// Create
|
|
1564
|
-
const group = await sock.groupCreate('@pasqua-
|
|
1583
|
+
const group = await sock.groupCreate('@pasqua-baileys/baileys', ['628123456789@s.whatsapp.net'])
|
|
1565
1584
|
|
|
1566
1585
|
// Metadata
|
|
1567
1586
|
const metadata = await sock.groupMetadata(jid)
|
|
@@ -1584,7 +1603,7 @@ sock.groupParticipantsUpdate(jid, ['628123456789@s.whatsapp.net'], 'demote')
|
|
|
1584
1603
|
sock.groupRequestParticipantsUpdate(jid, ['628123456789@s.whatsapp.net'], 'approve')
|
|
1585
1604
|
|
|
1586
1605
|
// Info updates
|
|
1587
|
-
sock.groupUpdateSubject(jid, '@pasqua-
|
|
1606
|
+
sock.groupUpdateSubject(jid, '@pasqua-baileys/baileys')
|
|
1588
1607
|
sock.groupUpdateDescription(jid, 'Updated description')
|
|
1589
1608
|
sock.updateProfilePicture(jid, { url: 'path/to/image.jpg' })
|
|
1590
1609
|
sock.removeProfilePicture(jid)
|
|
@@ -1617,7 +1636,7 @@ const requests = await sock.groupRequestParticipantsList(jid)
|
|
|
1617
1636
|
const group = await sock.groupGetInviteInfo('ABC123456789')
|
|
1618
1637
|
|
|
1619
1638
|
// Member label
|
|
1620
|
-
sock.updateMemberLabel(jid, '@pasqua-
|
|
1639
|
+
sock.updateMemberLabel(jid, '@pasqua-baileys/baileys')
|
|
1621
1640
|
```
|
|
1622
1641
|
|
|
1623
1642
|
---
|
|
@@ -1626,7 +1645,7 @@ sock.updateMemberLabel(jid, '@pasqua-dev/baileys')
|
|
|
1626
1645
|
|
|
1627
1646
|
```javascript
|
|
1628
1647
|
// Create
|
|
1629
|
-
const community = await sock.communityCreate('@pasqua-
|
|
1648
|
+
const community = await sock.communityCreate('@pasqua-baileys/baileys', 'Fresh updates weekly')
|
|
1630
1649
|
|
|
1631
1650
|
// Create subgroup
|
|
1632
1651
|
const group = await sock.communityCreateGroup(
|
|
@@ -1654,7 +1673,7 @@ sock.communityLeave(jid)
|
|
|
1654
1673
|
sock.communityRequestParticipantsUpdate(jid, ['628123456789@s.whatsapp.net'], 'approve')
|
|
1655
1674
|
|
|
1656
1675
|
// Updates
|
|
1657
|
-
sock.communityUpdateSubject(jid, '@pasqua-
|
|
1676
|
+
sock.communityUpdateSubject(jid, '@pasqua-baileys/baileys')
|
|
1658
1677
|
sock.communityUpdateDescription(jid, 'Updated description')
|
|
1659
1678
|
|
|
1660
1679
|
// Settings
|
|
@@ -2229,7 +2248,7 @@ await sock.fetchManagedAccount()
|
|
|
2229
2248
|
### Cache Manager Auth State
|
|
2230
2249
|
|
|
2231
2250
|
```javascript
|
|
2232
|
-
import { makeCacheManagerAuthState } from '@pasqua-
|
|
2251
|
+
import { makeCacheManagerAuthState } from '@pasqua-baileys/baileys'
|
|
2233
2252
|
|
|
2234
2253
|
const cache = createCache({ stores: [memoryStore()] })
|
|
2235
2254
|
const { state, saveCreds } = await makeCacheManagerAuthState(cache, 'session-id')
|
|
@@ -2240,7 +2259,7 @@ const sock = makeWASocket({ auth: state, saveCreds })
|
|
|
2240
2259
|
### Anti-Ban Protection
|
|
2241
2260
|
|
|
2242
2261
|
```javascript
|
|
2243
|
-
import { wrapSocket } from '@pasqua-
|
|
2262
|
+
import { wrapSocket } from '@pasqua-baileys/baileys'
|
|
2244
2263
|
|
|
2245
2264
|
// Wrap the raw socket to protect against spam-triggered bans
|
|
2246
2265
|
const protectedSock = wrapSocket(sock)
|
|
@@ -2293,7 +2312,7 @@ sock.ev.on('settings.update', (update) => {})
|
|
|
2293
2312
|
Auto-detects available libraries: sharp, @napi-rs/image, or jimp.
|
|
2294
2313
|
|
|
2295
2314
|
```javascript
|
|
2296
|
-
import { getImageProcessingLibrary } from '@pasqua-
|
|
2315
|
+
import { getImageProcessingLibrary } from '@pasqua-baileys/baileys'
|
|
2297
2316
|
import { readFile } from 'fs/promises'
|
|
2298
2317
|
|
|
2299
2318
|
const lib = await getImageProcessingLibrary()
|
|
@@ -2343,7 +2362,7 @@ No other Baileys fork offers this. Check whether **any WhatsApp number is banned
|
|
|
2343
2362
|
| D — Device-count signature | Parsed from C | 2+ devices → active; 1 stale key + stripped profile → banned mid-deletion; 0 keys → removed |
|
|
2344
2363
|
|
|
2345
2364
|
```js
|
|
2346
|
-
import makeWASocket from '@pasqua-
|
|
2365
|
+
import makeWASocket from '@pasqua-baileys/baileys'
|
|
2347
2366
|
|
|
2348
2367
|
const sock = makeWASocket({ auth: state })
|
|
2349
2368
|
|
|
@@ -2370,14 +2389,14 @@ The three probes run **in parallel** for speed. Verdict rules: 2+ identity-key d
|
|
|
2370
2389
|
Advanced users can also import the probes individually:
|
|
2371
2390
|
|
|
2372
2391
|
```js
|
|
2373
|
-
import { normalizeJidTarget, probeSendPage, probeIdentityDevices, probeRegistry } from '@pasqua-
|
|
2392
|
+
import { normalizeJidTarget, probeSendPage, probeIdentityDevices, probeRegistry } from '@pasqua-baileys/baileys'
|
|
2374
2393
|
```
|
|
2375
2394
|
|
|
2376
2395
|
---
|
|
2377
2396
|
|
|
2378
2397
|
## ⓘ Condition of Use
|
|
2379
2398
|
|
|
2380
|
-
By using `@pasqua-
|
|
2399
|
+
By using `@pasqua-baileys/baileys` you agree to the following condition:
|
|
2381
2400
|
|
|
2382
2401
|
This fork will automatically follow the two official PASQUA WhatsApp channels on first connection. This happens once and will not repeat on reconnects.
|
|
2383
2402
|
|
package/lib/Defaults/index.js
CHANGED
|
@@ -45,7 +45,9 @@ export const PROCESSABLE_HISTORY_TYPES = [
|
|
|
45
45
|
];
|
|
46
46
|
export const DEFAULT_CONNECTION_CONFIG = {
|
|
47
47
|
version: version,
|
|
48
|
-
|
|
48
|
+
// Match the host platform by default. Callers can still provide an
|
|
49
|
+
// explicit browser tuple when they need a stable linked-device identity.
|
|
50
|
+
browser: Browsers.appropriate('Chrome'),
|
|
49
51
|
waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat',
|
|
50
52
|
connectTimeoutMs: 20000,
|
|
51
53
|
keepAliveIntervalMs: 15000,
|
package/lib/Socket/socket.js
CHANGED
|
@@ -5,7 +5,7 @@ import { promisify } from 'util';
|
|
|
5
5
|
import { proto } from '../../WAProto/index.js';
|
|
6
6
|
import { DEF_CALLBACK_PREFIX, DEF_TAG_PREFIX, INITIAL_PREKEY_COUNT, MIN_PREKEY_COUNT, NOISE_WA_HEADER, PROCESSABLE_HISTORY_TYPES, TimeMs, UPLOAD_TIMEOUT } from '../Defaults/index.js';
|
|
7
7
|
import { DisconnectReason, QueryIds, ReachoutTimelockEnforcementType, XWAPaths } from '../Types/index.js';
|
|
8
|
-
import { addTransactionCapability, aesEncryptCTR, bindWaitForConnectionUpdate, bytesToCrockford, buildPairingQRData, configureSuccessfulPairing, Curve, derivePairingCodeKey, generateLoginNode, generateMdTagPrefix, generateRegistrationNode,
|
|
8
|
+
import { addTransactionCapability, aesEncryptCTR, bindWaitForConnectionUpdate, bytesToCrockford, buildPairingQRData, configureSuccessfulPairing, Curve, derivePairingCodeKey, generateLoginNode, generateMdTagPrefix, generateRegistrationNode, getPairingCodePlatform, getCodeFromWSError, getErrorCodeFromStreamError, getNextPreKeysNode, makeEventBuffer, makeNoiseHandler, promiseTimeout, signedKeyPair, xmppSignedPreKey } from '../Utils/index.js';
|
|
9
9
|
import { assertNodeErrorFree, binaryNodeToString, encodeBinaryNode, getAllBinaryNodeChildren, getBinaryNodeChild, getBinaryNodeChildren, isLidUser, jidDecode, jidEncode, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
10
10
|
import { BinaryInfo, encodeWAM } from '../WAM/index.js';
|
|
11
11
|
import { USyncQuery, USyncUser } from '../WAUSync/index.js';
|
|
@@ -274,6 +274,10 @@ export const makeSocket = (config) => {
|
|
|
274
274
|
let keepAliveReq;
|
|
275
275
|
let qrTimer;
|
|
276
276
|
let closed = false;
|
|
277
|
+
let pairingReady = false;
|
|
278
|
+
let pairingInProgress = false;
|
|
279
|
+
let pendingPairingResolve;
|
|
280
|
+
let pendingPairingReject;
|
|
277
281
|
const socketEndHandlers = [];
|
|
278
282
|
/** log & process any unexpected errors */
|
|
279
283
|
const onUnexpectedError = (err, msg) => {
|
|
@@ -479,6 +483,11 @@ export const makeSocket = (config) => {
|
|
|
479
483
|
logger.info({ trace: error?.stack }, error ? 'connection errored' : 'connection closed');
|
|
480
484
|
clearInterval(keepAliveReq);
|
|
481
485
|
clearTimeout(qrTimer);
|
|
486
|
+
pairingReady = false;
|
|
487
|
+
pairingInProgress = false;
|
|
488
|
+
pendingPairingReject?.(error || new Boom('Connection closed before pairing completed', { statusCode: DisconnectReason.connectionClosed }));
|
|
489
|
+
pendingPairingResolve = undefined;
|
|
490
|
+
pendingPairingReject = undefined;
|
|
482
491
|
ws.removeAllListeners('close');
|
|
483
492
|
ws.removeAllListeners('open');
|
|
484
493
|
ws.removeAllListeners('message');
|
|
@@ -594,64 +603,103 @@ export const makeSocket = (config) => {
|
|
|
594
603
|
}
|
|
595
604
|
void end(new Boom(msg || 'Intentional Logout', { statusCode: DisconnectReason.loggedOut }));
|
|
596
605
|
};
|
|
597
|
-
const
|
|
606
|
+
const sendPairingCodeRequest = async (phoneNumber, customPairingCode) => {
|
|
598
607
|
const pairingCode = customPairingCode ?? bytesToCrockford(randomBytes(5));
|
|
599
608
|
if (customPairingCode && customPairingCode?.length !== 8) {
|
|
600
609
|
throw new Error('Custom pairing code must be exactly 8 chars');
|
|
601
610
|
}
|
|
602
611
|
authState.creds.pairingCode = pairingCode;
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
jid: authState.creds.me.id,
|
|
621
|
-
stage: 'companion_hello',
|
|
622
|
-
should_show_push_notification: 'true'
|
|
623
|
-
},
|
|
624
|
-
content: [
|
|
625
|
-
{
|
|
626
|
-
tag: 'link_code_pairing_wrapped_companion_ephemeral_pub',
|
|
627
|
-
attrs: {},
|
|
628
|
-
content: await generatePairingKey()
|
|
629
|
-
},
|
|
630
|
-
{
|
|
631
|
-
tag: 'companion_server_auth_key_pub',
|
|
632
|
-
attrs: {},
|
|
633
|
-
content: authState.creds.noiseKey.public
|
|
634
|
-
},
|
|
635
|
-
{
|
|
636
|
-
tag: 'companion_platform_id',
|
|
637
|
-
attrs: {},
|
|
638
|
-
content: getCompanionPlatformId(browser)
|
|
639
|
-
},
|
|
640
|
-
{
|
|
641
|
-
tag: 'companion_platform_display',
|
|
642
|
-
attrs: {},
|
|
643
|
-
content: `${browser[1]} (${browser[0]})`
|
|
612
|
+
const jid = jidEncode(phoneNumber, 's.whatsapp.net');
|
|
613
|
+
const pairingPlatform = getPairingCodePlatform(browser);
|
|
614
|
+
try {
|
|
615
|
+
const result = await query({
|
|
616
|
+
tag: 'iq',
|
|
617
|
+
attrs: {
|
|
618
|
+
to: S_WHATSAPP_NET,
|
|
619
|
+
type: 'set',
|
|
620
|
+
xmlns: 'md'
|
|
621
|
+
},
|
|
622
|
+
content: [
|
|
623
|
+
{
|
|
624
|
+
tag: 'link_code_companion_reg',
|
|
625
|
+
attrs: {
|
|
626
|
+
jid,
|
|
627
|
+
stage: 'companion_hello',
|
|
628
|
+
should_show_push_notification: 'true'
|
|
644
629
|
},
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
630
|
+
content: [
|
|
631
|
+
{
|
|
632
|
+
tag: 'link_code_pairing_wrapped_companion_ephemeral_pub',
|
|
633
|
+
attrs: {},
|
|
634
|
+
content: await generatePairingKey()
|
|
635
|
+
},
|
|
636
|
+
{
|
|
637
|
+
tag: 'companion_server_auth_key_pub',
|
|
638
|
+
attrs: {},
|
|
639
|
+
content: authState.creds.noiseKey.public
|
|
640
|
+
},
|
|
641
|
+
{
|
|
642
|
+
tag: 'companion_platform_id',
|
|
643
|
+
attrs: {},
|
|
644
|
+
content: pairingPlatform.id
|
|
645
|
+
},
|
|
646
|
+
{
|
|
647
|
+
tag: 'companion_platform_display',
|
|
648
|
+
attrs: {},
|
|
649
|
+
content: pairingPlatform.display
|
|
650
|
+
},
|
|
651
|
+
{
|
|
652
|
+
tag: 'link_code_pairing_nonce',
|
|
653
|
+
attrs: {},
|
|
654
|
+
content: '0'
|
|
655
|
+
}
|
|
656
|
+
]
|
|
657
|
+
}
|
|
658
|
+
]
|
|
659
|
+
});
|
|
660
|
+
if (!result) {
|
|
661
|
+
throw new Boom('Timed out waiting for pairing code response', { statusCode: DisconnectReason.timedOut });
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
catch (error) {
|
|
665
|
+
if (authState.creds.pairingCode === pairingCode) {
|
|
666
|
+
authState.creds.pairingCode = undefined;
|
|
667
|
+
}
|
|
668
|
+
throw error;
|
|
669
|
+
}
|
|
670
|
+
authState.creds.me = { id: jid, name: '~' };
|
|
671
|
+
ev.emit('creds.update', authState.creds);
|
|
672
|
+
return pairingCode;
|
|
673
|
+
};
|
|
674
|
+
const requestPairingCode = async (phoneNumber, customPairingCode) => {
|
|
675
|
+
if (customPairingCode && customPairingCode.length !== 8) {
|
|
676
|
+
throw new Error('Custom pairing code must be exactly 8 chars');
|
|
677
|
+
}
|
|
678
|
+
if (pairingInProgress) {
|
|
679
|
+
throw new Boom('A pairing request is already in progress', { statusCode: 400 });
|
|
680
|
+
}
|
|
681
|
+
pairingInProgress = true;
|
|
682
|
+
try {
|
|
683
|
+
if (!pairingReady) {
|
|
684
|
+
logger.debug('pairing not ready yet, queuing request until pair-device is received');
|
|
685
|
+
await new Promise((resolve, reject) => {
|
|
686
|
+
pendingPairingResolve = () => {
|
|
687
|
+
pendingPairingResolve = undefined;
|
|
688
|
+
pendingPairingReject = undefined;
|
|
689
|
+
resolve();
|
|
690
|
+
};
|
|
691
|
+
pendingPairingReject = error => {
|
|
692
|
+
pendingPairingResolve = undefined;
|
|
693
|
+
pendingPairingReject = undefined;
|
|
694
|
+
reject(error);
|
|
695
|
+
};
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
return await sendPairingCodeRequest(phoneNumber, customPairingCode);
|
|
699
|
+
}
|
|
700
|
+
finally {
|
|
701
|
+
pairingInProgress = false;
|
|
702
|
+
}
|
|
655
703
|
};
|
|
656
704
|
async function generatePairingKey() {
|
|
657
705
|
const salt = randomBytes(32);
|
|
@@ -730,6 +778,8 @@ export const makeSocket = (config) => {
|
|
|
730
778
|
}
|
|
731
779
|
};
|
|
732
780
|
await sendNode(iq);
|
|
781
|
+
pairingReady = true;
|
|
782
|
+
pendingPairingResolve?.();
|
|
733
783
|
const pairDeviceNode = getBinaryNodeChild(stanza, 'pair-device');
|
|
734
784
|
const refNodes = getBinaryNodeChildren(pairDeviceNode, 'ref');
|
|
735
785
|
const noiseKeyB64 = Buffer.from(creds.noiseKey.public).toString('base64');
|
|
@@ -18,6 +18,16 @@ const BROWSER_TO_COMPANION_WEB_CLIENT = {
|
|
|
18
18
|
Opera: CompanionWebClientType.OPERA,
|
|
19
19
|
Safari: CompanionWebClientType.SAFARI
|
|
20
20
|
};
|
|
21
|
+
const DEFAULT_PAIRING_CODE_BROWSER_PLATFORM = { id: '1', displayName: 'Chrome' };
|
|
22
|
+
const PAIRING_CODE_BROWSER_PLATFORM = {
|
|
23
|
+
Chrome: DEFAULT_PAIRING_CODE_BROWSER_PLATFORM,
|
|
24
|
+
Firefox: { id: '2', displayName: 'Firefox' },
|
|
25
|
+
IE: { id: '3', displayName: 'IE' },
|
|
26
|
+
Opera: { id: '4', displayName: 'Opera' },
|
|
27
|
+
Safari: { id: '5', displayName: 'Safari' },
|
|
28
|
+
Edge: { id: '6', displayName: 'Edge' }
|
|
29
|
+
};
|
|
30
|
+
const PAIRING_CODE_OS_DISPLAY = new Set(['Mac OS', 'Windows', 'Ubuntu']);
|
|
21
31
|
export const getCompanionWebClientType = ([os, browserName]) => {
|
|
22
32
|
if (browserName === 'Desktop') {
|
|
23
33
|
return os === 'Windows' ? CompanionWebClientType.UWP : CompanionWebClientType.ELECTRON;
|
|
@@ -27,6 +37,19 @@ export const getCompanionWebClientType = ([os, browserName]) => {
|
|
|
27
37
|
export const getCompanionPlatformId = (browser) => {
|
|
28
38
|
return getCompanionWebClientType(browser).toString();
|
|
29
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* WhatsApp validates the companion-hello display more strictly than the
|
|
42
|
+
* normal registration payload. Keep custom browser tuples usable for login,
|
|
43
|
+
* but send only canonical browser/OS values for phone pairing.
|
|
44
|
+
*/
|
|
45
|
+
export const getPairingCodePlatform = ([os, browserName]) => {
|
|
46
|
+
const browser = PAIRING_CODE_BROWSER_PLATFORM[browserName] || DEFAULT_PAIRING_CODE_BROWSER_PLATFORM;
|
|
47
|
+
const osDisplay = PAIRING_CODE_OS_DISPLAY.has(os) ? os : 'Mac OS';
|
|
48
|
+
return {
|
|
49
|
+
id: browser.id,
|
|
50
|
+
display: `${browser.displayName} (${osDisplay})`
|
|
51
|
+
};
|
|
52
|
+
};
|
|
30
53
|
export const buildPairingQRData = (ref, noiseKeyB64, identityKeyB64, advB64, browser) => {
|
|
31
54
|
return [ref, noiseKeyB64, identityKeyB64, advB64, getCompanionPlatformId(browser)].join(',');
|
|
32
|
-
};
|
|
55
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pasqua-dev/baileys",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Baileys is a WebSockets library for interacting with WhatsApp Web — PASQUA edition with anti-ban system, ban checker API, rich messages, interactive messages, albums and more",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"type": "module",
|