@vatio-ai/cli 0.128.0 → 0.130.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 +7 -1
- package/lib/commands/channels.mjs +5 -13
- package/lib/commands/deploy.mjs +23 -3
- package/lib/commands/webhooks.mjs +38 -2
- package/lib/help.mjs +6 -2
- package/package.json +1 -1
package/lib/api-client.mjs
CHANGED
|
@@ -272,7 +272,13 @@ export class ApiClient extends HttpClient {
|
|
|
272
272
|
return this.get("/templates", { environment });
|
|
273
273
|
}
|
|
274
274
|
|
|
275
|
-
createTemplate({ name, language, category, body, examples = [], footer = null, buttons = []
|
|
275
|
+
createTemplate({ name, language, category, body = null, examples = [], footer = null, buttons = [], components = null,
|
|
276
|
+
parameterFormat = null }) {
|
|
277
|
+
if (components) {
|
|
278
|
+
const payload = { name, language, category, components };
|
|
279
|
+
if (parameterFormat) payload.parameter_format = parameterFormat;
|
|
280
|
+
return this.post("/templates", payload);
|
|
281
|
+
}
|
|
276
282
|
const payload = { name, language, category, body, examples };
|
|
277
283
|
if (String(footer ?? "").trim() !== "") payload.footer = String(footer).trim();
|
|
278
284
|
if (buttons.length > 0) payload.buttons = buttons;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// vatio.ai/workspaces is only for a server too old to send the link, and
|
|
6
6
|
// redirects to the inbox.
|
|
7
7
|
|
|
8
|
-
import { deployClient } from "./deploy.mjs";
|
|
8
|
+
import { deployClient, whatsappIssueLines } from "./deploy.mjs";
|
|
9
9
|
import { messages } from "./messages.mjs";
|
|
10
10
|
import { withSecondFactor } from "./team.mjs";
|
|
11
11
|
import { templates } from "./webhooks.mjs";
|
|
@@ -55,10 +55,10 @@ export async function whatsapp(config, args = []) {
|
|
|
55
55
|
}
|
|
56
56
|
case "check": {
|
|
57
57
|
// The number's two-step verification PIN registers it on the Cloud API
|
|
58
|
-
//
|
|
58
|
+
// first: the fix for an issue of kind not_registered.
|
|
59
59
|
const pin = takeValue(args, "--pin");
|
|
60
60
|
if (args.length) fail(WHATSAPP_USAGE);
|
|
61
|
-
if (pin !== null && !/^\d{6}$/.test(pin)) fail("--pin is the number's two-step verification PIN: 6 digits.");
|
|
61
|
+
if (pin !== null && !/^\d{6}$/.test(pin)) fail("--pin is the number's two-step verification PIN: 6 digits. A number with none takes them as its PIN.");
|
|
62
62
|
const number = await client().checkWhatsapp(pin);
|
|
63
63
|
printNumber(number, { json, checked: true });
|
|
64
64
|
// A check that leaves Meta refusing every send did not pass.
|
|
@@ -172,7 +172,8 @@ function printNumber(number, { json = false, checked = false } = {}) {
|
|
|
172
172
|
if (json) return console.log(JSON.stringify(number, null, 2));
|
|
173
173
|
const name = number.number ?? "Your number";
|
|
174
174
|
if (number.issue) {
|
|
175
|
-
|
|
175
|
+
console.log("");
|
|
176
|
+
for (const line of whatsappIssueLines(name, number.issue)) console.log(line);
|
|
176
177
|
} else {
|
|
177
178
|
const live = number.live
|
|
178
179
|
? paint("green", "live: the agent answers everyone who writes")
|
|
@@ -186,12 +187,3 @@ function printNumber(number, { json = false, checked = false } = {}) {
|
|
|
186
187
|
if (number.failed_deliveries) console.log(` ${number.failed_deliveries} failed deliveries: vatio whatsapp failed`);
|
|
187
188
|
}
|
|
188
189
|
|
|
189
|
-
// Meta refuses every send from the number, and the server API refuses your
|
|
190
|
-
// backend's messages with 409 whatsapp_number_unhealthy until a check passes.
|
|
191
|
-
function printIssue(name, issue) {
|
|
192
|
-
const code = issue.code ? ` (Meta ${issue.code})` : "";
|
|
193
|
-
console.log(`\n${name}: ${paint("red", `NOT SENDING since ${issue.since}${code}`)}`);
|
|
194
|
-
if (issue.message) console.log(` Meta: ${issue.message}`);
|
|
195
|
-
console.log(` Fix: ${issue.fix}`);
|
|
196
|
-
console.log(" Until a check passes, POST /messages answers 409 whatsapp_number_unhealthy and the agent's replies do not go out.");
|
|
197
|
-
}
|
package/lib/commands/deploy.mjs
CHANGED
|
@@ -522,10 +522,30 @@ function printPreviewHolds(payload) {
|
|
|
522
522
|
function printWhatsappIssue(whatsapp) {
|
|
523
523
|
const issue = whatsapp?.issue;
|
|
524
524
|
if (!issue) return;
|
|
525
|
+
for (const line of whatsappIssueLines(`WhatsApp ${whatsapp.number ?? "number"}`, issue)) console.error(line);
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
// The number's issue as `vatio whatsapp` and `vatio status` say it, and as the
|
|
529
|
+
// inbox's WhatsApp page and the MCP's get_whatsapp do. Not registered is also
|
|
530
|
+
// where a number lands the moment it is first connected, so it reads as that
|
|
531
|
+
// step, and its fix already says what Meta said.
|
|
532
|
+
export function whatsappIssueLines(name, issue) {
|
|
533
|
+
const until = "POST /messages answers 409 whatsapp_number_unhealthy and the agent's replies do not go out.";
|
|
534
|
+
if (issue.kind === "not_registered") {
|
|
535
|
+
return [
|
|
536
|
+
`${name}: ${paint("red", "NOT REGISTERED on the WhatsApp Cloud API: register it so it can send")}`,
|
|
537
|
+
` Fix: ${issue.fix}`,
|
|
538
|
+
" Register it: vatio whatsapp check --pin PIN",
|
|
539
|
+
` Until then, ${until}`,
|
|
540
|
+
];
|
|
541
|
+
}
|
|
525
542
|
const code = issue.code ? ` (Meta ${issue.code})` : "";
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
543
|
+
return [
|
|
544
|
+
`${name}: ${paint("red", `NOT SENDING since ${issue.since}${code}`)}`,
|
|
545
|
+
...(issue.message ? [` Meta: ${issue.message}`] : []),
|
|
546
|
+
` Fix: ${issue.fix}`,
|
|
547
|
+
` Until a check passes (vatio whatsapp check), ${until}`,
|
|
548
|
+
];
|
|
529
549
|
}
|
|
530
550
|
|
|
531
551
|
// What Vatio did for this workspace in the last 30 days, in one line a
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
// reports what happened. Sending itself is the backend's job, with a server
|
|
5
5
|
// key, not the CLI's.
|
|
6
6
|
|
|
7
|
+
import { readFileSync } from "node:fs";
|
|
8
|
+
|
|
7
9
|
import { deployClient } from "./deploy.mjs";
|
|
8
10
|
import { fail, paint, sleep, takeEnv, takeFlag, takeValue } from "../support.mjs";
|
|
9
11
|
|
|
@@ -19,7 +21,9 @@ function takeAll(args, name) {
|
|
|
19
21
|
const LIST_USAGE = "vatio whatsapp templates list [--env live] [--json]";
|
|
20
22
|
const CREATE_USAGE = "vatio whatsapp templates create NAME --language CODE --body TEXT [--example VALUE]... " +
|
|
21
23
|
"[--category utility|marketing] [--footer TEXT] [--button-url 'TEXT|URL']... [--button-example VALUE]... " +
|
|
22
|
-
"[--button-phone 'TEXT|PHONE'] [--button-quick-reply TEXT]... [--json]"
|
|
24
|
+
"[--button-phone 'TEXT|PHONE'] [--button-quick-reply TEXT]... [--json]\n" +
|
|
25
|
+
" vatio whatsapp templates create [NAME] --components FILE [--language CODE] " +
|
|
26
|
+
"[--category utility|marketing|authentication] [--parameter-format positional|named] [--json]";
|
|
23
27
|
const RM_USAGE = "vatio whatsapp templates rm NAME [--language CODE] [--json]";
|
|
24
28
|
const SYNC_USAGE = "vatio whatsapp templates sync [--json]";
|
|
25
29
|
|
|
@@ -83,6 +87,9 @@ export async function templates(config, args) {
|
|
|
83
87
|
// decides where, so there is no environment to choose.
|
|
84
88
|
async function createTemplate(config, args, json) {
|
|
85
89
|
takeValue(args, "--env");
|
|
90
|
+
const file = takeValue(args, "--components");
|
|
91
|
+
if (file !== null) return createFromComponents(config, args, json, file);
|
|
92
|
+
|
|
86
93
|
const language = takeValue(args, "--language");
|
|
87
94
|
const body = takeValue(args, "--body");
|
|
88
95
|
const category = takeValue(args, "--category") ?? "utility";
|
|
@@ -95,12 +102,41 @@ async function createTemplate(config, args, json) {
|
|
|
95
102
|
const workspace = config.resolveWorkspaceRequired();
|
|
96
103
|
const client = deployClient(config, workspace);
|
|
97
104
|
const template = await client.createTemplate({ name, language, category, body, examples, footer, buttons });
|
|
105
|
+
printCreated(template, json, template.parameter_count ?? examples.length);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Meta's own structure, as its Message Templates API takes it: a JSON file
|
|
109
|
+
// (or - for stdin) with the components list, or the whole request body
|
|
110
|
+
// ({ name, language, category, parameter_format, components }), whose fields
|
|
111
|
+
// the flags override.
|
|
112
|
+
async function createFromComponents(config, args, json, file) {
|
|
113
|
+
let parsed;
|
|
114
|
+
try {
|
|
115
|
+
parsed = JSON.parse(readFileSync(file === "-" ? 0 : file, "utf8"));
|
|
116
|
+
} catch (error) {
|
|
117
|
+
fail(`--components: could not read ${file === "-" ? "stdin" : file} as JSON (${error.message})`);
|
|
118
|
+
}
|
|
119
|
+
const request = Array.isArray(parsed) ? { components: parsed } : (parsed ?? {});
|
|
120
|
+
const language = takeValue(args, "--language") ?? request.language;
|
|
121
|
+
const category = takeValue(args, "--category") ?? request.category ?? "utility";
|
|
122
|
+
const parameterFormat = takeValue(args, "--parameter-format") ?? request.parameter_format;
|
|
123
|
+
const name = args.shift() ?? request.name;
|
|
124
|
+
if (!name || !language || !Array.isArray(request.components) || args.length > 0) fail(`Usage: ${CREATE_USAGE}`);
|
|
125
|
+
|
|
126
|
+
const client = deployClient(config, config.resolveWorkspaceRequired());
|
|
127
|
+
const template = await client.createTemplate({
|
|
128
|
+
name, language, category: String(category).toLowerCase(), components: request.components,
|
|
129
|
+
parameterFormat: parameterFormat ? String(parameterFormat).toLowerCase() : null
|
|
130
|
+
});
|
|
131
|
+
printCreated(template, json, template.parameter_count ?? 0);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function printCreated(template, json, count) {
|
|
98
135
|
if (json) {
|
|
99
136
|
console.log(JSON.stringify(template, null, 2));
|
|
100
137
|
return;
|
|
101
138
|
}
|
|
102
139
|
const own = template.whatsapp_connected === true;
|
|
103
|
-
const count = template.parameter_count ?? examples.length;
|
|
104
140
|
console.log(`Submitted ${template.name} (${template.language}) for Meta's review on ` +
|
|
105
141
|
`${own ? "your own number" : "Vatio's test number"}: ${template.category}, ` +
|
|
106
142
|
`${count} param${count === 1 ? "" : "s"}, ${paint("cyan", template.status)}.`);
|
package/lib/help.mjs
CHANGED
|
@@ -210,8 +210,9 @@ the two you are in. Commands default as listed.
|
|
|
210
210
|
whatsapp live on|off Answer everyone who writes, or nobody
|
|
211
211
|
whatsapp check [--pin PIN] Check the number with Meta and re-subscribe it;
|
|
212
212
|
a pass clears its problem. --pin (its 6-digit
|
|
213
|
-
two-step verification PIN
|
|
214
|
-
|
|
213
|
+
two-step verification PIN, or the one it takes
|
|
214
|
+
when it has none) registers it on the Cloud API
|
|
215
|
+
first: the fix for a number not registered
|
|
215
216
|
whatsapp disconnect [--yes]
|
|
216
217
|
whatsapp invite EMAIL [--code CODE]
|
|
217
218
|
Ask whoever manages the number to connect it:
|
|
@@ -225,6 +226,9 @@ the two you are in. Commands default as listed.
|
|
|
225
226
|
[--category utility|marketing] [--footer TEXT]
|
|
226
227
|
[--button-url 'TEXT|URL']... [--button-example VALUE]...
|
|
227
228
|
[--button-phone 'TEXT|PHONE'] [--button-quick-reply TEXT]...
|
|
229
|
+
whatsapp templates create [NAME] --components FILE [--language CODE]
|
|
230
|
+
[--category utility|marketing|authentication]
|
|
231
|
+
[--parameter-format positional|named]
|
|
228
232
|
Submit one for Meta's review: on your number, or
|
|
229
233
|
on Vatio's test number until you connect one
|
|
230
234
|
whatsapp templates rm NAME [--language CODE] | sync
|