waba-devtools 0.0.0-stage → 0.2.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,3 +1,860 @@
1
- # Temporary Holding Version
1
+ # WABA DevTools (`waba`)
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Retrieve and deploy or bulk-CSV-import **WhatsApp Business message templates** across several WhatsApp
4
+ Business Accounts (WABAs) — for example one WABA per pipeline stage (dev → qa → prod).
5
+
6
+ - Keep templates as JSON files in git and deploy them to every WABA of a stage.
7
+ - Copy templates straight from one stage's WABA to the next.
8
+ - Bulk-upsert template texts from a Google Sheets (CSV) export.
9
+ - Create what is missing, update what changed, leave the rest alone — a second deploy sends nothing.
10
+
11
+ It talks to Meta's Graph API directly and needs no other tool.
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ npm install -g waba-devtools
17
+ waba --help
18
+ ```
19
+
20
+ Node.js `^22.22.2 || >=24.15.0`.
21
+
22
+ ## Quick start
23
+
24
+ Before you start, you need:
25
+
26
+ - the **WABA IDs** — shown in
27
+ [Business settings](https://business.facebook.com/settings) → **Accounts** → **WhatsApp
28
+ accounts**, or found for you by [`waba discover`](#discover) once you have a token;
29
+ - an **access token** per environment — see [Access tokens](#access-tokens) for the steps.
30
+
31
+ Official Meta documentation:
32
+
33
+ | Topic | Link |
34
+ | ----------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
35
+ | Access tokens (system users) | [Access tokens](https://developers.facebook.com/documentation/business-messaging/whatsapp/access-tokens) |
36
+ | Creating the Meta app | [WhatsApp use case](https://developers.facebook.com/documentation/development/create-an-app/whatsapp-use-case) |
37
+ | Permissions | [Permissions](https://developers.facebook.com/documentation/business-messaging/whatsapp/permissions) |
38
+ | Message templates | [Template fundamentals](https://developers.facebook.com/documentation/business-messaging/whatsapp/templates/overview) |
39
+ | Template categories (Utility / Marketing) | [Template categorization](https://developers.facebook.com/documentation/business-messaging/whatsapp/templates/template-categorization) |
40
+ | Template review by Meta | [Template review](https://developers.facebook.com/documentation/business-messaging/whatsapp/templates/template-review/) |
41
+
42
+ 1. Create `.wabadevrc.json` in your project folder:
43
+
44
+ ```json
45
+ {
46
+ "stages": {
47
+ "dev": [{ "wabaId": "111111111111111", "tokenEnv": "WABA_TOKEN_NONPROD" }],
48
+ "qa": [{ "wabaId": "222222222222222", "tokenEnv": "WABA_TOKEN_NONPROD" }],
49
+ "prod": [
50
+ { "wabaId": "333333333333333", "tokenEnv": "WABA_TOKEN_PROD" },
51
+ { "wabaId": "444444444444444", "tokenEnv": "WABA_TOKEN_PROD" }
52
+ ]
53
+ }
54
+ }
55
+ ```
56
+
57
+ 2. Put the tokens into a `.env` file next to it (and add `.env` to `.gitignore`):
58
+
59
+ ```text
60
+ WABA_TOKEN_NONPROD=EAAG...
61
+ WABA_TOKEN_PROD=EAAG...
62
+ ```
63
+
64
+ 3. Check access, retrieve, preview, deploy:
65
+
66
+ ```bash
67
+ waba check
68
+ waba retrieve --from dev
69
+ waba deploy --to qa --dry-run
70
+ waba deploy --to qa
71
+ ```
72
+
73
+ Without a global install, use `npx -p waba-devtools waba check`. Plain `npx waba` could fetch an
74
+ unrelated npm package named `waba` instead.
75
+
76
+ ### Access tokens
77
+
78
+ `waba` needs a **System User access token** from the Meta business portfolio that owns your
79
+ WABAs. One-time setup (≈ 15 min), done by an admin of that portfolio. The labels below are Meta's
80
+ English ones (German in brackets). Meta follows your language setting; adding `&locale=en_US` to a
81
+ Business settings address shows it in English without changing your settings.
82
+
83
+ **Before you start, note your business portfolio ID:** open
84
+ [Business settings](https://business.facebook.com/latest/settings), check the portfolio name at the
85
+ top left, and copy the number after `business_id=` in the address bar. You need it in step 2 and
86
+ for `waba discover`.
87
+
88
+ 1. **Create a Meta app** — skip if the portfolio already has one for this. A token always belongs to
89
+ an app, also when your WABAs were connected through a provider such as Salesforce.
90
+ - [developers.facebook.com/apps](https://developers.facebook.com/apps) → **Create App** → app
91
+ name and e-mail.
92
+ - Use case: **Connect with customers through WhatsApp** → **Next**.
93
+ - Business portfolio: the one that owns your WABAs. Skip the publishing requirements with
94
+ **Next**, review, **Create app**.
95
+ 2. **Create a system user.**
96
+ - Open `https://business.facebook.com/latest/settings/system_users?business_id=<portfolio id>&locale=en_US`
97
+ (or **Settings** → **Users** → **System users** [_Nutzer → Systemnutzer_]).
98
+ - **+ Add** [_+ Hinzufügen_] (top right). The first time, Meta asks you to accept its
99
+ non-discrimination policy for system users (**I accept**).
100
+ <details><summary>Screenshot</summary>
101
+
102
+ ![System users page with the Add button](docs/images/system-user/1-system-users-add.png)
103
+
104
+ </details>
105
+
106
+ - Name, e.g. `wabadev-nonprod`, role **Employee** — it then only sees what you assign →
107
+ **Create system user**.
108
+ <details><summary>Screenshot</summary>
109
+
110
+ ![Create system user dialog: name and role Employee](docs/images/system-user/2-create-system-user.png)
111
+
112
+ </details>
113
+ 3. **Give the system user the app and the WABAs** — as little as `waba` needs.
114
+ - Select the system user. **Assign assets** [_Assets zuweisen_] is hidden in the **⋯** menu
115
+ next to **Generate token** and **Revoke tokens**.
116
+ <details><summary>Screenshot</summary>
117
+
118
+ ![The ⋯ menu next to Generate token holds Assign assets](docs/images/system-user/3-assign-assets-menu.png)
119
+
120
+ </details>
121
+
122
+ - The dialog **Select assets and assign permissions** has the asset types on the left. Tick the
123
+ asset, then switch on its permission on the right:
124
+ - **Apps** → your app → **Partial access: Test app**. That is enough to create the token (see
125
+ [Why the app?](#why-does-the-system-user-need-the-app) below).
126
+ <details><summary>Screenshot</summary>
127
+
128
+ ![App permissions: only Test app switched on](docs/images/system-user/4-assign-app.png)
129
+
130
+ </details>
131
+
132
+ - **Messaging accounts → Linked accounts** → each WABA this token should reach →
133
+ **Partial access: Message templates (view and manage)**. It covers everything `waba`
134
+ does; _Everything_ would also allow sending messages and seeing payment details. Careful:
135
+ the separate entry **WhatsApp accounts** [_WhatsApp-Konten_] lists other objects — the WABAs
136
+ are under _Messaging accounts_.
137
+ <details><summary>Screenshot</summary>
138
+
139
+ ![Messaging accounts → Linked accounts: the WABA with Message templates (view and manage)](docs/images/system-user/5-assign-waba.png)
140
+
141
+ </details>
142
+
143
+ - **Assign assets**. Check the tab **Assigned assets** [_Zugewiesene Assets_]: your app with
144
+ _Partial access (Test app)_, every WABA with _Message templates (view and manage)_.
145
+ <details><summary>Screenshot</summary>
146
+
147
+ ![Assigned assets: the app with Test app, the WABA with Message templates](docs/images/system-user/6-assigned-assets.png)
148
+
149
+ </details>
150
+
151
+ 4. **Generate the token** — **Generate token** [_Token generieren_], four steps:
152
+ - **Select app** [_App auswählen_] → your app → **Next**.
153
+ <details><summary>Screenshot</summary>
154
+
155
+ ![Generate token, step Select app](docs/images/system-user/7-token-select-app.png)
156
+
157
+ </details>
158
+
159
+ - **Set expiration** [_Ablaufdatum festlegen_]: pick **Never** [_Nie_]. Meta preselects _60 days_;
160
+ the token then simply stops working after two months.
161
+ <details><summary>Screenshot</summary>
162
+
163
+ ![Generate token, step Set expiration: Never](docs/images/system-user/8-token-expiration.png)
164
+
165
+ </details>
166
+
167
+ - **Assign permissions** [_Berechtigungen zuweisen_]: `whatsapp_business_management` only —
168
+ no `whatsapp_business_messaging`, as `waba` never sends messages. Add
169
+ `business_management` only if you want [`discover`](#discover) to find your WABAs (see below).
170
+ Then **Generate token**.
171
+ <details><summary>Screenshot</summary>
172
+
173
+ ![Generate token, step Assign permissions: whatsapp_business_management](docs/images/system-user/9-token-permissions.png)
174
+
175
+ </details>
176
+
177
+ - **Done**: copy the token with Meta's **Copy** button — not by selecting the text, which can copy
178
+ parts twice. Meta shows the token only once.
179
+
180
+ 5. **Store and test it.**
181
+ - Put it into `.env` as **one** line: `WABA_TOKEN_NONPROD=EAA…`.
182
+ - Put the WABA IDs into `.wabadevrc.json`, then run `waba check`. The ID is under the name in
183
+ **Settings → Accounts → Messaging accounts**
184
+ (`https://business.facebook.com/latest/settings/whatsapp_account?business_id=<portfolio id>`).
185
+ <details><summary>Screenshot</summary>
186
+
187
+ ![Messaging accounts: the WABA ID under its name](docs/images/system-user/11-messaging-account-id.png)
188
+
189
+ </details>
190
+
191
+ #### Why does the system user need the app?
192
+
193
+ The WABA permission decides **what** a token may change; the app decides **whether a token can
194
+ exist at all** — every Meta access token is issued for an app. Without an app role, **Generate
195
+ token** lists the app but stops at _Assign permissions_ with "No permissions available — Assign an
196
+ app role to the system user". The smallest role, **Test app**, removes that block (tested
197
+ 2026-11-22). _Manage app_ is not needed; it would let the token's owner change the app itself.
198
+
199
+ <details><summary>Screenshot: Generate token without an app role</summary>
200
+
201
+ ![No permissions available: Assign an app role to the system user](docs/images/system-user/10-token-no-app-role.png)
202
+
203
+ </details>
204
+
205
+ #### What the minimal setup can and cannot do
206
+
207
+ | Setup | `check`, `list`, `retrieve`, `deploy`, `backup`, `compare` | `discover` |
208
+ | ----------------------------------------------------------------------------------------------------- | ---------------------------------------------------------- | ---------------------------------- |
209
+ | App: Test app · WABA: Message templates (view and manage) · permission `whatsapp_business_management` | ✓ | ✗ |
210
+ | … plus app **Develop app** and permission `business_management` | ✓ | ✓ with `--business <portfolio id>` |
211
+
212
+ `discover` asks Meta to describe the token; Meta answers only when the system user can develop the
213
+ app, and it lists a portfolio's WABAs only with `business_management`. A new app may not offer
214
+ `business_management` yet: add it in the app dashboard under **Use cases → Customize → Permissions
215
+ and features**. If you know your WABA IDs, you do not need `discover` at all.
216
+
217
+ To **revoke** a token (e.g. after it was shared by mistake): select the system user → **Revoke
218
+ tokens** [_Tokens widerrufen_] → then generate a new one.
219
+
220
+ For production, repeat steps 2–5 with a second system user (e.g. `wabadev-prod`) that only gets the
221
+ prod WABAs. Then a non-production token can never change production.
222
+
223
+ A system user only reaches WABAs of **its own** portfolio. If your WABAs sit in several portfolios,
224
+ create a system user and token in each and give each stage the matching `tokenEnv`.
225
+
226
+ Where the token lives:
227
+
228
+ - **Locally:** a `.env` file in the project folder. `waba` loads it on start; variables that are
229
+ already set in your shell win.
230
+ - **CI/CD:** a secret of your pipeline, exposed as the environment variable named in `tokenEnv`.
231
+ - Tokens are never written to files, reports or `--json` output.
232
+
233
+ WABAs connected through a provider (for example Salesforce) are still owned by your portfolio, so
234
+ your own system user can be assigned to them in step 3. `waba check` confirms it works.
235
+
236
+ ## Configuration — `.wabadevrc.json`
237
+
238
+ | Key | Required | Meaning |
239
+ | --------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------ |
240
+ | `stages` | yes | Stage name → list of WABAs. A deploy to a stage goes to **all** of its WABAs (or only the ones picked with `--to-waba`). |
241
+ | `stages.<stage>[].wabaId` | yes | The WhatsApp Business Account ID. |
242
+ | `stages.<stage>[].tokenEnv` | yes | Name of the environment variable that holds the access token for this WABA. Several WABAs may share one. |
243
+ | `graphVersion` | no | Graph API version, default `v23.0`. |
244
+ | `templatesDir` | no | Folder for template files, default `templates`. |
245
+
246
+ The config never contains tokens. A WABA listed twice in the same stage is used once, with a warning.
247
+
248
+ ## File structure
249
+
250
+ There is **one set of template files for all stages**. The files contain no WABA IDs, phone
251
+ numbers or statuses, so the same file can be deployed to dev, qa and prod.
252
+
253
+ ```text
254
+ my-project/
255
+ ├── .wabadevrc.json # stages and WABA IDs
256
+ ├── .env # tokens — never commit
257
+ └── templates/
258
+ ├── order_shipped/
259
+ │ ├── en_US.json # one file per language
260
+ │ └── fr.json
261
+ └── welcome/
262
+ └── en_US.json
263
+ ```
264
+
265
+ One file = one template in one language:
266
+
267
+ ```json
268
+ {
269
+ "category": "UTILITY",
270
+ "components": [
271
+ {
272
+ "example": { "body_text": [["Jane", "A-1234"]] },
273
+ "text": "Hi {{1}}, order {{2}} is on its way.",
274
+ "type": "BODY"
275
+ }
276
+ ],
277
+ "language": "en_US",
278
+ "name": "order_shipped",
279
+ "parameter_format": "POSITIONAL"
280
+ }
281
+ ```
282
+
283
+ Typical flow: edit or `retrieve` the files → commit to git → `deploy` them stage by stage.
284
+
285
+ ## Commands
286
+
287
+ | Command | What it does |
288
+ | ----------------------- | ----------------------------------------------------------------- |
289
+ | [`discover`](#discover) | Shows the WABAs an access token can reach. Needs no config. |
290
+ | [`check`](#check) | Tests the access to every WABA. Changes nothing. |
291
+ | [`list`](#list) | Lists the templates of WABAs. Changes nothing, writes no files. |
292
+ | [`compare`](#compare) | Compares two backups: added, removed and changed templates. |
293
+ | [`backup`](#backup) | Saves a manual backup of WABAs now, without deploying. |
294
+ | [`retrieve`](#retrieve) | Downloads the templates of one WABA into files. |
295
+ | [`import`](#import) | Turns a CSV file (Google Sheets) into template files. |
296
+ | [`deploy`](#deploy) | Sends templates to WABAs (every WABA of a stage, or picked ones). |
297
+
298
+ Options that work with every command:
299
+
300
+ | Option | Meaning | Example |
301
+ | --------------- | ----------------------------------------- | ------------------- |
302
+ | `--json` | Print the result as JSON (for CI/scripts) | `waba check --json` |
303
+ | `-h, --help` | Show the help | `waba --help` |
304
+ | `-v, --version` | Show the installed version | `waba --version` |
305
+
306
+ ### `discover`
307
+
308
+ Shows every WABA an access token can manage — with its name and phone numbers. Use it to fill in
309
+ `.wabadevrc.json`. Needs no config file, only the token in an environment variable (or `.env`).
310
+
311
+ ```bash
312
+ waba discover --token-env <NAME> [--business <id>]
313
+ ```
314
+
315
+ | Option | Meaning | Example |
316
+ | -------------------- | -------------------------------------------------------------------------------- | -------------------------------- |
317
+ | `--token-env <NAME>` | **Required.** The variable that holds the token. | `--token-env WABA_TOKEN_NONPROD` |
318
+ | `--business <id>` | The business portfolio whose WABAs to list. Needed when Meta does not name them. | `--business 2218028909095892` |
319
+
320
+ Meta usually does **not** say which WABAs a token can reach:
321
+
322
+ - **Tokens with access to everything:** when a token is created through Meta's login dialog (e.g.
323
+ **Generate access token** in the app dashboard, or a connection set up by a provider) and
324
+ **All current and future WhatsApp accounts** was chosen, Meta lists no single WABAs for it. Your
325
+ admin may have chosen this long ago — nothing needs to change, just use `--business`.
326
+ - **System-user tokens:** Meta lists no WABAs either, even with each WABA assigned explicitly
327
+ (checked 2026-11).
328
+
329
+ In both cases `discover` needs the **business portfolio ID**: open
330
+ [Business settings](https://business.facebook.com/latest/settings) and copy the number after
331
+ `business_id=` in the address bar. Listing a portfolio's WABAs needs the `business_management`
332
+ permission, and a system user also needs the **Develop app** role — the minimal setup in
333
+ [Access tokens](#access-tokens) has neither (see
334
+ [What the minimal setup can and cannot do](#what-the-minimal-setup-can-and-cannot-do)). Without
335
+ them, `discover` stops with a message naming the missing piece; enter the WABA IDs by hand
336
+ instead (Settings → Accounts → Messaging accounts shows them).
337
+
338
+ When Meta describes the token, `discover` also prints its type and expiry (`--json`:
339
+ `tokenInfo: { type, expiresAt }`, `expiresAt` `null` for tokens that never expire) and warns about
340
+ user tokens, which stop working within hours.
341
+
342
+ ```bash
343
+ waba discover --token-env WABA_TOKEN_NONPROD --business 2218028909095892
344
+ # WABA 111111111111111 Acme Dev +1 555 0100 (Acme)
345
+ # WABA 222222222222222 Acme QA +1 555 0101 (Acme)
346
+ ```
347
+
348
+ ### `check`
349
+
350
+ Tests for each WABA: is the token set, can the WABA be reached, can its templates be read.
351
+ Read-only.
352
+
353
+ It also warns (`WARN`, exit code still 0) when Meta has disabled the WABA. Meta keeps answering
354
+ reads for a disabled WABA and even reports it as active. Only the account review (`REJECTED`) and
355
+ the WABA's health error 141014 show it. With `--json`, each entry has a `warnings` list
356
+ (`[{ "code": "WABA_DISABLED", "message": "…" }]`). Missing payment details and business
357
+ verification do not cause a warning. Unverified test portfolios always show them, and they only
358
+ block sending messages, which waba never does.
359
+
360
+ ```bash
361
+ waba check [--stage <stage>]
362
+ ```
363
+
364
+ | Option | Meaning | Example |
365
+ | ----------------- | ---------------------------------------------- | ----------------------- |
366
+ | `--stage <stage>` | Only check this stage. Without it: all stages. | `waba check --stage qa` |
367
+
368
+ ```bash
369
+ waba check # all stages
370
+ waba check --stage prod # only the prod WABAs
371
+ ```
372
+
373
+ ### `list`
374
+
375
+ Lists the templates of one or more WABAs: name, language, category and status. Fast — it skips the
376
+ template content and writes no files.
377
+
378
+ ```bash
379
+ waba list --from <stage> | --from-waba <id> | --to <stage> | --to-waba <id>…
380
+ ```
381
+
382
+ | Option | Meaning | Example |
383
+ | ------------------ | ----------------------------- | ----------------------------- |
384
+ | `--from <stage>` | The WABA of this stage. | `--from dev` |
385
+ | `--from-waba <id>` | This WABA. | `--from-waba 333333333333333` |
386
+ | `--to <stage>` | Every WABA of this stage. | `--to prod` |
387
+ | `--to-waba <id>` | These WABAs. Repeat for more. | `--to-waba 1… --to-waba 2…` |
388
+
389
+ ```bash
390
+ waba list --to prod # all prod WABAs
391
+ waba list --from dev --json # for scripts
392
+ ```
393
+
394
+ ### `compare`
395
+
396
+ Compares two backup sets and lists which templates were **added**, **removed** and
397
+ **changed** — and for changed ones, which fields changed, with the value before and after. The older
398
+ set is always "before", whatever order you give them in, so a deleted template never shows as added.
399
+ Line-ending differences do not count. Two sets of different WABAs can be compared too (e.g. qa vs
400
+ prod).
401
+
402
+ With `--live`, one backup set is compared with what is in the WABA **right now** — the live state is
403
+ only read, never saved. By default that is the WABA the backup was taken from; `--waba <id>` compares
404
+ with another one (e.g. a qa backup with prod today). Either WABA must be in `.wabadevrc.json`, because its
405
+ token comes from there.
406
+
407
+ Two WABAs can also be compared as they are **right now** — both are only read, nothing is saved. Here
408
+ there is no time order: you choose which WABA is "before" and which is "after" (e.g. qa before, prod
409
+ after: "what would change in prod").
410
+
411
+ ```bash
412
+ waba compare <backup set> <backup set> [--json]
413
+ waba compare <backup set> --live [--waba <id>] [--json]
414
+ waba compare --before-waba <id> --after-waba <id> [--json]
415
+ ```
416
+
417
+ | Option | Meaning | Example |
418
+ | -------------------- | ------------------------------------------------------- | ------------------------------- |
419
+ | `--live` | Compare the backup with the WABA's templates right now. | `--live` |
420
+ | `--waba <id>` | With `--live`: another WABA than the backup's own. | `--live --waba 444444444444444` |
421
+ | `--before-waba <id>` | Compare two WABAs right now: this one is "before". | `--before-waba 222222222222222` |
422
+ | `--after-waba <id>` | … and this one is "after". | `--after-waba 444444444444444` |
423
+
424
+ In `--json` output the two sides are `before` and `after` (for two backups: the older and the newer one).
425
+
426
+ ```bash
427
+ waba compare backups/444…_2026-11-20T18-26-04-123Z_before backups/444…_2026-11-20T18-26-04-123Z_after
428
+ # Before: WABA 444444444444444 (prod) backup 2026-11-20T18:26:04.512Z before
429
+ # After: WABA 444444444444444 (prod) backup 2026-11-20T18:26:09.871Z after
430
+ # Added (1):
431
+ # summer_sale (en_US)
432
+ # Removed (0):
433
+ # Changed (1):
434
+ # order_shipped (en_US)
435
+ # Body text:
436
+ # before: Hi {{1}}, your order shipped.
437
+ # after: Hi {{1}}, your order {{2}} shipped.
438
+ # Unchanged: 41
439
+ ```
440
+
441
+ ### `backup`
442
+
443
+ Saves a manual backup **now**, without deploying anything: one backup set per WABA, named
444
+ `<wabaId>_<time>_manual` (see [Backups](#backups)).
445
+
446
+ ```bash
447
+ waba backup --stage <stage> | --waba <id>… --backup <folder> [--json]
448
+ ```
449
+
450
+ | Option | Meaning | Example |
451
+ | ------------------- | --------------------------------------- | ------------------------ |
452
+ | `--stage <stage>` | Every WABA of this stage. | `--stage prod` |
453
+ | `--waba <id>` | This WABA. Repeat for more. | `--waba 444444444444444` |
454
+ | `--backup <folder>` | **Required.** Where the backup sets go. | `--backup backups` |
455
+
456
+ ```bash
457
+ waba backup --stage prod --backup backups
458
+ ```
459
+
460
+ ### `retrieve`
461
+
462
+ Downloads the templates of one WABA into `templates/<name>/<language>.json`. Commit these files to
463
+ git.
464
+
465
+ ```bash
466
+ waba retrieve --from <stage> | --from-waba <id> [-m <name>]
467
+ ```
468
+
469
+ | Option | Meaning | Example |
470
+ | ----------------------- | ------------------------------------------------------------------------------------ | ----------------------------- |
471
+ | `--from <stage>` | The stage to download from. Works when the stage has exactly one WABA. | `--from dev` |
472
+ | `--from-waba <id>` | The WABA to download from. No `--from` needed (see [Picking WABAs](#picking-wabas)). | `--from-waba 333333333333333` |
473
+ | `-m, --template <name>` | Only this template (all its languages). Repeat for more. | `-m order_shipped -m welcome` |
474
+
475
+ Give `--from` or `--from-waba` (or both). A stage with several WABAs needs `--from-waba` — without
476
+ it, retrieve stops with an error and writes nothing.
477
+
478
+ ```bash
479
+ waba retrieve --from dev # all templates of dev
480
+ waba retrieve --from dev -m order_shipped # just one template
481
+ waba retrieve --from-waba 333333333333333 # one WABA of prod
482
+ ```
483
+
484
+ Good to know:
485
+
486
+ - Files are overwritten with what is in the WABA.
487
+ - IDs and statuses are not saved — only what defines the template.
488
+ - Files of templates that no longer exist in the WABA are not deleted.
489
+
490
+ ### `import`
491
+
492
+ Reads a CSV file and writes one template file per row. Nothing is sent to Meta.
493
+
494
+ ```bash
495
+ waba import --csv <file>
496
+ ```
497
+
498
+ | Option | Meaning | Example |
499
+ | -------------- | ----------------------------------- | ------------------------- |
500
+ | `--csv <file>` | **Required.** The CSV file to read. | `--csv exports/sheet.csv` |
501
+
502
+ ```bash
503
+ waba import --csv sheet.csv
504
+ ```
505
+
506
+ Good to know:
507
+
508
+ - For a template file that already exists, only the parts the sheet has columns for are
509
+ replaced (see [CSV columns](#csv-columns)); the category stays.
510
+ - Rows with errors are listed with their row number and left out; all other rows are still
511
+ imported. `deploy --csv --dry-run` shows the same list before anything is sent. With
512
+ `deploy --csv --stop-on-error` (library: `stopOnRowErrors: true`), one row with an error stops the
513
+ whole deploy: every target reports why, nothing is sent, and the report has
514
+ `stoppedByRowErrors: true`.
515
+ - The file is cleaned up the same way sfmc-dataloader does it: empty rows are skipped, and empty
516
+ columns on the right (no header, no values) are removed. A value in such a column is an error.
517
+ The report says what was removed.
518
+
519
+ #### CSV columns
520
+
521
+ Export from Google Sheets with **File → Download → Comma-separated values (.csv)**. Header names
522
+ are not case-sensitive. Other columns (e.g. `Brand`) are ignored.
523
+
524
+ | Column | Required | Content | Example |
525
+ | ------------------------------- | ---------------------------------------------------- | ---------------------------------------------------------- | -------------------------------- |
526
+ | `Template name` | yes | Letters, digits, `_` | `order_shipped` |
527
+ | `Category` | yes | `Utility` or `Marketing` (used when a template is created) | `Utility` |
528
+ | `Language` | yes | Meta language code | `en_US`, `fr`, `it` |
529
+ | `Body` (or `Meta Template`) | yes | Message text, variables as `{{1}}`, `{{2}}`, … or named | `Hi {{1}}, order {{2}} shipped.` |
530
+ | `Body examples` (or `Examples`) | yes; filled when the body has variables | One example per variable, separated by `\|` | `Jane\|A-1234` |
531
+ | `Header` | no | Text header, at most one variable (`{{1}}` or named) | `Your order {{1}}` |
532
+ | `Header example` | with `Header`; filled when the header has a variable | Example for the header variable | `A-1234` |
533
+ | `Footer` | no | Short text, no variables | `Reply STOP to opt out` |
534
+ | `Quick replies` | no | Button labels, separated by `\|` | `Yes\|No\|Later` |
535
+ | `URL button` | no | `label\|URL`; the URL may end in `{{1}}` | `Track\|https://ex.com/t/{{1}}` |
536
+ | `URL example` | with `URL button`; filled when the URL has `{{1}}` | Example for the URL variable | `A-1234` |
537
+ | `Call button` | no | `label\|phone number` with country code | `Call us\|+15550100` |
538
+
539
+ - **Columns decide what is replaced** — for the whole sheet, by its header row. The sheet sets the
540
+ body, plus the header, the footer and each kind of button **if it has that column**. Anything
541
+ without a column stays as it is in the existing template: a sheet with only `Quick replies`
542
+ replaces quick replies but keeps URL and call buttons; an old sheet with only body columns touches
543
+ nothing else. A column that exists but is empty in a row **removes** that part — in template files
544
+ (`import`) and in WABAs (`deploy --csv`) alike.
545
+ - Every cell is trimmed, and line breaks inside a cell are stored as plain `\n` (no Windows `\r\n`),
546
+ so a re-import of the same sheet does not count as a change.
547
+ - Not possible in a sheet: image, video or document headers, authentication and carousel templates.
548
+
549
+ #### Examples are checked
550
+
551
+ Meta accepts a template without examples, but WhatsApp Manager then refuses to edit it until examples
552
+ are added. So the example columns are required (`Body examples` always, `Header example` when the
553
+ sheet has `Header`, `URL example` when it has `URL button`), and every row is checked before anything
554
+ is sent:
555
+
556
+ - **Error, the row is left out:** a variable of the body, the header or the URL without an example.
557
+ One message per row names every missing one, e.g.
558
+ `row 7: Body examples: no example for {{2}}, {{3}} (one per variable in the order {{1}}, {{2}}, …)`.
559
+ - **Warning, the row is used:** examples no variable needs — more numbered examples than variables,
560
+ an unknown name (`{{city}} is not in the text`), a name given twice (the first one is used), a part
561
+ that is not `name=value`, or an example for a header or URL without a variable.
562
+
563
+ #### Named variables
564
+
565
+ A row may use **named** variables instead of numbers — Meta calls this the "Name" variable type. The
566
+ format is decided per row from its body and header:
567
+
568
+ | Variables in body and header | Result |
569
+ | ---------------------------------------------------------------------------- | --------------------------------- |
570
+ | none, or all numbered (`{{1}}`, `{{2}}`) | numbered (as before) |
571
+ | all named: lower-case letters, digits and `_`, starting with a letter | named (`parameter_format: NAMED`) |
572
+ | mixed, or a name with capitals, spaces or a leading digit (`{{First Name}}`) | row error |
573
+
574
+ With named variables, write the examples as `name=value`, separated by `|`, in any order — every
575
+ variable exactly once:
576
+
577
+ | Column | Example |
578
+ | ---------------- | ------------------------------------------------ |
579
+ | `Body` | `Hi {{first_name}}, order {{order_id}} shipped.` |
580
+ | `Body examples` | `order_id=A-1234\|first_name=Jane` |
581
+ | `Header` | `Order {{order_id}}` |
582
+ | `Header example` | `order_id=A-1234` |
583
+
584
+ The URL button keeps `{{1}}` in both formats.
585
+
586
+ ### `deploy`
587
+
588
+ Makes the target WABAs match the source: creates missing templates and updates
589
+ changed ones. Everything else is left alone.
590
+
591
+ ```bash
592
+ waba deploy <target> [<source> | --csv <file>] [-m <name>] [--dry-run] [--prune [--yes]]
593
+
594
+ # <target>: --to <stage> and/or --to-waba <id>…
595
+ # <source>: --from <stage> and/or --from-waba <id> (default: the template files)
596
+ ```
597
+
598
+ Where the templates come from:
599
+
600
+ | Source | Command | Uses the files on disk? |
601
+ | ------------------------ | ------------------------------------- | -------------------------------------------------------- |
602
+ | Template files (default) | `waba deploy --to qa` | Yes — reads `templates/` |
603
+ | Another WABA | `waba deploy --from dev --to qa` | No — live clone from WABA to WABA, files are not touched |
604
+ | A CSV file | `waba deploy --csv sheet.csv --to qa` | No — reads the CSV, files are not touched |
605
+
606
+ | Option | Meaning | Example |
607
+ | ----------------------- | ------------------------------------------------------------------------------------------------------------ | -------------------------------------------------- |
608
+ | `--to <stage>` | Target: every WABA of this stage. | `--to qa` |
609
+ | `--to-waba <id>` | Target: only this WABA. Repeat for more. No `--to` needed; with `--to` it must be in that stage. | `--to-waba 444444444444444` |
610
+ | `--from <stage>` | Source: the WABA of this stage (instead of the files). | `--from dev` |
611
+ | `--from-waba <id>` | Source: this WABA. No `--from` needed; required when the `--from` stage has several. | `--from-waba 333333333333333` |
612
+ | `--csv <file>` | Take the templates from a CSV file (see [CSV columns](#csv-columns)). | `--csv sheet.csv` |
613
+ | `--stop-on-error` | With `--csv`: when any row has an error, send nothing at all (default: leave those rows out, send the rest). | `--stop-on-error` |
614
+ | `-m, --template <name>` | Only this template (all its languages). Repeat for more. | `-m order_shipped` |
615
+ | `--dry-run` | Only show what would happen, with each template's status at Meta. Sends nothing. | `--dry-run` |
616
+ | `--prune` | Also delete templates that exist only in the target (only with `--yes`; preview with `--dry-run`). | `--prune` |
617
+ | `--yes` | With `--prune`: really delete. | `--prune --yes` |
618
+ | `--expect <file>` | Send only what a previous `--dry-run` showed (see [Confirmed preview](#confirmed-preview)). | `--expect preview.json` |
619
+ | `--backup <folder>` | Before changing a WABA, save all its templates as a backup set in `<folder>` (see [Backups](#backups)). | `--backup backups` |
620
+ | `--backup-after` | With `--backup`: also save each changed WABA after the changes (`…_after`). | `--backup backups --backup-after` |
621
+ | `--from-dir <folder>` | Source: template files in this folder instead of `templates/` — e.g. a backup set. | `--from-dir backups/444…_2026-11-20T18-26-04-123Z` |
622
+ | `--limit-percent <n>` | Share of Meta's limits to use, 1–100 (default 80). See [Hourly limits](#hourly-limits-and-batches). | `--limit-percent 50` |
623
+ | `--wait` | Keep running and send each batch when its time comes (not with `--dry-run` / `--expect`). | `--wait` |
624
+
625
+ ```bash
626
+ waba deploy --to qa --dry-run # preview
627
+ waba deploy --to qa # all files → every qa WABA
628
+ waba deploy --to prod -m order_shipped # one template only
629
+ waba deploy --from qa --to prod # copy qa → prod
630
+ waba deploy --csv sheet.csv --to dev # CSV → dev, no files needed
631
+ waba deploy --from qa --to prod --prune --dry-run # preview, incl. what would be deleted
632
+ waba deploy --from qa --to prod --prune --yes # copy and delete the extras
633
+ waba deploy --to-waba 444444444444444 # files → one WABA only
634
+
635
+ # One WABA to one other WABA — any stages:
636
+ waba deploy --from-waba 333333333333333 --to-waba 444444444444444
637
+ ```
638
+
639
+ #### Picking WABAs
640
+
641
+ You can name WABAs directly with `--from-waba` / `--to-waba`. `waba` looks each one up in
642
+ `.wabadevrc.json` to find its token:
643
+
644
+ | The WABA is listed in… | Result |
645
+ | -------------------------------------------- | -------------------------------------------- |
646
+ | one stage | used |
647
+ | several stages, all with the same `tokenEnv` | used — the token is the same anyway |
648
+ | several stages with different `tokenEnv` | error: add `--from <stage>` / `--to <stage>` |
649
+ | no stage | error: add it to `.wabadevrc.json` |
650
+
651
+ With a stage given as well, the WABA must be part of that stage — a useful safety check in
652
+ scripts.
653
+
654
+ #### What happens to each template
655
+
656
+ Templates are matched by **name + language**.
657
+
658
+ | In the target WABA | Result |
659
+ | ---------------------------------------------- | --------------------------------------------- |
660
+ | Missing | **create** |
661
+ | Same content | **unchanged** |
662
+ | Different, status APPROVED, REJECTED or PAUSED | **update** |
663
+ | Different, other status (e.g. PENDING) | **blocked** — not sent, exit code 1 |
664
+ | Media header, authentication (OTP) or carousel | **skipped** — not supported yet |
665
+ | Only in the target | **extra** — only deleted with `--prune --yes` |
666
+
667
+ Good to know:
668
+
669
+ - **Category** is only set when a template is created. Meta does not allow changing it later.
670
+ - Created and updated templates are reviewed by Meta again and show `PENDING` for a while. Run
671
+ `--dry-run` later to see the new status.
672
+ - With `--csv`, only the parts the sheet has columns for are replaced in existing templates (see
673
+ [CSV columns](#csv-columns)).
674
+ - One failing template does not stop the others. The report shows Meta's error.
675
+
676
+ #### Hourly limits and batches
677
+
678
+ Meta allows **100 template creates per WABA per hour** and throttles an app that calls its API too often
679
+ for a WABA. `waba` stays below both, by default at **80 %** (`--limit-percent <n>`, 1–100; a warning is
680
+ printed above 80):
681
+
682
+ - **Template creates:** at most `floor(100 × percent / 100)` creates per target WABA in any hour — 80
683
+ by default. Updates and deletes are not limited by this (they still count as API calls, see below).
684
+ Before writing, `waba` counts the WABA's templates whose `last_updated_time` (from Meta) is within
685
+ the last hour, so templates created by colleagues or other tools count too. Meta's list cannot tell a
686
+ create from an edit, so a template edited in the last hour counts as well — unless the caller logged
687
+ that edit (`recentWrites` with `action: 'update'`, as the desktop app does). The CLI keeps no log:
688
+ right after a big update run, its next run counts those edits and may wait longer than needed.
689
+ - **API usage:** Meta reports its usage in the `X-Business-Use-Case-Usage` header of every answer
690
+ (calls, CPU time, total time, in percent of the hourly allowance). The report shows the highest
691
+ values per WABA, with a warning from 50 %. When any of them reaches the limit percentage, or Meta
692
+ names a time to regain access, `waba` stops writing to that WABA. On Meta's throttle error `80008` it
693
+ stops too.
694
+
695
+ What does not fit is **deferred**: not sent, reported with the time it can go (`deferred until …`),
696
+ plus the batch schedule and the time to run again. The exit code is `1` while anything is deferred.
697
+ `--dry-run` shows the same schedule, so you know before you start:
698
+
699
+ ```text
700
+ qa — WABA 444444444444444:
701
+ hourly budget (80 %): 0 of 80 creates in the last hour, 80 left
702
+ schedule: 3 batches: 80 now, 80 at 15:05, 40 at 16:05
703
+ create welcome_1 (en_US)
704
+ …
705
+ create welcome_81 (en_US) deferred until 2026-11-27T14:05:12.000Z — hourly create limit used up
706
+ Deferred templates: run the same command again after 15:05 …
707
+ ```
708
+
709
+ To continue, run the **same command** again after that time: deploy only sends what is still missing
710
+ or different, so it picks up exactly the deferred templates. Or add `--wait`: `waba` then stays running,
711
+ prints how long it waits, and sends each batch when its time comes until nothing is deferred. Ctrl+C
712
+ is safe (each create is independent; rerun to continue). Mind CI job time limits — a 250-template
713
+ deploy takes about three hours. With `--backup`, every batch writes its own backup set.
714
+
715
+ Not visible to `waba`: a template that was created **and deleted again** within the hour (Meta lists it
716
+ no longer, but it still counts at Meta). Leave room for that with the default 80 %. The desktop app
717
+ keeps its own write log for this and passes it to the library as `recentWrites`.
718
+
719
+ #### Backups
720
+
721
+ Meta keeps no history of templates: once a template is updated, its old text is gone. With
722
+ `--backup <folder>`, every target WABA that is about to change is saved first — **all** its templates,
723
+ in the same format as `retrieve`. Each WABA gets its own **backup set**, named by its WABA ID, the
724
+ time of the run (UTC) and `before`. With `--backup-after`, a second set `…_after` is saved once the
725
+ changes are sent — so you always have the state before and after:
726
+
727
+ ```text
728
+ backups/
729
+ ├── 444444444444444_2026-11-20T18-26-04-123Z_before/
730
+ │ ├── manifest.json # date, WABA, stage, source, list of templates with status
731
+ │ ├── order_shipped/
732
+ │ │ └── en_US.json
733
+ │ └── welcome/
734
+ │ └── en_US.json
735
+ └── 444444444444444_2026-11-20T18-26-04-123Z_after/
736
+ ```
737
+
738
+ Use the same `--backup` folder every time; new sets are added next to the old ones and never
739
+ overwritten. If a set cannot be written, nothing is sent to that WABA. WABAs without changes get no
740
+ set.
741
+
742
+ ```bash
743
+ waba deploy --from qa --to prod --backup backups # before only
744
+ waba deploy --from qa --to prod --backup backups --backup-after # before and after
745
+ ```
746
+
747
+ `manifest.json` is written automatically: it lets you (and the desktop app) see what a set contains,
748
+ when and from where it was taken, and each template's status at that moment.
749
+
750
+ To restore, deploy a set back with `--from-dir` (add `-m <name>` to restore only some templates):
751
+
752
+ ```bash
753
+ waba deploy --from-dir backups/444444444444444_2026-11-20T18-26-04-123Z_before --to-waba 444444444444444 --dry-run
754
+ waba deploy --from-dir backups/444444444444444_2026-11-20T18-26-04-123Z_before --to-waba 444444444444444
755
+ ```
756
+
757
+ - A restore is an edit too: Meta reviews the templates again and counts it against its edit limits.
758
+ - Templates created after the backup stay; add `--prune --yes` to get back exactly the saved set.
759
+ - Media, authentication and carousel templates are saved, but cannot be restored (`skipped`).
760
+ - `--backup` does nothing together with `--dry-run`; `--backup-after` needs `--backup`.
761
+ - If the after-backup fails, the changes stay sent; the report shows a WARNING.
762
+ - Manual backups without a deployment: [`waba backup`](#backup) (sets named `…_manual`).
763
+
764
+ #### Confirmed preview
765
+
766
+ Between a preview and the real run, someone else may change a WABA. With `--expect`, the real run sends
767
+ **only what the preview showed**: save the `--json` output of `deploy --dry-run`, review it, then pass
768
+ it to the real deploy with the same options.
769
+
770
+ ```bash
771
+ waba deploy --from qa --to prod --dry-run --json > preview.json
772
+ waba deploy --from qa --to prod --expect preview.json
773
+ ```
774
+
775
+ - For each WABA, the creates, updates and deletes (by name and language) must be exactly the ones in
776
+ the preview, **and nothing may differ from what the preview showed**: the preview stores a short
777
+ `fingerprint` per create, update and delete — a hash of the content to send and, for updates and
778
+ deletes, of the template in the WABA as it was at preview time. The real run compares them. So a
779
+ change on either side is caught: an edit to your template files or CSV, a colleague editing a template
780
+ in the WABA, or a template that was deleted and created again before your delete runs. If anything differs, **nothing** is sent to that WABA and it
781
+ reports `changed since preview — run the preview again` (exit code 1). Other WABAs are not affected.
782
+ - A WABA that was not in the preview gets nothing if it would need changes.
783
+ - The file is the whole `--json` report of `deploy --dry-run`, or just its `targets` list:
784
+ `[{ "wabaId": "…", "actions": [{ "name": "…", "language": "…", "action": "create", "fingerprint": "…" }] }]`.
785
+ Other fields are ignored. A preview without any fingerprints (older files) still works, but then only
786
+ the actions are checked; in a preview with fingerprints, every create, update and delete needs its own. A report of a real (not dry-run) deploy is refused.
787
+
788
+ #### `--prune` safety
789
+
790
+ - Works with the template files and with `--from` — whenever the whole set is deployed.
791
+ - Refused together with `-m` or `--csv`: those only send some templates, so "missing in the
792
+ source" would not mean "should be deleted".
793
+ - Refused when the source has no templates.
794
+ - Media, authentication and carousel templates are never deleted.
795
+ - Without `--yes`, nothing is deleted — but creates and updates **are** sent. To see everything first,
796
+ use `--prune --dry-run`.
797
+ - Meta may block a deleted template's name for a while, so it cannot be created again right away.
798
+
799
+ ## Output and exit codes
800
+
801
+ `--json` prints the full report as JSON (for scripts and CI). Each source and target has `stage`
802
+ (text) and `stages` (list) — a WABA found in several stages lists all of them in `stages`.
803
+
804
+ | Exit code | Meaning |
805
+ | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
806
+ | `0` | Everything succeeded. |
807
+ | `1` | Something failed: a Meta error, a blocked template, a deferred template (hourly limit), a CSV row error, or a target WABA that could not be reached (incl. its token variable not being set). |
808
+ | `2` | Wrong usage or configuration (unknown stage, missing option, invalid config, missing token for the source WABA, …). |
809
+
810
+ When a command stops with an error, `--json` prints `{ "command", "ok": false, "error" }`, plus a
811
+ stable `code` where one exists, so scripts need not match the text: `TOKEN_INVALID`,
812
+ `TOKEN_MISSING_PERMISSION`, `TOKEN_INFO_REFUSED`, `BUSINESS_ID_REQUIRED`, `BUSINESS_HAS_NO_WABAS`
813
+ (all from `discover`).
814
+
815
+ ## Meta limits to know
816
+
817
+ - Every WABA reviews its templates on its own: the same template can be approved in one WABA and
818
+ rejected or re-categorized in another.
819
+ - Meta limits how many templates can be created per WABA per hour (100), and how often approved
820
+ templates can be edited. `deploy` only sends what changed and stays below the hourly limits (see
821
+ [Hourly limits and batches](#hourly-limits-and-batches)).
822
+ - A template that is still in review (`PENDING`) cannot be edited — Meta refuses it, so `waba`
823
+ shows it as `blocked` without sending.
824
+ - Meta adds sample templates to new WABAs (`hello_world`, `jaspers_market_*`) and never lets you edit
825
+ or delete them. `waba` shows a change to them as `skipped` and keeps them with `--prune`.
826
+
827
+ ## Using it as a library
828
+
829
+ The desktop app uses `waba-devtools` as a library (`import { deploy, … } from 'waba-devtools'`). Besides
830
+ the commands, 0.2.0 adds:
831
+
832
+ - `deploy({ …, limitPercent, recentWrites })` — `limitPercent` as `--limit-percent`; `recentWrites`
833
+ is the caller's own write log, `[{ wabaId, name, language, at, action? }]` (`action`: `'create'`,
834
+ the default, or `'update'`). Logged creates count when younger than an hour and not already
835
+ counted from Meta's list; a logged update keeps that template's recent `last_updated_time` from
836
+ counting. Each target in the report has
837
+ `budget: { limitPercent, limit, usedLastHour, left, countedAt, schedule }` (`countedAt`: the counted
838
+ writes, oldest first; `schedule`: `[{ at, count }]`), `usage: { callCount, totalCputime, totalTime,
839
+ regainAccessMinutes }` when Meta sent the header, and `throttled: { retryAfter, error }` when writing
840
+ stopped. Deferred actions have `result: 'deferred'`, `deferredReason` (`budget` or `throttled`) and
841
+ `retryAfter`; sent ones have `at`.
842
+ - `planBatches({ wanted, limit, countedAt, now })` → `[{ at, count }]` — the batch schedule. Slots
843
+ that free up less than a minute apart are one batch, sent when the last one it needs is free.
844
+ - `writeBudget({ limit, live, recentWrites, now })` → `{ limit, usedLastHour, left, times }` — the
845
+ creates of one WABA in the last hour, counted like `deploy` does, from its live templates (listed
846
+ with `last_updated_time`) and the caller's write log. For a usage overview without deploying.
847
+ - `writesPerHour(limitPercent)`, `META_CREATES_PER_HOUR`, `DEFAULT_LIMIT_PERCENT`.
848
+ - `templatesToCsv(templates)` → `{ csv, skipped: [{ name, language, reason }] }` — writes templates in
849
+ the [CSV columns](#csv-columns), so a sheet can be edited and imported again. Every row reads back as
850
+ the same template; what the columns cannot hold (media headers, carousels, authentication, other
851
+ button types, …) is listed in `skipped`.
852
+
853
+ ## Not supported yet
854
+
855
+ - Templates with an image, video or document header.
856
+ - Authentication (OTP) and carousel templates.
857
+
858
+ ## License
859
+
860
+ MIT © Jörn Berkefeld