@bhanulabs/wacli 0.0.0-stage → 1.0.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/LICENSE +15 -0
- package/README.md +221 -2
- package/bin/wacli.js +127 -0
- package/package.json +46 -4
- package/src/config.js +30 -0
- package/src/media.js +441 -0
- package/src/sixel.js +184 -0
- package/src/store.js +214 -0
- package/src/text.js +62 -0
- package/src/tui.js +1011 -0
- package/src/whatsapp.js +474 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 bhanu-mantri
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,222 @@
|
|
|
1
|
-
#
|
|
1
|
+
# wacli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Chat with your WhatsApp contacts from the terminal. It logs in as a **linked device** (like WhatsApp Web)
|
|
4
|
+
by scanning a QR code, using [Baileys](https://github.com/WhiskeySockets/Baileys).
|
|
5
|
+
|
|
6
|
+
> ⚠️ Baileys is an unofficial client. Use it for normal personal chatting; bulk or spam messaging can get a number banned.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
Node.js 22.9 or newer.
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install -g @bhanulabs/wacli
|
|
14
|
+
wacli
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Or try it without installing: `npx @bhanulabs/wacli`.
|
|
18
|
+
|
|
19
|
+
From source:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
git clone https://github.com/bhanu-mantri/wacli.git
|
|
23
|
+
cd wacli
|
|
24
|
+
npm install
|
|
25
|
+
npm start # or: npm link, to get the wacli command
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Logging in
|
|
29
|
+
|
|
30
|
+
1. Run `wacli`. A QR code appears in the terminal.
|
|
31
|
+
2. On your phone: WhatsApp → **Settings** (iPhone) or **⋮** (Android) → **Linked devices** → **Link a device**, and scan it.
|
|
32
|
+
3. The chat screen opens. Your recent chats are synced from the phone over the first minute or so.
|
|
33
|
+
|
|
34
|
+
The session is saved, so later runs log straight in. If the QR doesn't scan well in your terminal
|
|
35
|
+
(small window, odd font), use `wacli --pair 919876543210` (your own number) and enter the code it shows under
|
|
36
|
+
**Link with phone number instead** on the phone.
|
|
37
|
+
|
|
38
|
+
## Screen
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
wacli ● Me +91… F1 help · Tab switch · Ctrl+C quit
|
|
42
|
+
Chats (4) │ Alice Kumar +919876543210 typing…
|
|
43
|
+
──────────────────────────────│──────────────────────────────────────────────────────
|
|
44
|
+
▌ Alice Kumar 11:10 am │ Today
|
|
45
|
+
📷 Photo: the menu │ Hi! Are we still on for dinner tonight? 10:41 am
|
|
46
|
+
Bob 🎸 Yesterday │
|
|
47
|
+
✓✓ Yes!! what a finish … 3 │ Yes, 8pm works. 10:46 am ✓✓
|
|
48
|
+
──────────────────────────────────────────────────────────────────────────────────────
|
|
49
|
+
› Message Alice Kumar
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Left: chats, newest first, with unread counts. Right: the conversation (yours on the right, with ✓ sent,
|
|
53
|
+
✓✓ delivered, blue ✓✓ read). Bottom: the message box. In a terminal narrower than 70 columns you see one side at a time.
|
|
54
|
+
|
|
55
|
+
## Keys
|
|
56
|
+
|
|
57
|
+
| Key | |
|
|
58
|
+
|---|---|
|
|
59
|
+
| Tab | switch between the chat list and the message box |
|
|
60
|
+
| ↑ / ↓ | choose a chat (list) or scroll messages (message box) |
|
|
61
|
+
| Enter | open the chat / send the message |
|
|
62
|
+
| Ctrl+J | new line in a message (pasted text keeps its line breaks too) |
|
|
63
|
+
| drop a file | attach it (see below); Backspace on an empty box removes it |
|
|
64
|
+
| Alt+V (Windows) / Ctrl+V (Mac, Linux) | paste a screenshot, copied files, or a GIF (see below) |
|
|
65
|
+
| PgUp / PgDn | scroll messages a page |
|
|
66
|
+
| Ctrl+N / Ctrl+P | next / previous chat |
|
|
67
|
+
| Esc | back to the list, or clear the search |
|
|
68
|
+
| ← → Home End, Ctrl+W, Ctrl+U | edit the message |
|
|
69
|
+
| F1 | help |
|
|
70
|
+
| Ctrl+C | quit |
|
|
71
|
+
|
|
72
|
+
**Search / new chat:** with the list focused, just type to filter by name or number. Type a full number with
|
|
73
|
+
country code (e.g. `919876543210`) and press Enter on **+ New chat with …** to message someone who isn't in the list.
|
|
74
|
+
|
|
75
|
+
## Sending photos and files
|
|
76
|
+
|
|
77
|
+
With a chat open, drag files from Explorer (or Finder) onto the wacli window, the same way you drop images into Claude Code.
|
|
78
|
+
They appear above the message box:
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
│─ 📎 📷 Screenshot 2026-12-04.png 233 KB 📄 report.pdf 1 KB ──────────
|
|
82
|
+
│ › Add a caption (optional) · Enter send · Backspace remove file
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
- Type a caption if you like (it goes with the first file) and press **Enter**.
|
|
86
|
+
- **Backspace** in an empty message box removes the last file.
|
|
87
|
+
- Pasting a file path, or several quoted paths, works too.
|
|
88
|
+
- Attached files stay with their chat if you switch to another one.
|
|
89
|
+
|
|
90
|
+
How they're sent:
|
|
91
|
+
|
|
92
|
+
| File | Sent as |
|
|
93
|
+
|---|---|
|
|
94
|
+
| jpg, png, webp, bmp, tiff, avif | photo (turned upright, resized to at most 2560 px and converted to JPEG, like the phone app does) |
|
|
95
|
+
| mp4, 3gp | video (100 MB max) |
|
|
96
|
+
| mp3, m4a, aac, ogg, opus, amr | audio (a caption goes as a separate message) |
|
|
97
|
+
| anything else, including gif, mov and heic | document, with its file name (2 GB max) |
|
|
98
|
+
|
|
99
|
+
The terminal only gives wacli the file's path, so a dropped file has to be on this computer.
|
|
100
|
+
|
|
101
|
+
### Pasting screenshots, GIFs and copied files
|
|
102
|
+
|
|
103
|
+
In a chat, press the paste key to attach what's on the clipboard:
|
|
104
|
+
|
|
105
|
+
| | Paste key | How wacli reads the clipboard |
|
|
106
|
+
|---|---|---|
|
|
107
|
+
| Windows | **Alt+V** | PowerShell (built in) |
|
|
108
|
+
| macOS | **Ctrl+V** | osascript (built in) |
|
|
109
|
+
| Linux | **Ctrl+V** | `wl-paste` on Wayland or `xclip` on X11: install with `sudo apt install wl-clipboard xclip` (or your distro's equivalent) |
|
|
110
|
+
|
|
111
|
+
What you can paste:
|
|
112
|
+
|
|
113
|
+
- **A screenshot or copied image:** Win + Shift + S or PrtScn (Windows), Cmd + Ctrl + Shift + 4 (Mac), Print Screen
|
|
114
|
+
(most Linux desktops), or "Copy image" in a browser. Sent as a photo.
|
|
115
|
+
- **Copied files:** from Explorer, Finder, Nautilus, Dolphin and so on. Attached like dropped files.
|
|
116
|
+
- **A GIF from GIPHY:** on Windows, press **Win + .**, open the GIF tab and pick one. Nothing appears in the terminal
|
|
117
|
+
(Windows puts the GIF on the clipboard), so then press **Alt+V**. On any OS, "Copy image" on a GIPHY GIF in a browser,
|
|
118
|
+
or a copied GIPHY link, works too. It's sent as a real WhatsApp GIF that loops on the phone:
|
|
119
|
+
WhatsApp GIFs are short MP4 videos, and GIPHY has an MP4 of every GIF, so wacli downloads that.
|
|
120
|
+
|
|
121
|
+
Why different keys? Windows Terminal keeps Ctrl+V for its own text paste, and with only an image on the clipboard
|
|
122
|
+
nothing reaches the app (Claude Code uses Alt+V on Windows for the same reason). Mac and Linux terminals paste with
|
|
123
|
+
Cmd+V / Ctrl+Shift+V and pass Ctrl+V through to the app, and Option+V on a Mac types "√". Both keys work everywhere
|
|
124
|
+
if your terminal lets them through.
|
|
125
|
+
|
|
126
|
+
Then add a caption if you like and press Enter, as with dropped files. Downloaded GIFs and pasted images are kept
|
|
127
|
+
in `~/.wacli/tmp` only until they're sent or removed.
|
|
128
|
+
A `.gif` file from elsewhere is still sent as a document, because turning it into a WhatsApp GIF would need ffmpeg.
|
|
129
|
+
|
|
130
|
+
## Receiving photos
|
|
131
|
+
|
|
132
|
+
Photos sent to you download automatically to `~/.wacli/media`. In the chat each one gets a number:
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
📷 Photo #3: the menu
|
|
136
|
+
/open 3 to view 11:10 am
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
- **Previews in the chat:** in a terminal that can show images (Windows Terminal 1.22+, WezTerm, foot, mlterm…),
|
|
140
|
+
downloaded photos appear right in the conversation, above their caption, up to 12 lines tall. wacli asks the
|
|
141
|
+
terminal at startup whether it supports this (sixel graphics), so other terminals simply show the text line.
|
|
142
|
+
Turn previews off with `--no-images` or `WACLI_IMAGES=0`. Force them on with `WACLI_IMAGES=1`, e.g. if your terminal supports sixel
|
|
143
|
+
but doesn't say so.
|
|
144
|
+
- **Ctrl+O** opens the latest photo in this chat in your normal image viewer (Photos on Windows).
|
|
145
|
+
- **`/open 3`** opens photo #3.
|
|
146
|
+
- Photos from the history synced at login aren't downloaded up front: `/open` downloads them when you ask.
|
|
147
|
+
WhatsApp only keeps media on its servers for a while, so wacli asks the sender's phone to upload it again if needed.
|
|
148
|
+
Very old ones may no longer be available.
|
|
149
|
+
- If a download fails, the line says so, and `/open` tries again.
|
|
150
|
+
- Photos you send are saved there too.
|
|
151
|
+
- View-once photos are never downloaded. They're meant to be seen once, on the phone.
|
|
152
|
+
- Photos older than the last 500 messages of a chat are deleted along with those messages, and `/logout` deletes them all.
|
|
153
|
+
|
|
154
|
+
## Commands (in the message box)
|
|
155
|
+
|
|
156
|
+
| Command | |
|
|
157
|
+
|---|---|
|
|
158
|
+
| `/new 919876543210` | start a chat with a number |
|
|
159
|
+
| `/open 3` | open photo #3 of this chat (Ctrl+O: the latest) |
|
|
160
|
+
| `/name Mom` | name this chat (only inside wacli; `/name` alone removes it) |
|
|
161
|
+
| `/logout` | unlink this device from your phone and delete the saved session and chats |
|
|
162
|
+
| `/quit` | exit |
|
|
163
|
+
| `//text` | send a message that starts with `/` |
|
|
164
|
+
|
|
165
|
+
## Options
|
|
166
|
+
|
|
167
|
+
```
|
|
168
|
+
--pair <number> log in with a code instead of the QR
|
|
169
|
+
--no-read-receipts don't send blue ticks when you open a chat
|
|
170
|
+
--invisible don't show as "online" (you won't see "typing…" from others either)
|
|
171
|
+
--no-images don't show photo previews in the chat
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
By default wacli behaves like WhatsApp Web: you show as online while it runs, the other person sees "typing…"
|
|
175
|
+
while you write, and opening a chat marks it read.
|
|
176
|
+
Note that while a linked device is online, WhatsApp may not push notifications to your phone.
|
|
177
|
+
|
|
178
|
+
## What it does and doesn't do
|
|
179
|
+
|
|
180
|
+
- Direct chats only. Groups, status updates and channels are skipped.
|
|
181
|
+
- Text messages are sent and shown in full. You can send photos, videos, audio and files by dropping them in.
|
|
182
|
+
Received photos are downloaded (see above). Videos, voice notes, stickers and documents show as a label with
|
|
183
|
+
their caption (e.g. `🎥 Video: the beach`) and aren't downloaded.
|
|
184
|
+
- History: what your phone sends at link time (recent chats), plus everything while wacli runs. Up to 500
|
|
185
|
+
messages per chat are kept.
|
|
186
|
+
- Reactions, edits and deletes aren't shown.
|
|
187
|
+
- Names come from your phone's address book when WhatsApp shares it, otherwise the person's own WhatsApp name.
|
|
188
|
+
Some contacts appear as "Unknown (hidden number)" until WhatsApp tells us their number; they're merged automatically.
|
|
189
|
+
|
|
190
|
+
## Files
|
|
191
|
+
|
|
192
|
+
Everything is in `~/.wacli` (set `WACLI_HOME` to use another folder, e.g. for a second account):
|
|
193
|
+
|
|
194
|
+
```
|
|
195
|
+
auth/ login session. Anyone with this folder can use your WhatsApp: keep it private
|
|
196
|
+
store.json chats, messages and names
|
|
197
|
+
media/ downloaded photos (keep private)
|
|
198
|
+
wacli.log errors and connection logs (LOG_LEVEL=debug for more)
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
Code:
|
|
202
|
+
|
|
203
|
+
```
|
|
204
|
+
bin/wacli.js entry point: options, QR / pairing screens, start and quit
|
|
205
|
+
src/whatsapp.js Baileys connection, reconnects, message parsing, send, read receipts, presence
|
|
206
|
+
src/store.js chats, messages, contact names, hidden-number merging, saving
|
|
207
|
+
src/tui.js the full-screen interface: layout, keys, rendering
|
|
208
|
+
src/media.js dropped files, clipboard paste on Windows / macOS / Linux, photo conversion, photo / video / GIF / document
|
|
209
|
+
src/sixel.js inline photo previews: terminal detection, palette reduction, sixel encoding
|
|
210
|
+
src/text.js text width / wrapping (emoji-aware)
|
|
211
|
+
src/config.js paths and logging
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Troubleshooting
|
|
215
|
+
|
|
216
|
+
- **Garbled lines or misaligned emoji:** use Windows Terminal (not the old console) or another modern terminal. Resize the window to redraw.
|
|
217
|
+
- **No photo previews:** run with `LOG_LEVEL=info` and look for the `terminal graphics` line in `~/.wacli/wacli.log`. It shows
|
|
218
|
+
what the terminal answered. If `sixel` is false but your terminal supports it, start with `WACLI_IMAGES=1`.
|
|
219
|
+
If previews overlap the text below them, your terminal is drawing at a different size than it reports. Please [open an issue](https://github.com/bhanu-mantri/wacli/issues), or use `--no-images`.
|
|
220
|
+
- **QR too big:** make the window taller or the font smaller, or use `--pair`.
|
|
221
|
+
- **"Reconnecting…" that never ends:** quit, delete `~/.wacli/auth`, start again and re-link.
|
|
222
|
+
- **Logged out on the phone:** wacli notices, clears the session and shows a new QR.
|
package/bin/wacli.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import QRCode from 'qrcode';
|
|
4
|
+
import { HOME, LOG_FILE, logger } from '../src/config.js';
|
|
5
|
+
import { store } from '../src/store.js';
|
|
6
|
+
import * as wa from '../src/whatsapp.js';
|
|
7
|
+
import { App } from '../src/tui.js';
|
|
8
|
+
import { cleanTmp } from '../src/media.js';
|
|
9
|
+
import { detectGraphics } from '../src/sixel.js';
|
|
10
|
+
|
|
11
|
+
const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
12
|
+
|
|
13
|
+
const USAGE = `wacli ${pkg.version} - chat with your WhatsApp contacts from the terminal
|
|
14
|
+
|
|
15
|
+
Usage: wacli [options]
|
|
16
|
+
|
|
17
|
+
--pair <number> log in with an 8-character code instead of scanning a QR
|
|
18
|
+
(your number with country code, e.g. 919876543210)
|
|
19
|
+
--no-read-receipts don't send blue ticks when you open a chat
|
|
20
|
+
--invisible don't appear "online" (you won't see "typing…" either)
|
|
21
|
+
--no-images don't show photo previews in the chat
|
|
22
|
+
-h, --help show this help
|
|
23
|
+
-v, --version show the version
|
|
24
|
+
|
|
25
|
+
Data (login session, messages) is kept in ${HOME}
|
|
26
|
+
Set WACLI_HOME to use another folder, e.g. for a second account.
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
// ---------------- arguments ----------------
|
|
30
|
+
const args = process.argv.slice(2);
|
|
31
|
+
let showImages = true;
|
|
32
|
+
for (let i = 0; i < args.length; i++) {
|
|
33
|
+
const a = args[i];
|
|
34
|
+
if (a === '-h' || a === '--help') { process.stdout.write(USAGE); process.exit(0); }
|
|
35
|
+
else if (a === '-v' || a === '--version') { process.stdout.write(pkg.version + '\n'); process.exit(0); }
|
|
36
|
+
else if (a === '--no-read-receipts') wa.options.readReceipts = false;
|
|
37
|
+
else if (a === '--invisible') wa.options.online = false;
|
|
38
|
+
else if (a === '--no-images') showImages = false;
|
|
39
|
+
else if (a === '--pair' || a.startsWith('--pair=')) {
|
|
40
|
+
const value = a.includes('=') ? a.split('=')[1] : args[++i];
|
|
41
|
+
const digits = String(value || '').replace(/\D/g, '');
|
|
42
|
+
if (digits.length < 8 || digits.length > 15) fail('--pair needs your number with country code, e.g. --pair 919876543210');
|
|
43
|
+
wa.options.pairNumber = digits;
|
|
44
|
+
} else fail(`Unknown option: ${a}\n\n${USAGE}`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function fail(msg) {
|
|
48
|
+
process.stderr.write(msg + '\n');
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) fail('wacli needs an interactive terminal.');
|
|
53
|
+
|
|
54
|
+
// ---------------- app ----------------
|
|
55
|
+
const write = (s) => process.stdout.write(s);
|
|
56
|
+
const clearScreen = () => write('\x1b[2J\x1b[3J\x1b[H');
|
|
57
|
+
let quitting = false;
|
|
58
|
+
|
|
59
|
+
const app = new App({ onQuit: quit });
|
|
60
|
+
|
|
61
|
+
async function quit(code = 0) {
|
|
62
|
+
if (quitting) return;
|
|
63
|
+
quitting = true;
|
|
64
|
+
app.stopTyping?.();
|
|
65
|
+
app.stop();
|
|
66
|
+
store.flush();
|
|
67
|
+
await wa.stop();
|
|
68
|
+
process.exit(code);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Before login the normal terminal is used, so Ctrl+C works as usual.
|
|
72
|
+
process.on('SIGINT', () => quit(0));
|
|
73
|
+
process.on('SIGTERM', () => quit(0));
|
|
74
|
+
|
|
75
|
+
wa.wa.on('qr', async (qr) => {
|
|
76
|
+
app.stop();
|
|
77
|
+
const code = await QRCode.toString(qr, { type: 'terminal', small: true });
|
|
78
|
+
clearScreen();
|
|
79
|
+
write('\n wacli: link your WhatsApp\n\n');
|
|
80
|
+
write(' 1. Open WhatsApp on your phone\n');
|
|
81
|
+
write(' 2. Settings (iPhone) or ⋮ menu (Android) → Linked devices → Link a device\n');
|
|
82
|
+
write(' 3. Point the phone at this QR code\n\n');
|
|
83
|
+
write(code.replace(/^/gm, ' ') + '\n');
|
|
84
|
+
write(' The code refreshes every ~20 seconds. Can\'t scan it? Run: wacli --pair <your number>\n');
|
|
85
|
+
if (wa.state.lastError) write(`\n ${wa.state.lastError}\n`);
|
|
86
|
+
write(' Ctrl+C to quit\n');
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
wa.wa.on('pairing-code', (code) => {
|
|
90
|
+
app.stop();
|
|
91
|
+
clearScreen();
|
|
92
|
+
write('\n wacli: link your WhatsApp with a code\n\n');
|
|
93
|
+
write(' 1. Open WhatsApp on your phone\n');
|
|
94
|
+
write(' 2. Settings (iPhone) or ⋮ menu (Android) → Linked devices → Link a device\n');
|
|
95
|
+
write(' 3. Tap "Link with phone number instead" and enter:\n\n');
|
|
96
|
+
write(` \x1b[1m${code}\x1b[0m\n\n`);
|
|
97
|
+
write(' Ctrl+C to quit\n');
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
wa.wa.on('logged-out', () => {
|
|
101
|
+
app.stop();
|
|
102
|
+
app.resetView();
|
|
103
|
+
clearScreen();
|
|
104
|
+
write('\n Logged out. This device was unlinked, and its saved chats were removed.\n Getting a new QR code…\n');
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
wa.wa.on('open', () => {
|
|
108
|
+
clearScreen();
|
|
109
|
+
app.start();
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
process.on('unhandledRejection', (err) => logger.error({ err }, 'unhandled rejection'));
|
|
113
|
+
process.on('uncaughtException', (err) => {
|
|
114
|
+
logger.fatal({ err }, 'crash');
|
|
115
|
+
app.stop();
|
|
116
|
+
store.flush();
|
|
117
|
+
process.stderr.write(`wacli crashed: ${err.stack || err}\nDetails are in ${LOG_FILE}\n`);
|
|
118
|
+
process.exit(1);
|
|
119
|
+
});
|
|
120
|
+
process.on('exit', () => app.stop());
|
|
121
|
+
|
|
122
|
+
store.load();
|
|
123
|
+
cleanTmp();
|
|
124
|
+
// Ask the terminal whether it can show images, before anything else reads the keyboard.
|
|
125
|
+
await detectGraphics({ enabled: showImages });
|
|
126
|
+
write('Connecting to WhatsApp…\n');
|
|
127
|
+
wa.start().catch((err) => fail(`Could not start: ${err.message}`));
|
package/package.json
CHANGED
|
@@ -1,6 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bhanulabs/wacli",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Chat with your WhatsApp contacts from the terminal: QR login, photos, GIFs, clipboard paste and inline image previews",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"whatsapp",
|
|
7
|
+
"cli",
|
|
8
|
+
"tui",
|
|
9
|
+
"terminal",
|
|
10
|
+
"chat",
|
|
11
|
+
"baileys",
|
|
12
|
+
"sixel"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://github.com/bhanu-mantri/wacli#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/bhanu-mantri/wacli/issues"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/bhanu-mantri/wacli.git"
|
|
21
|
+
},
|
|
22
|
+
"license": "ISC",
|
|
23
|
+
"author": "bhanu-mantri",
|
|
24
|
+
"type": "module",
|
|
25
|
+
"bin": {
|
|
26
|
+
"wacli": "bin/wacli.js"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"bin",
|
|
30
|
+
"src"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"start": "node bin/wacli.js"
|
|
34
|
+
},
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=22.9"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@whiskeysockets/baileys": "7.0.0-rc14",
|
|
40
|
+
"pino": "^10.4.0",
|
|
41
|
+
"qrcode": "^1.5.4",
|
|
42
|
+
"sharp": "^0.35.6",
|
|
43
|
+
"string-width": "^9.0.0"
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
}
|
|
48
|
+
}
|
package/src/config.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import util from 'node:util';
|
|
5
|
+
import pino from 'pino';
|
|
6
|
+
|
|
7
|
+
/** Everything wacli keeps (session, messages, log) lives here. Override with WACLI_HOME. */
|
|
8
|
+
export const HOME = path.resolve(process.env.WACLI_HOME || path.join(os.homedir(), '.wacli'));
|
|
9
|
+
export const AUTH_DIR = path.join(HOME, 'auth');
|
|
10
|
+
export const STORE_FILE = path.join(HOME, 'store.json');
|
|
11
|
+
export const LOG_FILE = path.join(HOME, 'wacli.log');
|
|
12
|
+
export const MEDIA_DIR = path.join(HOME, 'media'); // downloaded photos
|
|
13
|
+
|
|
14
|
+
fs.mkdirSync(HOME, { recursive: true });
|
|
15
|
+
|
|
16
|
+
// Start a fresh log when it gets big.
|
|
17
|
+
try {
|
|
18
|
+
if (fs.statSync(LOG_FILE).size > 5 * 1024 * 1024) fs.rmSync(LOG_FILE);
|
|
19
|
+
} catch {}
|
|
20
|
+
|
|
21
|
+
export const logger = pino(
|
|
22
|
+
{ level: process.env.LOG_LEVEL || 'warn' },
|
|
23
|
+
pino.destination({ dest: LOG_FILE, sync: true, mkdir: true }),
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
// Baileys' crypto library prints to console ("Closing session…" etc.), which would draw
|
|
27
|
+
// over the chat screen. Send all console output to the log file instead.
|
|
28
|
+
for (const level of ['log', 'info', 'debug', 'warn', 'error']) {
|
|
29
|
+
console[level] = (...args) => logger[level === 'log' || level === 'debug' ? 'info' : level](util.format(...args));
|
|
30
|
+
}
|