@wsapichat/cli 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/CHANGELOG.md +20 -0
- package/LICENSE +21 -0
- package/README.md +233 -0
- package/dist/index.js +1358 -0
- package/dist/index.js.map +1 -0
- package/package.json +62 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/), and this project adheres to [Semantic Versioning](https://semver.org/).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [0.1.0] - 2026-05-07
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- Initial release.
|
|
14
|
+
- `wsapi` binary built on Commander.js, exposing every endpoint in the WSAPI public OpenAPI spec.
|
|
15
|
+
- Twelve resource groups: `session`, `messages`, `groups`, `communities`, `contacts`, `users`, `media`, `chats`, `calls`, `newsletters`, `status`, plus a `config` group for managing local profiles.
|
|
16
|
+
- Layered configuration: CLI flags, `WSAPI_*` environment variables, and named profiles in `~/.wsapi/config.json` (or `$XDG_CONFIG_HOME/wsapi/config.json`).
|
|
17
|
+
- `--data <json>` escape hatch on every body-bearing command, with `@file.json` support.
|
|
18
|
+
- Local-file uploads (`--data-file`) for media, document, sticker, image and video status, group/community/newsletter pictures, and own profile picture.
|
|
19
|
+
- Binary download support for `session qr` (PNG) and `media download`, writing to `--output` or stdout.
|
|
20
|
+
- JSON output to stdout and structured JSON error reporting on stderr for easy piping into `jq`.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 WSAPI Development Team
|
|
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,233 @@
|
|
|
1
|
+
# WSApi CLI
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@wsapichat/cli)
|
|
4
|
+
[](https://github.com/wsapi-chat/wsapi-cli/actions/workflows/ci.yml)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
A command-line client for the [WSAPI](https://wsapi.chat) WhatsApp API. Wraps every REST endpoint
|
|
8
|
+
in the WSAPI public OpenAPI spec under a single `wsapi` binary, written in TypeScript on top of
|
|
9
|
+
[Commander.js](https://github.com/tj/commander.js).
|
|
10
|
+
|
|
11
|
+
This is an independent API and is not affiliated with META or WhatsApp.
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- **Full REST coverage** — every endpoint across messages, groups, communities, contacts, users,
|
|
16
|
+
chats, calls, newsletters, status, media, and session management.
|
|
17
|
+
- **JSON in, JSON out** — every command emits JSON to stdout, ready to pipe into `jq`, `xargs`,
|
|
18
|
+
scripts, or your shell of choice.
|
|
19
|
+
- **Layered configuration** — flags, environment variables, and named profiles in
|
|
20
|
+
`~/.wsapi/config.json`. Switch between staging and production with `--profile`.
|
|
21
|
+
- **`--data` escape hatch** — every body-bearing command accepts a `--data <json>` flag that
|
|
22
|
+
merges arbitrary fields on top of the typed flags, so you're never blocked when the spec adds
|
|
23
|
+
a new field.
|
|
24
|
+
- **Local file uploads** — pass `--data-file ./path` for any media command and the CLI will
|
|
25
|
+
base64-encode it inline.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Getting Started
|
|
30
|
+
|
|
31
|
+
### Prerequisites
|
|
32
|
+
|
|
33
|
+
- [Node.js](https://nodejs.org/) 18 or later
|
|
34
|
+
- A WSAPI instance ID and API key
|
|
35
|
+
|
|
36
|
+
### Installation
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npm install -g @wsapichat/cli
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Verify the installation:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
wsapi --version
|
|
46
|
+
wsapi --help
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Usage
|
|
52
|
+
|
|
53
|
+
### 1. Configure credentials
|
|
54
|
+
|
|
55
|
+
`wsapi` resolves credentials in this order, first match wins:
|
|
56
|
+
|
|
57
|
+
1. CLI flags: `--api-key`, `--instance-id`, `--base-url`
|
|
58
|
+
2. Environment variables: `WSAPI_API_KEY`, `WSAPI_INSTANCE_ID`, `WSAPI_BASE_URL`
|
|
59
|
+
3. The named profile from `--profile <name>` or `WSAPI_PROFILE`
|
|
60
|
+
4. The `defaultProfile` in the config file
|
|
61
|
+
|
|
62
|
+
Use the built-in `wsapi config` commands to manage profiles:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
# Create a profile and mark it as the default
|
|
66
|
+
wsapi config set-profile prod \
|
|
67
|
+
--api-key "ws_live_..." \
|
|
68
|
+
--instance-id "ins_..." \
|
|
69
|
+
--default
|
|
70
|
+
|
|
71
|
+
wsapi config list # list profile names
|
|
72
|
+
wsapi config use staging # switch the default
|
|
73
|
+
wsapi config rm staging # delete a profile
|
|
74
|
+
wsapi config path # print the config file path
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
The config file is stored at `~/.wsapi/config.json` (or `$XDG_CONFIG_HOME/wsapi/config.json`),
|
|
78
|
+
mode 0600.
|
|
79
|
+
|
|
80
|
+
You can also bypass the config file entirely with environment variables:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
export WSAPI_API_KEY="ws_live_..."
|
|
84
|
+
export WSAPI_INSTANCE_ID="ins_..."
|
|
85
|
+
|
|
86
|
+
wsapi session status
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### 2. Pair a device
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
# Save the QR PNG to a file and scan it with WhatsApp
|
|
93
|
+
wsapi session qr --output qr.png
|
|
94
|
+
|
|
95
|
+
# Or get the raw QR string (useful for rendering yourself)
|
|
96
|
+
wsapi session qr --text
|
|
97
|
+
|
|
98
|
+
# Pair via phone-number code instead of QR
|
|
99
|
+
wsapi session pair-code 15551234567
|
|
100
|
+
|
|
101
|
+
# Confirm the device is paired
|
|
102
|
+
wsapi session status
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### 3. Send messages
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
# Plain text
|
|
109
|
+
wsapi messages text \
|
|
110
|
+
--to 15551234567@s.whatsapp.net \
|
|
111
|
+
--text "Hello from the CLI"
|
|
112
|
+
|
|
113
|
+
# Image by URL with a caption
|
|
114
|
+
wsapi messages image \
|
|
115
|
+
--to 15551234567@s.whatsapp.net \
|
|
116
|
+
--url https://example.com/cat.jpg \
|
|
117
|
+
--caption "cat"
|
|
118
|
+
|
|
119
|
+
# Image from a local file
|
|
120
|
+
wsapi messages image \
|
|
121
|
+
--to 15551234567@s.whatsapp.net \
|
|
122
|
+
--data-file ./photo.jpg \
|
|
123
|
+
--view-once
|
|
124
|
+
|
|
125
|
+
# Document with a custom filename
|
|
126
|
+
wsapi messages document \
|
|
127
|
+
--to 15551234567@s.whatsapp.net \
|
|
128
|
+
--data-file ./report.pdf \
|
|
129
|
+
--filename "Q1 report.pdf" \
|
|
130
|
+
--caption "this quarter"
|
|
131
|
+
|
|
132
|
+
# React to a message
|
|
133
|
+
wsapi messages react 3EB0... --to 15551234567@s.whatsapp.net --reaction "👍"
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### 4. Group operations
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
# List joined groups, then print just their names
|
|
140
|
+
wsapi groups list | jq -r '.[].name'
|
|
141
|
+
|
|
142
|
+
# Get group info
|
|
143
|
+
wsapi groups get 1234567890@g.us
|
|
144
|
+
|
|
145
|
+
# Add a participant
|
|
146
|
+
wsapi groups update-participants 1234567890@g.us \
|
|
147
|
+
--action add \
|
|
148
|
+
--participants 15551234567@s.whatsapp.net
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### 5. Download inbound media
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
wsapi media download <mediaId> --output incoming.jpg
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Without `--output`, binary endpoints write to stdout. Pipe it into a file or another command.
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## Command overview
|
|
162
|
+
|
|
163
|
+
| Group | Examples |
|
|
164
|
+
| ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
165
|
+
| `session` | `status`, `qr`, `qr --text`, `pair-code <phone>`, `logout`, `flush-history` |
|
|
166
|
+
| `messages` | `text`, `image`, `video`, `audio`, `voice`, `document`, `sticker`, `contact`, `location`, `link`, `react`, `edit`, `read`, `star`, `pin`, `delete`, `delete-for-me` |
|
|
167
|
+
| `groups` | `list`, `get`, `create`, `set-name`, `set-description`, `set-picture`, `leave`, `participants`, `update-participants`, `invite-link`, `reset-invite`, `set-announce`, `set-locked`, `set-join-approval`, `set-member-add-mode`, `join-link`, `join-invite`, `invite-info`, `requests`, `update-requests` |
|
|
168
|
+
| `communities` | `list`, `get`, `create`, `leave`, `set-name`, `set-description`, `set-picture`, `set-locked`, `participants`, `update-participants`, `invite-link`, `reset-invite`, `subgroups`, `create-subgroup`, `link-subgroup`, `unlink-subgroup` |
|
|
169
|
+
| `contacts` | `list`, `get`, `create`, `sync`, `blocklist`, `block`, `unblock` |
|
|
170
|
+
| `users` | `me`, `update-me`, `set-presence`, `privacy`, `set-privacy`, `check`, `check-bulk`, `profile` |
|
|
171
|
+
| `media` | `download <id> --output <file>` |
|
|
172
|
+
| `chats` | `list`, `get`, `delete`, `picture`, `business`, `set-presence`, `subscribe-presence`, `set-ephemeral`, `mute`, `pin`, `archive`, `read`, `request-history`, `clear` |
|
|
173
|
+
| `calls` | `reject` |
|
|
174
|
+
| `newsletters` | `list`, `get`, `invite-info`, `create`, `subscribe`, `unsubscribe`, `mute`, `unmute` |
|
|
175
|
+
| `status` | `privacy`, `text`, `image`, `video`, `delete` |
|
|
176
|
+
|
|
177
|
+
Run `wsapi <group> --help` and `wsapi <group> <command> --help` for the full list of options
|
|
178
|
+
on each command.
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## Escape hatch: `--data`
|
|
183
|
+
|
|
184
|
+
Every body-bearing command supports a `--data <json>` flag whose JSON object is merged on top
|
|
185
|
+
of the typed flags. Keys in `--data` win over flags, so it's both an extension point (for fields
|
|
186
|
+
the CLI doesn't expose explicitly) and a full-body override.
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
# Add a field the CLI doesn't expose
|
|
190
|
+
wsapi messages text \
|
|
191
|
+
--to 15551234567@s.whatsapp.net \
|
|
192
|
+
--text "hi" \
|
|
193
|
+
--data '{"someNewField":true}'
|
|
194
|
+
|
|
195
|
+
# Load the body from a file
|
|
196
|
+
wsapi messages text \
|
|
197
|
+
--to 15551234567@s.whatsapp.net \
|
|
198
|
+
--text "ignored" \
|
|
199
|
+
--data @./body.json
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## Exit codes & error format
|
|
205
|
+
|
|
206
|
+
- `0` — success
|
|
207
|
+
- `1` — any error (config, API, network, validation)
|
|
208
|
+
|
|
209
|
+
API errors are emitted to stderr as JSON:
|
|
210
|
+
|
|
211
|
+
```json
|
|
212
|
+
{
|
|
213
|
+
"error": "device not paired",
|
|
214
|
+
"status": 403,
|
|
215
|
+
"body": { "status": 403, "detail": "device not paired" }
|
|
216
|
+
}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
CLI/config errors are plain text on stderr:
|
|
220
|
+
|
|
221
|
+
```
|
|
222
|
+
error: missing API key. Set WSAPI_API_KEY, pass --api-key, or run `wsapi config set-profile`.
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
## Contributing
|
|
228
|
+
|
|
229
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
230
|
+
|
|
231
|
+
## License
|
|
232
|
+
|
|
233
|
+
[MIT](LICENSE)
|