@pasqua-dev/baileys 1.0.0 → 2.8.11
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 +46 -46
- 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,20 +96,20 @@
|
|
|
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
115
|
---
|
|
@@ -117,7 +117,7 @@ const { makeWASocket } = require('@pasqua-dev/baileys')
|
|
|
117
117
|
## Quick Start
|
|
118
118
|
|
|
119
119
|
```javascript
|
|
120
|
-
import { makeWASocket, delay, DisconnectReason, useMultiFileAuthState } from '@pasqua-
|
|
120
|
+
import { makeWASocket, delay, DisconnectReason, useMultiFileAuthState } from '@pasqua-baileys/baileys'
|
|
121
121
|
import { Boom } from '@hapi/boom'
|
|
122
122
|
import pino from 'pino'
|
|
123
123
|
|
|
@@ -170,7 +170,7 @@ connectToWhatsApp()
|
|
|
170
170
|
### Multi-File Auth State (Recommended)
|
|
171
171
|
|
|
172
172
|
```javascript
|
|
173
|
-
import { useMultiFileAuthState } from '@pasqua-
|
|
173
|
+
import { useMultiFileAuthState } from '@pasqua-baileys/baileys'
|
|
174
174
|
|
|
175
175
|
const { state, saveCreds } = await useMultiFileAuthState('session')
|
|
176
176
|
```
|
|
@@ -178,7 +178,7 @@ const { state, saveCreds } = await useMultiFileAuthState('session')
|
|
|
178
178
|
### Single-File Auth State (Experimental)
|
|
179
179
|
|
|
180
180
|
```javascript
|
|
181
|
-
import { useSingleFileAuthState } from '@pasqua-
|
|
181
|
+
import { useSingleFileAuthState } from '@pasqua-baileys/baileys'
|
|
182
182
|
|
|
183
183
|
const { state, saveCreds } = await useSingleFileAuthState('session.json')
|
|
184
184
|
// Already includes internal caching — no need for makeCacheableSignalKeyStore
|
|
@@ -187,7 +187,7 @@ const { state, saveCreds } = await useSingleFileAuthState('session.json')
|
|
|
187
187
|
### SQLite Auth State (Experimental)
|
|
188
188
|
|
|
189
189
|
```javascript
|
|
190
|
-
import { useSqliteAuthState } from '@pasqua-
|
|
190
|
+
import { useSqliteAuthState } from '@pasqua-baileys/baileys'
|
|
191
191
|
|
|
192
192
|
const { state, saveCreds } = await useSqliteAuthState('session.db')
|
|
193
193
|
```
|
|
@@ -213,12 +213,12 @@ console.log('Pairing code:', customCode)
|
|
|
213
213
|
sock.sendMessage(jid, { text: 'Hello!' }, { quoted: message })
|
|
214
214
|
|
|
215
215
|
// With link preview
|
|
216
|
-
const url = 'https://www.npmjs.com/package/@pasqua-
|
|
216
|
+
const url = 'https://www.npmjs.com/package/@pasqua-baileys/baileys'
|
|
217
217
|
sock.sendMessage(jid, {
|
|
218
218
|
text: url + ' Check it out!',
|
|
219
219
|
linkPreview: {
|
|
220
220
|
'matched-text': url,
|
|
221
|
-
title: '@pasqua-
|
|
221
|
+
title: '@pasqua-baileys/baileys',
|
|
222
222
|
description: 'WhatsApp API for Node.js',
|
|
223
223
|
previewType: 0,
|
|
224
224
|
jpegThumbnail: fs.readFileSync('./thumb.jpg')
|
|
@@ -226,7 +226,7 @@ sock.sendMessage(jid, {
|
|
|
226
226
|
})
|
|
227
227
|
|
|
228
228
|
// Large link preview with favicon
|
|
229
|
-
import { prepareWAMessageMedia } from '@pasqua-
|
|
229
|
+
import { prepareWAMessageMedia } from '@pasqua-baileys/baileys'
|
|
230
230
|
|
|
231
231
|
const { imageMessage: image } = await prepareWAMessageMedia(
|
|
232
232
|
{ image: { url: './thumb.jpg' } },
|
|
@@ -240,7 +240,7 @@ sock.sendMessage(jid, {
|
|
|
240
240
|
text: url + ' Check it out!',
|
|
241
241
|
linkPreview: {
|
|
242
242
|
'matched-text': url,
|
|
243
|
-
title: '@pasqua-
|
|
243
|
+
title: '@pasqua-baileys/baileys',
|
|
244
244
|
description: 'WhatsApp API for Node.js',
|
|
245
245
|
previewType: 0,
|
|
246
246
|
jpegThumbnail: fs.readFileSync('./thumb.jpg'),
|
|
@@ -510,7 +510,7 @@ sock.sendMessage(jid, {
|
|
|
510
510
|
],
|
|
511
511
|
name: 'My Sticker Pack',
|
|
512
512
|
publisher: 'PASQUA',
|
|
513
|
-
description: '@pasqua-
|
|
513
|
+
description: '@pasqua-baileys/baileys'
|
|
514
514
|
})
|
|
515
515
|
```
|
|
516
516
|
|
|
@@ -524,7 +524,7 @@ sock.sendMessage(jid, {
|
|
|
524
524
|
// Buttons
|
|
525
525
|
sock.sendMessage(jid, {
|
|
526
526
|
text: 'Choose an option!',
|
|
527
|
-
footer: '@pasqua-
|
|
527
|
+
footer: '@pasqua-baileys/baileys',
|
|
528
528
|
buttons: [
|
|
529
529
|
{ text: 'Sign Up', id: '#SignUp' }
|
|
530
530
|
]
|
|
@@ -534,7 +534,7 @@ sock.sendMessage(jid, {
|
|
|
534
534
|
sock.sendMessage(jid, {
|
|
535
535
|
image: { url: './image.jpg' },
|
|
536
536
|
caption: 'Interactive buttons!',
|
|
537
|
-
footer: '@pasqua-
|
|
537
|
+
footer: '@pasqua-baileys/baileys',
|
|
538
538
|
buttons: [
|
|
539
539
|
{ text: 'Rating', id: '#Rating' },
|
|
540
540
|
{
|
|
@@ -561,7 +561,7 @@ sock.sendMessage(jid, {
|
|
|
561
561
|
// List (private chat only)
|
|
562
562
|
sock.sendMessage(jid, {
|
|
563
563
|
text: 'List menu!',
|
|
564
|
-
footer: '@pasqua-
|
|
564
|
+
footer: '@pasqua-baileys/baileys',
|
|
565
565
|
buttonText: 'Select',
|
|
566
566
|
title: 'Hello',
|
|
567
567
|
sections: [
|
|
@@ -588,7 +588,7 @@ sock.sendMessage(jid, {
|
|
|
588
588
|
sock.sendMessage(jid, {
|
|
589
589
|
image: { url: './image.jpg' },
|
|
590
590
|
caption: 'Interactive!',
|
|
591
|
-
footer: '@pasqua-
|
|
591
|
+
footer: '@pasqua-baileys/baileys',
|
|
592
592
|
optionText: 'Select Options',
|
|
593
593
|
optionTitle: 'Select Options',
|
|
594
594
|
offerText: 'New Coupon!',
|
|
@@ -598,7 +598,7 @@ sock.sendMessage(jid, {
|
|
|
598
598
|
nativeFlow: [
|
|
599
599
|
{ text: 'Greeting', id: '#Greeting', icon: 'review' },
|
|
600
600
|
{ text: 'Call', call: '628123456789' },
|
|
601
|
-
{ text: 'Copy', copy: '@pasqua-
|
|
601
|
+
{ text: 'Copy', copy: '@pasqua-baileys/baileys' },
|
|
602
602
|
{ text: 'Source', url: 'https://example.com', useWebview: true },
|
|
603
603
|
{
|
|
604
604
|
text: 'Select',
|
|
@@ -619,7 +619,7 @@ sock.sendMessage(jid, {
|
|
|
619
619
|
// Carousel with cards
|
|
620
620
|
sock.sendMessage(jid, {
|
|
621
621
|
text: 'Carousel!',
|
|
622
|
-
footer: '@pasqua-
|
|
622
|
+
footer: '@pasqua-baileys/baileys',
|
|
623
623
|
cards: [
|
|
624
624
|
{
|
|
625
625
|
image: { url: './img1.jpg' },
|
|
@@ -662,7 +662,7 @@ sock.sendMessage(jid, {
|
|
|
662
662
|
title: 'Hello',
|
|
663
663
|
image: { url: './image.jpg' },
|
|
664
664
|
caption: 'Template!',
|
|
665
|
-
footer: '@pasqua-
|
|
665
|
+
footer: '@pasqua-baileys/baileys',
|
|
666
666
|
templateButtons: [
|
|
667
667
|
{ text: 'Tap Here', id: '#Order' },
|
|
668
668
|
{ text: 'Source', url: 'https://example.com' },
|
|
@@ -691,7 +691,7 @@ sock.sendMessage(jid, {
|
|
|
691
691
|
// Supported languages: css, html, javascript, typescript, python, golang, rust, c, c#, c++, bash, bat, powershell
|
|
692
692
|
|
|
693
693
|
// Manual tokenization
|
|
694
|
-
import { tokenizeCode } from '@pasqua-
|
|
694
|
+
import { tokenizeCode } from '@pasqua-baileys/baileys'
|
|
695
695
|
|
|
696
696
|
const language = 'javascript'
|
|
697
697
|
const code = 'console.log("Hello, World!")'
|
|
@@ -900,7 +900,7 @@ await sock.sendMessage(jid, {
|
|
|
900
900
|
caption: 'Special GIF!',
|
|
901
901
|
externalAdReply: {
|
|
902
902
|
title: 'My Channel',
|
|
903
|
-
body: '@pasqua-
|
|
903
|
+
body: '@pasqua-baileys/baileys',
|
|
904
904
|
thumbnail: fs.readFileSync('./thumb.jpg'),
|
|
905
905
|
url: 'https://example.com'
|
|
906
906
|
}
|
|
@@ -929,7 +929,7 @@ Meta AI-style thinking indicators and live reasoning feeds. Works on all WhatsAp
|
|
|
929
929
|
Show a live thinking indicator that you control. Delete it manually when ready — no "edited" badge ever appears.
|
|
930
930
|
|
|
931
931
|
```javascript
|
|
932
|
-
import { metaTyping, buildSteps } from '@pasqua-
|
|
932
|
+
import { metaTyping, buildSteps } from '@pasqua-baileys/baileys'
|
|
933
933
|
|
|
934
934
|
const placeholder = await metaTyping(sock, jid, {
|
|
935
935
|
description: 'Thinking…',
|
|
@@ -964,7 +964,7 @@ Here is your answer!
|
|
|
964
964
|
Full flow: indicator shows → auto-deletes → clean final message lands. Works with every rich content type.
|
|
965
965
|
|
|
966
966
|
```javascript
|
|
967
|
-
import { sendMetaComposited, PlanningStepStatus } from '@pasqua-
|
|
967
|
+
import { sendMetaComposited, PlanningStepStatus } from '@pasqua-baileys/baileys'
|
|
968
968
|
|
|
969
969
|
// With code block
|
|
970
970
|
await sendMetaComposited(
|
|
@@ -1013,7 +1013,7 @@ await sendMetaComposited(
|
|
|
1013
1013
|
Live Meta AI-style reasoning feed — each step visibly completes in real time, then the final rich message lands clean.
|
|
1014
1014
|
|
|
1015
1015
|
```javascript
|
|
1016
|
-
import { replayPlanning, mixedSteps } from '@pasqua-
|
|
1016
|
+
import { replayPlanning, mixedSteps } from '@pasqua-baileys/baileys'
|
|
1017
1017
|
|
|
1018
1018
|
await replayPlanning(
|
|
1019
1019
|
sock, jid,
|
|
@@ -1070,7 +1070,7 @@ import {
|
|
|
1070
1070
|
buildSearchSteps, // isEnhancedSearch: true
|
|
1071
1071
|
mixedSteps, // mix any combination
|
|
1072
1072
|
buildSteps // plain steps
|
|
1073
|
-
} from '@pasqua-
|
|
1073
|
+
} from '@pasqua-baileys/baileys'
|
|
1074
1074
|
|
|
1075
1075
|
// All reasoning
|
|
1076
1076
|
buildReasoningSteps(['Analyzing the problem…', 'Checking edge cases…'])
|
|
@@ -1089,7 +1089,7 @@ mixedSteps([
|
|
|
1089
1089
|
Replay planning only (no final message):
|
|
1090
1090
|
|
|
1091
1091
|
```javascript
|
|
1092
|
-
import { replayPlanningOnly, buildSearchSteps } from '@pasqua-
|
|
1092
|
+
import { replayPlanningOnly, buildSearchSteps } from '@pasqua-baileys/baileys'
|
|
1093
1093
|
|
|
1094
1094
|
await replayPlanningOnly(
|
|
1095
1095
|
sock, jid,
|
|
@@ -1121,7 +1121,7 @@ Auto-greet new contacts with an interactive FAQ menu. Fires once per contact, ne
|
|
|
1121
1121
|
### Basic Setup
|
|
1122
1122
|
|
|
1123
1123
|
```javascript
|
|
1124
|
-
import { createWelcomeFlow } from '@pasqua-
|
|
1124
|
+
import { createWelcomeFlow } from '@pasqua-baileys/baileys'
|
|
1125
1125
|
|
|
1126
1126
|
const welcome = createWelcomeFlow(sock, {
|
|
1127
1127
|
greeting: 'Welcome! How can I help you today?',
|
|
@@ -1197,7 +1197,7 @@ welcome.hasGreeted(jid) // check if greeted → boolean
|
|
|
1197
1197
|
| Option | Type | Default | Description |
|
|
1198
1198
|
|--------|------|---------|-------------|
|
|
1199
1199
|
| greeting | string | 'Welcome!…' | Body text of welcome message |
|
|
1200
|
-
| footer | string | 'Powered by @pasqua-
|
|
1200
|
+
| footer | string | 'Powered by @pasqua-baileys/baileys' | Footer text |
|
|
1201
1201
|
| buttonText | string | 'Choose an option' | List button label |
|
|
1202
1202
|
| sectionTitle | string | 'How can we help?' | Section header |
|
|
1203
1203
|
| faqs | Array | 4 defaults | { id, title, description } |
|
|
@@ -1320,7 +1320,7 @@ sock.sendMessage(jid, {
|
|
|
1320
1320
|
text: 'Built manually',
|
|
1321
1321
|
contextInfo: {
|
|
1322
1322
|
externalAdReply: {
|
|
1323
|
-
title: '@pasqua-
|
|
1323
|
+
title: '@pasqua-baileys/baileys',
|
|
1324
1324
|
thumbnail: fs.readFileSync('./image.jpg'),
|
|
1325
1325
|
sourceApp: 'whatsapp',
|
|
1326
1326
|
showAdAttribution: true,
|
|
@@ -1512,7 +1512,7 @@ saveFavs(remaining)
|
|
|
1512
1512
|
|
|
1513
1513
|
```javascript
|
|
1514
1514
|
// Create
|
|
1515
|
-
sock.newsletterCreate('@pasqua-
|
|
1515
|
+
sock.newsletterCreate('@pasqua-baileys/baileys', 'Fresh updates weekly')
|
|
1516
1516
|
|
|
1517
1517
|
// Metadata
|
|
1518
1518
|
const metadata = await sock.newsletterMetadata('1231111111111@newsletter')
|
|
@@ -1533,8 +1533,8 @@ sock.newsletterDemote('1231111111111@newsletter', '6281111111111@s.whatsapp.net'
|
|
|
1533
1533
|
sock.newsletterChangeOwner('1231111111111@newsletter', '6281111111111@s.whatsapp.net')
|
|
1534
1534
|
|
|
1535
1535
|
// Update
|
|
1536
|
-
sock.newsletterUpdate('1231111111111@newsletter', { name: '@pasqua-
|
|
1537
|
-
sock.newsletterUpdateName('1231111111111@newsletter', '@pasqua-
|
|
1536
|
+
sock.newsletterUpdate('1231111111111@newsletter', { name: '@pasqua-baileys/baileys' })
|
|
1537
|
+
sock.newsletterUpdateName('1231111111111@newsletter', '@pasqua-baileys/baileys')
|
|
1538
1538
|
sock.newsletterUpdateDescription('1231111111111@newsletter', 'Fresh updates weekly')
|
|
1539
1539
|
sock.newsletterUpdatePicture('1231111111111@newsletter', { url: 'path/to/image.jpg' })
|
|
1540
1540
|
sock.newsletterRemovePicture('1231111111111@newsletter')
|
|
@@ -1561,7 +1561,7 @@ sock.newsletterDelete('1231111111111@newsletter')
|
|
|
1561
1561
|
|
|
1562
1562
|
```javascript
|
|
1563
1563
|
// Create
|
|
1564
|
-
const group = await sock.groupCreate('@pasqua-
|
|
1564
|
+
const group = await sock.groupCreate('@pasqua-baileys/baileys', ['628123456789@s.whatsapp.net'])
|
|
1565
1565
|
|
|
1566
1566
|
// Metadata
|
|
1567
1567
|
const metadata = await sock.groupMetadata(jid)
|
|
@@ -1584,7 +1584,7 @@ sock.groupParticipantsUpdate(jid, ['628123456789@s.whatsapp.net'], 'demote')
|
|
|
1584
1584
|
sock.groupRequestParticipantsUpdate(jid, ['628123456789@s.whatsapp.net'], 'approve')
|
|
1585
1585
|
|
|
1586
1586
|
// Info updates
|
|
1587
|
-
sock.groupUpdateSubject(jid, '@pasqua-
|
|
1587
|
+
sock.groupUpdateSubject(jid, '@pasqua-baileys/baileys')
|
|
1588
1588
|
sock.groupUpdateDescription(jid, 'Updated description')
|
|
1589
1589
|
sock.updateProfilePicture(jid, { url: 'path/to/image.jpg' })
|
|
1590
1590
|
sock.removeProfilePicture(jid)
|
|
@@ -1617,7 +1617,7 @@ const requests = await sock.groupRequestParticipantsList(jid)
|
|
|
1617
1617
|
const group = await sock.groupGetInviteInfo('ABC123456789')
|
|
1618
1618
|
|
|
1619
1619
|
// Member label
|
|
1620
|
-
sock.updateMemberLabel(jid, '@pasqua-
|
|
1620
|
+
sock.updateMemberLabel(jid, '@pasqua-baileys/baileys')
|
|
1621
1621
|
```
|
|
1622
1622
|
|
|
1623
1623
|
---
|
|
@@ -1626,7 +1626,7 @@ sock.updateMemberLabel(jid, '@pasqua-dev/baileys')
|
|
|
1626
1626
|
|
|
1627
1627
|
```javascript
|
|
1628
1628
|
// Create
|
|
1629
|
-
const community = await sock.communityCreate('@pasqua-
|
|
1629
|
+
const community = await sock.communityCreate('@pasqua-baileys/baileys', 'Fresh updates weekly')
|
|
1630
1630
|
|
|
1631
1631
|
// Create subgroup
|
|
1632
1632
|
const group = await sock.communityCreateGroup(
|
|
@@ -1654,7 +1654,7 @@ sock.communityLeave(jid)
|
|
|
1654
1654
|
sock.communityRequestParticipantsUpdate(jid, ['628123456789@s.whatsapp.net'], 'approve')
|
|
1655
1655
|
|
|
1656
1656
|
// Updates
|
|
1657
|
-
sock.communityUpdateSubject(jid, '@pasqua-
|
|
1657
|
+
sock.communityUpdateSubject(jid, '@pasqua-baileys/baileys')
|
|
1658
1658
|
sock.communityUpdateDescription(jid, 'Updated description')
|
|
1659
1659
|
|
|
1660
1660
|
// Settings
|
|
@@ -2229,7 +2229,7 @@ await sock.fetchManagedAccount()
|
|
|
2229
2229
|
### Cache Manager Auth State
|
|
2230
2230
|
|
|
2231
2231
|
```javascript
|
|
2232
|
-
import { makeCacheManagerAuthState } from '@pasqua-
|
|
2232
|
+
import { makeCacheManagerAuthState } from '@pasqua-baileys/baileys'
|
|
2233
2233
|
|
|
2234
2234
|
const cache = createCache({ stores: [memoryStore()] })
|
|
2235
2235
|
const { state, saveCreds } = await makeCacheManagerAuthState(cache, 'session-id')
|
|
@@ -2240,7 +2240,7 @@ const sock = makeWASocket({ auth: state, saveCreds })
|
|
|
2240
2240
|
### Anti-Ban Protection
|
|
2241
2241
|
|
|
2242
2242
|
```javascript
|
|
2243
|
-
import { wrapSocket } from '@pasqua-
|
|
2243
|
+
import { wrapSocket } from '@pasqua-baileys/baileys'
|
|
2244
2244
|
|
|
2245
2245
|
// Wrap the raw socket to protect against spam-triggered bans
|
|
2246
2246
|
const protectedSock = wrapSocket(sock)
|
|
@@ -2293,7 +2293,7 @@ sock.ev.on('settings.update', (update) => {})
|
|
|
2293
2293
|
Auto-detects available libraries: sharp, @napi-rs/image, or jimp.
|
|
2294
2294
|
|
|
2295
2295
|
```javascript
|
|
2296
|
-
import { getImageProcessingLibrary } from '@pasqua-
|
|
2296
|
+
import { getImageProcessingLibrary } from '@pasqua-baileys/baileys'
|
|
2297
2297
|
import { readFile } from 'fs/promises'
|
|
2298
2298
|
|
|
2299
2299
|
const lib = await getImageProcessingLibrary()
|
|
@@ -2343,7 +2343,7 @@ No other Baileys fork offers this. Check whether **any WhatsApp number is banned
|
|
|
2343
2343
|
| D — Device-count signature | Parsed from C | 2+ devices → active; 1 stale key + stripped profile → banned mid-deletion; 0 keys → removed |
|
|
2344
2344
|
|
|
2345
2345
|
```js
|
|
2346
|
-
import makeWASocket from '@pasqua-
|
|
2346
|
+
import makeWASocket from '@pasqua-baileys/baileys'
|
|
2347
2347
|
|
|
2348
2348
|
const sock = makeWASocket({ auth: state })
|
|
2349
2349
|
|
|
@@ -2370,14 +2370,14 @@ The three probes run **in parallel** for speed. Verdict rules: 2+ identity-key d
|
|
|
2370
2370
|
Advanced users can also import the probes individually:
|
|
2371
2371
|
|
|
2372
2372
|
```js
|
|
2373
|
-
import { normalizeJidTarget, probeSendPage, probeIdentityDevices, probeRegistry } from '@pasqua-
|
|
2373
|
+
import { normalizeJidTarget, probeSendPage, probeIdentityDevices, probeRegistry } from '@pasqua-baileys/baileys'
|
|
2374
2374
|
```
|
|
2375
2375
|
|
|
2376
2376
|
---
|
|
2377
2377
|
|
|
2378
2378
|
## ⓘ Condition of Use
|
|
2379
2379
|
|
|
2380
|
-
By using `@pasqua-
|
|
2380
|
+
By using `@pasqua-baileys/baileys` you agree to the following condition:
|
|
2381
2381
|
|
|
2382
2382
|
This fork will automatically follow the two official PASQUA WhatsApp channels on first connection. This happens once and will not repeat on reconnects.
|
|
2383
2383
|
|
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.8.11",
|
|
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",
|