waba-toolkit 0.2.0 → 0.3.1
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/ARCHITECTURE.md +783 -0
- package/README.md +238 -242
- package/dist/index.cli.js +863 -0
- package/dist/index.d.mts +180 -1
- package/dist/index.d.ts +180 -1
- package/dist/index.js +203 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +199 -0
- package/dist/index.mjs.map +1 -1
- package/docs/CLI.md +445 -0
- package/docs/MEDIA.md +576 -0
- package/docs/SENDING.md +635 -0
- package/docs/TROUBLESHOOTING.md +622 -0
- package/docs/WEBHOOKS.md +515 -0
- package/package.json +13 -3
package/docs/CLI.md
ADDED
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
# CLI Guide
|
|
2
|
+
|
|
3
|
+
Use waba-toolkit from the command line.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# Global (recommended)
|
|
11
|
+
npm install -g waba-toolkit
|
|
12
|
+
|
|
13
|
+
# Or use with npx
|
|
14
|
+
npx waba-toolkit --help
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Configure Once
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
waba-toolkit configure
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
**Prompts for:**
|
|
26
|
+
- Access token (required)
|
|
27
|
+
- Default phone number ID (optional)
|
|
28
|
+
- API version (optional, default: v22.0)
|
|
29
|
+
- WABA ID (optional)
|
|
30
|
+
- Business ID (optional)
|
|
31
|
+
|
|
32
|
+
**Config stored at:** `~/.waba-toolkit` (encrypted, machine-locked)
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Commands Overview
|
|
37
|
+
|
|
38
|
+
| Command | Description |
|
|
39
|
+
|---------|-------------|
|
|
40
|
+
| `configure` | Interactive setup wizard |
|
|
41
|
+
| `config show` | Display current configuration (masked) |
|
|
42
|
+
| `config set-default-phone` | Set default phone number ID |
|
|
43
|
+
| `config set <field> <value>` | Update config field |
|
|
44
|
+
| `register --pin <pin>` | Register phone number |
|
|
45
|
+
| `deregister` | Deregister phone number |
|
|
46
|
+
| `list-phones --waba-id <id>` | List all phone numbers |
|
|
47
|
+
| `send text` | Send text message |
|
|
48
|
+
| `send template` | Send template message from JSON |
|
|
49
|
+
| `send file` | Send custom message from JSON |
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Configuration Commands
|
|
54
|
+
|
|
55
|
+
### View Current Config
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
waba-toolkit config show
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**Output:**
|
|
62
|
+
```
|
|
63
|
+
Access Token: EAA...****...abc (masked)
|
|
64
|
+
Default Phone Number ID: 1234567890
|
|
65
|
+
API Version: v22.0
|
|
66
|
+
WABA ID: (not set)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Set Default Phone
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
waba-toolkit config set-default-phone 1234567890
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Update Config Fields
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
waba-toolkit config set access-token EAABsbCS...
|
|
79
|
+
waba-toolkit config set api-version v22.0
|
|
80
|
+
waba-toolkit config set waba-id 1234567890
|
|
81
|
+
waba-toolkit config set business-id 9876543210
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**Valid fields:**
|
|
85
|
+
- `access-token`
|
|
86
|
+
- `default-phone-number-id`
|
|
87
|
+
- `api-version`
|
|
88
|
+
- `waba-id`
|
|
89
|
+
- `business-id`
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## Environment Variables
|
|
94
|
+
|
|
95
|
+
Override config with environment variables:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
export WABA_TOOLKIT_ACCESS_TOKEN="your-token"
|
|
99
|
+
export WABA_TOOLKIT_PHONE_NUMBER_ID="your-phone-id"
|
|
100
|
+
export WABA_TOOLKIT_WABA_ID="your-waba-id"
|
|
101
|
+
export WABA_TOOLKIT_API_VERSION="v22.0"
|
|
102
|
+
export WABA_TOOLKIT_BUSINESS_ID="your-business-id"
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**Priority:** CLI flags > env vars > config file > defaults
|
|
106
|
+
|
|
107
|
+
**Use case:** CI/CD pipelines, temporary overrides, multi-environment setups
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## Phone Management
|
|
112
|
+
|
|
113
|
+
### Register Phone
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
# With default phone from config
|
|
117
|
+
waba-toolkit register --pin 123456
|
|
118
|
+
|
|
119
|
+
# With explicit phone ID
|
|
120
|
+
waba-toolkit register --bpid 1234567890 --pin 123456
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Deregister Phone
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
# With default phone from config
|
|
127
|
+
waba-toolkit deregister
|
|
128
|
+
|
|
129
|
+
# With explicit phone ID
|
|
130
|
+
waba-toolkit deregister --bpid 1234567890
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### List Phone Numbers
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
waba-toolkit list-phones --waba-id 1234567890
|
|
137
|
+
|
|
138
|
+
# Using environment variable
|
|
139
|
+
export WABA_TOOLKIT_WABA_ID=1234567890
|
|
140
|
+
waba-toolkit list-phones
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## Sending Messages
|
|
146
|
+
|
|
147
|
+
### Text Message
|
|
148
|
+
|
|
149
|
+
> See also: [Sending Messages via Library](SENDING.md#text-messages)
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
# Basic text
|
|
153
|
+
waba-toolkit send text --to 1234567890 --message "Hello World"
|
|
154
|
+
|
|
155
|
+
# With URL preview
|
|
156
|
+
waba-toolkit send text \
|
|
157
|
+
--to 1234567890 \
|
|
158
|
+
--message "Check this: https://example.com" \
|
|
159
|
+
--preview-url
|
|
160
|
+
|
|
161
|
+
# Reply to message
|
|
162
|
+
waba-toolkit send text \
|
|
163
|
+
--to 1234567890 \
|
|
164
|
+
--message "Got it!" \
|
|
165
|
+
--reply-to wamid.abc123
|
|
166
|
+
|
|
167
|
+
# With explicit phone number ID
|
|
168
|
+
waba-toolkit send text \
|
|
169
|
+
--bpid 9876543210 \
|
|
170
|
+
--to 1234567890 \
|
|
171
|
+
--message "Hello"
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Template Message
|
|
175
|
+
|
|
176
|
+
> See also: [Template Messages via Library](SENDING.md#template-messages)
|
|
177
|
+
|
|
178
|
+
**Create template.json:**
|
|
179
|
+
```json
|
|
180
|
+
{
|
|
181
|
+
"name": "order_confirmation",
|
|
182
|
+
"language": { "code": "en_US" },
|
|
183
|
+
"components": [
|
|
184
|
+
{
|
|
185
|
+
"type": "body",
|
|
186
|
+
"parameters": [
|
|
187
|
+
{ "type": "text", "text": "John Doe" },
|
|
188
|
+
{ "type": "text", "text": "ORD-12345" }
|
|
189
|
+
]
|
|
190
|
+
}
|
|
191
|
+
]
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
**Send:**
|
|
196
|
+
```bash
|
|
197
|
+
waba-toolkit send template --to 1234567890 --file template.json
|
|
198
|
+
|
|
199
|
+
# With explicit phone ID
|
|
200
|
+
waba-toolkit send template \
|
|
201
|
+
--bpid 9876543210 \
|
|
202
|
+
--to 1234567890 \
|
|
203
|
+
--file template.json
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Custom Message Payload
|
|
207
|
+
|
|
208
|
+
**Create message.json:**
|
|
209
|
+
```json
|
|
210
|
+
{
|
|
211
|
+
"messaging_product": "whatsapp",
|
|
212
|
+
"to": "1234567890",
|
|
213
|
+
"type": "image",
|
|
214
|
+
"image": {
|
|
215
|
+
"link": "https://example.com/image.jpg",
|
|
216
|
+
"caption": "Check this out!"
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
**Send:**
|
|
222
|
+
```bash
|
|
223
|
+
waba-toolkit send file --payload message.json
|
|
224
|
+
|
|
225
|
+
# With explicit phone ID
|
|
226
|
+
waba-toolkit send file --bpid 9876543210 --payload message.json
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
## Global Flags
|
|
232
|
+
|
|
233
|
+
Available on all commands:
|
|
234
|
+
|
|
235
|
+
| Flag | Description |
|
|
236
|
+
|------|-------------|
|
|
237
|
+
| `--bpid <id>` | Override phone number ID |
|
|
238
|
+
| `--phone-number-id <id>` | Alias for --bpid |
|
|
239
|
+
| `--api-version <version>` | Override API version |
|
|
240
|
+
| `--help` | Show command help |
|
|
241
|
+
| `--version` | Show package version |
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
## Examples
|
|
246
|
+
|
|
247
|
+
### First-Time Setup
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
# 1. Install
|
|
251
|
+
npm install -g waba-toolkit
|
|
252
|
+
|
|
253
|
+
# 2. Configure
|
|
254
|
+
waba-toolkit configure
|
|
255
|
+
# Enter: access token, phone ID
|
|
256
|
+
|
|
257
|
+
# 3. Register phone
|
|
258
|
+
waba-toolkit register --pin 123456
|
|
259
|
+
|
|
260
|
+
# 4. Send test message
|
|
261
|
+
waba-toolkit send text --to YOUR_NUMBER --message "Test"
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
### CI/CD Usage
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
# No config file needed - use env vars
|
|
268
|
+
export WABA_TOOLKIT_ACCESS_TOKEN="${SECRET_TOKEN}"
|
|
269
|
+
export WABA_TOOLKIT_PHONE_NUMBER_ID="1234567890"
|
|
270
|
+
|
|
271
|
+
# Send notification
|
|
272
|
+
waba-toolkit send text \
|
|
273
|
+
--to "${RECIPIENT}" \
|
|
274
|
+
--message "Deployment successful"
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### Multi-Environment
|
|
278
|
+
|
|
279
|
+
```bash
|
|
280
|
+
# Production
|
|
281
|
+
export WABA_TOOLKIT_ACCESS_TOKEN="${PROD_TOKEN}"
|
|
282
|
+
waba-toolkit send text --to 123 --message "Hello"
|
|
283
|
+
|
|
284
|
+
# Staging
|
|
285
|
+
export WABA_TOOLKIT_ACCESS_TOKEN="${STAGING_TOKEN}"
|
|
286
|
+
waba-toolkit send text --to 123 --message "Hello"
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## Message Payload Examples
|
|
292
|
+
|
|
293
|
+
### Image with Caption
|
|
294
|
+
|
|
295
|
+
```json
|
|
296
|
+
{
|
|
297
|
+
"messaging_product": "whatsapp",
|
|
298
|
+
"to": "1234567890",
|
|
299
|
+
"type": "image",
|
|
300
|
+
"image": {
|
|
301
|
+
"link": "https://example.com/photo.jpg",
|
|
302
|
+
"caption": "Amazing photo"
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### Interactive List
|
|
308
|
+
|
|
309
|
+
```json
|
|
310
|
+
{
|
|
311
|
+
"messaging_product": "whatsapp",
|
|
312
|
+
"to": "1234567890",
|
|
313
|
+
"type": "interactive",
|
|
314
|
+
"interactive": {
|
|
315
|
+
"type": "list",
|
|
316
|
+
"body": { "text": "Choose an option" },
|
|
317
|
+
"action": {
|
|
318
|
+
"button": "View Menu",
|
|
319
|
+
"sections": [
|
|
320
|
+
{
|
|
321
|
+
"title": "Options",
|
|
322
|
+
"rows": [
|
|
323
|
+
{
|
|
324
|
+
"id": "1",
|
|
325
|
+
"title": "Option 1",
|
|
326
|
+
"description": "First option"
|
|
327
|
+
}
|
|
328
|
+
]
|
|
329
|
+
}
|
|
330
|
+
]
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
### Location
|
|
337
|
+
|
|
338
|
+
```json
|
|
339
|
+
{
|
|
340
|
+
"messaging_product": "whatsapp",
|
|
341
|
+
"to": "1234567890",
|
|
342
|
+
"type": "location",
|
|
343
|
+
"location": {
|
|
344
|
+
"latitude": 37.7749,
|
|
345
|
+
"longitude": -122.4194,
|
|
346
|
+
"name": "San Francisco",
|
|
347
|
+
"address": "California, USA"
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
---
|
|
353
|
+
|
|
354
|
+
## Error Handling
|
|
355
|
+
|
|
356
|
+
### Configuration Errors
|
|
357
|
+
|
|
358
|
+
```bash
|
|
359
|
+
# Missing phone number ID
|
|
360
|
+
✗ Error: No phone number ID specified
|
|
361
|
+
|
|
362
|
+
You must either:
|
|
363
|
+
1. Set a default: waba-toolkit config set-default-phone <id>
|
|
364
|
+
2. Use environment variable: WABA_TOOLKIT_PHONE_NUMBER_ID=<id>
|
|
365
|
+
3. Specify with flag: --bpid <id>
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
### API Errors
|
|
369
|
+
|
|
370
|
+
API errors are printed as-is with full details:
|
|
371
|
+
|
|
372
|
+
```json
|
|
373
|
+
{
|
|
374
|
+
"error": {
|
|
375
|
+
"message": "(#131047) Re-engagement message",
|
|
376
|
+
"type": "OAuthException",
|
|
377
|
+
"code": 131047,
|
|
378
|
+
"error_data": {
|
|
379
|
+
"messaging_product": "whatsapp",
|
|
380
|
+
"details": "Message failed to send because more than 24 hours..."
|
|
381
|
+
},
|
|
382
|
+
"fbtrace_id": "A1B2C3D4E5F6G7H8"
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
Use `fbtrace_id` when contacting Meta support.
|
|
388
|
+
|
|
389
|
+
---
|
|
390
|
+
|
|
391
|
+
## Troubleshooting
|
|
392
|
+
|
|
393
|
+
### Config Decryption Failed
|
|
394
|
+
|
|
395
|
+
If you see "Failed to decrypt config":
|
|
396
|
+
|
|
397
|
+
**Causes:**
|
|
398
|
+
- Config moved to different machine
|
|
399
|
+
- Hostname changed
|
|
400
|
+
- MAC address changed
|
|
401
|
+
|
|
402
|
+
**Solution:**
|
|
403
|
+
```bash
|
|
404
|
+
# Reconfigure
|
|
405
|
+
waba-toolkit configure
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
Old config is automatically backed up.
|
|
409
|
+
|
|
410
|
+
### Permission Denied
|
|
411
|
+
|
|
412
|
+
```bash
|
|
413
|
+
# Install globally with sudo if needed
|
|
414
|
+
sudo npm install -g waba-toolkit
|
|
415
|
+
|
|
416
|
+
# Or use npx without install
|
|
417
|
+
npx waba-toolkit <command>
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
### Command Not Found
|
|
421
|
+
|
|
422
|
+
```bash
|
|
423
|
+
# Check installation
|
|
424
|
+
npm list -g waba-toolkit
|
|
425
|
+
|
|
426
|
+
# Reinstall
|
|
427
|
+
npm install -g waba-toolkit
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
---
|
|
431
|
+
|
|
432
|
+
## Tips
|
|
433
|
+
|
|
434
|
+
1. **Use env vars in CI/CD** - Avoid committing config files
|
|
435
|
+
2. **Save template JSONs** - Version control reusable templates
|
|
436
|
+
3. **Check fbtrace_id** - Include in support tickets
|
|
437
|
+
4. **Test with your number first** - Before sending to customers
|
|
438
|
+
|
|
439
|
+
---
|
|
440
|
+
|
|
441
|
+
## Next Steps
|
|
442
|
+
|
|
443
|
+
- [Send Messages (Library)](SENDING.md) - Use API client in code
|
|
444
|
+
- [Webhook Processing](WEBHOOKS.md) - Handle incoming webhooks
|
|
445
|
+
- [API Reference](../API_REFERENCE.md) - Complete API docs
|