@seguelac/aca-cli 0.8.1 → 0.9.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
@@ -2,6 +2,12 @@
2
2
 
3
3
  All notable changes to `aca-cli` are documented here. Format loosely follows [Keep a Changelog](https://keepachangelog.com/).
4
4
 
5
+ ## [0.9.0] - 2026-11-23
6
+
7
+ ### Added
8
+ - **Scheduled replies.** `aca reply <id> --at "2026-12-07 09:00"` queues the reply instead of sending it. It goes out at that time from the same mailbox and thread, with the signature, exactly like a reply sent now. It's cancelled automatically if the contact replies first; `--keep-on-reply` sends it regardless. `--at` takes local time (`YYYY-MM-DD HH:MM`) or an ISO timestamp with an offset.
9
+ - **`aca scheduled`**: `ls` (pending by default; `-c <conversationId>`, `--all`), `cancel <id>` and `reschedule <id> --at "..."`.
10
+
5
11
  ## [0.8.1] - 2026-11-09
6
12
 
7
13
  ### Fixed
package/README.md CHANGED
@@ -75,6 +75,9 @@ aca campaign leads <campaignId> --stuck --json | jq '.[] | .contact_id'
75
75
  | `aca inbox show <id>` | Show a conversation and its recent messages. |
76
76
  | `aca inbox list` | List all conversations. Filters: `--channel`, `--status`, `--intent`. |
77
77
  | `aca reply <id> -m "..."` | Reply to a conversation. Also accepts piped stdin. |
78
+ | `aca reply <id> -m "..." --at "2026-12-07 09:00"` | Schedule the reply instead of sending now (local time, or ISO with an offset). Cancelled automatically if the contact replies first; add `--keep-on-reply` to send regardless. |
79
+ | `aca scheduled ls` | Pending scheduled replies. `-c <conversationId>` for one thread, `--all` to include sent/cancelled/failed. |
80
+ | `aca scheduled cancel <id>` / `aca scheduled reschedule <id> --at "..."` | Cancel or move a pending scheduled reply. |
78
81
 
79
82
  ### Campaigns
80
83
  | Command | What it does |
@@ -11,8 +11,18 @@ export function registerReply(program) {
11
11
  .option('--subject <text>', 'Email subject (email channels only)')
12
12
  .option('--cc <emails>', 'Comma-separated CC list (email only)')
13
13
  .option('--bcc <emails>', 'Comma-separated BCC list (email only)')
14
+ .option('--at <datetime>', 'Schedule instead of sending now, e.g. "2026-12-07 09:00" (local time) or an ISO timestamp with offset')
15
+ .option('--keep-on-reply', 'With --at: still send even if the contact replies first (default: cancel on reply)')
14
16
  .option('--json', 'Emit JSON')
15
17
  .action(async (conversationId, opts) => {
18
+ if (opts.keepOnReply && !opts.at)
19
+ fail('--keep-on-reply only applies with --at');
20
+ let sendAt = null;
21
+ if (opts.at) {
22
+ sendAt = parseSendAt(opts.at);
23
+ if (sendAt.getTime() <= Date.now())
24
+ fail(`--at is in the past: ${sendAt.toString()}`);
25
+ }
16
26
  const piped = await readStdinIfPiped();
17
27
  const content = opts.message ?? piped;
18
28
  if (!content)
@@ -46,7 +56,18 @@ export function registerReply(program) {
46
56
  if (opts.bcc)
47
57
  body.email_bcc = opts.bcc.split(',').map((s) => s.trim());
48
58
  }
59
+ if (sendAt) {
60
+ body.send_at = sendAt.toISOString();
61
+ body.cancel_on_reply = !opts.keepOnReply;
62
+ }
49
63
  const result = await invokeFn('crm-send-message', body);
50
64
  output(result, { json: opts.json });
51
65
  });
52
66
  }
67
+ export function parseSendAt(value) {
68
+ const normalized = value.trim().replace(' ', 'T');
69
+ const d = new Date(normalized);
70
+ if (Number.isNaN(d.getTime()))
71
+ fail(`Can't parse --at "${value}". Use "YYYY-MM-DD HH:MM" or an ISO timestamp.`);
72
+ return d;
73
+ }
@@ -0,0 +1,67 @@
1
+ import { restGet, restPatch } from '../api.js';
2
+ import { output, fail } from '../output.js';
3
+ import { parseSendAt } from './reply.js';
4
+ const COLS = 'id,conversation_id,contact_id,channel,recipient_display_name,scheduled_for,status,cancel_on_reply,cancelled_reason,error_message,content';
5
+ export function registerScheduled(program) {
6
+ const cmd = program.command('scheduled').description('Scheduled inbox replies (send later)');
7
+ cmd
8
+ .command('ls')
9
+ .description('List scheduled replies (pending by default)')
10
+ .option('-c, --conversation <id>', 'Only this conversation')
11
+ .option('--all', 'Include sent, cancelled and failed')
12
+ .option('--limit <n>', 'Max rows', '50')
13
+ .option('--json', 'Emit JSON')
14
+ .action(async (opts) => {
15
+ const filters = ['source_type=eq.manual', 'conversation_id=not.is.null'];
16
+ if (!opts.all)
17
+ filters.push('status=eq.pending');
18
+ if (opts.conversation)
19
+ filters.push(`conversation_id=eq.${opts.conversation}`);
20
+ const rows = await restGet(`crm_message_queue?${filters.join('&')}&select=${COLS}&order=scheduled_for.${opts.all ? 'desc' : 'asc'}&limit=${Number(opts.limit) || 50}`);
21
+ if (opts.json)
22
+ return output(rows, { json: true });
23
+ output(rows.map((r) => ({
24
+ id: r.id,
25
+ to: r.recipient_display_name,
26
+ channel: r.channel,
27
+ send_at: new Date(r.scheduled_for).toLocaleString(),
28
+ status: r.cancelled_reason ? `${r.status} (${r.cancelled_reason})` : r.status,
29
+ cancel_on_reply: r.cancel_on_reply,
30
+ preview: r.content.replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim().slice(0, 60),
31
+ })));
32
+ });
33
+ cmd
34
+ .command('cancel')
35
+ .description('Cancel a pending scheduled reply')
36
+ .argument('<id>')
37
+ .option('--json', 'Emit JSON')
38
+ .action(async (id, opts) => {
39
+ const rows = await restPatch(`crm_message_queue?id=eq.${id}&status=eq.pending&select=${COLS}`, {
40
+ status: 'cancelled',
41
+ cancelled_reason: 'user_cancelled',
42
+ cancelled_at: new Date().toISOString(),
43
+ updated_at: new Date().toISOString(),
44
+ });
45
+ if (!rows?.length)
46
+ fail(`No pending scheduled reply ${id} (already sent, cancelled or not found)`);
47
+ output(rows[0], { json: opts.json });
48
+ });
49
+ cmd
50
+ .command('reschedule')
51
+ .description('Move a pending scheduled reply to a new time')
52
+ .argument('<id>')
53
+ .requiredOption('--at <datetime>', 'New time, e.g. "2026-12-08 09:00" (local) or ISO with offset')
54
+ .option('--json', 'Emit JSON')
55
+ .action(async (id, opts) => {
56
+ const at = parseSendAt(opts.at);
57
+ if (at.getTime() <= Date.now())
58
+ fail(`--at is in the past: ${at.toString()}`);
59
+ const rows = await restPatch(`crm_message_queue?id=eq.${id}&status=eq.pending&select=${COLS}`, {
60
+ scheduled_for: at.toISOString(),
61
+ updated_at: new Date().toISOString(),
62
+ });
63
+ if (!rows?.length)
64
+ fail(`No pending scheduled reply ${id} (already sent, cancelled or not found)`);
65
+ output(rows[0], { json: opts.json });
66
+ });
67
+ }
package/dist/index.js CHANGED
@@ -10,6 +10,7 @@ import { registerLists } from './commands/lists.js';
10
10
  import { registerLeads } from './commands/leads.js';
11
11
  import { registerInbox } from './commands/inbox.js';
12
12
  import { registerReply } from './commands/reply.js';
13
+ import { registerScheduled } from './commands/scheduled.js';
13
14
  import { registerCampaign } from './commands/campaign.js';
14
15
  import { registerSequence } from './commands/sequence.js';
15
16
  import { registerContact } from './commands/contact.js';
@@ -35,6 +36,7 @@ registerLists(program);
35
36
  registerLeads(program);
36
37
  registerInbox(program);
37
38
  registerReply(program);
39
+ registerScheduled(program);
38
40
  registerCampaign(program);
39
41
  registerSequence(program);
40
42
  registerContact(program);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seguelac/aca-cli",
3
- "version": "0.8.1",
3
+ "version": "0.9.0",
4
4
  "description": "Command-line interface for ACA (Automated Client Acquisition) — push leads to campaigns, triage replies, manage contacts, all from your terminal.",
5
5
  "type": "module",
6
6
  "bin": {