@neelegirl/wa-api 1.6.9 → 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,611 +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>
18
-
19
- | Package | Version | Role |
20
- |---|---:|---|
21
- | `@neelegirl/wa-api` | `1.6.9` | Convenience wrapper for session lifecycle and event-driven bot workflows |
22
-
23
- [Installation](#installation) · [Quickstart](#quickstart) · [API surface](#verified-api-surface) · [Events](#event-hooks) · [Storage](#session-storage) · [Release notes](#release-notes)
24
-
25
- </div>
26
-
27
- ---
3
+ ![Neelegirl wa-api](https://files.catbox.moe/6np1ii.JPG)
28
4
 
29
- ## Table of Contents
5
+ Conservative multi-session WhatsApp wrapper around `@neelegirl/baileys`, kept compatible with the local Neelegirl runtime while cleaning obvious runtime and publish issues.
30
6
 
31
- - [Overview](#overview)
32
- - [Stack relationship](#stack-relationship)
33
- - [What this package is](#what-this-package-is)
34
- - [What this package is not](#what-this-package-is-not)
35
- - [Installation](#installation)
36
- - [Quickstart](#quickstart)
37
- - [Session lifecycle](#session-lifecycle)
38
- - [Message sending](#message-sending)
39
- - [Event hooks](#event-hooks)
40
- - [Session storage](#session-storage)
41
- - [Working with the underlying socket](#working-with-the-underlying-socket)
42
- - [Verified API surface](#verified-api-surface)
43
- - [Recent maintenance notes](#recent-maintenance-notes)
44
- - [Release notes](#release-notes)
45
- - [Disclaimer](#disclaimer)
7
+ ## Package Status
46
8
 
47
- ## Overview
9
+ - Current package version: `1.7.0`
10
+ - Intended companion package: `@neelegirl/baileys@^2.0.3`
11
+ - Runtime format: CommonJS
48
12
 
49
- `@neelegirl/wa-api` is a small wrapper package built on top of `@neelegirl/baileys`. Its job is to simplify:
13
+ This package is a wrapper layer. It is not a replacement for Baileys itself.
50
14
 
51
- - starting sessions
52
- - reloading saved sessions
53
- - subscribing to high-level events
54
- - sending messages without wiring the socket boilerplate every time
15
+ ## What Was Cleaned Up
55
16
 
56
- It keeps the actual WhatsApp protocol handling inside the underlying Baileys fork.
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
57
24
 
58
- ## Stack relationship
25
+ ## Main API
59
26
 
60
- `@neelegirl/wa-api` is intentionally the thin layer at the top of the local stack:
27
+ Session management:
61
28
 
62
- | Package | Layer | Responsibility |
63
- |---|---|---|
64
- | `@neelegirl/libsignal` | crypto/session layer | session cipher state, identity keys, protocol primitives |
65
- | `@neelegirl/baileys` | WhatsApp Web runtime | socket, QR/pairing flow, device handling, events, media and message transport |
66
- | `@neelegirl/wa-api` | wrapper layer | multi-session lifecycle, convenience events, simplified send helpers |
29
+ - `startSession(sessionId, options?)`
30
+ - `startSessionWithPairingCode(sessionId, { phoneNumber }, customPairingCode?)`
31
+ - `deleteSession(sessionId)`
32
+ - `getAllSession()`
33
+ - `getSession(sessionId)`
34
+ - `getAllSessionData()`
35
+ - `loadSessionsFromStorage()`
67
36
 
68
- The wrapper should stay small on purpose: it makes common flows easier without pretending to be a separate protocol implementation.
37
+ Event registration:
69
38
 
70
- ## 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)`
71
46
 
72
- | Area | Purpose |
73
- |---|---|
74
- | session start helpers | launch QR or pairing-code sessions |
75
- | session lookup helpers | retrieve running sockets by session id |
76
- | event hooks | react to connection, QR, pairing, and message events |
77
- | message helpers | forward content into the underlying Baileys socket |
78
- | storage helpers | customize the credential folder name and suffix |
47
+ Messaging helpers:
79
48
 
80
- ## What this package is not
49
+ - `sendMessage(sessionId, jidOrPhone, content, options?)`
50
+ - `relayMessage(sessionId, jidOrPhone, content, options?)`
51
+ - `sendStatusMentions(sessionId, content, targets?)`
81
52
 
82
- - not a standalone REST API server
83
- - not a replacement for the full Baileys API surface
84
- - not a different transport layer
85
- - not a separate WhatsApp protocol implementation
53
+ Utilities:
86
54
 
87
- 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)`
88
58
 
89
59
  ## Installation
90
60
 
91
- Use npm:
92
-
93
61
  ```bash
94
62
  npm install @neelegirl/wa-api
95
63
  ```
96
64
 
97
- Use yarn:
98
-
99
- ```bash
100
- yarn add @neelegirl/wa-api
101
- ```
102
-
103
- Runtime requirement:
104
-
105
- ```text
106
- Node.js >= 20
107
- ```
108
-
109
- ## Quickstart
110
-
111
- ### Start a session with QR
112
-
113
- ```js
114
- const wa = require('@neelegirl/wa-api')
115
-
116
- wa.onConnected((sessionId) => {
117
- console.log('connected:', sessionId)
118
- })
119
-
120
- wa.onMessageReceived(async (msg) => {
121
- const text =
122
- msg.message?.conversation ||
123
- msg.message?.extendedTextMessage?.text ||
124
- ''
125
-
126
- if (text.toLowerCase() === 'ping') {
127
- await wa.sendMessage(msg.sessionId, msg.key.remoteJid, {
128
- text: 'pong'
129
- })
130
- }
131
- })
132
-
133
- async function main() {
134
- await wa.startSession('demo-session', { printQR: true })
135
- }
136
-
137
- main().catch(console.error)
138
- ```
139
-
140
- ### Start a session with pairing code
141
-
142
- ```js
143
- const wa = require('@neelegirl/wa-api')
144
-
145
- wa.onPairingCode((sessionId, code) => {
146
- console.log('pairing code for', sessionId, ':', code)
147
- })
148
-
149
- async function main() {
150
- await wa.startSessionWithPairingCode(
151
- 'pairing-session',
152
- { phoneNumber: '491234567890' }
153
- )
154
- }
155
-
156
- main().catch(console.error)
157
- ```
158
-
159
- `startSessionWithPairingCode(...)` also accepts a third argument for a custom pairing-code string when your workflow needs one.
160
-
161
- ## Session lifecycle
162
-
163
- ### Start a normal session
164
-
165
- ```js
166
- await wa.startSession('session-1', { printQR: true })
167
- ```
168
-
169
- ### Start with pairing code
170
-
171
- ```js
172
- await wa.startSessionWithPairingCode(
173
- 'session-2',
174
- { phoneNumber: '491234567890' }
175
- )
176
- ```
177
-
178
- ### Load saved sessions from disk
179
-
180
- ```js
181
- const loaded = await wa.loadSessionsFromStorage()
182
- console.log(loaded)
183
- ```
184
-
185
- ### Remove a session
186
-
187
- ```js
188
- await wa.deleteSession('session-1')
189
- ```
190
-
191
- ### Get running sessions
192
-
193
- ```js
194
- const one = wa.getSession('session-2')
195
- const allIds = wa.getAllSession()
196
- const allMap = wa.getAllSessionData()
197
- ```
198
-
199
- ## Message sending
200
-
201
- `sendMessage(...)` delegates to the Baileys socket of the chosen session.
202
-
203
- ### Send text
204
-
205
- ```js
206
- await wa.sendMessage('demo-session', '491234567890@s.whatsapp.net', {
207
- text: 'hello'
208
- })
209
- ```
210
-
211
- ### Send image
212
-
213
- ```js
214
- await wa.sendMessage('demo-session', '491234567890@s.whatsapp.net', {
215
- image: { url: './image.jpg' },
216
- caption: 'sample'
217
- })
218
- ```
219
-
220
- ### Send document
221
-
222
- ```js
223
- await wa.sendMessage('demo-session', '491234567890@s.whatsapp.net', {
224
- document: { url: './report.pdf' },
225
- mimetype: 'application/pdf',
226
- fileName: 'report.pdf'
227
- })
228
- ```
229
-
230
- ### React to a message
231
-
232
- ```js
233
- await wa.sendMessage('demo-session', '491234567890@s.whatsapp.net', {
234
- react: {
235
- text: '❤',
236
- key: message.key
237
- }
238
- })
239
- ```
240
-
241
- ### Relay an already prepared message payload
242
-
243
- ```js
244
- await wa.relayMessage('demo-session', jid, content, options)
245
- ```
246
-
247
- ### Send a status mention payload
248
-
249
- ```js
250
- await wa.sendStatusMentions('demo-session', content, options)
251
- ```
252
-
253
- ## Event hooks
254
-
255
- The wrapper exposes high-level callbacks for the most common flows.
256
-
257
- ### Connection events
258
-
259
- - `onConnected`
260
- - `onConnecting`
261
- - `onDisconnected`
262
-
263
- ### QR and pairing
264
-
265
- - `onQRUpdated`
266
- - `onPairingCode`
267
-
268
- ### Message events
269
-
270
- - `onMessageReceived`
271
- - `onMessageUpdate`
272
-
273
- ### Example
274
-
275
- ```js
276
- wa.onQRUpdated(({ sessionId, qr }) => {
277
- console.log('qr updated for', sessionId)
278
- })
279
-
280
- wa.onMessageUpdate((sessionId, data) => {
281
- console.log(sessionId, data.messageStatus)
282
- })
283
- ```
284
-
285
- ## Session storage
286
-
287
- Default storage values:
288
-
289
- | Setting | Default |
290
- |---|---|
291
- | credentials directory | `wa_credentials` |
292
- | credentials suffix | `_credentials` |
293
-
294
- You can customize both before starting sessions:
295
-
296
- ```js
297
- const wa = require('@neelegirl/wa-api')
298
-
299
- wa.setCredentialsDir('./sessions')
300
- wa.setCredentials('_auth')
301
- ```
302
-
303
- ## Working with the underlying socket
304
-
305
- When you need lower-level access, fetch the real Baileys socket:
65
+ ## Quick Start
306
66
 
307
67
  ```js
308
- const wa = require('@neelegirl/wa-api')
68
+ const onimai = require('@neelegirl/wa-api')
309
69
 
310
70
  async function main() {
311
- await wa.startSession('demo-session', { printQR: true })
312
-
313
- const sock = wa.getSession('demo-session')
314
- if (sock) {
315
- await sock.sendPresenceUpdate('unavailable')
316
- }
317
- }
318
-
319
- main().catch(console.error)
320
- ```
321
-
322
- This is the intended path for advanced features that are not directly re-wrapped by `wa-api`.
323
-
324
- ## Verified API surface
325
-
326
- The following exports were verified in the currently prepared package:
327
-
328
- ### Session lifecycle
329
-
330
- - `startSession`
331
- - `startSessionWithPairingCode`
332
- - `startWhatsapp`
333
- - `deleteSession`
334
- - `loadSessionsFromStorage`
335
-
336
- ### Session lookup
337
-
338
- - `getSession`
339
- - `getAllSession`
340
- - `getAllSessionData`
341
-
342
- ### Event hooks
343
-
344
- - `onMessageReceived`
345
- - `onMessageUpdate`
346
- - `onQRUpdated`
347
- - `onConnected`
348
- - `onConnecting`
349
- - `onDisconnected`
350
- - `onPairingCode`
351
-
352
- ### Messaging
353
-
354
- - `sendMessage`
355
- - `relayMessage`
356
- - `sendStatusMentions`
357
-
358
- ### Utilities
359
-
360
- - `phoneToJid`
361
- - `isExist`
362
- - `createDelay`
363
- - `setCredentialsDir`
364
- - `setCredentials`
365
-
366
- ## Recent maintenance notes
367
-
368
- - the README was rechecked on `2026-03-20` against the local source wrapper and the target runtime package
369
- - descriptions were kept aligned with the actual wrapper role instead of repeating full Baileys runtime claims
370
- - the type surface now includes `ON_PAIRING_CODE` in `dist/Defaults/index.d.ts`
371
- - `setCredentials` is now reflected in `dist/Utils/index.d.ts`
372
- - the package now tracks `@neelegirl/baileys@^2.1.9`
373
- - the README was kept aligned with the actual wrapper surface instead of promising Baileys internals that belong only to the lower runtime package
374
- - the README image was updated to the requested wa-api image
375
-
376
- ## Wrapper design notes
377
-
378
- This package intentionally stays small.
379
-
380
- ### Why
381
-
382
- The more logic gets duplicated here, the easier it becomes for the wrapper to drift away from the actual Baileys runtime below it.
383
-
384
- ### Design rule
385
-
386
- `wa-api` should:
71
+ await onimai.startSession('demo-session', { printQR: true })
387
72
 
388
- - make common session flows easier
389
- - expose clear event hooks
390
- - keep message sending simple
391
- - hand you the real socket when you need deeper access
392
-
393
- It should not:
394
-
395
- - re-implement the entire Baileys protocol surface
396
- - invent a second independent event system
397
- - hide every low-level concern behind an artificial abstraction
398
-
399
- ## More practical examples
400
-
401
- ### Load stored sessions automatically on boot
402
-
403
- ```js
404
- const wa = require('@neelegirl/wa-api')
405
-
406
- async function boot() {
407
- const loaded = await wa.loadSessionsFromStorage()
408
- console.log('loaded sessions:', loaded)
409
- }
410
-
411
- boot().catch(console.error)
412
- ```
413
-
414
- ### Start multiple sessions
415
-
416
- ```js
417
- const wa = require('@neelegirl/wa-api')
418
-
419
- async function boot() {
420
- await wa.startSession('alpha', { printQR: true })
421
- await wa.startSession('beta', { printQR: true })
422
- }
423
-
424
- boot().catch(console.error)
425
- ```
426
-
427
- ### Send through a looked-up socket
428
-
429
- ```js
430
- const wa = require('@neelegirl/wa-api')
431
-
432
- async function run() {
433
- await wa.startSession('demo', { printQR: true })
434
-
435
- const sock = wa.getSession('demo')
436
- if (!sock) {
437
- throw new Error('socket missing')
438
- }
439
-
440
- await sock.sendMessage('491234567890@s.whatsapp.net', {
441
- text: 'sent through direct socket access'
73
+ onimai.onConnected((sessionId) => {
74
+ console.log(`connected: ${sessionId}`)
442
75
  })
443
- }
444
-
445
- run().catch(console.error)
446
- ```
447
-
448
- ### Use `phoneToJid`
449
-
450
- ```js
451
- const wa = require('@neelegirl/wa-api')
452
-
453
- console.log(wa.phoneToJid({ to: '491234567890' }))
454
- console.log(wa.phoneToJid({ to: '12036304321-1612471065@g.us', isGroup: true }))
455
- ```
456
-
457
- ### Check if a target exists
458
76
 
459
- ```js
460
- const wa = require('@neelegirl/wa-api')
77
+ onimai.onMessageReceived(async (msg) => {
78
+ const text =
79
+ msg.message?.conversation ||
80
+ msg.message?.extendedTextMessage?.text ||
81
+ ''
461
82
 
462
- async function check() {
463
- const exists = await wa.isExist({
464
- sessionId: 'demo',
465
- to: '491234567890'
83
+ if (text.toLowerCase() === 'ping') {
84
+ await onimai.sendMessage(msg.sessionId, msg.key.remoteJid, { text: 'pong' })
85
+ }
466
86
  })
467
-
468
- console.log(exists)
469
87
  }
470
88
 
471
- check().catch(console.error)
89
+ main().catch(console.error)
472
90
  ```
473
91
 
474
- ### Delay helper
92
+ ## Pairing Code Example
475
93
 
476
94
  ```js
477
- const wa = require('@neelegirl/wa-api')
478
-
479
- async function example() {
480
- await wa.createDelay(1000)
481
- console.log('one second later')
482
- }
483
- ```
484
-
485
- ## Event behavior notes
486
-
487
- ### `onMessageReceived`
488
-
489
- This is the most useful hook for bot logic.
490
-
491
- The message object carries:
492
-
493
- - session id
494
- - original Baileys message structure
495
- - convenience save helpers for image, video, and document
95
+ const onimai = require('@neelegirl/wa-api')
496
96
 
497
- ### `onMessageUpdate`
498
-
499
- Use this when you want delivery-state style updates such as:
500
-
501
- - pending
502
- - server
503
- - delivered
504
- - read
505
- - played
506
- - error
507
-
508
- ### `onQRUpdated`
509
-
510
- This is useful when you want to surface QR codes in:
511
-
512
- - a terminal
513
- - a panel
514
- - a web page
515
- - a bot-admin dashboard
516
-
517
- ### `onPairingCode`
518
-
519
- Use this when a pairing-code flow is preferred over terminal QR scanning.
520
-
521
- ## Realistic update notice
522
-
523
- This package already performs an npm registry update check once per process in its current runtime.
524
-
525
- ### What that means
526
-
527
- - it can show a hint
528
- - it does not self-update
529
- - it does not rewrite your files
530
- - it only tells you a newer package version exists
531
-
532
- ### How to actually update
533
-
534
- ```bash
535
- npm install @neelegirl/wa-api@latest
536
- ```
537
-
538
- or:
97
+ onimai.onPairingCode((sessionId, code) => {
98
+ console.log(`pairing code for ${sessionId}: ${code}`)
99
+ })
539
100
 
540
- ```bash
541
- yarn add @neelegirl/wa-api@latest
101
+ onimai.startSessionWithPairingCode(
102
+ 'pairing-session',
103
+ { phoneNumber: '491234567890' },
104
+ 'ONIMAIII'
105
+ ).catch(console.error)
542
106
  ```
543
107
 
544
- ### Why this is the realistic behavior
545
-
546
- A wrapper package should not silently change itself inside a running project. A clear update notice is realistic; automatic mutation of dependencies is not.
547
-
548
- ## FAQ
549
-
550
- ### Can I use wa-api without knowing Baileys?
551
-
552
- Yes, for common session and message flows. But for advanced control, understanding the underlying Baileys socket is still useful.
553
-
554
- ### Is wa-api a web server?
555
-
556
- No.
557
-
558
- ### Does wa-api keep sessions between runs?
559
-
560
- Yes, if you keep the credential directory and let it persist.
561
-
562
- ### Does wa-api expose the raw socket?
563
-
564
- Yes, through `getSession(...)`.
565
-
566
- ### Does it auto-update itself?
567
-
568
- No. It may show an update hint, but installation remains manual.
569
-
570
- ### Is pairing code supported?
571
-
572
- Yes.
573
-
574
- ### Is QR supported?
575
-
576
- Yes.
577
-
578
- ## Release notes
579
-
580
- ### 1.6.9
581
-
582
- - dependency metadata aligned to `@neelegirl/baileys@2.1.9`
583
- - documentation refreshed after the hosted LID/session migration stabilization in the underlying runtime
584
- - public wrapper guidance rechecked against the current `dist` surface on `2026-03-20`
585
-
586
- ### 1.6.8
587
-
588
- - patch release aligned to `@neelegirl/baileys@2.1.8`
589
- - documentation refreshed so the wrapper release line matches the currently published stack
590
- - no fake auto-update behavior added; runtime update hints remain informational only
591
-
592
- ### 1.6.7
593
-
594
- - documentation expansion release
595
- - realistic update behavior note added
596
- - dependency metadata aligned to `@neelegirl/baileys@2.1.7`
597
-
598
- ### 1.6.6
108
+ ## Notes
599
109
 
600
- - aligned dependency metadata with `@neelegirl/baileys@2.1.6`
601
- - fixed missing public type exposure for `ON_PAIRING_CODE`
602
- - fixed missing public type exposure for `setCredentials`
603
- - 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
604
113
 
605
- ### 1.6.5
114
+ ## Requirements
606
115
 
607
- - previous local wrapper baseline before the current maintenance pass
116
+ - Node.js `>=16.0.0`
117
+ - `@neelegirl/baileys@^2.0.3`
608
118
 
609
- ## Disclaimer
119
+ ## License
610
120
 
611
- This project is not affiliated with WhatsApp. Use it responsibly. Do not use it for spam, stalking, or abusive automation.
121
+ ISC