waba-devtools 0.0.0-stage → 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/README.md CHANGED
@@ -1,3 +1,747 @@
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 restore point 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 (restore points) 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 restore point **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. All other rows are still imported.
511
+ - The file is cleaned up the same way sfmc-dataloader does it: empty rows are skipped, and empty
512
+ columns on the right (no header, no values) are removed. A value in such a column is an error.
513
+ The report says what was removed.
514
+
515
+ #### CSV columns
516
+
517
+ Export from Google Sheets with **File → Download → Comma-separated values (.csv)**. Header names
518
+ are not case-sensitive. Other columns (e.g. `Brand`) are ignored.
519
+
520
+ | Column | Required | Content | Example |
521
+ | ------------------------------- | --------------------------- | ---------------------------------------------------------- | -------------------------------- |
522
+ | `Template name` | yes | Letters, digits, `_` | `order_shipped` |
523
+ | `Category` | yes | `Utility` or `Marketing` (used when a template is created) | `Utility` |
524
+ | `Language` | yes | Meta language code | `en_US`, `fr`, `it` |
525
+ | `Body` (or `Meta Template`) | yes | Message text, variables as `{{1}}`, `{{2}}`, … | `Hi {{1}}, order {{2}} shipped.` |
526
+ | `Body examples` (or `Examples`) | when the body has variables | One example per variable, separated by `\|` | `Jane\|A-1234` |
527
+ | `Header` | no | Text header, at most one variable `{{1}}` | `Your order {{1}}` |
528
+ | `Header example` | when the header has `{{1}}` | Example for the header variable | `A-1234` |
529
+ | `Footer` | no | Short text, no variables | `Reply STOP to opt out` |
530
+ | `Quick replies` | no | Button labels, separated by `\|` | `Yes\|No\|Later` |
531
+ | `URL button` | no | `label\|URL`; the URL may end in `{{1}}` | `Track\|https://ex.com/t/{{1}}` |
532
+ | `URL example` | when the URL has `{{1}}` | Example for the URL variable | `A-1234` |
533
+ | `Call button` | no | `label\|phone number` with country code | `Call us\|+15550100` |
534
+
535
+ - **Columns decide what is replaced** — for the whole sheet, by its header row. The sheet sets the
536
+ body, plus the header, the footer and each kind of button **if it has that column**. Anything
537
+ without a column stays as it is in the existing template: a sheet with only `Quick replies`
538
+ replaces quick replies but keeps URL and call buttons; an old sheet with only body columns touches
539
+ nothing else. A column that exists but is empty in a row **removes** that part — in template files
540
+ (`import`) and in WABAs (`deploy --csv`) alike.
541
+ - Every cell is trimmed, and line breaks inside a cell are stored as plain `\n` (no Windows `\r\n`),
542
+ so a re-import of the same sheet does not count as a change.
543
+ - Not possible in a sheet: image, video or document headers, named variables, authentication and
544
+ carousel templates.
545
+
546
+ ### `deploy`
547
+
548
+ Makes the target WABAs match the source: creates missing templates and updates
549
+ changed ones. Everything else is left alone.
550
+
551
+ ```bash
552
+ waba deploy <target> [<source> | --csv <file>] [-m <name>] [--dry-run] [--prune [--yes]]
553
+
554
+ # <target>: --to <stage> and/or --to-waba <id>…
555
+ # <source>: --from <stage> and/or --from-waba <id> (default: the template files)
556
+ ```
557
+
558
+ Where the templates come from:
559
+
560
+ | Source | Command | Uses the files on disk? |
561
+ | ------------------------ | ------------------------------------- | -------------------------------------------------------- |
562
+ | Template files (default) | `waba deploy --to qa` | Yes — reads `templates/` |
563
+ | Another WABA | `waba deploy --from dev --to qa` | No — live clone from WABA to WABA, files are not touched |
564
+ | A CSV file | `waba deploy --csv sheet.csv --to qa` | No — reads the CSV, files are not touched |
565
+
566
+ | Option | Meaning | Example |
567
+ | ----------------------- | ------------------------------------------------------------------------------------------------------- | -------------------------------------------------- |
568
+ | `--to <stage>` | Target: every WABA of this stage. | `--to qa` |
569
+ | `--to-waba <id>` | Target: only this WABA. Repeat for more. No `--to` needed; with `--to` it must be in that stage. | `--to-waba 444444444444444` |
570
+ | `--from <stage>` | Source: the WABA of this stage (instead of the files). | `--from dev` |
571
+ | `--from-waba <id>` | Source: this WABA. No `--from` needed; required when the `--from` stage has several. | `--from-waba 333333333333333` |
572
+ | `--csv <file>` | Take the templates from a CSV file (see [CSV columns](#csv-columns)). | `--csv sheet.csv` |
573
+ | `-m, --template <name>` | Only this template (all its languages). Repeat for more. | `-m order_shipped` |
574
+ | `--dry-run` | Only show what would happen, with each template's status at Meta. Sends nothing. | `--dry-run` |
575
+ | `--prune` | Also delete templates that exist only in the target (only with `--yes`; preview with `--dry-run`). | `--prune` |
576
+ | `--yes` | With `--prune`: really delete. | `--prune --yes` |
577
+ | `--expect <file>` | Send only what a previous `--dry-run` showed (see [Confirmed preview](#confirmed-preview)). | `--expect preview.json` |
578
+ | `--backup <folder>` | Before changing a WABA, save all its templates as a backup set in `<folder>` (see [Backups](#backups)). | `--backup backups` |
579
+ | `--backup-after` | With `--backup`: also save each changed WABA after the changes (`…_after`). | `--backup backups --backup-after` |
580
+ | `--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` |
581
+
582
+ ```bash
583
+ waba deploy --to qa --dry-run # preview
584
+ waba deploy --to qa # all files → every qa WABA
585
+ waba deploy --to prod -m order_shipped # one template only
586
+ waba deploy --from qa --to prod # copy qa → prod
587
+ waba deploy --csv sheet.csv --to dev # CSV → dev, no files needed
588
+ waba deploy --from qa --to prod --prune --dry-run # preview, incl. what would be deleted
589
+ waba deploy --from qa --to prod --prune --yes # copy and delete the extras
590
+ waba deploy --to-waba 444444444444444 # files → one WABA only
591
+
592
+ # One WABA to one other WABA — any stages:
593
+ waba deploy --from-waba 333333333333333 --to-waba 444444444444444
594
+ ```
595
+
596
+ #### Picking WABAs
597
+
598
+ You can name WABAs directly with `--from-waba` / `--to-waba`. `waba` looks each one up in
599
+ `.wabadevrc.json` to find its token:
600
+
601
+ | The WABA is listed in… | Result |
602
+ | -------------------------------------------- | -------------------------------------------- |
603
+ | one stage | used |
604
+ | several stages, all with the same `tokenEnv` | used — the token is the same anyway |
605
+ | several stages with different `tokenEnv` | error: add `--from <stage>` / `--to <stage>` |
606
+ | no stage | error: add it to `.wabadevrc.json` |
607
+
608
+ With a stage given as well, the WABA must be part of that stage — a useful safety check in
609
+ scripts.
610
+
611
+ #### What happens to each template
612
+
613
+ Templates are matched by **name + language**.
614
+
615
+ | In the target WABA | Result |
616
+ | ---------------------------------------------- | --------------------------------------------- |
617
+ | Missing | **create** |
618
+ | Same content | **unchanged** |
619
+ | Different, status APPROVED, REJECTED or PAUSED | **update** |
620
+ | Different, other status (e.g. PENDING) | **blocked** — not sent, exit code 1 |
621
+ | Media header, authentication (OTP) or carousel | **skipped** — not supported yet |
622
+ | Only in the target | **extra** — only deleted with `--prune --yes` |
623
+
624
+ Good to know:
625
+
626
+ - **Category** is only set when a template is created. Meta does not allow changing it later.
627
+ - Created and updated templates are reviewed by Meta again and show `PENDING` for a while. Run
628
+ `--dry-run` later to see the new status.
629
+ - With `--csv`, only the parts the sheet has columns for are replaced in existing templates (see
630
+ [CSV columns](#csv-columns)).
631
+ - One failing template does not stop the others. The report shows Meta's error.
632
+
633
+ #### Backups
634
+
635
+ Meta keeps no history of templates: once a template is updated, its old text is gone. With
636
+ `--backup <folder>`, every target WABA that is about to change is saved first — **all** its templates,
637
+ in the same format as `retrieve`. Each WABA gets its own **backup set**, named by its WABA ID, the
638
+ time of the run (UTC) and `before`. With `--backup-after`, a second set `…_after` is saved once the
639
+ changes are sent — so you always have the state before and after:
640
+
641
+ ```text
642
+ backups/
643
+ ├── 444444444444444_2026-11-20T18-26-04-123Z_before/
644
+ │ ├── manifest.json # date, WABA, stage, source, list of templates with status
645
+ │ ├── order_shipped/
646
+ │ │ └── en_US.json
647
+ │ └── welcome/
648
+ │ └── en_US.json
649
+ └── 444444444444444_2026-11-20T18-26-04-123Z_after/
650
+ ```
651
+
652
+ Use the same `--backup` folder every time; new sets are added next to the old ones and never
653
+ overwritten. If a set cannot be written, nothing is sent to that WABA. WABAs without changes get no
654
+ set.
655
+
656
+ ```bash
657
+ waba deploy --from qa --to prod --backup backups # before only
658
+ waba deploy --from qa --to prod --backup backups --backup-after # before and after
659
+ ```
660
+
661
+ `manifest.json` is written automatically: it lets you (and the desktop app) see what a set contains,
662
+ when and from where it was taken, and each template's status at that moment.
663
+
664
+ To restore, deploy a set back with `--from-dir` (add `-m <name>` to restore only some templates):
665
+
666
+ ```bash
667
+ waba deploy --from-dir backups/444444444444444_2026-11-20T18-26-04-123Z_before --to-waba 444444444444444 --dry-run
668
+ waba deploy --from-dir backups/444444444444444_2026-11-20T18-26-04-123Z_before --to-waba 444444444444444
669
+ ```
670
+
671
+ - A restore is an edit too: Meta reviews the templates again and counts it against its edit limits.
672
+ - Templates created after the backup stay; add `--prune --yes` to get back exactly the saved set.
673
+ - Media, authentication and carousel templates are saved, but cannot be restored (`skipped`).
674
+ - `--backup` does nothing together with `--dry-run`; `--backup-after` needs `--backup`.
675
+ - If the after-backup fails, the changes stay sent; the report shows a WARNING.
676
+ - Restore points without a deployment: [`waba backup`](#backup) (sets named `…_manual`).
677
+
678
+ #### Confirmed preview
679
+
680
+ Between a preview and the real run, someone else may change a WABA. With `--expect`, the real run sends
681
+ **only what the preview showed**: save the `--json` output of `deploy --dry-run`, review it, then pass
682
+ it to the real deploy with the same options.
683
+
684
+ ```bash
685
+ waba deploy --from qa --to prod --dry-run --json > preview.json
686
+ waba deploy --from qa --to prod --expect preview.json
687
+ ```
688
+
689
+ - For each WABA, the creates, updates and deletes (by name and language) must be exactly the ones in
690
+ the preview, **and nothing may differ from what the preview showed**: the preview stores a short
691
+ `fingerprint` per create, update and delete — a hash of the content to send and, for updates and
692
+ deletes, of the template in the WABA as it was at preview time. The real run compares them. So a
693
+ change on either side is caught: an edit to your template files or CSV, a colleague editing a template
694
+ 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
695
+ reports `changed since preview — run the preview again` (exit code 1). Other WABAs are not affected.
696
+ - A WABA that was not in the preview gets nothing if it would need changes.
697
+ - The file is the whole `--json` report of `deploy --dry-run`, or just its `targets` list:
698
+ `[{ "wabaId": "…", "actions": [{ "name": "…", "language": "…", "action": "create", "fingerprint": "…" }] }]`.
699
+ Other fields are ignored. A preview without any fingerprints (older files) still works, but then only
700
+ 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.
701
+
702
+ #### `--prune` safety
703
+
704
+ - Works with the template files and with `--from` — whenever the whole set is deployed.
705
+ - Refused together with `-m` or `--csv`: those only send some templates, so "missing in the
706
+ source" would not mean "should be deleted".
707
+ - Refused when the source has no templates.
708
+ - Media, authentication and carousel templates are never deleted.
709
+ - Without `--yes`, nothing is deleted — but creates and updates **are** sent. To see everything first,
710
+ use `--prune --dry-run`.
711
+ - Meta may block a deleted template's name for a while, so it cannot be created again right away.
712
+
713
+ ## Output and exit codes
714
+
715
+ `--json` prints the full report as JSON (for scripts and CI). Each source and target has `stage`
716
+ (text) and `stages` (list) — a WABA found in several stages lists all of them in `stages`.
717
+
718
+ | Exit code | Meaning |
719
+ | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
720
+ | `0` | Everything succeeded. |
721
+ | `1` | Something failed: a Meta error, a blocked template, a CSV row error, or a target WABA that could not be reached (incl. its token variable not being set). |
722
+ | `2` | Wrong usage or configuration (unknown stage, missing option, invalid config, missing token for the source WABA, …). |
723
+
724
+ When a command stops with an error, `--json` prints `{ "command", "ok": false, "error" }`, plus a
725
+ stable `code` where one exists, so scripts need not match the text: `TOKEN_INVALID`,
726
+ `TOKEN_MISSING_PERMISSION`, `TOKEN_INFO_REFUSED`, `BUSINESS_ID_REQUIRED`, `BUSINESS_HAS_NO_WABAS`
727
+ (all from `discover`).
728
+
729
+ ## Meta limits to know
730
+
731
+ - Every WABA reviews its templates on its own: the same template can be approved in one WABA and
732
+ rejected or re-categorized in another.
733
+ - Meta limits how many templates can be created per WABA per hour, and how often approved
734
+ templates can be edited. Deploying only what changed keeps you well below these limits.
735
+ - A template that is still in review (`PENDING`) cannot be edited — Meta refuses it, so `waba`
736
+ shows it as `blocked` without sending.
737
+ - Meta adds sample templates to new WABAs (`hello_world`, `jaspers_market_*`) and never lets you edit
738
+ or delete them. `waba` shows a change to them as `skipped` and keeps them with `--prune`.
739
+
740
+ ## Not supported yet
741
+
742
+ - Templates with an image, video or document header.
743
+ - Authentication (OTP) and carousel templates.
744
+
745
+ ## License
746
+
747
+ MIT © Jörn Berkefeld