@neelegirl/wa-api 1.6.5 → 1.6.7
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 +482 -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.7",
|
|
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.7",
|
|
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.7"
|
|
45
45
|
},
|
|
46
46
|
"engines": {
|
|
47
47
|
"node": ">=20.0.0"
|
package/readme.md
CHANGED
|
@@ -1,222 +1,583 @@
|
|
|
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.7` | 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.7`
|
|
358
|
+
- the README image was updated to the requested wa-api image
|
|
359
|
+
|
|
360
|
+
## Wrapper design notes
|
|
361
|
+
|
|
362
|
+
This package intentionally stays small.
|
|
363
|
+
|
|
364
|
+
### Why
|
|
365
|
+
|
|
366
|
+
The more logic gets duplicated here, the easier it becomes for the wrapper to drift away from the actual Baileys runtime below it.
|
|
367
|
+
|
|
368
|
+
### Design rule
|
|
369
|
+
|
|
370
|
+
`wa-api` should:
|
|
371
|
+
|
|
372
|
+
- make common session flows easier
|
|
373
|
+
- expose clear event hooks
|
|
374
|
+
- keep message sending simple
|
|
375
|
+
- hand you the real socket when you need deeper access
|
|
376
|
+
|
|
377
|
+
It should not:
|
|
378
|
+
|
|
379
|
+
- re-implement the entire Baileys protocol surface
|
|
380
|
+
- invent a second independent event system
|
|
381
|
+
- hide every low-level concern behind an artificial abstraction
|
|
382
|
+
|
|
383
|
+
## More practical examples
|
|
384
|
+
|
|
385
|
+
### Load stored sessions automatically on boot
|
|
386
|
+
|
|
387
|
+
```js
|
|
388
|
+
const wa = require('@neelegirl/wa-api')
|
|
389
|
+
|
|
390
|
+
async function boot() {
|
|
391
|
+
const loaded = await wa.loadSessionsFromStorage()
|
|
392
|
+
console.log('loaded sessions:', loaded)
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
boot().catch(console.error)
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
### Start multiple sessions
|
|
399
|
+
|
|
400
|
+
```js
|
|
401
|
+
const wa = require('@neelegirl/wa-api')
|
|
402
|
+
|
|
403
|
+
async function boot() {
|
|
404
|
+
await wa.startSession('alpha', { printQR: true })
|
|
405
|
+
await wa.startSession('beta', { printQR: true })
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
boot().catch(console.error)
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
### Send through a looked-up socket
|
|
412
|
+
|
|
413
|
+
```js
|
|
414
|
+
const wa = require('@neelegirl/wa-api')
|
|
415
|
+
|
|
416
|
+
async function run() {
|
|
417
|
+
await wa.startSession('demo', { printQR: true })
|
|
418
|
+
|
|
419
|
+
const sock = wa.getSession('demo')
|
|
420
|
+
if (!sock) {
|
|
421
|
+
throw new Error('socket missing')
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
await sock.sendMessage('491234567890@s.whatsapp.net', {
|
|
425
|
+
text: 'sent through direct socket access'
|
|
426
|
+
})
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
run().catch(console.error)
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
### Use `phoneToJid`
|
|
433
|
+
|
|
434
|
+
```js
|
|
435
|
+
const wa = require('@neelegirl/wa-api')
|
|
436
|
+
|
|
437
|
+
console.log(wa.phoneToJid({ to: '491234567890' }))
|
|
438
|
+
console.log(wa.phoneToJid({ to: '12036304321-1612471065@g.us', isGroup: true }))
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
### Check if a target exists
|
|
442
|
+
|
|
443
|
+
```js
|
|
444
|
+
const wa = require('@neelegirl/wa-api')
|
|
445
|
+
|
|
446
|
+
async function check() {
|
|
447
|
+
const exists = await wa.isExist({
|
|
448
|
+
sessionId: 'demo',
|
|
449
|
+
to: '491234567890'
|
|
450
|
+
})
|
|
451
|
+
|
|
452
|
+
console.log(exists)
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
check().catch(console.error)
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
### Delay helper
|
|
459
|
+
|
|
460
|
+
```js
|
|
461
|
+
const wa = require('@neelegirl/wa-api')
|
|
462
|
+
|
|
463
|
+
async function example() {
|
|
464
|
+
await wa.createDelay(1000)
|
|
465
|
+
console.log('one second later')
|
|
466
|
+
}
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
## Event behavior notes
|
|
470
|
+
|
|
471
|
+
### `onMessageReceived`
|
|
472
|
+
|
|
473
|
+
This is the most useful hook for bot logic.
|
|
474
|
+
|
|
475
|
+
The message object carries:
|
|
476
|
+
|
|
477
|
+
- session id
|
|
478
|
+
- original Baileys message structure
|
|
479
|
+
- convenience save helpers for image, video, and document
|
|
480
|
+
|
|
481
|
+
### `onMessageUpdate`
|
|
482
|
+
|
|
483
|
+
Use this when you want delivery-state style updates such as:
|
|
484
|
+
|
|
485
|
+
- pending
|
|
486
|
+
- server
|
|
487
|
+
- delivered
|
|
488
|
+
- read
|
|
489
|
+
- played
|
|
490
|
+
- error
|
|
491
|
+
|
|
492
|
+
### `onQRUpdated`
|
|
493
|
+
|
|
494
|
+
This is useful when you want to surface QR codes in:
|
|
495
|
+
|
|
496
|
+
- a terminal
|
|
497
|
+
- a panel
|
|
498
|
+
- a web page
|
|
499
|
+
- a bot-admin dashboard
|
|
500
|
+
|
|
501
|
+
### `onPairingCode`
|
|
502
|
+
|
|
503
|
+
Use this when a pairing-code flow is preferred over terminal QR scanning.
|
|
504
|
+
|
|
505
|
+
## Realistic update notice
|
|
506
|
+
|
|
507
|
+
This package already performs an npm registry update check once per process in its current runtime.
|
|
508
|
+
|
|
509
|
+
### What that means
|
|
510
|
+
|
|
511
|
+
- it can show a hint
|
|
512
|
+
- it does not self-update
|
|
513
|
+
- it does not rewrite your files
|
|
514
|
+
- it only tells you a newer package version exists
|
|
515
|
+
|
|
516
|
+
### How to actually update
|
|
517
|
+
|
|
518
|
+
```bash
|
|
519
|
+
npm install @neelegirl/wa-api@latest
|
|
520
|
+
```
|
|
521
|
+
|
|
522
|
+
or:
|
|
523
|
+
|
|
524
|
+
```bash
|
|
525
|
+
yarn add @neelegirl/wa-api@latest
|
|
526
|
+
```
|
|
527
|
+
|
|
528
|
+
### Why this is the realistic behavior
|
|
529
|
+
|
|
530
|
+
A wrapper package should not silently change itself inside a running project. A clear update notice is realistic; automatic mutation of dependencies is not.
|
|
531
|
+
|
|
532
|
+
## FAQ
|
|
533
|
+
|
|
534
|
+
### Can I use wa-api without knowing Baileys?
|
|
535
|
+
|
|
536
|
+
Yes, for common session and message flows. But for advanced control, understanding the underlying Baileys socket is still useful.
|
|
537
|
+
|
|
538
|
+
### Is wa-api a web server?
|
|
539
|
+
|
|
540
|
+
No.
|
|
541
|
+
|
|
542
|
+
### Does wa-api keep sessions between runs?
|
|
543
|
+
|
|
544
|
+
Yes, if you keep the credential directory and let it persist.
|
|
545
|
+
|
|
546
|
+
### Does wa-api expose the raw socket?
|
|
547
|
+
|
|
548
|
+
Yes, through `getSession(...)`.
|
|
549
|
+
|
|
550
|
+
### Does it auto-update itself?
|
|
551
|
+
|
|
552
|
+
No. It may show an update hint, but installation remains manual.
|
|
553
|
+
|
|
554
|
+
### Is pairing code supported?
|
|
555
|
+
|
|
556
|
+
Yes.
|
|
557
|
+
|
|
558
|
+
### Is QR supported?
|
|
559
|
+
|
|
560
|
+
Yes.
|
|
561
|
+
|
|
562
|
+
## Release notes
|
|
563
|
+
|
|
564
|
+
### 1.6.7
|
|
565
|
+
|
|
566
|
+
- documentation expansion release
|
|
567
|
+
- realistic update behavior note added
|
|
568
|
+
- dependency metadata aligned to `@neelegirl/baileys@2.1.7`
|
|
569
|
+
|
|
570
|
+
### 1.6.6
|
|
571
|
+
|
|
572
|
+
- aligned dependency metadata with `@neelegirl/baileys@2.1.6`
|
|
573
|
+
- fixed missing public type exposure for `ON_PAIRING_CODE`
|
|
574
|
+
- fixed missing public type exposure for `setCredentials`
|
|
575
|
+
- expanded and corrected package documentation
|
|
576
|
+
|
|
577
|
+
### 1.6.5
|
|
578
|
+
|
|
579
|
+
- previous local wrapper baseline before the current maintenance pass
|
|
219
580
|
|
|
220
|
-
##
|
|
581
|
+
## Disclaimer
|
|
221
582
|
|
|
222
|
-
|
|
583
|
+
This project is not affiliated with WhatsApp. Use it responsibly. Do not use it for spam, stalking, or abusive automation.
|