@wsapichat/cli 0.1.2 → 3.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/CHANGELOG.md CHANGED
@@ -4,7 +4,20 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/), and this project adheres to [Semantic Versioning](https://semver.org/).
6
6
 
7
- ## [Unreleased]
7
+ ## [3.2.0] - 2026-11-25
8
+
9
+ ### Added
10
+
11
+ - `wsapi session passkey` subcommands for accounts that require passkey (WebAuthn) verification to link a device: `status` (`GET /session/passkey`), `request` (`POST /session/passkey/request`), `submit [file]` (`POST /session/passkey`, reads the `PublicKeyCredential.toJSON()` assertion from a JSON file or stdin, supports `--data`), and `confirm` (`POST /session/passkey/confirm`, optional — the server now confirms automatically).
12
+
13
+ ### Changed
14
+
15
+ - `wsapi groups create`: `--participants` is now optional; omit it to create a group with only the paired account.
16
+ - README documents the passkey flow and that `session qr` / `session pair-code` return HTTP 409 while a passkey step is pending.
17
+
18
+ ## [3.0.0]
19
+
20
+ Every body-bearing command now supports --data JSON/file merging. Corrected the Node runtime requirement to >=20, API scope documentation, and unpaired-device error to 409. Added command/HTTP contract tests. Updated compatible dependency fixes.
8
21
 
9
22
  ## [0.1.2] - 2026-05-07
10
23
 
package/README.md CHANGED
@@ -12,9 +12,9 @@ This is an independent API and is not affiliated with META or WhatsApp.
12
12
 
13
13
  ## Features
14
14
 
15
- - **Full REST coverage** — every endpoint across messages, groups, communities, contacts, users,
15
+ - **WhatsApp REST coverage** — every endpoint across messages, groups, communities, contacts, users,
16
16
  chats, calls, newsletters, status, media, and session management.
17
- - **JSON in, JSON out** — every command emits JSON to stdout, ready to pipe into `jq`, `xargs`,
17
+ - **JSON in, JSON out** — JSON commands emit JSON to stdout; binary endpoints emit bytes, ready to pipe into `jq`, `xargs`,
18
18
  scripts, or your shell of choice.
19
19
  - **Layered configuration** — flags, environment variables, and named profiles in
20
20
  `~/.wsapi/config.json`. Switch between staging and production with `--profile`.
@@ -30,7 +30,7 @@ This is an independent API and is not affiliated with META or WhatsApp.
30
30
 
31
31
  ### Prerequisites
32
32
 
33
- - [Node.js](https://nodejs.org/) 18 or later
33
+ - [Node.js](https://nodejs.org/) 20 or later
34
34
  - A WSAPI instance ID and API key
35
35
 
36
36
  ### Installation
@@ -102,6 +102,30 @@ wsapi session pair-code 15551234567
102
102
  wsapi session status
103
103
  ```
104
104
 
105
+ #### Passkey verification
106
+
107
+ Some WhatsApp accounts require the owner's passkey (WebAuthn) to link a new device. When
108
+ that happens, `session status` reports `passkeyStatus: "required"` and `session qr` /
109
+ `session pair-code` fail with HTTP 409 — stop polling them and complete the passkey step:
110
+
111
+ ```bash
112
+ # Inspect the passkey state (status, challenge, origin, ...)
113
+ wsapi session passkey status
114
+
115
+ # Ask WhatsApp for a challenge if none arrived on its own
116
+ wsapi session passkey request
117
+
118
+ # Run navigator.credentials.get() on https://web.whatsapp.com with the challenge, then submit
119
+ # the PublicKeyCredential.toJSON() output from a file...
120
+ wsapi session passkey submit assertion.json
121
+
122
+ # ...or from stdin
123
+ cat assertion.json | wsapi session passkey submit
124
+
125
+ # Optional: the server sends the confirmation automatically; kept for compatibility
126
+ wsapi session passkey confirm
127
+ ```
128
+
105
129
  ### 3. Send messages
106
130
 
107
131
  ```bash
@@ -142,6 +166,9 @@ wsapi groups list | jq -r '.[].name'
142
166
  # Get group info
143
167
  wsapi groups get 1234567890@g.us
144
168
 
169
+ # Create a group (omit --participants to create it with only the paired account)
170
+ wsapi groups create --name "Team" --participants 15551234567@s.whatsapp.net
171
+
145
172
  # Add a participant
146
173
  wsapi groups update-participants 1234567890@g.us \
147
174
  --action add \
@@ -162,7 +189,7 @@ Without `--output`, binary endpoints write to stdout. Pipe it into a file or ano
162
189
 
163
190
  | Group | Examples |
164
191
  | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
165
- | `session` | `status`, `qr`, `qr --text`, `pair-code <phone>`, `logout`, `flush-history` |
192
+ | `session` | `status`, `qr`, `qr --text`, `pair-code <phone>`, `passkey status`, `passkey request`, `passkey submit [file]`, `passkey confirm`, `logout`, `flush-history` |
166
193
  | `messages` | `text`, `image`, `video`, `audio`, `voice`, `document`, `sticker`, `contact`, `location`, `link`, `react`, `edit`, `read`, `star`, `pin`, `delete`, `delete-for-me` |
167
194
  | `groups` | `list`, `get`, `create`, `set-name`, `set-description`, `set-picture`, `leave`, `participants`, `update-participants`, `invite-link`, `reset-invite`, `set-announce`, `set-locked`, `set-join-approval`, `set-member-add-mode`, `join-link`, `join-invite`, `invite-info`, `requests`, `update-requests` |
168
195
  | `communities` | `list`, `get`, `create`, `leave`, `set-name`, `set-description`, `set-picture`, `set-locked`, `participants`, `update-participants`, `invite-link`, `reset-invite`, `subgroups`, `create-subgroup`, `link-subgroup`, `unlink-subgroup` |
@@ -211,8 +238,8 @@ API errors are emitted to stderr as JSON:
211
238
  ```json
212
239
  {
213
240
  "error": "device not paired",
214
- "status": 403,
215
- "body": { "status": 403, "detail": "device not paired" }
241
+ "status": 409,
242
+ "body": { "status": 409, "detail": "device not paired" }
216
243
  }
217
244
  ```
218
245
 
@@ -231,3 +258,7 @@ See [CONTRIBUTING.md](CONTRIBUTING.md).
231
258
  ## License
232
259
 
233
260
  [MIT](LICENSE)
261
+
262
+ ## API scope
263
+
264
+ Covers all 101 WhatsApp operations. Cloud Account/subscription management and OSS `/admin/instances` endpoints are separate and are not CLI commands.
package/dist/index.js CHANGED
@@ -74,7 +74,6 @@ var WsApiClient = class {
74
74
  constructor(cfg) {
75
75
  this.cfg = cfg;
76
76
  }
77
- cfg;
78
77
  url(path, query) {
79
78
  const base = this.cfg.baseUrl.replace(/\/$/, "");
80
79
  const cleanPath = path.startsWith("/") ? path : `/${path}`;
@@ -348,11 +347,31 @@ function registerConfigCommand(program2) {
348
347
  }
349
348
  });
350
349
  }
351
-
352
- // src/commands/session.ts
350
+ function readPasskeyAssertion(source) {
351
+ const fromStdin = !source || source === "-";
352
+ if (fromStdin && process.stdin.isTTY) {
353
+ throw new CliError("no assertion given: pass a JSON file path, or pipe the assertion JSON on stdin");
354
+ }
355
+ let raw;
356
+ try {
357
+ raw = readFileSync(fromStdin ? 0 : source, "utf8");
358
+ } catch (e) {
359
+ throw new CliError(`failed to read assertion from ${fromStdin ? "stdin" : source}: ${e.message}`);
360
+ }
361
+ let parsed;
362
+ try {
363
+ parsed = JSON.parse(raw);
364
+ } catch (e) {
365
+ throw new CliError(`failed to parse assertion as JSON: ${e.message}`);
366
+ }
367
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
368
+ throw new CliError("assertion must be a JSON object (PublicKeyCredential.toJSON() output)");
369
+ }
370
+ return parsed;
371
+ }
353
372
  function registerSessionCommands(program2) {
354
373
  const session = program2.command("session").description("Manage WhatsApp session (login, logout, status)");
355
- session.command("status").description("Get session status (isConnected, isLoggedIn, deviceId)").action(action((c) => c.request("/session/status")));
374
+ session.command("status").description("Get session status (isConnected, isLoggedIn, deviceId, passkeyStatus)").action(action((c) => c.request("/session/status")));
356
375
  session.command("qr").description("Fetch the pairing QR code").option("-o, --output <file>", "write the PNG to a file (default: stdout)").option("--text", "fetch the QR as a raw text string instead of a PNG").action(async function(options) {
357
376
  try {
358
377
  const c = makeClient(this);
@@ -373,6 +392,24 @@ function registerSessionCommands(program2) {
373
392
  return c.request(`/session/pair-code/${encodeURIComponent(phone)}`);
374
393
  })
375
394
  );
395
+ const passkey = session.command("passkey").description("Passkey (WebAuthn) verification for accounts that require it to link a device");
396
+ passkey.command("status").description("Get the passkey verification state (status, challenge, origin, ...)").action(action((c) => c.request("/session/passkey")));
397
+ passkey.command("request").description("Ask WhatsApp for a passkey challenge for the unpaired device").action(action((c) => c.request("/session/passkey/request", { method: "POST" })));
398
+ passkey.command("submit [file]").description("Submit a passkey assertion (PublicKeyCredential.toJSON() output) from a JSON file or stdin").option("--data <json>", "extra body fields as JSON; prefix with @ to load from file").action(
399
+ action((c, cmd) => {
400
+ const [file] = cmd.args;
401
+ return c.request("/session/passkey", {
402
+ method: "POST",
403
+ body: buildBody(readPasskeyAssertion(file), cmd.opts().data)
404
+ });
405
+ })
406
+ );
407
+ passkey.command("confirm").description("Send the passkey confirmation (optional: the server now sends it automatically)").action(
408
+ action(async (c) => {
409
+ await c.request("/session/passkey/confirm", { method: "POST" });
410
+ return { status: "ok" };
411
+ })
412
+ );
376
413
  session.command("logout").description("Logout from WhatsApp").action(
377
414
  action(async (c) => {
378
415
  await c.request("/session/logout", { method: "POST" });
@@ -668,7 +705,11 @@ function registerGroupsCommands(program2) {
668
705
  return c.request(`/groups/${encodeURIComponent(id)}`);
669
706
  })
670
707
  );
671
- g.command("create").description("Create a new group").requiredOption("--name <name>", "group name").requiredOption("--participants <jids>", "comma-separated participant JIDs", commaList).option("--data <json>", "extra body fields as JSON").action(
708
+ g.command("create").description("Create a new group").requiredOption("--name <name>", "group name").option(
709
+ "--participants <jids>",
710
+ "comma-separated participant JIDs (omit to create a group with only you)",
711
+ commaList
712
+ ).option("--data <json>", "extra body fields as JSON; prefix with @ to load from file").action(
672
713
  action((c, cmd) => {
673
714
  const o = cmd.opts();
674
715
  return c.request("/groups", {
@@ -677,34 +718,34 @@ function registerGroupsCommands(program2) {
677
718
  });
678
719
  })
679
720
  );
680
- g.command("set-name <id>").description("Set group name").requiredOption("--name <name>", "new group name").action(
721
+ g.command("set-name <id>").description("Set group name").requiredOption("--name <name>", "new group name").option("--data <json>", "extra body fields as JSON; prefix with @ to load from file").action(
681
722
  action(async (c, cmd) => {
682
723
  const [id] = cmd.args;
683
724
  await c.request(`/groups/${encodeURIComponent(id)}/name`, {
684
725
  method: "PUT",
685
- body: { name: cmd.opts().name }
726
+ body: buildBody({ name: cmd.opts().name }, cmd.opts().data)
686
727
  });
687
728
  return { status: "ok" };
688
729
  })
689
730
  );
690
- g.command("set-description <id>").description("Set group description").option("--description <text>", "description (omit for empty)").action(
731
+ g.command("set-description <id>").description("Set group description").option("--description <text>", "description (omit for empty)").option("--data <json>", "extra body fields as JSON; prefix with @ to load from file").action(
691
732
  action(async (c, cmd) => {
692
733
  const [id] = cmd.args;
693
734
  await c.request(`/groups/${encodeURIComponent(id)}/description`, {
694
735
  method: "PUT",
695
- body: { description: cmd.opts().description ?? "" }
736
+ body: buildBody({ description: cmd.opts().description ?? "" }, cmd.opts().data)
696
737
  });
697
738
  return { status: "ok" };
698
739
  })
699
740
  );
700
- g.command("set-picture <id>").description("Set group picture (JPEG)").option("--data-file <path>", "JPEG file to upload (base64 encoded)").option("--data-base64 <base64>", "base64-encoded JPEG image").action(
741
+ g.command("set-picture <id>").description("Set group picture (JPEG)").option("--data-file <path>", "JPEG file to upload (base64 encoded)").option("--data-base64 <base64>", "base64-encoded JPEG image").option("--data <json>", "extra body fields as JSON; prefix with @ to load from file").action(
701
742
  action(async (c, cmd) => {
702
743
  const [id] = cmd.args;
703
744
  const o = cmd.opts();
704
745
  const data = o.dataFile ? await readFileToBase64(o.dataFile) : o.dataBase64;
705
746
  return c.request(`/groups/${encodeURIComponent(id)}/picture`, {
706
747
  method: "POST",
707
- body: { data }
748
+ body: buildBody({ data }, cmd.opts().data)
708
749
  });
709
750
  })
710
751
  );
@@ -721,13 +762,13 @@ function registerGroupsCommands(program2) {
721
762
  return c.request(`/groups/${encodeURIComponent(id)}/participants`);
722
763
  })
723
764
  );
724
- g.command("update-participants <id>").description("Add, remove, promote, or demote participants").requiredOption("--action <action>", "add | remove | promote | demote").requiredOption("--participants <jids>", "comma-separated JIDs", commaList).action(
765
+ g.command("update-participants <id>").description("Add, remove, promote, or demote participants").requiredOption("--action <action>", "add | remove | promote | demote").requiredOption("--participants <jids>", "comma-separated JIDs", commaList).option("--data <json>", "extra body fields as JSON; prefix with @ to load from file").action(
725
766
  action(async (c, cmd) => {
726
767
  const [id] = cmd.args;
727
768
  const o = cmd.opts();
728
769
  await c.request(`/groups/${encodeURIComponent(id)}/participants`, {
729
770
  method: "PUT",
730
- body: { participants: o.participants, action: o.action }
771
+ body: buildBody({ participants: o.participants, action: o.action }, cmd.opts().data)
731
772
  });
732
773
  return { status: "ok" };
733
774
  })
@@ -749,35 +790,35 @@ function registerGroupsCommands(program2) {
749
790
  { cmd: "set-locked", path: "locked", help: "Toggle locked mode (only admins can edit info)" },
750
791
  { cmd: "set-join-approval", path: "join-approval", help: "Toggle join approval requirement" }
751
792
  ]) {
752
- g.command(`${setting.cmd} <id>`).description(setting.help).requiredOption("--enabled <bool>", "true | false").action(
793
+ g.command(`${setting.cmd} <id>`).description(setting.help).requiredOption("--enabled <bool>", "true | false").option("--data <json>", "extra body fields as JSON; prefix with @ to load from file").action(
753
794
  action(async (c, cmd) => {
754
795
  const [id] = cmd.args;
755
796
  const enabled = cmd.opts().enabled === "true" || cmd.opts().enabled === true;
756
797
  await c.request(`/groups/${encodeURIComponent(id)}/settings/${setting.path}`, {
757
798
  method: "PUT",
758
- body: { enabled }
799
+ body: buildBody({ enabled }, cmd.opts().data)
759
800
  });
760
801
  return { status: "ok" };
761
802
  })
762
803
  );
763
804
  }
764
- g.command("set-member-add-mode <id>").description("Control whether only admins can add members").requiredOption("--only-admin-add <bool>", "true | false").action(
805
+ g.command("set-member-add-mode <id>").description("Control whether only admins can add members").requiredOption("--only-admin-add <bool>", "true | false").option("--data <json>", "extra body fields as JSON; prefix with @ to load from file").action(
765
806
  action(async (c, cmd) => {
766
807
  const [id] = cmd.args;
767
808
  const v = cmd.opts().onlyAdminAdd;
768
809
  const onlyAdminAdd = v === "true" || v === true;
769
810
  await c.request(`/groups/${encodeURIComponent(id)}/settings/member-add-mode`, {
770
811
  method: "PUT",
771
- body: { onlyAdminAdd }
812
+ body: buildBody({ onlyAdminAdd }, cmd.opts().data)
772
813
  });
773
814
  return { status: "ok" };
774
815
  })
775
816
  );
776
- g.command("join-link").description("Join a group via an invite link code").requiredOption("--code <code>", "invite link code (the part after https://chat.whatsapp.com/)").action(
817
+ g.command("join-link").description("Join a group via an invite link code").requiredOption("--code <code>", "invite link code (the part after https://chat.whatsapp.com/)").option("--data <json>", "extra body fields as JSON; prefix with @ to load from file").action(
777
818
  action((c, cmd) => {
778
819
  return c.request("/groups/join/link", {
779
820
  method: "POST",
780
- body: { code: cmd.opts().code }
821
+ body: buildBody({ code: cmd.opts().code }, cmd.opts().data)
781
822
  });
782
823
  })
783
824
  );
@@ -808,13 +849,13 @@ function registerGroupsCommands(program2) {
808
849
  return c.request(`/groups/${encodeURIComponent(id)}/requests`);
809
850
  })
810
851
  );
811
- g.command("update-requests <id>").description("Approve or reject pending join requests").requiredOption("--action <action>", "approve | reject").requiredOption("--participants <jids>", "comma-separated JIDs", commaList).action(
852
+ g.command("update-requests <id>").description("Approve or reject pending join requests").requiredOption("--action <action>", "approve | reject").requiredOption("--participants <jids>", "comma-separated JIDs", commaList).option("--data <json>", "extra body fields as JSON; prefix with @ to load from file").action(
812
853
  action(async (c, cmd) => {
813
854
  const [id] = cmd.args;
814
855
  const o = cmd.opts();
815
856
  await c.request(`/groups/${encodeURIComponent(id)}/requests`, {
816
857
  method: "PUT",
817
- body: { participants: o.participants, action: o.action }
858
+ body: buildBody({ participants: o.participants, action: o.action }, cmd.opts().data)
818
859
  });
819
860
  return { status: "ok" };
820
861
  })
@@ -854,44 +895,44 @@ function registerCommunitiesCommands(program2) {
854
895
  return { status: "ok" };
855
896
  })
856
897
  );
857
- cm.command("set-name <id>").description("Set community name").requiredOption("--name <name>", "new name").action(
898
+ cm.command("set-name <id>").description("Set community name").requiredOption("--name <name>", "new name").option("--data <json>", "extra body fields as JSON; prefix with @ to load from file").action(
858
899
  action(async (c, cmd) => {
859
900
  const [id] = cmd.args;
860
901
  await c.request(`/communities/${encodeURIComponent(id)}/name`, {
861
902
  method: "PUT",
862
- body: { name: cmd.opts().name }
903
+ body: buildBody({ name: cmd.opts().name }, cmd.opts().data)
863
904
  });
864
905
  return { status: "ok" };
865
906
  })
866
907
  );
867
- cm.command("set-description <id>").description("Set community description").option("--description <text>", "description").action(
908
+ cm.command("set-description <id>").description("Set community description").option("--description <text>", "description").option("--data <json>", "extra body fields as JSON; prefix with @ to load from file").action(
868
909
  action(async (c, cmd) => {
869
910
  const [id] = cmd.args;
870
911
  await c.request(`/communities/${encodeURIComponent(id)}/description`, {
871
912
  method: "PUT",
872
- body: { description: cmd.opts().description ?? "" }
913
+ body: buildBody({ description: cmd.opts().description ?? "" }, cmd.opts().data)
873
914
  });
874
915
  return { status: "ok" };
875
916
  })
876
917
  );
877
- cm.command("set-picture <id>").description("Set community picture (JPEG)").option("--data-file <path>", "JPEG file to upload").option("--data-base64 <base64>", "base64-encoded JPEG image").action(
918
+ cm.command("set-picture <id>").description("Set community picture (JPEG)").option("--data-file <path>", "JPEG file to upload").option("--data-base64 <base64>", "base64-encoded JPEG image").option("--data <json>", "extra body fields as JSON; prefix with @ to load from file").action(
878
919
  action(async (c, cmd) => {
879
920
  const [id] = cmd.args;
880
921
  const o = cmd.opts();
881
922
  const data = o.dataFile ? await readFileToBase64(o.dataFile) : o.dataBase64;
882
923
  return c.request(`/communities/${encodeURIComponent(id)}/picture`, {
883
924
  method: "POST",
884
- body: { data }
925
+ body: buildBody({ data }, cmd.opts().data)
885
926
  });
886
927
  })
887
928
  );
888
- cm.command("set-locked <id>").description("Set community locked mode").requiredOption("--enabled <bool>", "true | false").action(
929
+ cm.command("set-locked <id>").description("Set community locked mode").requiredOption("--enabled <bool>", "true | false").option("--data <json>", "extra body fields as JSON; prefix with @ to load from file").action(
889
930
  action(async (c, cmd) => {
890
931
  const [id] = cmd.args;
891
932
  const enabled = cmd.opts().enabled === "true" || cmd.opts().enabled === true;
892
933
  await c.request(`/communities/${encodeURIComponent(id)}/settings/locked`, {
893
934
  method: "PUT",
894
- body: { enabled }
935
+ body: buildBody({ enabled }, cmd.opts().data)
895
936
  });
896
937
  return { status: "ok" };
897
938
  })
@@ -902,13 +943,13 @@ function registerCommunitiesCommands(program2) {
902
943
  return c.request(`/communities/${encodeURIComponent(id)}/participants`);
903
944
  })
904
945
  );
905
- cm.command("update-participants <id>").description("Add, remove, promote, or demote participants").requiredOption("--action <action>", "add | remove | promote | demote").requiredOption("--participants <jids>", "comma-separated JIDs", commaList).action(
946
+ cm.command("update-participants <id>").description("Add, remove, promote, or demote participants").requiredOption("--action <action>", "add | remove | promote | demote").requiredOption("--participants <jids>", "comma-separated JIDs", commaList).option("--data <json>", "extra body fields as JSON; prefix with @ to load from file").action(
906
947
  action(async (c, cmd) => {
907
948
  const [id] = cmd.args;
908
949
  const o = cmd.opts();
909
950
  await c.request(`/communities/${encodeURIComponent(id)}/participants`, {
910
951
  method: "PUT",
911
- body: { participants: o.participants, action: o.action }
952
+ body: buildBody({ participants: o.participants, action: o.action }, cmd.opts().data)
912
953
  });
913
954
  return { status: "ok" };
914
955
  })
@@ -941,12 +982,12 @@ function registerCommunitiesCommands(program2) {
941
982
  });
942
983
  })
943
984
  );
944
- cm.command("link-subgroup <id>").description("Link an existing group to a community as a sub-group").requiredOption("--group-id <jid>", "group JID to link").action(
985
+ cm.command("link-subgroup <id>").description("Link an existing group to a community as a sub-group").requiredOption("--group-id <jid>", "group JID to link").option("--data <json>", "extra body fields as JSON; prefix with @ to load from file").action(
945
986
  action(async (c, cmd) => {
946
987
  const [id] = cmd.args;
947
988
  await c.request(`/communities/${encodeURIComponent(id)}/groups/link`, {
948
989
  method: "POST",
949
- body: { groupId: cmd.opts().groupId }
990
+ body: buildBody({ groupId: cmd.opts().groupId }, cmd.opts().data)
950
991
  });
951
992
  return { status: "ok" };
952
993
  })
@@ -1027,22 +1068,22 @@ function registerUsersCommands(program2) {
1027
1068
  return { status: "ok" };
1028
1069
  })
1029
1070
  );
1030
- u.command("set-presence").description("Set presence to available or unavailable").requiredOption("--presence <state>", "available | unavailable").action(
1071
+ u.command("set-presence").description("Set presence to available or unavailable").requiredOption("--presence <state>", "available | unavailable").option("--data <json>", "extra body fields as JSON; prefix with @ to load from file").action(
1031
1072
  action(async (c, cmd) => {
1032
1073
  await c.request("/users/me/presence", {
1033
1074
  method: "PUT",
1034
- body: { presence: cmd.opts().presence }
1075
+ body: buildBody({ presence: cmd.opts().presence }, cmd.opts().data)
1035
1076
  });
1036
1077
  return { status: "ok" };
1037
1078
  })
1038
1079
  );
1039
1080
  u.command("privacy").description("Get privacy settings").action(action((c) => c.request("/users/me/privacy")));
1040
- u.command("set-privacy").description("Update a single privacy setting").requiredOption("--setting <name>", "groupadd | last | status | profile | readreceipts | online | calladd").requiredOption("--value <value>", "all | contacts | contact_blacklist | match_last_seen | known | none").action(
1081
+ u.command("set-privacy").description("Update a single privacy setting").requiredOption("--setting <name>", "groupadd | last | status | profile | readreceipts | online | calladd").requiredOption("--value <value>", "all | contacts | contact_blacklist | match_last_seen | known | none").option("--data <json>", "extra body fields as JSON; prefix with @ to load from file").action(
1041
1082
  action((c, cmd) => {
1042
1083
  const o = cmd.opts();
1043
1084
  return c.request("/users/me/privacy", {
1044
1085
  method: "PUT",
1045
- body: { setting: o.setting, value: o.value }
1086
+ body: buildBody({ setting: o.setting, value: o.value }, cmd.opts().data)
1046
1087
  });
1047
1088
  })
1048
1089
  );
@@ -1052,11 +1093,11 @@ function registerUsersCommands(program2) {
1052
1093
  return c.request(`/users/${encodeURIComponent(phone)}/check`);
1053
1094
  })
1054
1095
  );
1055
- u.command("check-bulk").description("Bulk check phone numbers on WhatsApp").requiredOption("--phones <list>", "comma-separated phone numbers", commaList).action(
1096
+ u.command("check-bulk").description("Bulk check phone numbers on WhatsApp").requiredOption("--phones <list>", "comma-separated phone numbers", commaList).option("--data <json>", "extra body fields as JSON; prefix with @ to load from file").action(
1056
1097
  action((c, cmd) => {
1057
1098
  return c.request("/users/check", {
1058
1099
  method: "POST",
1059
- body: { phones: cmd.opts().phones }
1100
+ body: buildBody({ phones: cmd.opts().phones }, cmd.opts().data)
1060
1101
  });
1061
1102
  })
1062
1103
  );
@@ -1114,12 +1155,12 @@ function registerChatsCommands(program2) {
1114
1155
  return c.request(`/chats/${encodeURIComponent(chatId)}/business`);
1115
1156
  })
1116
1157
  );
1117
- ch.command("set-presence <chatId>").description("Send chat presence (typing, paused, recording)").requiredOption("--state <state>", "typing | paused | recording").action(
1158
+ ch.command("set-presence <chatId>").description("Send chat presence (typing, paused, recording)").requiredOption("--state <state>", "typing | paused | recording").option("--data <json>", "extra body fields as JSON; prefix with @ to load from file").action(
1118
1159
  action(async (c, cmd) => {
1119
1160
  const [chatId] = cmd.args;
1120
1161
  await c.request(`/chats/${encodeURIComponent(chatId)}/presence`, {
1121
1162
  method: "PUT",
1122
- body: { state: cmd.opts().state }
1163
+ body: buildBody({ state: cmd.opts().state }, cmd.opts().data)
1123
1164
  });
1124
1165
  return { status: "ok" };
1125
1166
  })
@@ -1131,52 +1172,52 @@ function registerChatsCommands(program2) {
1131
1172
  return { status: "ok" };
1132
1173
  })
1133
1174
  );
1134
- ch.command("set-ephemeral <chatId>").description("Set disappearing-messages timer").requiredOption("--expiration <off|24h|7d|90d>", "timer value").action(
1175
+ ch.command("set-ephemeral <chatId>").description("Set disappearing-messages timer").requiredOption("--expiration <off|24h|7d|90d>", "timer value").option("--data <json>", "extra body fields as JSON; prefix with @ to load from file").action(
1135
1176
  action(async (c, cmd) => {
1136
1177
  const [chatId] = cmd.args;
1137
1178
  await c.request(`/chats/${encodeURIComponent(chatId)}/ephemeral`, {
1138
1179
  method: "PUT",
1139
- body: { expiration: cmd.opts().expiration }
1180
+ body: buildBody({ expiration: cmd.opts().expiration }, cmd.opts().data)
1140
1181
  });
1141
1182
  return { status: "ok" };
1142
1183
  })
1143
1184
  );
1144
- ch.command("mute <chatId>").description("Mute or unmute a chat").requiredOption("--duration <8h|1w|always|off>", "mute duration").action(
1185
+ ch.command("mute <chatId>").description("Mute or unmute a chat").requiredOption("--duration <8h|1w|always|off>", "mute duration").option("--data <json>", "extra body fields as JSON; prefix with @ to load from file").action(
1145
1186
  action(async (c, cmd) => {
1146
1187
  const [chatId] = cmd.args;
1147
1188
  await c.request(`/chats/${encodeURIComponent(chatId)}/mute`, {
1148
1189
  method: "PUT",
1149
- body: { duration: cmd.opts().duration }
1190
+ body: buildBody({ duration: cmd.opts().duration }, cmd.opts().data)
1150
1191
  });
1151
1192
  return { status: "ok" };
1152
1193
  })
1153
1194
  );
1154
- ch.command("pin <chatId>").description("Pin or unpin a chat").option("--unpin", "unpin instead of pinning").action(
1195
+ ch.command("pin <chatId>").description("Pin or unpin a chat").option("--unpin", "unpin instead of pinning").option("--data <json>", "extra body fields as JSON; prefix with @ to load from file").action(
1155
1196
  action(async (c, cmd) => {
1156
1197
  const [chatId] = cmd.args;
1157
1198
  await c.request(`/chats/${encodeURIComponent(chatId)}/pin`, {
1158
1199
  method: "PUT",
1159
- body: { pinned: !cmd.opts().unpin }
1200
+ body: buildBody({ pinned: !cmd.opts().unpin }, cmd.opts().data)
1160
1201
  });
1161
1202
  return { status: "ok" };
1162
1203
  })
1163
1204
  );
1164
- ch.command("archive <chatId>").description("Archive or unarchive a chat").option("--unarchive", "unarchive instead of archiving").action(
1205
+ ch.command("archive <chatId>").description("Archive or unarchive a chat").option("--unarchive", "unarchive instead of archiving").option("--data <json>", "extra body fields as JSON; prefix with @ to load from file").action(
1165
1206
  action(async (c, cmd) => {
1166
1207
  const [chatId] = cmd.args;
1167
1208
  await c.request(`/chats/${encodeURIComponent(chatId)}/archive`, {
1168
1209
  method: "PUT",
1169
- body: { archived: !cmd.opts().unarchive }
1210
+ body: buildBody({ archived: !cmd.opts().unarchive }, cmd.opts().data)
1170
1211
  });
1171
1212
  return { status: "ok" };
1172
1213
  })
1173
1214
  );
1174
- ch.command("read <chatId>").description("Mark a chat as read or unread").option("--unread", "mark unread instead of read").action(
1215
+ ch.command("read <chatId>").description("Mark a chat as read or unread").option("--unread", "mark unread instead of read").option("--data <json>", "extra body fields as JSON; prefix with @ to load from file").action(
1175
1216
  action(async (c, cmd) => {
1176
1217
  const [chatId] = cmd.args;
1177
1218
  await c.request(`/chats/${encodeURIComponent(chatId)}/read`, {
1178
1219
  method: "PUT",
1179
- body: { read: !cmd.opts().unread }
1220
+ body: buildBody({ read: !cmd.opts().unread }, cmd.opts().data)
1180
1221
  });
1181
1222
  return { status: "ok" };
1182
1223
  })
@@ -1210,12 +1251,12 @@ function registerChatsCommands(program2) {
1210
1251
  // src/commands/calls.ts
1211
1252
  function registerCallsCommands(program2) {
1212
1253
  const calls = program2.command("calls").description("Call management");
1213
- calls.command("reject <callId>").description("Reject an incoming call").requiredOption("--caller-id <jid>", "JID of the caller").action(
1254
+ calls.command("reject <callId>").description("Reject an incoming call").requiredOption("--caller-id <jid>", "JID of the caller").option("--data <json>", "extra body fields as JSON; prefix with @ to load from file").action(
1214
1255
  action(async (c, cmd) => {
1215
1256
  const [callId] = cmd.args;
1216
1257
  await c.request(`/calls/${encodeURIComponent(callId)}/reject`, {
1217
1258
  method: "POST",
1218
- body: { callerId: cmd.opts().callerId }
1259
+ body: buildBody({ callerId: cmd.opts().callerId }, cmd.opts().data)
1219
1260
  });
1220
1261
  return { status: "ok" };
1221
1262
  })
@@ -1255,42 +1296,42 @@ function registerNewslettersCommands(program2) {
1255
1296
  });
1256
1297
  })
1257
1298
  );
1258
- n.command("subscribe <id>").description("Subscribe to a newsletter").action(
1299
+ n.command("subscribe <id>").description("Subscribe to a newsletter").option("--data <json>", "extra body fields as JSON; prefix with @ to load from file").action(
1259
1300
  action(async (c, cmd) => {
1260
1301
  const [id] = cmd.args;
1261
1302
  await c.request(`/newsletters/${encodeURIComponent(id)}/subscription`, {
1262
1303
  method: "PUT",
1263
- body: { subscribed: true }
1304
+ body: buildBody({ subscribed: true }, cmd.opts().data)
1264
1305
  });
1265
1306
  return { status: "ok" };
1266
1307
  })
1267
1308
  );
1268
- n.command("unsubscribe <id>").description("Unsubscribe from a newsletter").action(
1309
+ n.command("unsubscribe <id>").description("Unsubscribe from a newsletter").option("--data <json>", "extra body fields as JSON; prefix with @ to load from file").action(
1269
1310
  action(async (c, cmd) => {
1270
1311
  const [id] = cmd.args;
1271
1312
  await c.request(`/newsletters/${encodeURIComponent(id)}/subscription`, {
1272
1313
  method: "PUT",
1273
- body: { subscribed: false }
1314
+ body: buildBody({ subscribed: false }, cmd.opts().data)
1274
1315
  });
1275
1316
  return { status: "ok" };
1276
1317
  })
1277
1318
  );
1278
- n.command("mute <id>").description("Mute a newsletter").action(
1319
+ n.command("mute <id>").description("Mute a newsletter").option("--data <json>", "extra body fields as JSON; prefix with @ to load from file").action(
1279
1320
  action(async (c, cmd) => {
1280
1321
  const [id] = cmd.args;
1281
1322
  await c.request(`/newsletters/${encodeURIComponent(id)}/mute`, {
1282
1323
  method: "PUT",
1283
- body: { mute: true }
1324
+ body: buildBody({ mute: true }, cmd.opts().data)
1284
1325
  });
1285
1326
  return { status: "ok" };
1286
1327
  })
1287
1328
  );
1288
- n.command("unmute <id>").description("Unmute a newsletter").action(
1329
+ n.command("unmute <id>").description("Unmute a newsletter").option("--data <json>", "extra body fields as JSON; prefix with @ to load from file").action(
1289
1330
  action(async (c, cmd) => {
1290
1331
  const [id] = cmd.args;
1291
1332
  await c.request(`/newsletters/${encodeURIComponent(id)}/mute`, {
1292
1333
  method: "PUT",
1293
- body: { mute: false }
1334
+ body: buildBody({ mute: false }, cmd.opts().data)
1294
1335
  });
1295
1336
  return { status: "ok" };
1296
1337
  })
@@ -1301,11 +1342,11 @@ function registerNewslettersCommands(program2) {
1301
1342
  function registerStatusCommands(program2) {
1302
1343
  const s = program2.command("status").description("Status / story posting");
1303
1344
  s.command("privacy").description("Get status broadcast privacy settings").action(action((c) => c.request("/status/privacy")));
1304
- s.command("text").description("Post a text status").requiredOption("--text <text>", "status text").action(
1345
+ s.command("text").description("Post a text status").requiredOption("--text <text>", "status text").option("--data <json>", "extra body fields as JSON; prefix with @ to load from file").action(
1305
1346
  action((c, cmd) => {
1306
1347
  return c.request("/status/text", {
1307
1348
  method: "POST",
1308
- body: { text: cmd.opts().text }
1349
+ body: buildBody({ text: cmd.opts().text }, cmd.opts().data)
1309
1350
  });
1310
1351
  })
1311
1352
  );
@@ -1340,7 +1381,7 @@ function registerStatusCommands(program2) {
1340
1381
 
1341
1382
  // src/index.ts
1342
1383
  var program = new Command();
1343
- program.name("wsapi").description("Command-line client for the WSAPI WhatsApp cloud API").version("0.1.2").option("--profile <name>", "named profile from the config file").option("--api-key <key>", "WSAPI API key (overrides env and config)").option("--instance-id <id>", "WSAPI instance ID (overrides env and config)").option("--base-url <url>", "API base URL (default https://api.wsapi.chat)").option("--config <path>", "path to config file (default ~/.wsapi/config.json)");
1384
+ program.name("wsapi").description("Command-line client for the WSAPI WhatsApp cloud API").version("3.2.0").option("--profile <name>", "named profile from the config file").option("--api-key <key>", "WSAPI API key (overrides env and config)").option("--instance-id <id>", "WSAPI instance ID (overrides env and config)").option("--base-url <url>", "API base URL (default https://api.wsapi.chat)").option("--config <path>", "path to config file (default ~/.wsapi/config.json)");
1344
1385
  registerConfigCommand(program);
1345
1386
  registerSessionCommands(program);
1346
1387
  registerMessagesCommands(program);