@neelegirl/wa-api 1.6.5 → 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/Utils/index.d.ts +2 -1
- package/package.json +4 -4
- package/readme.md +274 -121
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/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,7 +41,7 @@
|
|
|
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"
|
package/readme.md
CHANGED
|
@@ -1,222 +1,375 @@
|
|
|
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
|
-
|
|
|
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) · [
|
|
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
|
|
|
24
27
|
---
|
|
25
28
|
|
|
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
|
-
- [Session
|
|
32
|
-
- [
|
|
33
|
-
- [Event
|
|
34
|
-
- [
|
|
35
|
-
- [
|
|
36
|
-
- [
|
|
37
|
-
- [
|
|
38
|
-
- [
|
|
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)
|
|
39
45
|
|
|
40
|
-
|
|
46
|
+
## Overview
|
|
41
47
|
|
|
42
|
-
|
|
48
|
+
`@neelegirl/wa-api` is a small wrapper package built on top of `@neelegirl/baileys`. Its job is to simplify:
|
|
43
49
|
|
|
44
|
-
|
|
50
|
+
- starting sessions
|
|
51
|
+
- reloading saved sessions
|
|
52
|
+
- subscribing to high-level events
|
|
53
|
+
- sending messages without wiring the socket boilerplate every time
|
|
45
54
|
|
|
46
|
-
|
|
55
|
+
It keeps the actual WhatsApp protocol handling inside the underlying Baileys fork.
|
|
47
56
|
|
|
48
|
-
|
|
49
|
-
- Session-Laden aus Storage
|
|
50
|
-
- Event-Hooks fuer Message/Connection/QR/Pairing
|
|
51
|
-
- Helper fuer `sendMessage`, `sendStatusMentions`, `relayMessage`
|
|
52
|
-
- technische Hinweise zu Reconnect, Credentials-Pfad und Update-Check
|
|
57
|
+
## What this package is
|
|
53
58
|
|
|
54
|
-
|
|
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.
|
|
55
75
|
|
|
56
76
|
## Installation
|
|
57
77
|
|
|
78
|
+
Use npm:
|
|
79
|
+
|
|
58
80
|
```bash
|
|
59
81
|
npm install @neelegirl/wa-api
|
|
60
82
|
```
|
|
61
83
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
```js
|
|
65
|
-
// CommonJS
|
|
66
|
-
const wa = require('@neelegirl/wa-api')
|
|
84
|
+
Use yarn:
|
|
67
85
|
|
|
68
|
-
|
|
69
|
-
|
|
86
|
+
```bash
|
|
87
|
+
yarn add @neelegirl/wa-api
|
|
70
88
|
```
|
|
71
89
|
|
|
72
|
-
|
|
90
|
+
Runtime requirement:
|
|
91
|
+
|
|
92
|
+
```text
|
|
93
|
+
Node.js >= 20
|
|
94
|
+
```
|
|
73
95
|
|
|
74
96
|
## Quickstart
|
|
75
97
|
|
|
98
|
+
### Start a session with QR
|
|
99
|
+
|
|
76
100
|
```js
|
|
77
101
|
const wa = require('@neelegirl/wa-api')
|
|
78
102
|
|
|
79
|
-
wa.onQRUpdated(({ sessionId, qr }) => {
|
|
80
|
-
console.log('QR for', sessionId)
|
|
81
|
-
console.log(qr)
|
|
82
|
-
})
|
|
83
|
-
|
|
84
103
|
wa.onConnected((sessionId) => {
|
|
85
|
-
console.log('
|
|
104
|
+
console.log('connected:', sessionId)
|
|
86
105
|
})
|
|
87
106
|
|
|
88
107
|
wa.onMessageReceived(async (msg) => {
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
+
})
|
|
94
117
|
}
|
|
95
118
|
})
|
|
96
119
|
|
|
97
|
-
|
|
120
|
+
async function main() {
|
|
121
|
+
await wa.startSession('demo-session', { printQR: true })
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
main().catch(console.error)
|
|
98
125
|
```
|
|
99
126
|
|
|
100
|
-
|
|
127
|
+
### Start a session with pairing code
|
|
128
|
+
|
|
129
|
+
```js
|
|
130
|
+
const wa = require('@neelegirl/wa-api')
|
|
101
131
|
|
|
102
|
-
|
|
132
|
+
wa.onPairingCode((sessionId, code) => {
|
|
133
|
+
console.log('pairing code for', sessionId, ':', code)
|
|
134
|
+
})
|
|
103
135
|
|
|
104
|
-
|
|
136
|
+
async function main() {
|
|
137
|
+
await wa.startSessionWithPairingCode(
|
|
138
|
+
'pairing-session',
|
|
139
|
+
{ phoneNumber: '491234567890' }
|
|
140
|
+
)
|
|
141
|
+
}
|
|
105
142
|
|
|
106
|
-
|
|
107
|
-
|
|
143
|
+
main().catch(console.error)
|
|
144
|
+
```
|
|
108
145
|
|
|
109
|
-
|
|
146
|
+
`startSessionWithPairingCode(...)` also accepts a third argument for a custom pairing-code string when your workflow needs one.
|
|
110
147
|
|
|
111
|
-
|
|
112
|
-
- `getAllSession()`
|
|
113
|
-
- `deleteSession(sessionId)`
|
|
114
|
-
- `loadSessionsFromStorage()`
|
|
148
|
+
## Session lifecycle
|
|
115
149
|
|
|
116
|
-
###
|
|
150
|
+
### Start a normal session
|
|
117
151
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
152
|
+
```js
|
|
153
|
+
await wa.startSession('session-1', { printQR: true })
|
|
154
|
+
```
|
|
121
155
|
|
|
122
|
-
|
|
156
|
+
### Start with pairing code
|
|
123
157
|
|
|
124
|
-
|
|
158
|
+
```js
|
|
159
|
+
await wa.startSessionWithPairingCode(
|
|
160
|
+
'session-2',
|
|
161
|
+
{ phoneNumber: '491234567890' }
|
|
162
|
+
)
|
|
163
|
+
```
|
|
125
164
|
|
|
126
|
-
###
|
|
165
|
+
### Load saved sessions from disk
|
|
127
166
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
167
|
+
```js
|
|
168
|
+
const loaded = await wa.loadSessionsFromStorage()
|
|
169
|
+
console.log(loaded)
|
|
170
|
+
```
|
|
131
171
|
|
|
132
|
-
###
|
|
172
|
+
### Remove a session
|
|
133
173
|
|
|
134
174
|
```js
|
|
135
|
-
|
|
136
|
-
|
|
175
|
+
await wa.deleteSession('session-1')
|
|
176
|
+
```
|
|
137
177
|
|
|
138
|
-
|
|
139
|
-
|
|
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', {
|
|
140
202
|
image: { url: './image.jpg' },
|
|
141
|
-
caption: '
|
|
203
|
+
caption: 'sample'
|
|
142
204
|
})
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### Send document
|
|
143
208
|
|
|
144
|
-
|
|
145
|
-
await wa.sendMessage('
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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'
|
|
149
214
|
})
|
|
150
215
|
```
|
|
151
216
|
|
|
152
|
-
|
|
217
|
+
### React to a message
|
|
153
218
|
|
|
154
|
-
|
|
219
|
+
```js
|
|
220
|
+
await wa.sendMessage('demo-session', '491234567890@s.whatsapp.net', {
|
|
221
|
+
react: {
|
|
222
|
+
text: '❤',
|
|
223
|
+
key: message.key
|
|
224
|
+
}
|
|
225
|
+
})
|
|
226
|
+
```
|
|
155
227
|
|
|
156
|
-
|
|
228
|
+
### Relay an already prepared message payload
|
|
157
229
|
|
|
158
|
-
|
|
159
|
-
-
|
|
160
|
-
|
|
161
|
-
- `onConnected(listener)`
|
|
162
|
-
- `onConnecting(listener)`
|
|
163
|
-
- `onDisconnected(listener)`
|
|
164
|
-
- `onPairingCode(listener)`
|
|
230
|
+
```js
|
|
231
|
+
await wa.relayMessage('demo-session', jid, content, options)
|
|
232
|
+
```
|
|
165
233
|
|
|
166
|
-
|
|
234
|
+
### Send a status mention payload
|
|
167
235
|
|
|
168
236
|
```js
|
|
237
|
+
await wa.sendStatusMentions('demo-session', content, options)
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
## Event hooks
|
|
241
|
+
|
|
242
|
+
The wrapper exposes high-level callbacks for the most common flows.
|
|
243
|
+
|
|
244
|
+
### Connection events
|
|
245
|
+
|
|
246
|
+
- `onConnected`
|
|
247
|
+
- `onConnecting`
|
|
248
|
+
- `onDisconnected`
|
|
249
|
+
|
|
250
|
+
### QR and pairing
|
|
251
|
+
|
|
252
|
+
- `onQRUpdated`
|
|
253
|
+
- `onPairingCode`
|
|
254
|
+
|
|
255
|
+
### Message events
|
|
256
|
+
|
|
257
|
+
- `onMessageReceived`
|
|
258
|
+
- `onMessageUpdate`
|
|
259
|
+
|
|
260
|
+
### Example
|
|
261
|
+
|
|
262
|
+
```js
|
|
263
|
+
wa.onQRUpdated(({ sessionId, qr }) => {
|
|
264
|
+
console.log('qr updated for', sessionId)
|
|
265
|
+
})
|
|
266
|
+
|
|
169
267
|
wa.onMessageUpdate((sessionId, data) => {
|
|
170
|
-
console.log(
|
|
268
|
+
console.log(sessionId, data.messageStatus)
|
|
171
269
|
})
|
|
172
270
|
```
|
|
173
271
|
|
|
174
|
-
|
|
272
|
+
## Session storage
|
|
175
273
|
|
|
176
|
-
|
|
274
|
+
Default storage values:
|
|
177
275
|
|
|
178
|
-
|
|
276
|
+
| Setting | Default |
|
|
277
|
+
|---|---|
|
|
278
|
+
| credentials directory | `wa_credentials` |
|
|
279
|
+
| credentials suffix | `_credentials` |
|
|
179
280
|
|
|
180
|
-
|
|
281
|
+
You can customize both before starting sessions:
|
|
181
282
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
- technische Hinweise zu Stability/Update/Session-Speicherung
|
|
283
|
+
```js
|
|
284
|
+
const wa = require('@neelegirl/wa-api')
|
|
185
285
|
|
|
186
|
-
|
|
286
|
+
wa.setCredentialsDir('./sessions')
|
|
287
|
+
wa.setCredentials('_auth')
|
|
288
|
+
```
|
|
187
289
|
|
|
188
|
-
|
|
189
|
-
- Aussagen zu Features, die im lokalen Paket nicht eindeutig vorhanden sind
|
|
290
|
+
## Working with the underlying socket
|
|
190
291
|
|
|
191
|
-
|
|
292
|
+
When you need lower-level access, fetch the real Baileys socket:
|
|
192
293
|
|
|
193
|
-
|
|
294
|
+
```js
|
|
295
|
+
const wa = require('@neelegirl/wa-api')
|
|
194
296
|
|
|
195
|
-
|
|
297
|
+
async function main() {
|
|
298
|
+
await wa.startSession('demo-session', { printQR: true })
|
|
196
299
|
|
|
197
|
-
|
|
300
|
+
const sock = wa.getSession('demo-session')
|
|
301
|
+
if (sock) {
|
|
302
|
+
await sock.sendPresenceUpdate('unavailable')
|
|
303
|
+
}
|
|
304
|
+
}
|
|
198
305
|
|
|
199
|
-
|
|
306
|
+
main().catch(console.error)
|
|
307
|
+
```
|
|
200
308
|
|
|
201
|
-
|
|
309
|
+
This is the intended path for advanced features that are not directly re-wrapped by `wa-api`.
|
|
202
310
|
|
|
203
|
-
|
|
311
|
+
## Verified API surface
|
|
204
312
|
|
|
205
|
-
|
|
313
|
+
The following exports were verified in the currently prepared package:
|
|
206
314
|
|
|
207
|
-
###
|
|
315
|
+
### Session lifecycle
|
|
208
316
|
|
|
209
|
-
-
|
|
210
|
-
-
|
|
211
|
-
-
|
|
317
|
+
- `startSession`
|
|
318
|
+
- `startSessionWithPairingCode`
|
|
319
|
+
- `startWhatsapp`
|
|
320
|
+
- `deleteSession`
|
|
321
|
+
- `loadSessionsFromStorage`
|
|
212
322
|
|
|
213
|
-
###
|
|
323
|
+
### Session lookup
|
|
214
324
|
|
|
215
|
-
-
|
|
216
|
-
-
|
|
325
|
+
- `getSession`
|
|
326
|
+
- `getAllSession`
|
|
327
|
+
- `getAllSessionData`
|
|
217
328
|
|
|
218
|
-
|
|
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
|
|
219
372
|
|
|
220
|
-
##
|
|
373
|
+
## Disclaimer
|
|
221
374
|
|
|
222
|
-
|
|
375
|
+
This project is not affiliated with WhatsApp. Use it responsibly. Do not use it for spam, stalking, or abusive automation.
|