@neelegirl/wa-api 1.6.8 → 1.7.0

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 CHANGED
@@ -1,589 +1,121 @@
1
- <div align="center">
2
-
3
1
  # @neelegirl/wa-api
4
2
 
5
- ### Multi-session wrapper around `@neelegirl/baileys`
6
- ### QR login, pairing code login, session management, and event hooks
7
-
8
- [![npm version](https://img.shields.io/npm/v/@neelegirl/wa-api?style=for-the-badge&color=ff69b4&logo=npm)](https://www.npmjs.com/package/@neelegirl/wa-api)
9
- [![depends on](https://img.shields.io/badge/depends%20on-@neelegirl%2Fbaileys-9b59b6?style=for-the-badge)](https://www.npmjs.com/package/@neelegirl/baileys)
10
- [![node](https://img.shields.io/badge/node-%3E%3D20-2ea043?style=for-the-badge&logo=node.js)](https://nodejs.org)
11
- [![license](https://img.shields.io/badge/license-MIT-f97316?style=for-the-badge)](LICENSE)
12
-
13
- ---
14
-
15
- <p align="center">
16
- <img src="https://files.catbox.moe/6np1ii.JPG" width="760" alt="@neelegirl/wa-api" />
17
- </p>
3
+ ![Neelegirl wa-api](https://files.catbox.moe/6np1ii.JPG)
18
4
 
19
- | Package | Version | Role |
20
- |---|---:|---|
21
- | `@neelegirl/wa-api` | `1.6.8` | Convenience wrapper for session lifecycle and event-driven bot workflows |
5
+ Conservative multi-session WhatsApp wrapper around `@neelegirl/baileys`, kept compatible with the local Neelegirl runtime while cleaning obvious runtime and publish issues.
22
6
 
23
- [Installation](#installation) · [Quickstart](#quickstart) · [API surface](#verified-api-surface) · [Events](#event-hooks) · [Storage](#session-storage) · [Release notes](#release-notes)
7
+ ## Package Status
24
8
 
25
- </div>
9
+ - Current package version: `1.7.0`
10
+ - Intended companion package: `@neelegirl/baileys@^2.0.3`
11
+ - Runtime format: CommonJS
26
12
 
27
- ---
13
+ This package is a wrapper layer. It is not a replacement for Baileys itself.
28
14
 
29
- ## Table of Contents
15
+ ## What Was Cleaned Up
30
16
 
31
- - [Overview](#overview)
32
- - [What this package is](#what-this-package-is)
33
- - [What this package is not](#what-this-package-is-not)
34
- - [Installation](#installation)
35
- - [Quickstart](#quickstart)
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)
17
+ - Fixed broken helper paths in `dist/Socket/index.js`
18
+ - Fixed pairing callback registration
19
+ - Fixed `loadSessionsFromStorage()` so it can run without undefined globals
20
+ - Fixed `sendMessage()` and `relayMessage()` JID conversion paths
21
+ - Removed the direct import side effect in `dist/whatsapp/index.js`
22
+ - Aligned the `.d.ts` files with the exported runtime API
23
+ - Rewrote the README to match the code that is actually present
45
24
 
46
- ## Overview
25
+ ## Main API
47
26
 
48
- `@neelegirl/wa-api` is a small wrapper package built on top of `@neelegirl/baileys`. Its job is to simplify:
27
+ Session management:
49
28
 
50
- - starting sessions
51
- - reloading saved sessions
52
- - subscribing to high-level events
53
- - sending messages without wiring the socket boilerplate every time
29
+ - `startSession(sessionId, options?)`
30
+ - `startSessionWithPairingCode(sessionId, { phoneNumber }, customPairingCode?)`
31
+ - `deleteSession(sessionId)`
32
+ - `getAllSession()`
33
+ - `getSession(sessionId)`
34
+ - `getAllSessionData()`
35
+ - `loadSessionsFromStorage()`
54
36
 
55
- It keeps the actual WhatsApp protocol handling inside the underlying Baileys fork.
37
+ Event registration:
56
38
 
57
- ## What this package is
39
+ - `onMessageReceived(listener)`
40
+ - `onQRUpdated(listener)`
41
+ - `onConnected(listener)`
42
+ - `onDisconnected(listener)`
43
+ - `onConnecting(listener)`
44
+ - `onMessageUpdate(listener)`
45
+ - `onPairingCode(listener)`
58
46
 
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 |
47
+ Messaging helpers:
66
48
 
67
- ## What this package is not
49
+ - `sendMessage(sessionId, jidOrPhone, content, options?)`
50
+ - `relayMessage(sessionId, jidOrPhone, content, options?)`
51
+ - `sendStatusMentions(sessionId, content, targets?)`
68
52
 
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
53
+ Utilities:
73
54
 
74
- If you need deeper socket control, use `getSession(...)` and work directly with the returned Baileys socket.
55
+ - `phoneToJid({ to, isGroup? })`
56
+ - `setCredentialsDir(dirname)`
57
+ - `setCredentials(dirname)`
75
58
 
76
59
  ## Installation
77
60
 
78
- Use npm:
79
-
80
61
  ```bash
81
62
  npm install @neelegirl/wa-api
82
63
  ```
83
64
 
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
- ```
95
-
96
- ## Quickstart
97
-
98
- ### Start a session with QR
99
-
100
- ```js
101
- const wa = require('@neelegirl/wa-api')
102
-
103
- wa.onConnected((sessionId) => {
104
- console.log('connected:', sessionId)
105
- })
106
-
107
- wa.onMessageReceived(async (msg) => {
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
208
-
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
224
- }
225
- })
226
- ```
227
-
228
- ### Relay an already prepared message payload
229
-
230
- ```js
231
- await wa.relayMessage('demo-session', jid, content, options)
232
- ```
233
-
234
- ### Send a status mention payload
235
-
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
-
267
- wa.onMessageUpdate((sessionId, data) => {
268
- console.log(sessionId, data.messageStatus)
269
- })
270
- ```
271
-
272
- ## Session storage
273
-
274
- Default storage values:
275
-
276
- | Setting | Default |
277
- |---|---|
278
- | credentials directory | `wa_credentials` |
279
- | credentials suffix | `_credentials` |
280
-
281
- You can customize both before starting sessions:
282
-
283
- ```js
284
- const wa = require('@neelegirl/wa-api')
285
-
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:
65
+ ## Quick Start
293
66
 
294
67
  ```js
295
- const wa = require('@neelegirl/wa-api')
68
+ const onimai = require('@neelegirl/wa-api')
296
69
 
297
70
  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.8`
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:
71
+ await onimai.startSession('demo-session', { printQR: true })
371
72
 
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'
73
+ onimai.onConnected((sessionId) => {
74
+ console.log(`connected: ${sessionId}`)
426
75
  })
427
- }
428
76
 
429
- run().catch(console.error)
430
- ```
431
-
432
- ### Use `phoneToJid`
433
-
434
- ```js
435
- const wa = require('@neelegirl/wa-api')
77
+ onimai.onMessageReceived(async (msg) => {
78
+ const text =
79
+ msg.message?.conversation ||
80
+ msg.message?.extendedTextMessage?.text ||
81
+ ''
436
82
 
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'
83
+ if (text.toLowerCase() === 'ping') {
84
+ await onimai.sendMessage(msg.sessionId, msg.key.remoteJid, { text: 'pong' })
85
+ }
450
86
  })
451
-
452
- console.log(exists)
453
87
  }
454
88
 
455
- check().catch(console.error)
89
+ main().catch(console.error)
456
90
  ```
457
91
 
458
- ### Delay helper
92
+ ## Pairing Code Example
459
93
 
460
94
  ```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
95
+ const onimai = require('@neelegirl/wa-api')
517
96
 
518
- ```bash
519
- npm install @neelegirl/wa-api@latest
520
- ```
521
-
522
- or:
97
+ onimai.onPairingCode((sessionId, code) => {
98
+ console.log(`pairing code for ${sessionId}: ${code}`)
99
+ })
523
100
 
524
- ```bash
525
- yarn add @neelegirl/wa-api@latest
101
+ onimai.startSessionWithPairingCode(
102
+ 'pairing-session',
103
+ { phoneNumber: '491234567890' },
104
+ 'ONIMAIII'
105
+ ).catch(console.error)
526
106
  ```
527
107
 
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.8
565
-
566
- - patch release aligned to `@neelegirl/baileys@2.1.8`
567
- - documentation refreshed so the wrapper release line matches the currently published stack
568
- - no fake auto-update behavior added; runtime update hints remain informational only
569
-
570
- ### 1.6.7
571
-
572
- - documentation expansion release
573
- - realistic update behavior note added
574
- - dependency metadata aligned to `@neelegirl/baileys@2.1.7`
575
-
576
- ### 1.6.6
108
+ ## Notes
577
109
 
578
- - aligned dependency metadata with `@neelegirl/baileys@2.1.6`
579
- - fixed missing public type exposure for `ON_PAIRING_CODE`
580
- - fixed missing public type exposure for `setCredentials`
581
- - expanded and corrected package documentation
110
+ - This wrapper depends on the current local behavior of `@neelegirl/baileys`
111
+ - QR handling and reconnect behavior stay in the socket layer, not in the messaging helper
112
+ - `dist/whatsapp/index.js` is a legacy internal file and is not the primary public entrypoint
582
113
 
583
- ### 1.6.5
114
+ ## Requirements
584
115
 
585
- - previous local wrapper baseline before the current maintenance pass
116
+ - Node.js `>=16.0.0`
117
+ - `@neelegirl/baileys@^2.0.3`
586
118
 
587
- ## Disclaimer
119
+ ## License
588
120
 
589
- This project is not affiliated with WhatsApp. Use it responsibly. Do not use it for spam, stalking, or abusive automation.
121
+ ISC