@vatio-ai/cli 0.127.0 → 0.128.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 +2 -1
- package/lib/commands/webhooks.mjs +39 -2
- package/lib/help.mjs +2 -0
- package/package.json +1 -1
package/lib/api-client.mjs
CHANGED
|
@@ -272,9 +272,10 @@ 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 }) {
|
|
275
|
+
createTemplate({ name, language, category, body, examples = [], footer = null, buttons = [] }) {
|
|
276
276
|
const payload = { name, language, category, body, examples };
|
|
277
277
|
if (String(footer ?? "").trim() !== "") payload.footer = String(footer).trim();
|
|
278
|
+
if (buttons.length > 0) payload.buttons = buttons;
|
|
278
279
|
return this.post("/templates", payload);
|
|
279
280
|
}
|
|
280
281
|
|
|
@@ -18,7 +18,8 @@ function takeAll(args, name) {
|
|
|
18
18
|
|
|
19
19
|
const LIST_USAGE = "vatio whatsapp templates list [--env live] [--json]";
|
|
20
20
|
const CREATE_USAGE = "vatio whatsapp templates create NAME --language CODE --body TEXT [--example VALUE]... " +
|
|
21
|
-
"[--category utility|marketing] [--footer TEXT] [--
|
|
21
|
+
"[--category utility|marketing] [--footer TEXT] [--button-url 'TEXT|URL']... [--button-example VALUE]... " +
|
|
22
|
+
"[--button-phone 'TEXT|PHONE'] [--button-quick-reply TEXT]... [--json]";
|
|
22
23
|
const RM_USAGE = "vatio whatsapp templates rm NAME [--language CODE] [--json]";
|
|
23
24
|
const SYNC_USAGE = "vatio whatsapp templates sync [--json]";
|
|
24
25
|
|
|
@@ -69,6 +70,7 @@ export async function templates(config, args) {
|
|
|
69
70
|
const count = template.parameter_count ?? "?";
|
|
70
71
|
console.log(` ${template.name} (${template.language}) ${template.category} ${status} ${count} param${count === 1 ? "" : "s"}`);
|
|
71
72
|
if (template.body) console.log(` ${template.body.replace(/\n/g, "\n ")}`);
|
|
73
|
+
if (template.buttons?.length) console.log(` buttons: ${template.buttons.map(describeButton).join(" · ")}`);
|
|
72
74
|
if (template.status === "REJECTED" && template.rejected_reason) console.log(` ${paint("red", "rejected:")} ${template.rejected_reason}`);
|
|
73
75
|
if (template.status === "APPROVED") console.log(` "template": ${JSON.stringify(template.example)}`);
|
|
74
76
|
}
|
|
@@ -86,12 +88,13 @@ async function createTemplate(config, args, json) {
|
|
|
86
88
|
const category = takeValue(args, "--category") ?? "utility";
|
|
87
89
|
const footer = takeValue(args, "--footer");
|
|
88
90
|
const examples = takeAll(args, "--example");
|
|
91
|
+
const buttons = takeButtons(args);
|
|
89
92
|
const name = args.shift();
|
|
90
93
|
if (!name || !language || !body || args.length > 0) fail(`Usage: ${CREATE_USAGE}`);
|
|
91
94
|
|
|
92
95
|
const workspace = config.resolveWorkspaceRequired();
|
|
93
96
|
const client = deployClient(config, workspace);
|
|
94
|
-
const template = await client.createTemplate({ name, language, category, body, examples, footer });
|
|
97
|
+
const template = await client.createTemplate({ name, language, category, body, examples, footer, buttons });
|
|
95
98
|
if (json) {
|
|
96
99
|
console.log(JSON.stringify(template, null, 2));
|
|
97
100
|
return;
|
|
@@ -114,6 +117,40 @@ async function createTemplate(config, args, json) {
|
|
|
114
117
|
}
|
|
115
118
|
}
|
|
116
119
|
|
|
120
|
+
// In the order WhatsApp draws them: links, the phone, then quick replies,
|
|
121
|
+
// which Meta wants together. A link ending in {{1}} takes its value per
|
|
122
|
+
// message, and its --button-example for Meta's review, in order.
|
|
123
|
+
function takeButtons(args) {
|
|
124
|
+
const pair = (flag, value, second) => {
|
|
125
|
+
const at = value.indexOf("|");
|
|
126
|
+
if (at <= 0 || at === value.length - 1) fail(`${flag} takes "TEXT|${second}", like "Ver pedido|https://example.com/orders/{{1}}"`);
|
|
127
|
+
return [value.slice(0, at).trim(), value.slice(at + 1).trim()];
|
|
128
|
+
};
|
|
129
|
+
const urls = takeAll(args, "--button-url").map((value) => {
|
|
130
|
+
const [text, url] = pair("--button-url", value, "URL");
|
|
131
|
+
return { type: "url", text, url };
|
|
132
|
+
});
|
|
133
|
+
const phones = takeAll(args, "--button-phone").map((value) => {
|
|
134
|
+
const [text, phone] = pair("--button-phone", value, "PHONE");
|
|
135
|
+
return { type: "phone_number", text, phone_number: phone };
|
|
136
|
+
});
|
|
137
|
+
const replies = takeAll(args, "--button-quick-reply").map((text) => ({ type: "quick_reply", text }));
|
|
138
|
+
|
|
139
|
+
const examples = takeAll(args, "--button-example");
|
|
140
|
+
const dynamic = urls.filter((button) => button.url.endsWith("{{1}}"));
|
|
141
|
+
if (examples.length !== dynamic.length) {
|
|
142
|
+
fail(`--button-example: ${examples.length} given, ${dynamic.length} needed, one per --button-url ` +
|
|
143
|
+
"ending in {{1}}, in order.");
|
|
144
|
+
}
|
|
145
|
+
dynamic.forEach((button, index) => { button.example = examples[index]; });
|
|
146
|
+
return [...urls, ...phones, ...replies];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function describeButton(button) {
|
|
150
|
+
const target = button.url ?? button.phone_number;
|
|
151
|
+
return target ? `${button.text} (${target})` : button.text;
|
|
152
|
+
}
|
|
153
|
+
|
|
117
154
|
// Where create put it: the workspace's own number, or Vatio's test number
|
|
118
155
|
// before it has one. Every language under the name unless one is given.
|
|
119
156
|
async function deleteTemplate(config, args, json) {
|
package/lib/help.mjs
CHANGED
|
@@ -223,6 +223,8 @@ the two you are in. Commands default as listed.
|
|
|
223
223
|
The number's templates and the "template" to send
|
|
224
224
|
whatsapp templates create NAME --language CODE --body TEXT [--example VALUE]...
|
|
225
225
|
[--category utility|marketing] [--footer TEXT]
|
|
226
|
+
[--button-url 'TEXT|URL']... [--button-example VALUE]...
|
|
227
|
+
[--button-phone 'TEXT|PHONE'] [--button-quick-reply TEXT]...
|
|
226
228
|
Submit one for Meta's review: on your number, or
|
|
227
229
|
on Vatio's test number until you connect one
|
|
228
230
|
whatsapp templates rm NAME [--language CODE] | sync
|