@vatio-ai/cli 0.76.0 → 0.77.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 +10 -0
- package/lib/commands/channels.mjs +54 -2
- package/lib/help.mjs +3 -0
- package/lib/telemetry.mjs +1 -0
- package/package.json +1 -1
package/lib/api-client.mjs
CHANGED
|
@@ -15,6 +15,16 @@ export class ApiClient extends HttpClient {
|
|
|
15
15
|
return this.get("/status");
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
// --- whatsapp -------------------------------------------------------
|
|
19
|
+
|
|
20
|
+
getWhatsapp() {
|
|
21
|
+
return this.get("/whatsapp");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
updateWhatsapp(body) {
|
|
25
|
+
return this.patch("/whatsapp", body);
|
|
26
|
+
}
|
|
27
|
+
|
|
18
28
|
deployedManifest({ environment = "live" } = {}) {
|
|
19
29
|
return this.get("/manifest", { environment });
|
|
20
30
|
}
|
|
@@ -3,11 +3,33 @@
|
|
|
3
3
|
// accounts are a form with a code. The CLI only says where, and that depends
|
|
4
4
|
// on whether the workspace has published: before, only the Test page is in the
|
|
5
5
|
// console's sidebar; after, the channel's own page under Integrations.
|
|
6
|
+
//
|
|
7
|
+
// One thing about your own WhatsApp number is set here too: who the agent
|
|
8
|
+
// answers on it (`vatio whatsapp only` / `everyone`). Everyone else's messages
|
|
9
|
+
// still reach the inbox.
|
|
6
10
|
|
|
7
11
|
import { deployClient } from "./deploy.mjs";
|
|
12
|
+
import { fail, paint } from "../support.mjs";
|
|
13
|
+
|
|
14
|
+
const WHATSAPP_USAGE = "Usage: vatio whatsapp [only NUMBER [NUMBER]... | everyone]";
|
|
15
|
+
|
|
16
|
+
export async function whatsapp(config, args = []) {
|
|
17
|
+
const sub = args.shift();
|
|
18
|
+
if (sub === undefined) {
|
|
19
|
+
await inConsole(config, { name: "WhatsApp", key: "whatsapp", own: "number", test: "phone" });
|
|
20
|
+
return printAgentNumbers(config);
|
|
21
|
+
}
|
|
22
|
+
if (sub === "only") {
|
|
23
|
+
if (args.length === 0) fail(WHATSAPP_USAGE);
|
|
24
|
+
return setAgentNumbers(config, args.splice(0));
|
|
25
|
+
}
|
|
26
|
+
if (sub === "everyone") {
|
|
27
|
+
if (args.length > 0) fail(WHATSAPP_USAGE);
|
|
28
|
+
return setAgentNumbers(config, []);
|
|
29
|
+
}
|
|
30
|
+
fail(WHATSAPP_USAGE);
|
|
31
|
+
}
|
|
8
32
|
|
|
9
|
-
export const whatsapp = (config) =>
|
|
10
|
-
inConsole(config, { name: "WhatsApp", key: "whatsapp", own: "number", test: "phone" });
|
|
11
33
|
export const instagram = (config) =>
|
|
12
34
|
inConsole(config, { name: "Instagram", key: "instagram", own: "account", test: "account" });
|
|
13
35
|
|
|
@@ -24,3 +46,33 @@ async function inConsole(config, channel) {
|
|
|
24
46
|
}
|
|
25
47
|
console.log(` ${url}`);
|
|
26
48
|
}
|
|
49
|
+
|
|
50
|
+
async function setAgentNumbers(config, numbers) {
|
|
51
|
+
const client = deployClient(config, config.resolveWorkspaceRequired());
|
|
52
|
+
printAnswers(await client.updateWhatsapp({ agent_numbers: numbers }));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// After the console link: a workspace with no number of its own has nothing
|
|
56
|
+
// more to show, and the link already says what to do.
|
|
57
|
+
async function printAgentNumbers(config) {
|
|
58
|
+
const client = deployClient(config, config.resolveWorkspaceRequired());
|
|
59
|
+
try {
|
|
60
|
+
printAnswers(await client.getWhatsapp());
|
|
61
|
+
} catch (error) {
|
|
62
|
+
if (error?.body?.error?.code === "whatsapp_not_connected") return;
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function printAnswers(number) {
|
|
68
|
+
const list = Array.isArray(number.agent_numbers) ? number.agent_numbers : [];
|
|
69
|
+
const live = number.live ? paint("green", "live") : paint("cyan", "paused: Live is off in the console");
|
|
70
|
+
console.log(`\n${number.display_phone_number ?? "Your number"}: ${live}`);
|
|
71
|
+
if (list.length === 0) {
|
|
72
|
+
console.log(" The agent answers everyone. To answer only some numbers: vatio whatsapp only +56912345678");
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
console.log(` The agent answers only: ${list.join(", ")}`);
|
|
76
|
+
console.log(" Everyone else's messages reach the inbox unanswered; your routines' numbers always count.");
|
|
77
|
+
console.log(" Back to everyone: vatio whatsapp everyone");
|
|
78
|
+
}
|
package/lib/help.mjs
CHANGED
|
@@ -135,6 +135,9 @@ Commands default as listed.
|
|
|
135
135
|
Channels:
|
|
136
136
|
whatsapp Set up in the console; prints the link (Test page
|
|
137
137
|
until you publish, then Integrations)
|
|
138
|
+
whatsapp only NUMBER...|everyone
|
|
139
|
+
Who the agent answers on your own number; the
|
|
140
|
+
rest still reach the inbox
|
|
138
141
|
instagram The same, for Instagram
|
|
139
142
|
|
|
140
143
|
Everything else:
|
package/lib/telemetry.mjs
CHANGED
|
@@ -35,6 +35,7 @@ const SUBCOMMANDS = {
|
|
|
35
35
|
templates: ["list", "create"],
|
|
36
36
|
webhooks: ["list", "create", "test", "deliveries", "enable", "rm"],
|
|
37
37
|
routines: ["list", "create", "update", "test", "runs", "enable", "rm"],
|
|
38
|
+
whatsapp: ["only", "everyone"],
|
|
38
39
|
config: ["show", "get", "set", "unset"],
|
|
39
40
|
"share-session": ["--should-ask", "--never"]
|
|
40
41
|
};
|