openzca 0.1.48 → 0.1.50

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.
Files changed (3) hide show
  1. package/README.md +90 -2
  2. package/dist/cli.js +3142 -153
  3. package/package.json +3 -1
package/README.md CHANGED
@@ -40,8 +40,38 @@ openzca msg send GROUP_ID "Hello team" --group
40
40
  openzca msg send GROUP_ID "Hi @Alice Nguyen" --group
41
41
  openzca msg send GROUP_ID "Hi @123456789" --group
42
42
 
43
+ # Reply using a stored DB message id
44
+ openzca msg send USER_ID "Reply text" --reply-id MSG_ID
45
+
46
+ # Reply without DB using a listen --raw payload
47
+ openzca msg send USER_ID "Reply text" --reply-message '{"threadId":"...","msgId":"...","cliMsgId":"...","content":"...","msgType":"webchat","senderId":"...","toId":"...","ts":"..."}'
48
+
43
49
  # Listen for incoming messages
44
50
  openzca listen
51
+
52
+ # Enable the local SQLite DB for this profile
53
+ openzca db enable
54
+
55
+ # Backfill full group history plus recent DM/chat windows into the DB
56
+ openzca db sync
57
+
58
+ # List stored groups
59
+ openzca db group list --json
60
+
61
+ # Show stored info for one group
62
+ openzca db group info GROUP_ID --json
63
+
64
+ # Read the last 24 hours for one group
65
+ openzca db group messages GROUP_ID --since 24h --json
66
+
67
+ # Read an explicit date range
68
+ openzca db group messages GROUP_ID --from 2026-03-21T00:00:00+07:00 --to 2026-03-22T00:00:00+07:00 --json
69
+
70
+ # Read the latest 20 stored rows by default
71
+ openzca db group messages GROUP_ID --json
72
+
73
+ # Read all matching rows
74
+ openzca db group messages GROUP_ID --all --json
45
75
  ```
46
76
 
47
77
  ## Commands
@@ -67,7 +97,7 @@ You can also open the saved file manually (for example: `open qr.png` on macOS).
67
97
 
68
98
  | Command | Description |
69
99
  |---------|-------------|
70
- | `openzca msg send <threadId> <message>` | Send text with formatting (`**bold**`, `*italic*`, `~~strike~~`, etc.) and group @mention resolution (`--raw` to skip formatting) |
100
+ | `openzca msg send <threadId> <message>` | Send text with formatting (`**bold**`, `*italic*`, `~~strike~~`, etc.), group @mention resolution (`--raw` to skip formatting), and quote replies via `--reply-id` or `--reply-message` |
71
101
  | `openzca msg image <threadId> [file]` | Send image(s) from file or URL |
72
102
  | `openzca msg video <threadId> [file]` | Send video(s) from file or URL; single `.mp4` inputs try native video mode |
73
103
  | `openzca msg voice <threadId> [file]` | Send voice message from local file or URL (`.aac`, `.mp3`, `.m4a`, `.wav`, `.ogg`) |
@@ -81,7 +111,7 @@ You can also open the saved file manually (for example: `open qr.png` on macOS).
81
111
  | `openzca msg edit <msgId> <cliMsgId> <threadId> <message>` | Edit message (undo + resend shim) |
82
112
  | `openzca msg undo <msgId> <cliMsgId> <threadId>` | Recall a sent message |
83
113
  | `openzca msg upload <arg1> [arg2]` | Upload and send file(s) |
84
- | `openzca msg recent <threadId>` | List recent messages (`-n`, `--json`, newest-first); group mode prefers direct group-history endpoint (websocket fallback) |
114
+ | `openzca msg recent <threadId>` | List recent messages (`-n`, `--json`, newest-first); defaults to live history, supports `--source live|db|auto`; group mode prefers direct group-history endpoint (websocket fallback) |
85
115
  | `openzca msg pin <threadId>` | Pin a conversation |
86
116
  | `openzca msg unpin <threadId>` | Unpin a conversation |
87
117
  | `openzca msg list-pins` | List pinned conversations |
@@ -91,6 +121,12 @@ Media commands accept local files, `file://` paths, and repeatable `--url` optio
91
121
  `openzca msg video` attempts native video send for a single `.mp4` input by uploading the video and thumbnail to Zalo first. If `ffmpeg` is unavailable, the input is not a single `.mp4`, or native send fails, it falls back to the normal attachment send path. Use `--thumbnail <path-or-url>` to supply the preview image explicitly.
92
122
  Local paths using `~` are expanded automatically (for positional file args, `--url`, and `OPENZCA_LISTEN_MEDIA_DIR`).
93
123
  Group text sends via `openzca msg send --group` resolve unique `@Name` or `@userId` mentions against the current group member list using member ids, display names, and usernames. Mention offsets are computed after formatting markers are parsed, so messages like `**@Alice Nguyen** hello` work. If multiple members share the same label, the command fails instead of guessing.
124
+ Reply flows:
125
+
126
+ - `--reply-id <id>` resolves a stored message from the local DB by `msgId`, `cliMsgId`, or internal message uid. This requires DB persistence to be enabled for the profile.
127
+ - `--reply-message <json>` accepts either the original `message.data` object from `zca-js` or the current `openzca listen --raw` payload. Use this path when DB is disabled or when a caller already has the inbound payload in memory.
128
+ - Use exactly one of `--reply-id` or `--reply-message`.
129
+ `msg recent` keeps the previous live behavior by default. Use `--source db` to read only from the local SQLite store, or `--source auto` to try DB first and fall back to live history.
94
130
 
95
131
  ### Debug Logging
96
132
 
@@ -197,6 +233,54 @@ Poll creation currently targets group threads only and maps to the existing `zca
197
233
  | `openzca me status <online\|offline>` | Set online status |
198
234
  | `openzca me last-online <userId>` | Check last online time |
199
235
 
236
+ ### db — Local SQLite source-of-truth
237
+
238
+ | Command | Description |
239
+ |---------|-------------|
240
+ | `openzca db enable` | Enable profile-scoped SQLite persistence (`--path <sqlite-file>` optional) |
241
+ | `openzca db disable` | Disable automatic DB persistence for the active profile |
242
+ | `openzca db status` | Show DB status, counts, and configured path |
243
+ | `openzca db me info` | Show the stored self profile snapshot |
244
+ | `openzca db me id` | Show the stored self user ID |
245
+ | `openzca db group list` | List groups stored in the DB |
246
+ | `openzca db group info <groupId>` | Show stored info for a group |
247
+ | `openzca db group members <groupId>` | List the stored member snapshot for a group |
248
+ | `openzca db group messages <groupId>` | List stored messages for a group (defaults to latest 20 newest-first; use `--all`, `--since <duration>`, `--from`/`--to`, `--limit`, or `--oldest-first`) |
249
+ | `openzca db friend list` | List friends stored in the DB |
250
+ | `openzca db friend find <query>` | Find stored friends by user ID or name |
251
+ | `openzca db friend info <userId>` | Show stored info for a friend |
252
+ | `openzca db friend messages <userId>` | List stored direct-message rows for a friend (defaults to latest 20 newest-first; use `--all`, `--since <duration>`, `--from`/`--to`, `--limit`, or `--oldest-first`) |
253
+ | `openzca db chat list` | List all chats stored in the DB |
254
+ | `openzca db chat info <chatId>` | Show stored info for a chat (`-g` to force group lookup) |
255
+ | `openzca db chat messages <chatId>` | List stored messages for any chat (`-g`; defaults to latest 20 newest-first; use `--all`, `--since <duration>`, `--from`/`--to`, `--limit`, or `--oldest-first`) |
256
+ | `openzca db message get <id>` | Read a single stored message by `msgId`, `cliMsgId`, or internal message uid |
257
+ | `openzca db sync` | Sync full group history, friend directory, and recent DM/chat windows into the DB |
258
+ | `openzca db sync all` | Explicit full sync |
259
+ | `openzca db sync groups` | Sync group directory, members, and full group history |
260
+ | `openzca db sync friends` | Sync friend directory only |
261
+ | `openzca db sync chats` | Sync discoverable chats and recent DM windows |
262
+ | `openzca db sync group <groupId>` | Sync one group with full group history |
263
+ | `openzca db sync chat <chatId>` | Sync one chat |
264
+
265
+ The DB is per-profile and is intended to be a factual local store for later querying. By default it lives at:
266
+
267
+ ```text
268
+ ~/.openzca/profiles/<profile>/messages.sqlite
269
+ ```
270
+
271
+ Notes:
272
+
273
+ - DB reads are explicit. Existing live commands keep their current default behavior.
274
+ - If DB is enabled, successful send commands and `listen` write in the background on a best-effort path so normal CLI flow is not blocked by SQLite work.
275
+ - Group sync is thread-scoped and more reliable because it uses the dedicated group history API when available.
276
+ - DM/chat sync is best-effort only. `zca-js` exposes old DM messages by user-message stream, not by exact DM thread, so `db sync chats` and `db sync chat <id>` should be treated as recent-window fills, not perfect historical mirrors.
277
+ - For DMs, the DB stores messages under a stable peer-based conversation key rather than trusting the raw listener `threadId` alone.
278
+ - Time filters accept:
279
+ - exact timestamps like `2026-03-21T10:00:00+07:00`
280
+ - unix seconds or milliseconds
281
+ - unix seconds or milliseconds
282
+ - relative durations like `7m`, `24h`, `1d`, or `1d2h30m`
283
+
200
284
  ### listen — Real-time listener
201
285
 
202
286
  | Command | Description |
@@ -206,6 +290,8 @@ Poll creation currently targets group threads only and maps to the existing `zca
206
290
  | `openzca listen --prefix <prefix>` | Only process messages matching prefix |
207
291
  | `openzca listen --webhook <url>` | POST message payload to a webhook URL |
208
292
  | `openzca listen --raw` | Output raw JSON per line |
293
+ | `openzca listen --db` | Force DB writes for this listener session |
294
+ | `openzca listen --no-db` | Disable DB writes for this listener session |
209
295
  | `openzca listen --keep-alive` | Auto-reconnect on disconnect |
210
296
  | `openzca listen --supervised --raw` | Supervisor mode with lifecycle JSON events (`session_id`, `connected`, `heartbeat`, `error`, `closed`) |
211
297
  | `openzca listen --keep-alive --recycle-ms <ms>` | Periodically recycle listener process to avoid stale sessions |
@@ -358,6 +444,8 @@ Profile data is stored in `~/.openzca/` (override with `OPENZCA_HOME`):
358
444
  profiles.json
359
445
  profiles/<name>/credentials.json
360
446
  profiles/<name>/cache/*.json
447
+ profiles/<name>/db.json
448
+ profiles/<name>/messages.sqlite
361
449
  ```
362
450
 
363
451
  ## Development