@vatio-ai/cli 0.128.0 → 0.129.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/webhooks.mjs +38 -2
- package/lib/help.mjs +3 -0
- 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;
|
|
@@ -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
|
@@ -225,6 +225,9 @@ the two you are in. Commands default as listed.
|
|
|
225
225
|
[--category utility|marketing] [--footer TEXT]
|
|
226
226
|
[--button-url 'TEXT|URL']... [--button-example VALUE]...
|
|
227
227
|
[--button-phone 'TEXT|PHONE'] [--button-quick-reply TEXT]...
|
|
228
|
+
whatsapp templates create [NAME] --components FILE [--language CODE]
|
|
229
|
+
[--category utility|marketing|authentication]
|
|
230
|
+
[--parameter-format positional|named]
|
|
228
231
|
Submit one for Meta's review: on your number, or
|
|
229
232
|
on Vatio's test number until you connect one
|
|
230
233
|
whatsapp templates rm NAME [--language CODE] | sync
|