@vatio-ai/cli 0.93.0 → 0.94.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/bin/vatio.mjs +3 -0
- package/lib/api-client.mjs +12 -0
- package/lib/commands/messages.mjs +91 -0
- package/lib/help.mjs +13 -0
- package/lib/telemetry.mjs +1 -0
- package/package.json +1 -1
package/bin/vatio.mjs
CHANGED
|
@@ -21,6 +21,7 @@ import { kb } from "../lib/commands/knowledge.mjs";
|
|
|
21
21
|
import { business } from "../lib/commands/business.mjs";
|
|
22
22
|
import { instagram, whatsapp } from "../lib/commands/channels.mjs";
|
|
23
23
|
import { docs, feedback, shareSession } from "../lib/commands/support-commands.mjs";
|
|
24
|
+
import { messages } from "../lib/commands/messages.mjs";
|
|
24
25
|
import { evalCommand, flags, test, tools } from "../lib/commands/improve.mjs";
|
|
25
26
|
import { printUpdateNotice, startUpdateCheck } from "../lib/update-notice.mjs";
|
|
26
27
|
import { runLatest } from "../lib/run-latest.mjs";
|
|
@@ -104,6 +105,8 @@ async function run(command, args) {
|
|
|
104
105
|
return await auth(config, args);
|
|
105
106
|
case "chat":
|
|
106
107
|
return await chat(config, args);
|
|
108
|
+
case "messages":
|
|
109
|
+
return await messages(config, args);
|
|
107
110
|
case "kb":
|
|
108
111
|
return await kb(config, args);
|
|
109
112
|
case "business":
|
package/lib/api-client.mjs
CHANGED
|
@@ -9,6 +9,18 @@ import { HttpClient } from "./http.mjs";
|
|
|
9
9
|
const encode = (value) => encodeURIComponent(String(value));
|
|
10
10
|
|
|
11
11
|
export class ApiClient extends HttpClient {
|
|
12
|
+
// --- outbound WhatsApp messages ------------------------------------
|
|
13
|
+
|
|
14
|
+
failedMessages({ environment = "live", since = null, until = null, errorCode = null, errorContains = null, before = null } = {}) {
|
|
15
|
+
return this.get("/messages", {
|
|
16
|
+
environment, since, until, error_code: errorCode, error_contains: errorContains, before
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
resendMessage(id, { environment = "live" } = {}) {
|
|
21
|
+
return this.post(`/messages/${encode(id)}/resend`, { environment });
|
|
22
|
+
}
|
|
23
|
+
|
|
12
24
|
// --- deploy ---------------------------------------------------------
|
|
13
25
|
|
|
14
26
|
deployStatus() {
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Review and deliberately resend failed outbound WhatsApp messages. The
|
|
2
|
+
// platform owns the retry relationship and idempotency key; the CLI only
|
|
3
|
+
// selects attempts and makes the operator see them before sending.
|
|
4
|
+
|
|
5
|
+
import { deployClient } from "./deploy.mjs";
|
|
6
|
+
import { ask, fail, sleep, takeEnv, takeFlag, takeValue } from "../support.mjs";
|
|
7
|
+
|
|
8
|
+
const MAX_BATCH = 200;
|
|
9
|
+
const USAGE = "vatio messages failed [--since DATE] [--until DATE] [--error-code CODE] [--error-contains TEXT] [--before ID] [--json]\n" +
|
|
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]";
|
|
12
|
+
|
|
13
|
+
export async function messages(config, args) {
|
|
14
|
+
const environment = takeEnv(args, { fallback: "live" });
|
|
15
|
+
const json = takeFlag(args, "--json");
|
|
16
|
+
const yes = takeFlag(args, "--yes") || takeFlag(args, "-y");
|
|
17
|
+
const since = takeValue(args, "--since");
|
|
18
|
+
const until = takeValue(args, "--until");
|
|
19
|
+
const errorCode = takeValue(args, "--error-code");
|
|
20
|
+
const errorContains = takeValue(args, "--error-contains");
|
|
21
|
+
const before = takeValue(args, "--before");
|
|
22
|
+
const status = takeValue(args, "--status");
|
|
23
|
+
const sub = args.shift() ?? "failed";
|
|
24
|
+
if (status !== null && status !== "failed") fail("Only --status failed is supported");
|
|
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}`);
|
|
27
|
+
if (before !== null && !/^[1-9]\d*$/.test(before)) fail("--before needs a positive message ID");
|
|
28
|
+
|
|
29
|
+
const workspace = config.resolveWorkspaceRequired();
|
|
30
|
+
const client = deployClient(config, workspace);
|
|
31
|
+
|
|
32
|
+
if (sub === "resend" && args.length === 1) {
|
|
33
|
+
if (!/^\d+$/.test(args[0]) || since || until || errorCode || errorContains || before) fail(`Usage: ${USAGE}`);
|
|
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) {
|
|
49
|
+
console.log(` #${row.id} ${row.created_at} ${row.mode} ${row.error_code || "?"} ${row.error_message || ""}`);
|
|
50
|
+
}
|
|
51
|
+
if (nextBefore) console.log(`More may match. Continue with --before ${nextBefore} after this batch.`);
|
|
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 };
|
|
91
|
+
}
|
package/lib/help.mjs
CHANGED
|
@@ -144,6 +144,19 @@ Commands default as listed.
|
|
|
144
144
|
Your users sign in with Supabase: verify their
|
|
145
145
|
session, no keys or signing code
|
|
146
146
|
|
|
147
|
+
Recover outbound WhatsApp messages (with your developer login):
|
|
148
|
+
Live templates rejected for payment eligibility retry automatically;
|
|
149
|
+
these commands inspect progress and recover other confirmed failures.
|
|
150
|
+
messages failed [--since DATE] [--until DATE] [--error-code CODE]
|
|
151
|
+
[--error-contains TEXT] [--before ID] [--json]
|
|
152
|
+
List failed outgoing messages, including Meta's
|
|
153
|
+
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
|
+
|
|
147
160
|
Sending from your backend (WhatsApp, with a server key):
|
|
148
161
|
templates list [--env live] [--json]
|
|
149
162
|
The number's templates, parameter counts, and the
|
package/lib/telemetry.mjs
CHANGED
|
@@ -26,6 +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", "resend"],
|
|
29
30
|
env: ["list", "rm"],
|
|
30
31
|
kb: ["list", "show", "create", "rm", "write", "cat", "rm-entry", "status", "publish", "history"],
|
|
31
32
|
business: ["show", "set"],
|