@neelegirl/wa-api 1.6.4 → 1.6.6
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/dist/Defaults/index.d.ts +3 -2
- package/dist/Socket/index.js +1 -1
- package/dist/Utils/index.d.ts +2 -1
- package/package.json +6 -6
- package/readme.md +306 -76
package/dist/Defaults/index.d.ts
CHANGED
|
@@ -8,11 +8,12 @@ export declare enum CALLBACK_KEY {
|
|
|
8
8
|
ON_CONNECTED = "on-connected",
|
|
9
9
|
ON_DISCONNECTED = "on-disconnected",
|
|
10
10
|
ON_CONNECTING = "on-connecting",
|
|
11
|
-
ON_MESSAGE_UPDATED = "on-message-updated"
|
|
11
|
+
ON_MESSAGE_UPDATED = "on-message-updated",
|
|
12
|
+
ON_PAIRING_CODE = "on-pairing-code"
|
|
12
13
|
}
|
|
13
14
|
export declare abstract class Messages {
|
|
14
15
|
static sessionAlreadyExist: (sessionId: string) => string;
|
|
15
16
|
static sessionNotFound: (sessionId: string) => string;
|
|
16
17
|
static paremetersRequired: (props: string[] | string) => string;
|
|
17
18
|
}
|
|
18
|
-
//# sourceMappingURL=index.d.ts.map
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/Socket/index.js
CHANGED
package/dist/Utils/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
{
|
|
2
2
|
"name": "@neelegirl/wa-api",
|
|
3
|
-
"version": "1.6.
|
|
4
|
-
"description": "Multi-session WhatsApp
|
|
3
|
+
"version": "1.6.6",
|
|
4
|
+
"description": "Multi-session WhatsApp wrapper built on top of @neelegirl/baileys",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"repository": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"author": "Neele",
|
|
26
26
|
"license": "MIT",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@neelegirl/baileys": "^2.1.
|
|
28
|
+
"@neelegirl/baileys": "^2.1.6",
|
|
29
29
|
"pino": "^8.11.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
@@ -41,9 +41,9 @@
|
|
|
41
41
|
"neelegirl"
|
|
42
42
|
],
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"@neelegirl/baileys": "^2.1.
|
|
44
|
+
"@neelegirl/baileys": "^2.1.6"
|
|
45
45
|
},
|
|
46
46
|
"engines": {
|
|
47
47
|
"node": ">=20.0.0"
|
|
48
48
|
}
|
|
49
|
-
}
|
|
49
|
+
}
|
package/readme.md
CHANGED
|
@@ -1,23 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
2
|
|
|
3
3
|
# @neelegirl/wa-api
|
|
4
4
|
|
|
5
|
-
###
|
|
5
|
+
### Multi-session wrapper around `@neelegirl/baileys`
|
|
6
|
+
### QR login, pairing code login, session management, and event hooks
|
|
6
7
|
|
|
7
|
-
[](https://www.npmjs.com/package/@neelegirl/wa-api)
|
|
9
|
+
[](https://www.npmjs.com/package/@neelegirl/baileys)
|
|
10
|
+
[](https://nodejs.org)
|
|
11
|
+
[](LICENSE)
|
|
12
|
+
|
|
13
|
+
---
|
|
11
14
|
|
|
12
15
|
<p align="center">
|
|
13
|
-
<img src="https://files.catbox.moe/6np1ii.JPG" width="760" alt="
|
|
16
|
+
<img src="https://files.catbox.moe/6np1ii.JPG" width="760" alt="@neelegirl/wa-api" />
|
|
14
17
|
</p>
|
|
15
18
|
|
|
16
|
-
| Package |
|
|
19
|
+
| Package | Version | Role |
|
|
17
20
|
|---|---:|---|
|
|
18
|
-
| `@neelegirl/wa-api` | `1.6.
|
|
21
|
+
| `@neelegirl/wa-api` | `1.6.6` | Convenience wrapper for session lifecycle and event-driven bot workflows |
|
|
19
22
|
|
|
20
|
-
[Installation](#installation) · [Quickstart](#quickstart) · [API
|
|
23
|
+
[Installation](#installation) · [Quickstart](#quickstart) · [API surface](#verified-api-surface) · [Events](#event-hooks) · [Storage](#session-storage) · [Release notes](#release-notes)
|
|
21
24
|
|
|
22
25
|
</div>
|
|
23
26
|
|
|
@@ -26,120 +29,347 @@
|
|
|
26
29
|
## Table of Contents
|
|
27
30
|
|
|
28
31
|
- [Overview](#overview)
|
|
32
|
+
- [What this package is](#what-this-package-is)
|
|
33
|
+
- [What this package is not](#what-this-package-is-not)
|
|
29
34
|
- [Installation](#installation)
|
|
30
35
|
- [Quickstart](#quickstart)
|
|
31
|
-
- [
|
|
32
|
-
- [
|
|
33
|
-
- [
|
|
34
|
-
- [
|
|
35
|
-
- [
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
- [Session lifecycle](#session-lifecycle)
|
|
37
|
+
- [Message sending](#message-sending)
|
|
38
|
+
- [Event hooks](#event-hooks)
|
|
39
|
+
- [Session storage](#session-storage)
|
|
40
|
+
- [Working with the underlying socket](#working-with-the-underlying-socket)
|
|
41
|
+
- [Verified API surface](#verified-api-surface)
|
|
42
|
+
- [Recent maintenance notes](#recent-maintenance-notes)
|
|
43
|
+
- [Release notes](#release-notes)
|
|
44
|
+
- [Disclaimer](#disclaimer)
|
|
38
45
|
|
|
39
46
|
## Overview
|
|
40
47
|
|
|
41
|
-
`@neelegirl/wa-api`
|
|
48
|
+
`@neelegirl/wa-api` is a small wrapper package built on top of `@neelegirl/baileys`. Its job is to simplify:
|
|
42
49
|
|
|
43
|
-
|
|
50
|
+
- starting sessions
|
|
51
|
+
- reloading saved sessions
|
|
52
|
+
- subscribing to high-level events
|
|
53
|
+
- sending messages without wiring the socket boilerplate every time
|
|
44
54
|
|
|
45
|
-
|
|
46
|
-
- QR callback flow and pairing-code callback flow
|
|
47
|
-
- Message receive/update callbacks
|
|
48
|
-
- Helper senders (`sendMessage`, `sendStatusMentions`, `relayMessage`)
|
|
49
|
-
- File-based credential persistence per session
|
|
55
|
+
It keeps the actual WhatsApp protocol handling inside the underlying Baileys fork.
|
|
50
56
|
|
|
51
|
-
|
|
57
|
+
## What this package is
|
|
58
|
+
|
|
59
|
+
| Area | Purpose |
|
|
60
|
+
|---|---|
|
|
61
|
+
| session start helpers | launch QR or pairing-code sessions |
|
|
62
|
+
| session lookup helpers | retrieve running sockets by session id |
|
|
63
|
+
| event hooks | react to connection, QR, pairing, and message events |
|
|
64
|
+
| message helpers | forward content into the underlying Baileys socket |
|
|
65
|
+
| storage helpers | customize the credential folder name and suffix |
|
|
66
|
+
|
|
67
|
+
## What this package is not
|
|
68
|
+
|
|
69
|
+
- not a standalone REST API server
|
|
70
|
+
- not a replacement for the full Baileys API surface
|
|
71
|
+
- not a different transport layer
|
|
72
|
+
- not a separate WhatsApp protocol implementation
|
|
73
|
+
|
|
74
|
+
If you need deeper socket control, use `getSession(...)` and work directly with the returned Baileys socket.
|
|
52
75
|
|
|
53
76
|
## Installation
|
|
54
77
|
|
|
78
|
+
Use npm:
|
|
79
|
+
|
|
55
80
|
```bash
|
|
56
81
|
npm install @neelegirl/wa-api
|
|
57
82
|
```
|
|
58
83
|
|
|
59
|
-
|
|
84
|
+
Use yarn:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
yarn add @neelegirl/wa-api
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Runtime requirement:
|
|
91
|
+
|
|
92
|
+
```text
|
|
93
|
+
Node.js >= 20
|
|
94
|
+
```
|
|
60
95
|
|
|
61
96
|
## Quickstart
|
|
62
97
|
|
|
98
|
+
### Start a session with QR
|
|
99
|
+
|
|
63
100
|
```js
|
|
64
101
|
const wa = require('@neelegirl/wa-api')
|
|
65
102
|
|
|
66
|
-
wa.onQRUpdated(({ sessionId, qr }) => {
|
|
67
|
-
console.log('QR updated:', sessionId)
|
|
68
|
-
console.log(qr)
|
|
69
|
-
})
|
|
70
|
-
|
|
71
103
|
wa.onConnected((sessionId) => {
|
|
72
|
-
console.log('
|
|
104
|
+
console.log('connected:', sessionId)
|
|
73
105
|
})
|
|
74
106
|
|
|
75
107
|
wa.onMessageReceived(async (msg) => {
|
|
76
|
-
const
|
|
77
|
-
|
|
108
|
+
const text =
|
|
109
|
+
msg.message?.conversation ||
|
|
110
|
+
msg.message?.extendedTextMessage?.text ||
|
|
111
|
+
''
|
|
112
|
+
|
|
113
|
+
if (text.toLowerCase() === 'ping') {
|
|
114
|
+
await wa.sendMessage(msg.sessionId, msg.key.remoteJid, {
|
|
115
|
+
text: 'pong'
|
|
116
|
+
})
|
|
117
|
+
}
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
async function main() {
|
|
121
|
+
await wa.startSession('demo-session', { printQR: true })
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
main().catch(console.error)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Start a session with pairing code
|
|
128
|
+
|
|
129
|
+
```js
|
|
130
|
+
const wa = require('@neelegirl/wa-api')
|
|
131
|
+
|
|
132
|
+
wa.onPairingCode((sessionId, code) => {
|
|
133
|
+
console.log('pairing code for', sessionId, ':', code)
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
async function main() {
|
|
137
|
+
await wa.startSessionWithPairingCode(
|
|
138
|
+
'pairing-session',
|
|
139
|
+
{ phoneNumber: '491234567890' }
|
|
140
|
+
)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
main().catch(console.error)
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
`startSessionWithPairingCode(...)` also accepts a third argument for a custom pairing-code string when your workflow needs one.
|
|
147
|
+
|
|
148
|
+
## Session lifecycle
|
|
149
|
+
|
|
150
|
+
### Start a normal session
|
|
151
|
+
|
|
152
|
+
```js
|
|
153
|
+
await wa.startSession('session-1', { printQR: true })
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Start with pairing code
|
|
157
|
+
|
|
158
|
+
```js
|
|
159
|
+
await wa.startSessionWithPairingCode(
|
|
160
|
+
'session-2',
|
|
161
|
+
{ phoneNumber: '491234567890' }
|
|
162
|
+
)
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Load saved sessions from disk
|
|
166
|
+
|
|
167
|
+
```js
|
|
168
|
+
const loaded = await wa.loadSessionsFromStorage()
|
|
169
|
+
console.log(loaded)
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Remove a session
|
|
173
|
+
|
|
174
|
+
```js
|
|
175
|
+
await wa.deleteSession('session-1')
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Get running sessions
|
|
179
|
+
|
|
180
|
+
```js
|
|
181
|
+
const one = wa.getSession('session-2')
|
|
182
|
+
const allIds = wa.getAllSession()
|
|
183
|
+
const allMap = wa.getAllSessionData()
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## Message sending
|
|
187
|
+
|
|
188
|
+
`sendMessage(...)` delegates to the Baileys socket of the chosen session.
|
|
189
|
+
|
|
190
|
+
### Send text
|
|
191
|
+
|
|
192
|
+
```js
|
|
193
|
+
await wa.sendMessage('demo-session', '491234567890@s.whatsapp.net', {
|
|
194
|
+
text: 'hello'
|
|
195
|
+
})
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Send image
|
|
199
|
+
|
|
200
|
+
```js
|
|
201
|
+
await wa.sendMessage('demo-session', '491234567890@s.whatsapp.net', {
|
|
202
|
+
image: { url: './image.jpg' },
|
|
203
|
+
caption: 'sample'
|
|
204
|
+
})
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### Send document
|
|
78
208
|
|
|
79
|
-
|
|
80
|
-
|
|
209
|
+
```js
|
|
210
|
+
await wa.sendMessage('demo-session', '491234567890@s.whatsapp.net', {
|
|
211
|
+
document: { url: './report.pdf' },
|
|
212
|
+
mimetype: 'application/pdf',
|
|
213
|
+
fileName: 'report.pdf'
|
|
214
|
+
})
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### React to a message
|
|
218
|
+
|
|
219
|
+
```js
|
|
220
|
+
await wa.sendMessage('demo-session', '491234567890@s.whatsapp.net', {
|
|
221
|
+
react: {
|
|
222
|
+
text: '❤',
|
|
223
|
+
key: message.key
|
|
81
224
|
}
|
|
82
225
|
})
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Relay an already prepared message payload
|
|
83
229
|
|
|
84
|
-
|
|
230
|
+
```js
|
|
231
|
+
await wa.relayMessage('demo-session', jid, content, options)
|
|
85
232
|
```
|
|
86
233
|
|
|
87
|
-
|
|
234
|
+
### Send a status mention payload
|
|
88
235
|
|
|
89
|
-
|
|
236
|
+
```js
|
|
237
|
+
await wa.sendStatusMentions('demo-session', content, options)
|
|
238
|
+
```
|
|
90
239
|
|
|
91
|
-
|
|
240
|
+
## Event hooks
|
|
92
241
|
|
|
93
|
-
-
|
|
94
|
-
- `startSessionWithPairingCode(sessionId, { phoneNumber }, pairingCode?)`
|
|
95
|
-
- `deleteSession(sessionId)`
|
|
96
|
-
- `getSession(sessionId)`
|
|
97
|
-
- `getAllSession()`
|
|
98
|
-
- `loadSessionsFromStorage()`
|
|
242
|
+
The wrapper exposes high-level callbacks for the most common flows.
|
|
99
243
|
|
|
100
|
-
|
|
244
|
+
### Connection events
|
|
101
245
|
|
|
102
|
-
- `
|
|
103
|
-
- `
|
|
104
|
-
- `
|
|
246
|
+
- `onConnected`
|
|
247
|
+
- `onConnecting`
|
|
248
|
+
- `onDisconnected`
|
|
105
249
|
|
|
106
|
-
|
|
250
|
+
### QR and pairing
|
|
107
251
|
|
|
108
|
-
- `
|
|
109
|
-
- `
|
|
110
|
-
- `onQRUpdated(listener)`
|
|
111
|
-
- `onConnected(listener)`
|
|
112
|
-
- `onConnecting(listener)`
|
|
113
|
-
- `onDisconnected(listener)`
|
|
114
|
-
- `onPairingCode(listener)`
|
|
252
|
+
- `onQRUpdated`
|
|
253
|
+
- `onPairingCode`
|
|
115
254
|
|
|
116
|
-
|
|
255
|
+
### Message events
|
|
117
256
|
|
|
118
|
-
|
|
257
|
+
- `onMessageReceived`
|
|
258
|
+
- `onMessageUpdate`
|
|
119
259
|
|
|
120
|
-
|
|
121
|
-
- Credentials default path: `wa_credentials/<session>_credentials`
|
|
122
|
-
- Reconnect retries are handled internally
|
|
123
|
-
- Depends on `@neelegirl/baileys` runtime behavior, including custom Neelegirl compatibility logic
|
|
260
|
+
### Example
|
|
124
261
|
|
|
125
|
-
|
|
262
|
+
```js
|
|
263
|
+
wa.onQRUpdated(({ sessionId, qr }) => {
|
|
264
|
+
console.log('qr updated for', sessionId)
|
|
265
|
+
})
|
|
126
266
|
|
|
127
|
-
|
|
267
|
+
wa.onMessageUpdate((sessionId, data) => {
|
|
268
|
+
console.log(sessionId, data.messageStatus)
|
|
269
|
+
})
|
|
270
|
+
```
|
|
128
271
|
|
|
129
|
-
|
|
272
|
+
## Session storage
|
|
130
273
|
|
|
131
|
-
|
|
274
|
+
Default storage values:
|
|
132
275
|
|
|
133
|
-
|
|
276
|
+
| Setting | Default |
|
|
277
|
+
|---|---|
|
|
278
|
+
| credentials directory | `wa_credentials` |
|
|
279
|
+
| credentials suffix | `_credentials` |
|
|
134
280
|
|
|
135
|
-
|
|
281
|
+
You can customize both before starting sessions:
|
|
136
282
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
- Dependency/peer range updated to `@neelegirl/baileys ^2.1.4`
|
|
283
|
+
```js
|
|
284
|
+
const wa = require('@neelegirl/wa-api')
|
|
140
285
|
|
|
141
|
-
|
|
286
|
+
wa.setCredentialsDir('./sessions')
|
|
287
|
+
wa.setCredentials('_auth')
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
## Working with the underlying socket
|
|
291
|
+
|
|
292
|
+
When you need lower-level access, fetch the real Baileys socket:
|
|
293
|
+
|
|
294
|
+
```js
|
|
295
|
+
const wa = require('@neelegirl/wa-api')
|
|
296
|
+
|
|
297
|
+
async function main() {
|
|
298
|
+
await wa.startSession('demo-session', { printQR: true })
|
|
299
|
+
|
|
300
|
+
const sock = wa.getSession('demo-session')
|
|
301
|
+
if (sock) {
|
|
302
|
+
await sock.sendPresenceUpdate('unavailable')
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
main().catch(console.error)
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
This is the intended path for advanced features that are not directly re-wrapped by `wa-api`.
|
|
310
|
+
|
|
311
|
+
## Verified API surface
|
|
312
|
+
|
|
313
|
+
The following exports were verified in the currently prepared package:
|
|
314
|
+
|
|
315
|
+
### Session lifecycle
|
|
316
|
+
|
|
317
|
+
- `startSession`
|
|
318
|
+
- `startSessionWithPairingCode`
|
|
319
|
+
- `startWhatsapp`
|
|
320
|
+
- `deleteSession`
|
|
321
|
+
- `loadSessionsFromStorage`
|
|
322
|
+
|
|
323
|
+
### Session lookup
|
|
324
|
+
|
|
325
|
+
- `getSession`
|
|
326
|
+
- `getAllSession`
|
|
327
|
+
- `getAllSessionData`
|
|
328
|
+
|
|
329
|
+
### Event hooks
|
|
330
|
+
|
|
331
|
+
- `onMessageReceived`
|
|
332
|
+
- `onMessageUpdate`
|
|
333
|
+
- `onQRUpdated`
|
|
334
|
+
- `onConnected`
|
|
335
|
+
- `onConnecting`
|
|
336
|
+
- `onDisconnected`
|
|
337
|
+
- `onPairingCode`
|
|
338
|
+
|
|
339
|
+
### Messaging
|
|
340
|
+
|
|
341
|
+
- `sendMessage`
|
|
342
|
+
- `relayMessage`
|
|
343
|
+
- `sendStatusMentions`
|
|
344
|
+
|
|
345
|
+
### Utilities
|
|
346
|
+
|
|
347
|
+
- `phoneToJid`
|
|
348
|
+
- `isExist`
|
|
349
|
+
- `createDelay`
|
|
350
|
+
- `setCredentialsDir`
|
|
351
|
+
- `setCredentials`
|
|
352
|
+
|
|
353
|
+
## Recent maintenance notes
|
|
354
|
+
|
|
355
|
+
- the type surface now includes `ON_PAIRING_CODE` in `dist/Defaults/index.d.ts`
|
|
356
|
+
- `setCredentials` is now reflected in `dist/Utils/index.d.ts`
|
|
357
|
+
- the package depends on `@neelegirl/baileys@^2.1.6`
|
|
358
|
+
- the README image was updated to the requested wa-api image
|
|
359
|
+
|
|
360
|
+
## Release notes
|
|
361
|
+
|
|
362
|
+
### 1.6.6
|
|
363
|
+
|
|
364
|
+
- aligned dependency metadata with `@neelegirl/baileys@2.1.6`
|
|
365
|
+
- fixed missing public type exposure for `ON_PAIRING_CODE`
|
|
366
|
+
- fixed missing public type exposure for `setCredentials`
|
|
367
|
+
- expanded and corrected package documentation
|
|
368
|
+
|
|
369
|
+
### 1.6.5
|
|
370
|
+
|
|
371
|
+
- previous local wrapper baseline before the current maintenance pass
|
|
142
372
|
|
|
143
|
-
##
|
|
373
|
+
## Disclaimer
|
|
144
374
|
|
|
145
|
-
This project is not affiliated with WhatsApp. Use responsibly
|
|
375
|
+
This project is not affiliated with WhatsApp. Use it responsibly. Do not use it for spam, stalking, or abusive automation.
|