@vatio-ai/cli 0.94.0 → 0.95.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/lib/api-client.mjs +0 -4
- package/lib/commands/messages.mjs +10 -70
- package/lib/help.mjs +1 -7
- package/lib/telemetry.mjs +1 -1
- package/package.json +1 -1
package/lib/api-client.mjs
CHANGED
|
@@ -17,10 +17,6 @@ export class ApiClient extends HttpClient {
|
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
resendMessage(id, { environment = "live" } = {}) {
|
|
21
|
-
return this.post(`/messages/${encode(id)}/resend`, { environment });
|
|
22
|
-
}
|
|
23
|
-
|
|
24
20
|
// --- deploy ---------------------------------------------------------
|
|
25
21
|
|
|
26
22
|
deployStatus() {
|
|
@@ -1,91 +1,31 @@
|
|
|
1
|
-
// Review
|
|
2
|
-
// platform owns the retry relationship and idempotency key; the CLI only
|
|
3
|
-
// selects attempts and makes the operator see them before sending.
|
|
1
|
+
// Review terminal failures after Vatio has finished its automatic attempts.
|
|
4
2
|
|
|
5
3
|
import { deployClient } from "./deploy.mjs";
|
|
6
|
-
import {
|
|
4
|
+
import { fail, takeEnv, takeFlag, takeValue } from "../support.mjs";
|
|
7
5
|
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
" vatio messages resend ID [--env live]\n" +
|
|
11
|
-
" vatio messages resend --since DATE (--error-code CODE|--error-contains TEXT) [--until DATE] [--before ID] [--yes]";
|
|
6
|
+
const USAGE = "vatio messages failed [--since DATE] [--until DATE] [--error-code CODE] " +
|
|
7
|
+
"[--error-contains TEXT] [--before ID] [--json]";
|
|
12
8
|
|
|
13
9
|
export async function messages(config, args) {
|
|
14
10
|
const environment = takeEnv(args, { fallback: "live" });
|
|
15
11
|
const json = takeFlag(args, "--json");
|
|
16
|
-
const yes = takeFlag(args, "--yes") || takeFlag(args, "-y");
|
|
17
12
|
const since = takeValue(args, "--since");
|
|
18
13
|
const until = takeValue(args, "--until");
|
|
19
14
|
const errorCode = takeValue(args, "--error-code");
|
|
20
15
|
const errorContains = takeValue(args, "--error-contains");
|
|
21
16
|
const before = takeValue(args, "--before");
|
|
22
|
-
const status = takeValue(args, "--status");
|
|
23
17
|
const sub = args.shift() ?? "failed";
|
|
24
|
-
if (
|
|
25
|
-
if (!(["failed", "resend"].includes(sub)) || (sub === "resend" && json)) fail(`Usage: ${USAGE}`);
|
|
26
|
-
if (args.length > 1 || (sub === "failed" && args.length > 0)) fail(`Usage: ${USAGE}`);
|
|
18
|
+
if (sub !== "failed" || args.length > 0) fail(`Usage: ${USAGE}`);
|
|
27
19
|
if (before !== null && !/^[1-9]\d*$/.test(before)) fail("--before needs a positive message ID");
|
|
28
20
|
|
|
29
21
|
const workspace = config.resolveWorkspaceRequired();
|
|
30
22
|
const client = deployClient(config, workspace);
|
|
23
|
+
const page = await client.failedMessages({ environment, since, until, errorCode, errorContains, before });
|
|
24
|
+
if (json) return console.log(JSON.stringify(page, null, 2));
|
|
31
25
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const { message, replayed } = await client.resendMessage(args[0], { environment });
|
|
35
|
-
console.log(`Message #${args[0]} → retry #${message.id} (${message.status})${replayed ? " — already created" : ""}`);
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (sub === "resend" && (!since || (!errorCode && !errorContains))) {
|
|
40
|
-
fail("A batch resend needs --since and --error-code or --error-contains, so it cannot catch unrelated failures.\n" + USAGE);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const selection = { environment, since, until, errorCode, errorContains, before };
|
|
44
|
-
const { list, nextBefore } = await collect(client, selection);
|
|
45
|
-
if (sub === "failed" && json) return console.log(JSON.stringify({ messages: list, next_before: nextBefore }, null, 2));
|
|
46
|
-
|
|
47
|
-
console.log(`${list.length} failed message${list.length === 1 ? "" : "s"} on ${workspace} (${environment}):`);
|
|
48
|
-
for (const row of list) {
|
|
26
|
+
console.log(`${page.messages.length} failed messages on ${workspace} (${environment}):`);
|
|
27
|
+
for (const row of page.messages) {
|
|
49
28
|
console.log(` #${row.id} ${row.created_at} ${row.mode} ${row.error_code || "?"} ${row.error_message || ""}`);
|
|
50
29
|
}
|
|
51
|
-
if (
|
|
52
|
-
if (sub === "failed" || list.length === 0) return;
|
|
53
|
-
|
|
54
|
-
if (!yes) {
|
|
55
|
-
if (!process.stdin.isTTY) fail("Nothing resent. Review the selection above, then pass --yes.");
|
|
56
|
-
const answer = (await ask(`Resend these ${list.length} messages? [y/N] `)).trim().toLowerCase();
|
|
57
|
-
if (!["y", "yes", "s", "si", "sí"].includes(answer)) return console.log("Nothing resent.");
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
let resent = 0;
|
|
61
|
-
let replayed = 0;
|
|
62
|
-
let failed = 0;
|
|
63
|
-
for (const [index, row] of list.entries()) {
|
|
64
|
-
try {
|
|
65
|
-
const result = await client.resendMessage(row.id, { environment });
|
|
66
|
-
console.log(` #${row.id} → #${result.message.id} (${result.message.status})${result.replayed ? " — already created" : ""}`);
|
|
67
|
-
if (result.replayed) replayed += 1;
|
|
68
|
-
else resent += 1;
|
|
69
|
-
} catch (error) {
|
|
70
|
-
console.error(` #${row.id} → could not resend: ${error.message}`);
|
|
71
|
-
failed += 1;
|
|
72
|
-
if ([401, 403, 429].includes(error.status)) break;
|
|
73
|
-
}
|
|
74
|
-
if (index < list.length - 1) await sleep(1_100);
|
|
75
|
-
}
|
|
76
|
-
const skipped = list.length - resent - replayed - failed;
|
|
77
|
-
console.log(`Queued ${resent} new retry attempt${resent === 1 ? "" : "s"}; ${replayed} already existed; ${failed} refused; ${skipped} not attempted.`);
|
|
78
|
-
if (failed > 0 || skipped > 0) process.exitCode = 1;
|
|
79
|
-
console.log("Follow their status in the inbox or server API.");
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
async function collect(client, selection) {
|
|
83
|
-
const list = [];
|
|
84
|
-
let before = selection.before;
|
|
85
|
-
do {
|
|
86
|
-
const page = await client.failedMessages({ ...selection, before });
|
|
87
|
-
list.push(...(page.messages ?? []));
|
|
88
|
-
before = page.next_before ?? null;
|
|
89
|
-
} while (before !== null && list.length < MAX_BATCH);
|
|
90
|
-
return { list, nextBefore: before };
|
|
30
|
+
if (page.next_before) console.log(`More may match. Continue with --before ${page.next_before}.`);
|
|
91
31
|
}
|
package/lib/help.mjs
CHANGED
|
@@ -145,17 +145,11 @@ Commands default as listed.
|
|
|
145
145
|
session, no keys or signing code
|
|
146
146
|
|
|
147
147
|
Recover outbound WhatsApp messages (with your developer login):
|
|
148
|
-
|
|
149
|
-
these commands inspect progress and recover other confirmed failures.
|
|
148
|
+
Vatio retries confirmed failures automatically. Inspect terminal failures:
|
|
150
149
|
messages failed [--since DATE] [--until DATE] [--error-code CODE]
|
|
151
150
|
[--error-contains TEXT] [--before ID] [--json]
|
|
152
151
|
List failed outgoing messages, including Meta's
|
|
153
152
|
delivery failures (default: live)
|
|
154
|
-
messages resend ID Retry one confirmed failure once
|
|
155
|
-
messages resend --since DATE (--error-code CODE|--error-contains TEXT) [--before ID] [--yes]
|
|
156
|
-
Preview a matching batch, then retry it. --yes
|
|
157
|
-
is required without a terminal. At most 200
|
|
158
|
-
messages per batch; use --before to continue
|
|
159
153
|
|
|
160
154
|
Sending from your backend (WhatsApp, with a server key):
|
|
161
155
|
templates list [--env live] [--json]
|
package/lib/telemetry.mjs
CHANGED
|
@@ -26,7 +26,7 @@ const MAX_MESSAGE = 2_000;
|
|
|
26
26
|
// there is a value (`vatio chat "hola"`), and values are not sent.
|
|
27
27
|
const SUBCOMMANDS = {
|
|
28
28
|
chat: ["show"],
|
|
29
|
-
messages: ["failed"
|
|
29
|
+
messages: ["failed"],
|
|
30
30
|
env: ["list", "rm"],
|
|
31
31
|
kb: ["list", "show", "create", "rm", "write", "cat", "rm-entry", "status", "publish", "history"],
|
|
32
32
|
business: ["show", "set"],
|