cli-whatsapp 0.1.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/COMMANDS.md ADDED
@@ -0,0 +1,297 @@
1
+ # WhatsApp CLI — Command Guide
2
+
3
+ A fast, terminal-first WhatsApp client with a WhatsApp-green interface. Read,
4
+ search, send, and receive messages without a browser. Reading is instant and
5
+ offline (served from a local cache); only login, sync, send, watch, download,
6
+ and group actions use the network.
7
+
8
+ > **Tip:** run `wa` with no arguments for the interactive app (banner, live
9
+ > chat, slash commands) — see [§10](#10-interactive-mode). Everything is also
10
+ > available as one-shot commands below.
11
+
12
+ ---
13
+
14
+ ## 1. Getting started
15
+
16
+ ### Requirements
17
+ - **Node.js ≥ 22.5** (tested on Node 25). No build step — TypeScript runs natively.
18
+
19
+ ### Install
20
+ ```bash
21
+ cd whatsapp-cli
22
+ npm install
23
+ npm link # optional: makes the `wa` command available everywhere
24
+ ```
25
+
26
+ ### How you run commands
27
+ | If you ran… | Use this form |
28
+ | --- | --- |
29
+ | `npm link` | `wa <command>` |
30
+ | nothing | `node bin/wa.js <command>` |
31
+
32
+ > The examples below use `wa`. If you didn't `npm link`, just replace `wa` with `node bin/wa.js`.
33
+
34
+ ### First-time login (one time)
35
+ ```bash
36
+ wa login # a QR code appears in your terminal
37
+ ```
38
+ On your phone: **WhatsApp → Settings → Linked Devices → Link a Device**, then scan the QR.
39
+ Your session is saved locally, so you won't scan again unless you log out.
40
+
41
+ ```bash
42
+ wa sync # pull your recent chats & messages into the local cache
43
+ wa chats # you're ready — list your conversations
44
+ ```
45
+
46
+ ---
47
+
48
+ ## 2. Account
49
+
50
+ | Command | What it does | Example |
51
+ | --- | --- | --- |
52
+ | `wa login` | Link with a short pairing code (prompts for your number) | `wa login` |
53
+ | `wa login --phone <number>` | Same, but skip the prompt | `wa login --phone 9371432334` |
54
+ | `wa login qr` | Link by scanning a QR code instead | `wa login qr` |
55
+ | `wa logout` | Unlink this device and wipe the local session | `wa logout` |
56
+ | `wa status` | Show login state and cache size (offline) | `wa status` |
57
+
58
+ **Default login (pairing code):** `wa login` asks for your WhatsApp number and
59
+ shows an 8-character code — no QR needed. A bare 10-digit number gets your
60
+ country code added automatically (`+91` by default), or type the full
61
+ international number. On your phone: **Linked Devices → Link a Device → "Link
62
+ with phone number instead"**, then enter the code.
63
+
64
+ **QR login:** prefer scanning? `wa login qr` shows a QR; scan it and the window
65
+ confirms and closes on its own. (Tip: shrink your terminal font — Cmd/Ctrl **−**
66
+ — to make the QR smaller; it stays scannable.)
67
+
68
+ If a code or QR expires before you link, you'll get a clear message telling you
69
+ to re-run the command for a fresh one.
70
+
71
+ ---
72
+
73
+ ## 3. Reading (instant, works offline)
74
+
75
+ | Command | What it does | Example |
76
+ | --- | --- | --- |
77
+ | `wa chats` | List conversations, most recent first | `wa chats` |
78
+ | `wa chats -a` | Include archived chats | `wa chats -a` |
79
+ | `wa chats -n <N>` | Limit how many chats are shown | `wa chats -n 20` |
80
+ | `wa recent` | Most recently active chats (ignores pins) | `wa recent -n 10` |
81
+ | `wa open <chat>` | Show latest messages in a chat | `wa open Alice` |
82
+ | `wa open <chat> -n <N>` | Show N messages | `wa open Alice -n 50` |
83
+ | `wa history <chat>` | Extended history (defaults to 200) | `wa history Alice` |
84
+ | `wa search <text>` | Search all cached messages | `wa search invoice` |
85
+ | `wa contacts` | List saved contacts | `wa contacts` |
86
+
87
+ > `<chat>` can be a **name** (fuzzy, e.g. `ali` → Alice), a **phone number**
88
+ > (`916302810814`), or a full **jid**. Message ids like `#123` shown in `open`
89
+ > are used by `reply` and `download`.
90
+
91
+ ---
92
+
93
+ ## 4. Sending
94
+
95
+ | Command | What it does | Example |
96
+ | --- | --- | --- |
97
+ | `wa send <chat> <message>` | Send a text message | `wa send Alice "on my way"` |
98
+ | `wa send <chat> [caption] --file <path>` | Send media (type auto-detected) | `wa send Alice "look" --file pic.jpg` |
99
+ | `wa reply <id> <message>` | Reply to a cached message, quoting it | `wa reply 123 "thanks!"` |
100
+
101
+ **Media types** (detected from the file extension):
102
+
103
+ | Extension | Sent as |
104
+ | --- | --- |
105
+ | `.jpg .jpeg .png .gif` | image (with optional caption) |
106
+ | `.mp4 .mov .webm` | video (with optional caption) |
107
+ | `.mp3 .ogg .m4a .opus .wav` | audio |
108
+ | `.webp` | sticker (image if a caption is given) |
109
+ | anything else (`.pdf`, `.zip`, …) | document |
110
+
111
+ ```bash
112
+ wa send Bob --file ~/Downloads/invoice.pdf # document, no caption
113
+ wa send Family "trip clip 🎥" --file clip.mp4 # video with caption
114
+ ```
115
+
116
+ ---
117
+
118
+ ## 5. Sync & live
119
+
120
+ | Command | What it does | Example |
121
+ | --- | --- | --- |
122
+ | `wa sync` | Pull recent chats & messages (~12s) | `wa sync` |
123
+ | `wa sync -s <seconds>` | Sync for longer (3–120s) | `wa sync -s 30` |
124
+ | `wa watch` | Stream incoming messages live (Ctrl+C to stop) | `wa watch` |
125
+
126
+ ---
127
+
128
+ ## 6. Media
129
+
130
+ | Command | What it does | Example |
131
+ | --- | --- | --- |
132
+ | `wa media` | List all cached media | `wa media` |
133
+ | `wa media <type>` | Filter: `photos`, `videos`, `audio`, `documents`, `stickers`, `all` | `wa media photos` |
134
+ | `wa media -n <N>` | Limit results | `wa media videos -n 10` |
135
+ | `wa download <id>` | Download & decrypt a media message by `#id` | `wa download 51` |
136
+ | `wa download <id> -o <file>` | Save to a specific path | `wa download 51 -o ~/Desktop/pic.jpg` |
137
+
138
+ > Downloads are saved under `media/` by default.
139
+
140
+ ---
141
+
142
+ ## 7. Organize (local)
143
+
144
+ These change how chats appear in **your** CLI listing (they don't sync back to WhatsApp).
145
+
146
+ | Command | What it does | Example |
147
+ | --- | --- | --- |
148
+ | `wa pin <chat>` | Pin a chat to the top | `wa pin Alice` |
149
+ | `wa unpin <chat>` | Unpin a chat | `wa unpin Alice` |
150
+ | `wa archive <chat>` | Hide a chat from `wa chats` | `wa archive Spam` |
151
+ | `wa unarchive <chat>` | Unhide a chat | `wa unarchive Spam` |
152
+
153
+ ---
154
+
155
+ ## 8. Groups
156
+
157
+ Manage the groups you're in. These need a connection and (for most actions)
158
+ admin rights in the group.
159
+
160
+ | Command | What it does | Example |
161
+ | --- | --- | --- |
162
+ | `wa group info <group>` | Show subject, members, admins, description | `wa group info Family` |
163
+ | `wa group invite <group>` | Get the group's invite link | `wa group invite Family` |
164
+ | `wa group rename <group> <subject>` | Change the group subject | `wa group rename Family "Family 2.0"` |
165
+ | `wa group add <group> <number…>` | Add participants | `wa group add Family 919999999999` |
166
+ | `wa group remove <group> <number…>` | Remove participants | `wa group remove Family 919999999999` |
167
+ | `wa group promote <group> <number…>` | Make participants admin | `wa group promote Family 919999999999` |
168
+ | `wa group demote <group> <number…>` | Remove admin | `wa group demote Family 919999999999` |
169
+ | `wa group leave <group>` | Leave the group | `wa group leave "Old Team"` |
170
+ | `wa group create <subject> <number…>` | Create a new group | `wa group create "Trip" 9199… 9198…` |
171
+
172
+ ---
173
+
174
+ ## 9. Export
175
+
176
+ | Command | What it does | Example |
177
+ | --- | --- | --- |
178
+ | `wa export <chat>` | Export a conversation to Markdown | `wa export Alice` |
179
+ | `wa export <chat> -f <fmt>` | Format: `md`, `txt`, or `json` | `wa export Alice -f json` |
180
+ | `wa export <chat> -n <N>` | Limit messages exported | `wa export Alice -n 500` |
181
+ | `wa export <chat> -o <file>` | Output file (`-` for stdout) | `wa export Alice -o chat.md` |
182
+
183
+ ---
184
+
185
+ ## 10. Utility
186
+
187
+ | Command | What it does | Example |
188
+ | --- | --- | --- |
189
+ | `wa config` | Show current configuration | `wa config` |
190
+ | `wa config set <key> <value>` | Edit a setting (`openLimit`, `time24h`, `notifications`, `ai.enabled`) | `wa config set notifications false` |
191
+ | `wa doctor` | Run self-diagnostics | `wa doctor` |
192
+ | `wa version` | Print the version | `wa version` |
193
+ | `wa --help` | Show all commands | `wa --help` |
194
+ | `wa <command> --help` | Help for one command | `wa send --help` |
195
+
196
+ ---
197
+
198
+ ## 11. Interactive mode (the app)
199
+
200
+ Run `wa` with **no arguments** (or `wa shell` / `wa chat`) to launch the
201
+ interactive app — a WhatsApp-green banner, a persistent prompt, tab-completion,
202
+ and a real chat experience.
203
+
204
+ ```
205
+ ✆ WhatsApp CLI interactive
206
+ ● linked 973 chats · 11948 messages
207
+
208
+ ● Alice › hi, running 5 min late ← just type to send (chat is open)
209
+ 20:41 Alice: no worries! ← incoming messages stream in live
210
+ 🔔 Bob: are we still on? ← notifications from other chats
211
+ ```
212
+
213
+ **How it works**
214
+ - `/open <chat>` focuses a chat — the prompt shows its name and **plain text you
215
+ type is sent to it** (no command needed). `/close` leaves the chat.
216
+ - **Attach a file with `@`:** with a chat open, press `@` to open an interactive
217
+ file picker — **↑/↓** to move, **type** to filter, **Enter** to pick a file
218
+ (or open a folder), **Backspace** to go up, **Esc** to cancel. The chosen file
219
+ is inserted as `@path`; send it and the rest of your line becomes the caption
220
+ (e.g. `look at this @photo.jpg`). Just like Claude Code's `@`.
221
+ - **Live by default:** on launch the app goes **live** automatically (if linked)
222
+ — one persistent connection so sends are instant and incoming messages appear
223
+ in real time (with desktop notifications). The prompt dot shows status:
224
+ `○` offline · `◐` connecting · `●` live. Turn off auto-connect with
225
+ `/set autoConnect false`; use `/connect` to go live manually and `/disconnect`
226
+ to go offline (your cached chats stay readable either way).
227
+ - **Slash menu:** type `/` at the start of a line to open a command menu —
228
+ **↑/↓** to move, **type** to filter, **Enter** to pick, **Esc** to cancel.
229
+ - **Tab** also completes chat names. **↑/↓** recalls history. **Ctrl+C** clears
230
+ the line (again to exit).
231
+
232
+ | Slash command | Same as |
233
+ | --- | --- |
234
+ | *(type text with a chat open)* | send to the current chat |
235
+ | `@` *(with a chat open)* | open the file picker to attach (↑↓/type/Enter) |
236
+ | `/open <chat>` · `/close` | focus / leave a chat |
237
+ | `/connect` · `/disconnect` | go live (receive) / drop the connection |
238
+ | `/chats [n]` · `/recent [n]` · `/contacts` | list chats / recent / contacts |
239
+ | `/history [n]` · `/search <text>` | more history / search |
240
+ | `/send <chat> <msg>` · `/sendfile <chat> <path> [caption]` | send text / media |
241
+ | `/reply <id> <msg>` · `/media [type]` | reply / list media |
242
+ | `/pin` · `/unpin` · `/archive` · `/unarchive` `<chat>` | organize |
243
+ | `/status` · `/settings` · `/set <key> <value>` | status / settings |
244
+ | `/clear` · `/help` · `/quit` | clear screen / help / exit |
245
+
246
+ > Group management (`wa group …`) is a one-shot command, not a slash command,
247
+ > so it never opens a second connection alongside a live interactive session.
248
+
249
+ ---
250
+
251
+ ## 12. Notifications & theme
252
+
253
+ - **Desktop notifications** pop for incoming messages during `wa watch` and while
254
+ the interactive app is **live**. On by default; toggle with
255
+ `wa config set notifications false` (or `/set notifications false`).
256
+ Supported on macOS (`osascript`) and Linux (`notify-send`).
257
+ - **Theme** uses WhatsApp's signature green (`#25D366`). Colors auto-disable
258
+ under `NO_COLOR` or when output isn't a terminal.
259
+
260
+ ---
261
+
262
+ ## 13. Tips
263
+
264
+ | Want to… | Do this |
265
+ | --- | --- |
266
+ | See verbose connection logs | prefix with `WA_DEBUG=1`, e.g. `WA_DEBUG=1 wa sync` |
267
+ | Disable colored output | `NO_COLOR=1 wa chats` |
268
+ | Store data elsewhere | set `WA_HOME=/path` (holds `sessions/`, `data/`, `media/`, `config.json`) |
269
+
270
+ > **Privacy:** your session lives in `sessions/` and is as sensitive as being
271
+ > logged in. It's gitignored — never share or commit it.
272
+
273
+ ---
274
+
275
+ ## Typical session, start to finish
276
+
277
+ One-shot commands:
278
+ ```bash
279
+ wa login # scan QR once
280
+ wa sync # pull chats & messages
281
+ wa chats # browse
282
+ wa open Alice # read a conversation
283
+ wa send Alice "hello 👋" # reply (or: wa send Alice "look" --file pic.jpg)
284
+ wa search invoice # find something
285
+ wa media photos # see received photos
286
+ wa download 51 # save one
287
+ wa group info Family # inspect a group
288
+ wa watch # listen for new messages live (with notifications)
289
+ ```
290
+
291
+ Or just live in the app:
292
+ ```bash
293
+ wa # launch interactive mode
294
+ wa › /connect # go live
295
+ wa › /open Alice # open a chat…
296
+ wa › on my way 🚗 # …and just type to send
297
+ ```
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Piyush Patil
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,109 @@
1
+ # WhatsApp CLI
2
+
3
+ A lightweight, fast, terminal-first WhatsApp client with a WhatsApp-green
4
+ interface. Read, search, send, and receive messages entirely from your terminal —
5
+ no browser, no Electron. Includes a live interactive app, media send/download,
6
+ basic group management, and desktop notifications.
7
+
8
+ > Personal use only. Uses [Baileys](https://github.com/WhiskeySockets/Baileys)
9
+ > to talk to WhatsApp Web. Not affiliated with WhatsApp/Meta.
10
+
11
+ **📖 Full command reference: [COMMANDS.md](COMMANDS.md)**
12
+
13
+ ## Requirements
14
+
15
+ - **Node.js ≥ 22.5** (uses the built-in `node:sqlite` and native TypeScript
16
+ execution — no build step). Tested on Node 25.
17
+ - A phone with WhatsApp to link the device via QR.
18
+
19
+ ## Install
20
+
21
+ ```bash
22
+ npm install
23
+ npm link # optional: puts `wa` on your PATH
24
+ ```
25
+
26
+ Without `npm link`, run commands as `node bin/wa.js <command>` or `npm run wa -- <command>`.
27
+
28
+ ## Quick start
29
+
30
+ ```bash
31
+ wa login # link with a pairing code (prompts for your number)
32
+ # or: wa login qr # link by scanning a QR instead
33
+ wa sync # pull recent chats & messages into the local cache
34
+ wa chats # list conversations
35
+ wa open Alice # read a conversation (fuzzy name match)
36
+ wa send Alice "Hi" # send a message
37
+ wa send Alice --file pic.jpg # send media (caption optional)
38
+ wa search invoice # search cached messages
39
+ wa watch # stream incoming messages live (+ notifications)
40
+ ```
41
+
42
+ Or launch the **interactive app** — just run `wa` with no arguments:
43
+
44
+ ```
45
+ ✆ WhatsApp CLI interactive
46
+ ● linked 973 chats · 11948 messages
47
+
48
+ wa › /connect # go live
49
+ wa › /open Alice # open a chat…
50
+ Alice › on my way 🚗 # …then just type to send
51
+ ```
52
+
53
+ ## Architecture
54
+
55
+ **Local-first.** All reads (`chats`, `open`, `history`, `search`, `contacts`,
56
+ `export`) serve from a local SQLite cache — instant and fully offline. Only
57
+ `login`, `sync`, `send`, `reply`, `watch`, `download`, and `group` open the
58
+ WhatsApp connection. The interactive app holds a single persistent connection so
59
+ sends are instant and messages arrive live.
60
+
61
+ ```
62
+ CLI (commander) → command → { SQLite cache | Baileys socket → events → SQLite }
63
+ ```
64
+
65
+ - `src/cli` — command dispatcher and command implementations
66
+ - `src/whatsapp` — Baileys client, auth, and event→DB persistence
67
+ - `src/db` — `node:sqlite` schema and queries
68
+ - `src/config`, `src/utils` — paths/config and formatting helpers
69
+
70
+ State lives under the project directory by default (or `$WA_HOME` if set):
71
+ `sessions/` (credentials — gitignored), `data/whatsapp.db`, `media/`, `config.json`.
72
+
73
+ ## Commands
74
+
75
+ | Command | Description |
76
+ | --- | --- |
77
+ | `wa login` / `logout` / `status` | Link (pairing code), unlink, inspect the session |
78
+ | `wa login qr` | Link by scanning a QR instead of a code |
79
+ | `wa chats [-a] [-n N]` | List conversations |
80
+ | `wa contacts [-n N]` | List contacts |
81
+ | `wa open <chat> [-n N]` | Read latest messages |
82
+ | `wa history <chat> [-n N]` | Read extended history |
83
+ | `wa search <text> [-n N]` | Search cached messages |
84
+ | `wa send <chat> [message] [--file path]` | Send a text message or media |
85
+ | `wa reply <id> <message>` | Reply to a cached message by `#id` |
86
+ | `wa sync [-s seconds]` | Pull recent chats/messages |
87
+ | `wa watch` | Stream incoming messages live (+ notifications) |
88
+ | `wa media [type] [-n N]` | List cached media (photos/videos/audio/documents/stickers/all) |
89
+ | `wa download <id> [-o file]` | Download & decrypt a cached media message |
90
+ | `wa group <action> …` | Group management (info/invite/rename/add/remove/promote/demote/leave/create) |
91
+ | `wa export <chat> [-f md\|txt\|json] [-o file]` | Export a conversation |
92
+ | `wa recent [-n N]` | Most recently active chats |
93
+ | `wa pin/unpin/archive/unarchive <chat>` | Organize chats (local) |
94
+ | `wa shell` / `wa chat` (or just `wa`) | Interactive app (live chat, slash commands) |
95
+ | `wa config [set <key> <value>]` | View/edit preferences |
96
+ | `wa doctor` | Self-diagnostics |
97
+
98
+ See **[COMMANDS.md](COMMANDS.md)** for the full guide with every flag, the
99
+ interactive slash commands, group management, and notification/theme settings.
100
+
101
+ Set `WA_DEBUG=1` to see verbose Baileys connection logs.
102
+
103
+ ## Notes
104
+
105
+ - **Baileys version matters.** WhatsApp rejects outdated protocol versions at
106
+ the registration handshake. This project uses Baileys `7.x`; older `6.x`
107
+ releases fail to connect against current WhatsApp servers.
108
+ - Your session credentials in `sessions/` are as sensitive as being logged in.
109
+ They are gitignored — never commit or share them.
package/bin/wa.js ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ // Thin launcher. Node (>=22.5 with --experimental-strip-types, default in >=23.6)
3
+ // strips TypeScript types at runtime, so no build step is required.
4
+ import '../src/cli/index.ts';
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "cli-whatsapp",
3
+ "version": "0.1.0",
4
+ "description": "A lightweight, fast, terminal-first WhatsApp client. Read, search, send, media, groups, and live notifications — from your terminal.",
5
+ "type": "module",
6
+ "bin": {
7
+ "wa": "bin/wa.js"
8
+ },
9
+ "files": [
10
+ "bin/",
11
+ "src/",
12
+ "README.md",
13
+ "COMMANDS.md",
14
+ "LICENSE"
15
+ ],
16
+ "keywords": [
17
+ "whatsapp",
18
+ "cli",
19
+ "terminal",
20
+ "tui",
21
+ "chat",
22
+ "messaging",
23
+ "baileys",
24
+ "keyboard-first",
25
+ "local-first"
26
+ ],
27
+ "scripts": {
28
+ "wa": "node bin/wa.js",
29
+ "typecheck": "tsc --noEmit",
30
+ "test": "node --test tests/",
31
+ "prepublishOnly": "npm run typecheck"
32
+ },
33
+ "engines": {
34
+ "node": ">=22.6.0"
35
+ },
36
+ "license": "MIT",
37
+ "author": "Piyush Patil <piyushpatil7911@gmail.com>",
38
+ "dependencies": {
39
+ "@whiskeysockets/baileys": "^7.0.0-rc13",
40
+ "commander": "^15.0.0",
41
+ "qrcode-terminal": "^0.12.0"
42
+ },
43
+ "devDependencies": {
44
+ "@types/node": "^22.0.0",
45
+ "@types/qrcode-terminal": "^0.12.2",
46
+ "typescript": "^5.6.0"
47
+ }
48
+ }