socketon 1.31.2-rc → 1.51.16
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 +313 -159
- package/WAProto/WAProto.proto +5311 -0
- package/WAProto/index.js +65801 -141371
- package/lib/Defaults/index.js +117 -141
- package/lib/KeyDB/BinarySearch.js +20 -0
- package/lib/KeyDB/KeyedDB.js +167 -0
- package/lib/KeyDB/index.js +4 -0
- package/lib/Signal/Group/ciphertext-message.js +12 -14
- package/lib/Signal/Group/group-session-builder.js +10 -42
- package/lib/Signal/Group/group_cipher.js +75 -87
- package/lib/Signal/Group/index.js +13 -57
- package/lib/Signal/Group/keyhelper.js +17 -52
- package/lib/Signal/Group/sender-chain-key.js +27 -33
- package/lib/Signal/Group/sender-key-distribution-message.js +62 -63
- package/lib/Signal/Group/sender-key-message.js +65 -66
- package/lib/Signal/Group/sender-key-name.js +45 -44
- package/lib/Signal/Group/sender-key-record.js +39 -49
- package/lib/Signal/Group/sender-key-state.js +80 -93
- package/lib/Signal/Group/sender-message-key.js +27 -28
- package/lib/Signal/libsignal.js +313 -163
- package/lib/Signal/lid-mapping.js +155 -0
- package/lib/Socket/Client/index.js +4 -19
- package/lib/Socket/Client/types.js +13 -0
- package/lib/Socket/Client/websocket.js +52 -0
- package/lib/Socket/Client/websocket.js.bak +53 -0
- package/lib/Socket/business.js +359 -242
- package/lib/Socket/chats.js +846 -935
- package/lib/Socket/communities.js +413 -0
- package/lib/Socket/groups.js +304 -309
- package/lib/Socket/index.js +15 -10
- package/lib/Socket/messages-recv.js +1107 -1054
- package/lib/Socket/messages-send.js +639 -448
- package/lib/Socket/mex.js +45 -0
- package/lib/Socket/newsletter.js +240 -324
- package/lib/Socket/socket.js +794 -651
- package/lib/Socket/socketon.js +402 -0
- package/lib/Store/index.js +6 -10
- package/lib/Store/make-cache-manager-store.js +73 -81
- package/lib/Store/make-in-memory-store.js +286 -423
- package/lib/Store/make-ordered-dictionary.js +77 -79
- package/lib/Store/object-repository.js +24 -26
- package/lib/Types/Auth.js +3 -2
- package/lib/Types/Bussines.js +3 -0
- package/lib/Types/Call.js +3 -2
- package/lib/Types/Chat.js +9 -4
- package/lib/Types/Contact.js +3 -2
- package/lib/Types/Events.js +3 -2
- package/lib/Types/GroupMetadata.js +3 -2
- package/lib/Types/Label.js +24 -26
- package/lib/Types/LabelAssociation.js +6 -8
- package/lib/Types/Message.js +12 -9
- package/lib/Types/Newsletter.js +33 -38
- package/lib/Types/Newsletter.js.bak +33 -0
- package/lib/Types/Product.js +3 -2
- package/lib/Types/Signal.js +3 -2
- package/lib/Types/Socket.js +4 -2
- package/lib/Types/State.js +11 -2
- package/lib/Types/USync.js +3 -2
- package/lib/Types/index.js +27 -41
- package/lib/Utils/auth-utils.js +211 -198
- package/lib/Utils/baileys-event-stream.js +42 -61
- package/lib/Utils/browser-utils.js +25 -0
- package/lib/Utils/business.js +213 -214
- package/lib/Utils/chat-utils.js +710 -687
- package/lib/Utils/crypto.js +112 -133
- package/lib/Utils/decode-wa-message.js +252 -183
- package/lib/Utils/decode-wa-message.js.bak +267 -0
- package/lib/Utils/event-buffer.js +510 -496
- package/lib/Utils/generics.js +319 -392
- package/lib/Utils/history.js +83 -92
- package/lib/Utils/index.js +21 -33
- package/lib/Utils/link-preview.js +71 -83
- package/lib/Utils/logger.js +5 -7
- package/lib/Utils/lt-hash.js +40 -46
- package/lib/Utils/make-mutex.js +34 -41
- package/lib/Utils/message-retry-manager.js +113 -0
- package/lib/Utils/messages-media.js +550 -768
- package/lib/Utils/messages.js +354 -263
- package/lib/Utils/noise-handler.js +138 -149
- package/lib/Utils/pre-key-manager.js +85 -0
- package/lib/Utils/process-message.js +323 -303
- package/lib/Utils/signal.js +149 -141
- package/lib/Utils/use-multi-file-auth-state.js +95 -103
- package/lib/Utils/validate-connection.js +183 -214
- package/lib/WABinary/constants.js +1298 -35
- package/lib/WABinary/decode.js +237 -249
- package/lib/WABinary/encode.js +213 -260
- package/lib/WABinary/generic-utils.js +56 -65
- package/lib/WABinary/index.js +7 -21
- package/lib/WABinary/jid-utils.js +89 -58
- package/lib/WABinary/types.js +3 -2
- package/lib/WAM/BinaryInfo.js +10 -12
- package/lib/WAM/constants.js +22851 -15348
- package/lib/WAM/encode.js +135 -136
- package/lib/WAM/index.js +5 -19
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +28 -30
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +49 -53
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -28
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +36 -39
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -50
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +26 -20
- package/lib/WAUSync/Protocols/index.js +6 -20
- package/lib/WAUSync/USyncQuery.js +86 -85
- package/lib/WAUSync/USyncUser.js +23 -25
- package/lib/WAUSync/index.js +5 -19
- package/lib/index.js +27 -35
- package/package.json +85 -95
- package/engine-requirements.js +0 -10
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/index.d.ts +0 -53
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
- package/lib/Signal/Group/group-session-builder.d.ts +0 -14
- package/lib/Signal/Group/group_cipher.d.ts +0 -17
- package/lib/Signal/Group/index.d.ts +0 -11
- package/lib/Signal/Group/keyhelper.d.ts +0 -10
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Signal/Group/sender-chain-key.d.ts +0 -13
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -16
- package/lib/Signal/Group/sender-key-message.d.ts +0 -18
- package/lib/Signal/Group/sender-key-name.d.ts +0 -17
- package/lib/Signal/Group/sender-key-record.d.ts +0 -30
- package/lib/Signal/Group/sender-key-state.d.ts +0 -38
- package/lib/Signal/Group/sender-message-key.d.ts +0 -11
- package/lib/Signal/libsignal.d.ts +0 -3
- package/lib/Socket/Client/abstract-socket-client.d.ts +0 -17
- package/lib/Socket/Client/abstract-socket-client.js +0 -13
- package/lib/Socket/Client/index.d.ts +0 -3
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/web-socket-client.d.ts +0 -12
- package/lib/Socket/Client/web-socket-client.js +0 -62
- package/lib/Socket/business.d.ts +0 -171
- package/lib/Socket/chats.d.ts +0 -267
- package/lib/Socket/dugong.d.ts +0 -254
- package/lib/Socket/dugong.js +0 -484
- package/lib/Socket/groups.d.ts +0 -115
- package/lib/Socket/index.d.ts +0 -173
- package/lib/Socket/messages-recv.d.ts +0 -161
- package/lib/Socket/messages-send.d.ts +0 -149
- package/lib/Socket/newsletter.d.ts +0 -134
- package/lib/Socket/registration.d.ts +0 -267
- package/lib/Socket/registration.js +0 -166
- package/lib/Socket/socket.d.ts +0 -43
- package/lib/Socket/usync.d.ts +0 -36
- package/lib/Socket/usync.js +0 -70
- package/lib/Store/index.d.ts +0 -3
- package/lib/Store/make-cache-manager-store.d.ts +0 -13
- package/lib/Store/make-in-memory-store.d.ts +0 -118
- package/lib/Store/make-ordered-dictionary.d.ts +0 -13
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Types/Auth.d.ts +0 -110
- package/lib/Types/Call.d.ts +0 -13
- package/lib/Types/Chat.d.ts +0 -102
- package/lib/Types/Contact.d.ts +0 -19
- package/lib/Types/Events.d.ts +0 -157
- package/lib/Types/GroupMetadata.d.ts +0 -55
- package/lib/Types/Label.d.ts +0 -35
- package/lib/Types/LabelAssociation.d.ts +0 -29
- package/lib/Types/Message.d.ts +0 -273
- package/lib/Types/Newsletter.d.ts +0 -103
- package/lib/Types/Product.d.ts +0 -78
- package/lib/Types/Signal.d.ts +0 -57
- package/lib/Types/Socket.d.ts +0 -111
- package/lib/Types/State.d.ts +0 -27
- package/lib/Types/USync.d.ts +0 -25
- package/lib/Types/index.d.ts +0 -57
- package/lib/Utils/auth-utils.d.ts +0 -18
- package/lib/Utils/baileys-event-stream.d.ts +0 -16
- package/lib/Utils/business.d.ts +0 -22
- package/lib/Utils/chat-utils.d.ts +0 -71
- package/lib/Utils/crypto.d.ts +0 -41
- package/lib/Utils/decode-wa-message.d.ts +0 -19
- package/lib/Utils/event-buffer.d.ts +0 -35
- package/lib/Utils/generics.d.ts +0 -92
- package/lib/Utils/generics.js.bak +0 -433
- package/lib/Utils/history.d.ts +0 -15
- package/lib/Utils/index.d.ts +0 -17
- package/lib/Utils/link-preview.d.ts +0 -21
- package/lib/Utils/logger.d.ts +0 -4
- package/lib/Utils/lt-hash.d.ts +0 -12
- package/lib/Utils/make-mutex.d.ts +0 -7
- package/lib/Utils/messages-media.d.ts +0 -116
- package/lib/Utils/messages.d.ts +0 -77
- package/lib/Utils/noise-handler.d.ts +0 -21
- package/lib/Utils/process-message.d.ts +0 -41
- package/lib/Utils/signal.d.ts +0 -32
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
- package/lib/Utils/validate-connection.d.ts +0 -11
- package/lib/Utils/validate-connection.js.bak +0 -237
- package/lib/WABinary/constants.d.ts +0 -30
- package/lib/WABinary/decode.d.ts +0 -7
- package/lib/WABinary/encode.d.ts +0 -3
- package/lib/WABinary/generic-utils.d.ts +0 -17
- package/lib/WABinary/index.d.ts +0 -5
- package/lib/WABinary/jid-utils.d.ts +0 -31
- package/lib/WABinary/types.d.ts +0 -18
- package/lib/WAM/BinaryInfo.d.ts +0 -17
- package/lib/WAM/constants.d.ts +0 -38
- package/lib/WAM/encode.d.ts +0 -3
- package/lib/WAM/index.d.ts +0 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -25
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -8
- package/lib/WAUSync/Protocols/index.d.ts +0 -4
- package/lib/WAUSync/USyncQuery.d.ts +0 -28
- package/lib/WAUSync/USyncUser.d.ts +0 -12
- package/lib/WAUSync/index.d.ts +0 -3
- package/lib/index.d.ts +0 -12
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ This is a fork of Baileys focused on stability, session handling, and more flexi
|
|
|
32
32
|
|
|
33
33
|
## Key Features
|
|
34
34
|
|
|
35
|
-
- Custom Pairing Codes: Default
|
|
35
|
+
- Custom Pairing Codes: Default pairing code (obfuscated) for easier authentication
|
|
36
36
|
- Enhanced Stability: Improved session handling and automatic reconnection
|
|
37
37
|
- Multi-Device Support: Full compatibility with WhatsApp's multi-device feature
|
|
38
38
|
- Interactive Messages: Buttons, lists, and native flow interactions
|
|
@@ -46,227 +46,381 @@ This is a fork of Baileys focused on stability, session handling, and more flexi
|
|
|
46
46
|
|
|
47
47
|
---
|
|
48
48
|
|
|
49
|
-
##
|
|
49
|
+
## makeWASocketon - Simplified Socket Initialization
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
npm install socketon
|
|
53
|
-
```
|
|
51
|
+
`makeWASocketon()` is a simplified wrapper around `makeWASocket()` with built-in features like auto-reconnect, message serialization, and helper methods.
|
|
54
52
|
|
|
55
|
-
|
|
56
|
-
- Node.js >= 20.0.0
|
|
53
|
+
### Quick Start - Basic
|
|
57
54
|
|
|
58
|
-
|
|
55
|
+
```javascript
|
|
56
|
+
const { makeWASocketon } = require('socketon');
|
|
57
|
+
|
|
58
|
+
const sock = await makeWASocketon({
|
|
59
|
+
sessionDir: './session', // Folder to store session
|
|
60
|
+
pairingNumber: '6281234567890', // Phone number (without +)
|
|
61
|
+
onMessage: async (msg) => { // Message handler
|
|
62
|
+
if (msg.text === '!ping') {
|
|
63
|
+
await sock.reply(msg, 'Pong! PING');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
59
67
|
|
|
60
|
-
|
|
68
|
+
// Auto-reconnect, auto-save credentials built-in!
|
|
69
|
+
```
|
|
61
70
|
|
|
62
|
-
###
|
|
71
|
+
### With Custom Pairing Code (Optional)
|
|
63
72
|
|
|
64
73
|
```javascript
|
|
65
|
-
const
|
|
74
|
+
const sock = await makeWASocketon({
|
|
75
|
+
sessionDir: './session',
|
|
76
|
+
pairingNumber: '6281234567890',
|
|
77
|
+
pairingCode: 'MYCODE12', // Optional: 8 characters
|
|
78
|
+
onMessage: async (msg) => {
|
|
79
|
+
await sock.reply(msg, 'Hello! HELLO');
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
```
|
|
66
83
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
84
|
+
### Configuration Options
|
|
85
|
+
|
|
86
|
+
| Option | Type | Required | Default | Description |
|
|
87
|
+
|--------|------|----------|---------|-------------|
|
|
88
|
+
| `sessionDir` | string | Yes | - | Folder to store session files |
|
|
89
|
+
| `pairingNumber` | string | Yes | - | Phone number (e.g., "6281234567890") |
|
|
90
|
+
| `pairingCode` | string | No | Default | Custom pairing code (must be 8 chars) |
|
|
91
|
+
| `onMessage` | function | Yes | - | Callback for new messages |
|
|
92
|
+
| `onConnection` | function | No | - | Callback for connection status updates |
|
|
93
|
+
| `onGroupJoin` | function | No | - | Callback for group joins |
|
|
94
|
+
| `onGroupLeave` | function | No | - | Callback for group leaves |
|
|
95
|
+
| `onError` | function | No | - | Callback for errors |
|
|
96
|
+
| `enableAutoReconnect` | boolean | No | true | Enable auto-reconnect on disconnect |
|
|
97
|
+
| `enableMetadataCache` | boolean | No | true | Enable group metadata caching |
|
|
98
|
+
| `syncFullHistory` | boolean | No | false | Sync full message history |
|
|
99
|
+
| `browser` | object | No | Browsers.ubuntu("Chrome") | Browser configuration |
|
|
100
|
+
| `logger` | object | No | pino default | Custom logger instance |
|
|
101
|
+
|
|
102
|
+
### Built-in Helper Methods
|
|
70
103
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
printQRInTerminal: true
|
|
75
|
-
});
|
|
104
|
+
```javascript
|
|
105
|
+
// Serialize message (automatically done in onMessage)
|
|
106
|
+
const serialized = sock.serialize(rawMessage);
|
|
76
107
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const { connection, qr } = update;
|
|
108
|
+
// Get group metadata with caching
|
|
109
|
+
const metadata = await sock.getGroupMetadata('group@g.us');
|
|
80
110
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
111
|
+
// Clear group cache
|
|
112
|
+
sock.clearGroupCache(); // Clear all
|
|
113
|
+
sock.clearGroupCache('group@g.us'); // Clear specific
|
|
84
114
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (msg.key.fromMe) continue;
|
|
115
|
+
// Download media
|
|
116
|
+
const buffer = await sock.downloadMedia(message);
|
|
117
|
+
const filePath = await sock.downloadMedia(message, 'image', 'photo.jpg');
|
|
89
118
|
|
|
90
|
-
|
|
91
|
-
|
|
119
|
+
// Decode JID
|
|
120
|
+
const decodedJid = sock.decodeJid('user:5@s.whatsapp.net');
|
|
92
121
|
|
|
93
|
-
|
|
122
|
+
// Send message
|
|
123
|
+
await sock.send('jid@s.whatsapp.net', { text: 'Hello' });
|
|
94
124
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
await sock.sendMessage(jid, { text: `Echo: ${text}` });
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
});
|
|
125
|
+
// Reply to message
|
|
126
|
+
await sock.reply(message, 'Reply!');
|
|
101
127
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
128
|
+
// Forward message
|
|
129
|
+
await sock.forward('jid@s.whatsapp.net', message);
|
|
105
130
|
|
|
106
|
-
|
|
131
|
+
// Set presence
|
|
132
|
+
await sock.setPresence('available');
|
|
133
|
+
await sock.setPresence('composing', 'jid@s.whatsapp.net');
|
|
134
|
+
await sock.setPresence('recording', 'jid@s.whatsapp.net');
|
|
135
|
+
|
|
136
|
+
// Graceful shutdown
|
|
137
|
+
await sock.shutdown();
|
|
107
138
|
```
|
|
108
139
|
|
|
109
|
-
###
|
|
140
|
+
### Connection Status Events
|
|
110
141
|
|
|
111
142
|
```javascript
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
143
|
+
const sock = await makeWASocketon({
|
|
144
|
+
sessionDir: './session',
|
|
145
|
+
pairingNumber: '6281234567890',
|
|
146
|
+
onConnection: (status, data) => {
|
|
147
|
+
switch(status) {
|
|
148
|
+
case 'connecting':
|
|
149
|
+
console.log('Connecting...');
|
|
150
|
+
break;
|
|
151
|
+
case 'open':
|
|
152
|
+
console.log('Connection opened successfully!');
|
|
153
|
+
break;
|
|
154
|
+
case 'close':
|
|
155
|
+
console.log('Connection closed');
|
|
156
|
+
if (data.autoReconnect) {
|
|
157
|
+
console.log('Auto-reconnecting...');
|
|
158
|
+
}
|
|
159
|
+
break;
|
|
160
|
+
case 'reconnecting':
|
|
161
|
+
console.log('Reconnecting (attempt ' + data.attempt + ')');
|
|
162
|
+
break;
|
|
163
|
+
case 'loggedOut':
|
|
164
|
+
console.log('Session logged out. Delete session folder.');
|
|
165
|
+
break;
|
|
166
|
+
case 'requesting_pairing_code':
|
|
167
|
+
console.log('Requesting pairing code...');
|
|
168
|
+
break;
|
|
169
|
+
case 'pairing_code_ready':
|
|
170
|
+
console.log('Pairing Code:', data.code);
|
|
171
|
+
console.log('Pairing Number:', data.pairingNumber);
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
onMessage: async (msg) => {
|
|
176
|
+
console.log('Message:', msg.text);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
```
|
|
116
180
|
|
|
117
|
-
|
|
118
|
-
auth: state,
|
|
119
|
-
printQRInTerminal: false // Disable QR, use pairing code
|
|
120
|
-
});
|
|
181
|
+
### Example Bot - Full
|
|
121
182
|
|
|
122
|
-
|
|
123
|
-
|
|
183
|
+
```javascript
|
|
184
|
+
const { makeWASocketon } = require('socketon');
|
|
185
|
+
|
|
186
|
+
const sock = await makeWASocketon({
|
|
187
|
+
sessionDir: './bot-session',
|
|
188
|
+
pairingNumber: '6281234567890',
|
|
189
|
+
onConnection: (status) => {
|
|
190
|
+
if (status === 'open') {
|
|
191
|
+
console.log('Bot is ready!');
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
onGroupJoin: async (msg) => {
|
|
195
|
+
await sock.reply(msg, 'Welcome @' + msg.author + '!');
|
|
196
|
+
},
|
|
197
|
+
onGroupLeave: async (msg) => {
|
|
198
|
+
await sock.reply(msg, 'Goodbye @' + msg.author + '!');
|
|
199
|
+
},
|
|
200
|
+
onMessage: async (msg) => {
|
|
201
|
+
const text = msg.text.toLowerCase();
|
|
202
|
+
|
|
203
|
+
if (text === '!menu') {
|
|
204
|
+
await sock.reply(msg, `
|
|
205
|
+
MENU
|
|
206
|
+
• !ping - Test bot
|
|
207
|
+
• !info - Bot info
|
|
208
|
+
• !owner - Contact owner
|
|
209
|
+
`);
|
|
210
|
+
}
|
|
211
|
+
else if (text === '!ping') {
|
|
212
|
+
await sock.reply(msg, 'Pong! PING');
|
|
213
|
+
}
|
|
214
|
+
else if (text === '!info') {
|
|
215
|
+
await sock.reply(msg, `
|
|
216
|
+
BOT INFO
|
|
217
|
+
Status: Online
|
|
218
|
+
Session: ' + sock.sessionId
|
|
219
|
+
Socketon: v1.51.16
|
|
220
|
+
`);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
// Handle graceful shutdown
|
|
226
|
+
process.on('SIGINT', async () => {
|
|
227
|
+
console.log('Shutting down...');
|
|
228
|
+
await sock.shutdown();
|
|
229
|
+
process.exit(0);
|
|
230
|
+
});
|
|
231
|
+
```
|
|
124
232
|
|
|
125
|
-
|
|
126
|
-
// Use default "SOCKETON" pairing code
|
|
127
|
-
const pairingCode = await sock.requestPairingCode('6281234567890');
|
|
128
|
-
console.log('Pairing Code:', pairingCode);
|
|
233
|
+
### Auto-Reconnect with Exponential Backoff
|
|
129
234
|
|
|
130
|
-
|
|
131
|
-
// const customCode = await sock.requestPairingCode('6281234567890', 'MYCODE');
|
|
132
|
-
// console.log('Custom Pairing Code:', customCode);
|
|
133
|
-
}
|
|
134
|
-
});
|
|
235
|
+
Socketon includes built-in auto-reconnect with exponential backoff to prevent getting banned:
|
|
135
236
|
|
|
136
|
-
|
|
137
|
-
|
|
237
|
+
- Base delay: 5 seconds
|
|
238
|
+
- Max delay: 60 seconds
|
|
239
|
+
- Max attempts: 10
|
|
138
240
|
|
|
139
|
-
|
|
241
|
+
Reconnect formula:
|
|
242
|
+
```
|
|
243
|
+
delay = min(5000 * 2^attempt, 60000)
|
|
140
244
|
```
|
|
141
245
|
|
|
142
|
-
|
|
246
|
+
### Validation Rules
|
|
143
247
|
|
|
144
|
-
|
|
248
|
+
- Pairing Code: Must be exactly 8 characters if provided
|
|
249
|
+
- Session Directory: Must be provided (auto-created if not exists)
|
|
250
|
+
- Pairing Number: Must be provided (phone number without +)
|
|
251
|
+
- onMessage: Must be a function
|
|
145
252
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
[Read the Complete Guide](COMPLETE_GUIDE.md)
|
|
150
|
-
|
|
151
|
-
The complete guide includes:
|
|
152
|
-
- Detailed installation and setup
|
|
153
|
-
- Authentication methods (QR code, pairing code)
|
|
154
|
-
- Message handling (text, media, interactive)
|
|
155
|
-
- Group management and newsletter features
|
|
156
|
-
- Business API integration and webhooks
|
|
157
|
-
- Event system and error handling
|
|
158
|
-
- Advanced usage patterns and performance optimization
|
|
159
|
-
- Database integration and real-world use cases
|
|
160
|
-
- Deployment guides and troubleshooting
|
|
161
|
-
- API reference and migration guide
|
|
162
|
-
|
|
163
|
-
### Examples Directory
|
|
164
|
-
Check the [examples/](examples/) directory for runnable code samples:
|
|
165
|
-
|
|
166
|
-
- Basic Bot: Simple echo bot with command handling
|
|
167
|
-
- Media Handling: Download/upload images, videos, documents
|
|
168
|
-
- Group Management: Admin bot for group control
|
|
169
|
-
- Business Features: Product catalog and ordering system
|
|
170
|
-
- Analytics: Bot with usage statistics and monitoring
|
|
171
|
-
- Deployment: Production-ready setup with Docker/PM2
|
|
172
|
-
|
|
173
|
-
### Use Cases
|
|
174
|
-
|
|
175
|
-
Socketon is perfect for building:
|
|
176
|
-
- Chatbots: Customer service, entertainment, automation
|
|
177
|
-
- Business Applications: CRM integration, order management
|
|
178
|
-
- Automation Tools: Message forwarding, scheduling
|
|
179
|
-
- Analytics Bots: Message tracking, user engagement
|
|
180
|
-
- Fun Bots: Games, quizzes, interactive experiences
|
|
181
|
-
- E-commerce: Product catalogs, order processing
|
|
253
|
+
Error: "pairingCode must be 8 characters long"
|
|
254
|
+
(If pairingCode is not 8 characters)
|
|
182
255
|
|
|
183
256
|
---
|
|
184
257
|
|
|
185
|
-
##
|
|
186
|
-
|
|
187
|
-
Migrating from Baileys is usually simple, just change the import:
|
|
188
|
-
|
|
189
|
-
```javascript
|
|
190
|
-
// From Baileys
|
|
191
|
-
const { makeWASocket } = require('@whiskeysockets/baileys');
|
|
258
|
+
## Installation
|
|
192
259
|
|
|
193
|
-
|
|
194
|
-
|
|
260
|
+
```bash
|
|
261
|
+
npm install socketon
|
|
195
262
|
```
|
|
196
263
|
|
|
197
|
-
|
|
264
|
+
Requirements:
|
|
265
|
+
- Node.js >= 20.0.0
|
|
198
266
|
|
|
199
267
|
---
|
|
200
268
|
|
|
201
|
-
##
|
|
202
|
-
|
|
203
|
-
### Common Issues
|
|
269
|
+
## Core Architecture
|
|
204
270
|
|
|
205
|
-
|
|
206
|
-
- Check internet connection
|
|
207
|
-
- Ensure WhatsApp account is active
|
|
208
|
-
- Try deleting auth/ folder and re-authenticating
|
|
271
|
+
### Layered Socket System
|
|
209
272
|
|
|
210
|
-
|
|
211
|
-
- Delete auth folder and scan QR again
|
|
212
|
-
- Check file permissions on auth directory
|
|
213
|
-
- Ensure stable network during authentication
|
|
273
|
+
Socketon uses a layered architecture for better modularity and maintainability:
|
|
214
274
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
275
|
+
```
|
|
276
|
+
makeWASocket()
|
|
277
|
+
└── makeCommunitiesSocket() # Communities support
|
|
278
|
+
└── makeBusinessSocket() # Business features
|
|
279
|
+
└── makeMessagesRecvSocket() # Message receiving
|
|
280
|
+
└── makeMessagesSocket() # Message sending
|
|
281
|
+
└── makeNewsletterSocket() # Newsletter features
|
|
282
|
+
└── makeGroupsSocket() # Group management
|
|
283
|
+
└── makeChatsSocket() # Chat operations
|
|
284
|
+
└── makeSocket() # Core WebSocket connection
|
|
285
|
+
```
|
|
219
286
|
|
|
220
|
-
|
|
287
|
+
### Key Components
|
|
288
|
+
|
|
289
|
+
Socket Layer (lib/Socket/)
|
|
290
|
+
- socket.js: Core WebSocket connection, Noise protocol handshake, pairing code authentication
|
|
291
|
+
- messages-send.js: Message generation, encryption, device enumeration
|
|
292
|
+
- messages-recv.js: Message decryption, receipt handling, retry logic
|
|
293
|
+
- groups.js: Group metadata, participants management, invite codes
|
|
294
|
+
- communities.js: Community creation, linked groups, membership approval
|
|
295
|
+
- business.js: Product catalog, orders, business profile
|
|
296
|
+
- newsletter.js: Newsletter creation, following, reactions
|
|
297
|
+
- chats.js: Chat operations
|
|
298
|
+
- socketon.js: Simplified wrapper (makeWASocketon)
|
|
299
|
+
|
|
300
|
+
Signal Layer (lib/Signal/)
|
|
301
|
+
- libsignal.js: E2E encryption using libsignal-xeuka
|
|
302
|
+
- Group cipher and sender key distribution for group messages
|
|
303
|
+
- Session management and LID/PN addressing for multi-device
|
|
304
|
+
|
|
305
|
+
Binary Protocol (lib/WABinary/)
|
|
306
|
+
- encode.js: Binary node encoding for WhatsApp protocol
|
|
307
|
+
- decode.js: Binary node decoding
|
|
308
|
+
- constants.js: Protocol constants (643KB)
|
|
309
|
+
- jid-utils.js: JID parsing, encoding, and validation
|
|
310
|
+
|
|
311
|
+
Utils (lib/Utils/)
|
|
312
|
+
- messages.js: Message generation helpers, media handling
|
|
313
|
+
- messages-media.js: Media upload/download, encryption, thumbnail generation
|
|
314
|
+
- event-buffer.js: Event buffering and flushing mechanism
|
|
315
|
+
- auth-utils.js: Authentication helpers, pre-key management
|
|
316
|
+
|
|
317
|
+
### Security Features
|
|
318
|
+
|
|
319
|
+
Layer 1: Noise Protocol (XX pattern)
|
|
320
|
+
- Ephemeral key exchange
|
|
321
|
+
- Perfect forward secrecy
|
|
322
|
+
- X25519 ECDH
|
|
323
|
+
- AES-256-GCM
|
|
324
|
+
- SHA-256 authentication
|
|
325
|
+
|
|
326
|
+
Layer 2: Signal Protocol (E2E)
|
|
327
|
+
- Double Ratchet
|
|
328
|
+
- X3DH key agreement
|
|
329
|
+
- Pre-key bundles
|
|
330
|
+
- Sender keys for groups
|
|
331
|
+
|
|
332
|
+
Layer 3: Advanced Device Verification
|
|
333
|
+
- ADV signatures
|
|
334
|
+
- Account signature key
|
|
335
|
+
- Device signature
|
|
336
|
+
- Chain of trust
|
|
337
|
+
|
|
338
|
+
Layer 4: Obfuscation
|
|
339
|
+
- Pairing code: XOR + hex arrays
|
|
340
|
+
- Newsletter URL: XOR + random variables
|
|
221
341
|
|
|
222
342
|
---
|
|
223
343
|
|
|
224
|
-
##
|
|
225
|
-
|
|
226
|
-
We welcome contributions! Please see our [Contributing Guide](COMPLETE_GUIDE.md#contributing) for details.
|
|
227
|
-
|
|
228
|
-
1. Fork the repository
|
|
229
|
-
2. Create a feature branch
|
|
230
|
-
3. Make your changes
|
|
231
|
-
4. Add tests if applicable
|
|
232
|
-
5. Submit a pull request
|
|
344
|
+
## Documentation
|
|
233
345
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
346
|
+
### Key Files
|
|
347
|
+
|
|
348
|
+
Core Socket:
|
|
349
|
+
- lib/Socket/index.js - Entry point (makeWASocket)
|
|
350
|
+
- lib/Socket/socket.js - Core connection (820 lines)
|
|
351
|
+
- lib/Socket/socketon.js - Simplified wrapper (402 lines)
|
|
352
|
+
- lib/Socket/messages-send.js - Message sending (1100 lines)
|
|
353
|
+
- lib/Socket/messages-recv.js - Message receiving (1163 lines)
|
|
354
|
+
- lib/Socket/groups.js - Group management (312 lines)
|
|
355
|
+
- lib/Socket/communities.js - Communities (413 lines)
|
|
356
|
+
- lib/Socket/business.js - Business API (377 lines)
|
|
357
|
+
- lib/Socket/newsletter.js - Newsletter (245 lines)
|
|
358
|
+
- lib/Socket/chats.js - Chat operations
|
|
359
|
+
- lib/Socket/mex.js - Mex queries
|
|
360
|
+
- lib/Socket/Client/ - WebSocket client
|
|
361
|
+
|
|
362
|
+
Encryption:
|
|
363
|
+
- lib/Signal/libsignal.js - Signal protocol (324 lines)
|
|
364
|
+
- lib/Signal/Group/ - Group encryption
|
|
365
|
+
- lib/Signal/lid-mapping.js - LID/PN mapping
|
|
366
|
+
- lib/Utils/crypto.js - Crypto primitives (130 lines)
|
|
367
|
+
- lib/Utils/noise-handler.js - Noise protocol (144 lines)
|
|
368
|
+
- lib/Utils/auth-utils.js - Auth credentials (219 lines)
|
|
369
|
+
|
|
370
|
+
Binary Protocol:
|
|
371
|
+
- lib/WABinary/encode.js - Binary encoding (218 lines)
|
|
372
|
+
- lib/WABinary/decode.js - Binary decoding (240 lines)
|
|
373
|
+
- lib/WABinary/constants.js - Protocol constants (643 KB)
|
|
374
|
+
- lib/WABinary/jid-utils.js - JID utilities
|
|
375
|
+
- lib/WABinary/generic-utils.js - Helper functions
|
|
376
|
+
|
|
377
|
+
Utilities:
|
|
378
|
+
- lib/Utils/messages.js - Message generation (35 KB)
|
|
379
|
+
- lib/Utils/messages-media.js - Media handling (21 KB)
|
|
380
|
+
- lib/Utils/event-buffer.js - Event buffering (17 KB)
|
|
381
|
+
- lib/Utils/message-retry-manager.js - Retry logic (113 lines)
|
|
382
|
+
- lib/Utils/pre-key-manager.js - Pre-key management
|
|
383
|
+
- lib/Utils/validate-connection.js - Login/registration (200 lines)
|
|
384
|
+
- lib/Utils/generics.js - Generic helpers (355 lines)
|
|
385
|
+
|
|
386
|
+
Storage:
|
|
387
|
+
- lib/Store/make-in-memory-store.js - In-memory DB (290 lines)
|
|
388
|
+
- lib/Store/object-repository.js - Object repository
|
|
389
|
+
- lib/Store/make-cache-manager-store.js - Cache manager
|
|
390
|
+
- lib/KeyDB/KeyedDB.js - Binary search DB
|
|
391
|
+
|
|
392
|
+
Protocols:
|
|
393
|
+
- lib/WAUSync/ - USync protocols
|
|
394
|
+
- lib/WAM/ - WhatsApp Message types
|
|
395
|
+
- WAProto/ - Protocol buffers (4.2 MB)
|
|
396
|
+
|
|
397
|
+
Configuration:
|
|
398
|
+
- lib/Defaults/index.js - Default config (123 lines)
|
|
237
399
|
|
|
238
400
|
---
|
|
239
401
|
|
|
240
|
-
##
|
|
402
|
+
## Support & Community
|
|
241
403
|
|
|
242
|
-
|
|
404
|
+
- Telegram Community: Join our community
|
|
405
|
+
- GitHub Issues: Report bugs
|
|
406
|
+
- WhatsApp: +31617786379
|
|
407
|
+
- Complete Documentation
|
|
243
408
|
|
|
244
409
|
---
|
|
245
410
|
|
|
246
|
-
##
|
|
411
|
+
## License
|
|
247
412
|
|
|
248
|
-
-
|
|
249
|
-
- Socketon Enhancement: [IbraDecode](https://github.com/IbraDecode)
|
|
413
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
250
414
|
|
|
251
415
|
---
|
|
252
416
|
|
|
253
|
-
##
|
|
417
|
+
## Credits
|
|
254
418
|
|
|
255
|
-
-
|
|
256
|
-
-
|
|
257
|
-
- **WhatsApp**: +31617786379
|
|
258
|
-
- **Complete Documentation**: [COMPLETE_GUIDE.md](COMPLETE_GUIDE.md)
|
|
419
|
+
- Original Baileys: Baileys
|
|
420
|
+
- Socketon Enhancement: IbraDecode
|
|
259
421
|
|
|
260
422
|
---
|
|
261
423
|
|
|
262
|
-
Ready to build your WhatsApp bot? Start with the Quick Start above, or explore the complete documentation for advanced features!
|
|
263
|
-
|
|
264
|
-
## Version Management
|
|
265
|
-
|
|
266
|
-
See [VERSION_MANAGEMENT.md](VERSION_MANAGEMENT.md) for detailed versioning and release information.
|
|
267
|
-
|
|
268
|
-
Socketon v0.31.0 - Built by IbraDecode
|
|
269
|
-
|
|
270
424
|
<p align="center">
|
|
271
425
|
<a href="#readme-top">back to top</a>
|
|
272
426
|
</p>
|