@vatio-ai/cli 0.62.0 → 0.63.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.
@@ -198,6 +198,12 @@ export class ApiClient extends HttpClient {
198
198
  return this.get("/templates", { environment });
199
199
  }
200
200
 
201
+ createTemplate({ name, language, category, body, examples = [], footer = null }) {
202
+ const payload = { name, language, category, body, examples };
203
+ if (String(footer ?? "").trim() !== "") payload.footer = String(footer).trim();
204
+ return this.post("/templates", payload);
205
+ }
206
+
201
207
  listWebhookEndpoints() {
202
208
  return this.get("/webhook_endpoints");
203
209
  }
@@ -1,16 +1,26 @@
1
1
  // whatsapp / instagram -- both are set up in the console now: connecting your
2
2
  // own number or account needs Meta's consent screen, and test phones and
3
- // accounts are a form with a code. The CLI only says where.
3
+ // accounts are a form with a code. The CLI only says where, and that depends
4
+ // on whether the workspace has published: before, only the Test page is in the
5
+ // console's sidebar; after, the channel's own page under Integrations.
4
6
 
5
7
  import { deployClient } from "./deploy.mjs";
6
8
 
7
- export const whatsapp = (config) => inConsole(config, "WhatsApp");
8
- export const instagram = (config) => inConsole(config, "Instagram");
9
+ export const whatsapp = (config) =>
10
+ inConsole(config, { name: "WhatsApp", key: "whatsapp", own: "number", test: "phone" });
11
+ export const instagram = (config) =>
12
+ inConsole(config, { name: "Instagram", key: "instagram", own: "account", test: "account" });
9
13
 
10
14
  async function inConsole(config, channel) {
11
15
  const status = await deployClient(config, config.resolveWorkspaceRequired()).deployStatus();
12
- const url = status.integrations_url ?? `${config.resolveBaseUrl()}/workspaces`;
13
- console.log(`${channel} is set up in the console: your own account, and the test phones and`);
14
- console.log("accounts that reach a preview or a branch.");
16
+ const url = status[`${channel.key}_url`] ?? status.integrations_url ?? `${config.resolveBaseUrl()}/workspaces`;
17
+ // An older server sends no `published`; a live deployment means the same.
18
+ const published = status.published ?? Boolean(status.live);
19
+
20
+ if (published) {
21
+ console.log(`Connect your own ${channel.own} and manage test ${channel.test}s in the console:`);
22
+ } else {
23
+ console.log(`Test ${channel.name} on the console's Test page: verify your ${channel.test} there and talk to your agent.`);
24
+ }
15
25
  console.log(` ${url}`);
16
26
  }
@@ -1,7 +1,8 @@
1
1
  // `vatio templates` / `vatio webhooks` — what a developer sets up so their
2
2
  // backend can send WhatsApp messages through the server API: the templates
3
- // the number can send, and where Vatio reports what happened. Sending itself
4
- // is the backend's job, with a server key, not the CLI's.
3
+ // the number can send and new ones for Meta to approve, and where Vatio
4
+ // reports what happened. Sending itself is the backend's job, with a server
5
+ // key, not the CLI's.
5
6
 
6
7
  import { deployClient } from "./deploy.mjs";
7
8
  import { fail, paint, sleep, takeEnv, takeFlag, takeValue } from "../support.mjs";
@@ -15,13 +16,21 @@ function takeAll(args, name) {
15
16
  return values;
16
17
  }
17
18
 
19
+ const LIST_USAGE = "vatio templates list [--env live] [--json]";
20
+ const CREATE_USAGE = "vatio templates create NAME --language CODE --body TEXT [--example VALUE]... " +
21
+ "[--category utility|marketing] [--footer TEXT] [--json]";
22
+
18
23
  export async function templates(config, args) {
19
- const environment = takeEnv(args, { fallback: "live", cwd: config.workspaceRoot });
20
24
  const json = takeFlag(args, "--json");
25
+ if (args[0] === "create") {
26
+ args.shift();
27
+ return createTemplate(config, args, json);
28
+ }
29
+ const environment = takeEnv(args, { fallback: "live", cwd: config.workspaceRoot });
21
30
  const workspace = config.resolveWorkspaceRequired();
22
31
  const client = deployClient(config, workspace);
23
32
  const sub = args.shift() ?? "list";
24
- if (sub !== "list") fail("Usage: vatio templates list [--env live] [--json]");
33
+ if (sub !== "list") fail(`Usage: ${LIST_USAGE}\n ${CREATE_USAGE}`);
25
34
 
26
35
  const payload = await client.listTemplates({ environment });
27
36
  const list = Array.isArray(payload.templates) ? payload.templates : [];
@@ -29,22 +38,69 @@ export async function templates(config, args) {
29
38
  console.log(JSON.stringify(list, null, 2));
30
39
  return;
31
40
  }
41
+ const live = environment === "live";
32
42
  if (list.length === 0) {
33
- console.log(environment === "live"
34
- ? "No templates on this workspace's WhatsApp number. Create them on the console's Channels → WhatsApp page."
35
- : "Templates belong to the workspace's own number; the preview number has none of yours. Use --env live.");
43
+ if (live && payload.whatsapp_connected === false) {
44
+ console.log("This workspace has no WhatsApp number of its own yet. The templates you create stay on Vatio's " +
45
+ "test number until you connect one, and then Vatio moves them to it: vatio templates list --env preview");
46
+ } else if (!live && payload.whatsapp_connected === true) {
47
+ console.log("This workspace has its own WhatsApp number, so its templates are there: vatio templates list");
48
+ } else {
49
+ console.log(`No templates on ${live ? "this workspace's WhatsApp number" : "Vatio's test number for this workspace"} yet. Create one:`);
50
+ console.log(' vatio templates create order_shipped --language es --body "Hi {{1}}, order {{2}} is on its way." ' +
51
+ '--example Ana --example "#1042"');
52
+ }
36
53
  return;
37
54
  }
38
- console.log(`Templates on the workspace's number (${list.length}):`);
55
+ console.log(`Templates on ${live ? "the workspace's number" : "Vatio's test number"} (${list.length}):`);
39
56
  for (const template of list) {
40
57
  const status = template.status === "APPROVED" ? paint("green", template.status) : paint("cyan", template.status);
41
58
  const count = template.parameter_count ?? "?";
42
59
  console.log(` ${template.name} (${template.language}) ${template.category} ${status} ${count} param${count === 1 ? "" : "s"}`);
43
60
  if (template.body) console.log(` ${template.body.replace(/\n/g, "\n ")}`);
61
+ if (template.status === "REJECTED" && template.rejected_reason) console.log(` ${paint("red", "rejected:")} ${template.rejected_reason}`);
44
62
  if (template.status === "APPROVED") console.log(` "template": ${JSON.stringify(template.example)}`);
45
63
  }
46
64
  }
47
65
 
66
+ // On the workspace's own number once it has one, and before that on Vatio's
67
+ // test number, where a preview key sends it to the workspace's test phones
68
+ // until Vatio moves it to the number the workspace connects. The backend
69
+ // decides where, so there is no environment to choose.
70
+ async function createTemplate(config, args, json) {
71
+ takeValue(args, "--env");
72
+ const language = takeValue(args, "--language");
73
+ const body = takeValue(args, "--body");
74
+ const category = takeValue(args, "--category") ?? "utility";
75
+ const footer = takeValue(args, "--footer");
76
+ const examples = takeAll(args, "--example");
77
+ const name = args.shift();
78
+ if (!name || !language || !body || args.length > 0) fail(`Usage: ${CREATE_USAGE}`);
79
+
80
+ const workspace = config.resolveWorkspaceRequired();
81
+ const client = deployClient(config, workspace);
82
+ const template = await client.createTemplate({ name, language, category, body, examples, footer });
83
+ if (json) {
84
+ console.log(JSON.stringify(template, null, 2));
85
+ return;
86
+ }
87
+ const own = template.whatsapp_connected === true;
88
+ const count = template.parameter_count ?? examples.length;
89
+ console.log(`Submitted ${template.name} (${template.language}) for Meta's review on ` +
90
+ `${own ? "your own number" : "Vatio's test number"}: ${template.category}, ` +
91
+ `${count} param${count === 1 ? "" : "s"}, ${paint("cyan", template.status)}.`);
92
+ console.log("Meta usually decides within minutes, at most 24 hours. Check with: vatio templates list" +
93
+ (own ? "" : " --env preview"));
94
+ console.log(own
95
+ ? "Once APPROVED, your backend sends it with a live key outside the 24-hour window with:"
96
+ : "Once APPROVED, a preview key sends it to your test phones outside the 24-hour window with:");
97
+ console.log(` "template": ${JSON.stringify(template.example)}`);
98
+ if (!own) {
99
+ console.log("When you connect your own number, Vatio moves your templates to it, and from then on your backend " +
100
+ "sends from it with a live key: `vatio whatsapp` prints where.");
101
+ }
102
+ }
103
+
48
104
  export async function webhooks(config, args) {
49
105
  const environment = takeEnv(args, { fallback: "live", cwd: config.workspaceRoot });
50
106
  const label = takeValue(args, "--label");
package/lib/help.mjs CHANGED
@@ -103,12 +103,18 @@ and the one its pull request deploys to. Elsewhere commands default as listed.
103
103
  templates list [--env live] [--json]
104
104
  The number's templates, parameter counts, and the
105
105
  "template" object to send
106
+ templates create NAME --language CODE --body TEXT [--example VALUE]...
107
+ [--category utility|marketing] [--footer TEXT] [--json]
108
+ Submit a template for Meta's review: on your number,
109
+ or on Vatio's test number until you connect one;
110
+ one --example per {{n}} in the body
106
111
  webhooks list|create URL [--event NAME]...|test ID|deliveries ID|enable ID|rm ID
107
112
  Where Vatio tells your backend what happened
108
113
 
109
114
  Channels:
110
- whatsapp Set up in the console; prints the link
111
- instagram Set up in the console; prints the link
115
+ whatsapp Set up in the console; prints the link (Test page
116
+ until you publish, then Integrations)
117
+ instagram The same, for Instagram
112
118
 
113
119
  Everything else:
114
120
  config show|get KEY|set KEY VALUE|unset KEY
package/lib/telemetry.mjs CHANGED
@@ -32,7 +32,7 @@ const SUBCOMMANDS = {
32
32
  secrets: ["list", "set", "rm"],
33
33
  tokens: ["list", "create", "revoke", "origins"],
34
34
  keys: ["list", "create", "revoke"],
35
- templates: ["list"],
35
+ templates: ["list", "create"],
36
36
  webhooks: ["list", "create", "test", "deliveries", "enable", "rm"],
37
37
  config: ["show", "get", "set", "unset"]
38
38
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vatio-ai/cli",
3
- "version": "0.62.0",
3
+ "version": "0.63.0",
4
4
  "description": "Vatio CLI — deploy and manage Vatio agent workspaces",
5
5
  "keywords": [
6
6
  "vatio",