@vatio-ai/cli 0.103.0 → 0.104.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 +9 -0
- package/lib/commands/channels.mjs +41 -5
- package/lib/help.mjs +4 -0
- package/package.json +1 -1
package/lib/api-client.mjs
CHANGED
|
@@ -38,6 +38,15 @@ export class ApiClient extends HttpClient {
|
|
|
38
38
|
return this.patch("/whatsapp", body);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
// "Your numbers", which need no number connected.
|
|
42
|
+
ownerNumbers() {
|
|
43
|
+
return this.get("/whatsapp/owner_numbers");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
updateOwnerNumbers(numbers) {
|
|
47
|
+
return this.patch("/whatsapp/owner_numbers", { owner_numbers: numbers });
|
|
48
|
+
}
|
|
49
|
+
|
|
41
50
|
deployedManifest({ environment = "live" } = {}) {
|
|
42
51
|
return this.get("/manifest", { environment });
|
|
43
52
|
}
|
|
@@ -6,14 +6,16 @@
|
|
|
6
6
|
// vatio.ai/workspaces is only for a server too old to send the link, and
|
|
7
7
|
// redirects to the inbox.
|
|
8
8
|
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
// still reach the inbox
|
|
9
|
+
// Two things about WhatsApp are set here too: who the agent answers on your
|
|
10
|
+
// own number (`vatio whatsapp only` / `everyone`; everyone else's messages
|
|
11
|
+
// still reach the inbox), and your numbers (`vatio whatsapp mine`), the
|
|
12
|
+
// business's own conversations, which need no number connected.
|
|
12
13
|
|
|
13
14
|
import { deployClient } from "./deploy.mjs";
|
|
14
15
|
import { fail, paint, takeFlag } from "../support.mjs";
|
|
15
16
|
|
|
16
|
-
const WHATSAPP_USAGE =
|
|
17
|
+
const WHATSAPP_USAGE =
|
|
18
|
+
"Usage: vatio whatsapp [test-phones [--json] | only NUMBER [NUMBER]... | everyone | mine [NUMBER... | --clear]]";
|
|
17
19
|
|
|
18
20
|
export async function whatsapp(config, args = []) {
|
|
19
21
|
const sub = args.shift();
|
|
@@ -23,7 +25,11 @@ export async function whatsapp(config, args = []) {
|
|
|
23
25
|
await printTestPhones(config).catch((error) => {
|
|
24
26
|
if (error?.status !== 404 && error?.body?.error?.code !== "not_found") throw error;
|
|
25
27
|
});
|
|
26
|
-
|
|
28
|
+
await printAgentNumbers(config);
|
|
29
|
+
// A server that predates the route answers 404; nothing more to show.
|
|
30
|
+
return printOwnerNumbers(config).catch((error) => {
|
|
31
|
+
if (error?.status !== 404 && error?.body?.error?.code !== "not_found") throw error;
|
|
32
|
+
});
|
|
27
33
|
}
|
|
28
34
|
if (sub === "test-phones") {
|
|
29
35
|
const json = takeFlag(args, "--json");
|
|
@@ -38,6 +44,12 @@ export async function whatsapp(config, args = []) {
|
|
|
38
44
|
if (args.length > 0) fail(WHATSAPP_USAGE);
|
|
39
45
|
return setAgentNumbers(config, []);
|
|
40
46
|
}
|
|
47
|
+
if (sub === "mine") {
|
|
48
|
+
const clear = takeFlag(args, "--clear");
|
|
49
|
+
if (clear && args.length > 0) fail(WHATSAPP_USAGE);
|
|
50
|
+
if (!clear && args.length === 0) return printOwnerNumbers(config);
|
|
51
|
+
return setOwnerNumbers(config, clear ? [] : args.splice(0));
|
|
52
|
+
}
|
|
41
53
|
fail(WHATSAPP_USAGE);
|
|
42
54
|
}
|
|
43
55
|
|
|
@@ -88,6 +100,30 @@ async function printAgentNumbers(config) {
|
|
|
88
100
|
}
|
|
89
101
|
}
|
|
90
102
|
|
|
103
|
+
async function setOwnerNumbers(config, numbers) {
|
|
104
|
+
const client = deployClient(config, config.resolveWorkspaceRequired());
|
|
105
|
+
printOwners(await client.updateOwnerNumbers(numbers));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async function printOwnerNumbers(config) {
|
|
109
|
+
const client = deployClient(config, config.resolveWorkspaceRequired());
|
|
110
|
+
printOwners(await client.ownerNumbers());
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function printOwners(body) {
|
|
114
|
+
const list = Array.isArray(body.owner_numbers) ? body.owner_numbers : [];
|
|
115
|
+
if (list.length === 0) {
|
|
116
|
+
console.log("\nYour numbers: none yet.");
|
|
117
|
+
console.log(" On the preview number every verified test phone counts as one until you list some.");
|
|
118
|
+
console.log(" List the business's own: vatio whatsapp mine +56912345678");
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
console.log(`\nYour numbers: ${list.join(", ")}`);
|
|
122
|
+
console.log(" In these conversations the agent works for the business: `access: owner` tools are");
|
|
123
|
+
console.log(" there, and what you send from the WhatsApp Business app is a message to the agent.");
|
|
124
|
+
console.log(" Change them: vatio whatsapp mine NUMBER... Empty the list: vatio whatsapp mine --clear");
|
|
125
|
+
}
|
|
126
|
+
|
|
91
127
|
function printAnswers(number) {
|
|
92
128
|
const list = Array.isArray(number.agent_numbers) ? number.agent_numbers : [];
|
|
93
129
|
const live = number.live ? paint("green", "live") : paint("cyan", "paused: Live is off in the inbox, under Channels → WhatsApp");
|
package/lib/help.mjs
CHANGED
|
@@ -206,6 +206,10 @@ the two you are in. Commands default as listed.
|
|
|
206
206
|
whatsapp only NUMBER...|everyone
|
|
207
207
|
Who the agent answers on your own number; the
|
|
208
208
|
rest still reach the inbox
|
|
209
|
+
whatsapp mine [NUMBER...|--clear]
|
|
210
|
+
Your numbers: the business's own conversations,
|
|
211
|
+
the only ones with access: owner tools. Needs
|
|
212
|
+
no number connected; prints them without args
|
|
209
213
|
instagram The same, for Instagram
|
|
210
214
|
|
|
211
215
|
Everything else:
|