@vatio-ai/cli 0.138.0 → 0.140.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/chat.mjs +6 -3
- package/lib/commands/reach.mjs +29 -3
- package/lib/commands/team.mjs +31 -8
- package/lib/help.mjs +10 -5
- package/package.json +1 -1
package/lib/api-client.mjs
CHANGED
|
@@ -399,11 +399,12 @@ export class ApiClient extends HttpClient {
|
|
|
399
399
|
return this.get(`/chats/${encode(chatId)}/turn`, { after, wait });
|
|
400
400
|
}
|
|
401
401
|
|
|
402
|
-
exportChats({ from, to = null, environment = null, channel = null, after = null }) {
|
|
402
|
+
exportChats({ from, to = null, environment = null, channel = null, campaign = null, after = null }) {
|
|
403
403
|
const params = { from };
|
|
404
404
|
if (to) params.to = to;
|
|
405
405
|
if (environment) params.environment = environment;
|
|
406
406
|
if (channel) params.channel = channel;
|
|
407
|
+
if (campaign) params.utm_campaign = campaign;
|
|
407
408
|
if (after) params.after = after;
|
|
408
409
|
return this.get("/chats/export", params);
|
|
409
410
|
}
|
package/lib/commands/chat.mjs
CHANGED
|
@@ -168,10 +168,12 @@ for reading them in bulk -- with a coding agent, say. Vatio redacts it before
|
|
|
168
168
|
it leaves: names, emails, phone numbers and RUTs it knows are [FILTERED], and
|
|
169
169
|
\`person\` stands for whoever it was without naming them. Anyone on the
|
|
170
170
|
workspace's team can run it, a viewer too, and every call is in the
|
|
171
|
-
workspace's activity. Dates are whole days; --to defaults to now
|
|
171
|
+
workspace's activity. Dates are whole days; --to defaults to now. A web
|
|
172
|
+
conversation carries \`attribution\`, where the visit came from (landing page,
|
|
173
|
+
referrer, utm_* and ad click ids); --campaign NAME exports only that campaign's.`;
|
|
172
174
|
}
|
|
173
175
|
|
|
174
|
-
const EXPORT_USAGE = "vatio chat export --from DATE [--to DATE] [--team] [--channel NAME] [--out FILE]";
|
|
176
|
+
const EXPORT_USAGE = "vatio chat export --from DATE [--to DATE] [--team] [--channel NAME] [--campaign NAME] [--out FILE]";
|
|
175
177
|
|
|
176
178
|
// One page at a time, written as it arrives: a month of a busy WhatsApp number
|
|
177
179
|
// does not have to fit in memory to be read.
|
|
@@ -180,6 +182,7 @@ async function exportChats(config, args) {
|
|
|
180
182
|
const from = takeValue(args, "--from");
|
|
181
183
|
const to = takeValue(args, "--to");
|
|
182
184
|
const channel = takeValue(args, "--channel");
|
|
185
|
+
const campaign = takeValue(args, "--campaign");
|
|
183
186
|
const out = takeValue(args, "--out");
|
|
184
187
|
const apiUrl = takeValue(args, "--api-url");
|
|
185
188
|
const token = takeValue(args, "--token");
|
|
@@ -193,7 +196,7 @@ async function exportChats(config, args) {
|
|
|
193
196
|
let chats = 0;
|
|
194
197
|
let messages = 0;
|
|
195
198
|
for (;;) {
|
|
196
|
-
const page = await api.exportChats({ from, to, environment, channel, after });
|
|
199
|
+
const page = await api.exportChats({ from, to, environment, channel, campaign, after });
|
|
197
200
|
const rows = Array.isArray(page.data) ? page.data : [];
|
|
198
201
|
if (rows.length > 0) {
|
|
199
202
|
const lines = `${rows.map((row) => JSON.stringify(row)).join("\n")}\n`;
|
package/lib/commands/reach.mjs
CHANGED
|
@@ -53,17 +53,43 @@ function showWidget(answer, json) {
|
|
|
53
53
|
export async function analytics(config, args) {
|
|
54
54
|
const json = takeFlag(args, "--json");
|
|
55
55
|
const days = takeValue(args, "--days");
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
const campaign = takeValue(args, "--campaign");
|
|
57
|
+
if (args.length) fail("Usage: vatio analytics [--days N] [--campaign NAME] [--json]");
|
|
58
|
+
const answer = await deployClient(config, config.resolveWorkspaceRequired()).get("/analytics", { days, utm_campaign: campaign });
|
|
58
59
|
if (json) return print(answer);
|
|
59
60
|
const change = (block) => (block?.previous_total ? ` (${block.previous_total} the ${answer.days} days before)` : "");
|
|
60
|
-
console.log(`Last ${answer.days} days, your customers:`);
|
|
61
|
+
console.log(`Last ${answer.days} days, your customers${campaign ? ` from the campaign ${campaign}` : ""}:`);
|
|
61
62
|
console.log(` conversations ${answer.conversations?.total ?? 0}${change(answer.conversations)}`);
|
|
62
63
|
console.log(` messages ${answer.messages?.total ?? 0}${change(answer.messages)}`);
|
|
63
64
|
if (answer.saved_replies) console.log(` replies Vatio saved ${answer.saved_replies.total ?? 0}`);
|
|
64
65
|
if (answer.after_hours) console.log(` conversations after hours ${answer.after_hours.after_hours ?? 0}`);
|
|
65
66
|
if (answer.asked_team) console.log(` questions to the team ${answer.asked_team.questions ?? 0} (${answer.asked_team.answered ?? 0} answered)`);
|
|
66
67
|
if (answer.flags) console.log(` reports ${answer.flags.opened ?? 0} opened, ${answer.flags.resolved ?? 0} resolved`);
|
|
68
|
+
printOrigins(answer.origins, answer.days);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const ORIGIN_LABELS = { utm_campaign: "campaign", utm_source: "source", utm_medium: "medium", landing_page: "landing page", referrer: "referrer" };
|
|
72
|
+
|
|
73
|
+
// Where the period's conversations came from: the biggest of each, against
|
|
74
|
+
// the period before, with how they went. `--json` has every row.
|
|
75
|
+
function printOrigins(origins, days) {
|
|
76
|
+
if (!origins?.attributed) return;
|
|
77
|
+
console.log(`\nWhere they came from (${origins.attributed} of ${origins.conversations} with a page, a referrer or a campaign):`);
|
|
78
|
+
for (const [key, label] of Object.entries(ORIGIN_LABELS)) {
|
|
79
|
+
const rows = (origins.dimensions?.[key]?.rows ?? []).filter((row) => row.value !== null).slice(0, 5);
|
|
80
|
+
if (!rows.length) continue;
|
|
81
|
+
console.log(` ${label}`);
|
|
82
|
+
for (const row of rows) {
|
|
83
|
+
const ratings = row.ratings ?? {};
|
|
84
|
+
const outcome = [
|
|
85
|
+
`${row.previous_conversations} the ${days} days before`,
|
|
86
|
+
ratings.good || ratings.neutral || ratings.bad ? `rated 👍 ${ratings.good} 😐 ${ratings.neutral} 👎 ${ratings.bad}` : null,
|
|
87
|
+
row.reported ? `${row.reported} reported` : null,
|
|
88
|
+
row.handed_off ? `${row.handed_off} answered by a person` : null
|
|
89
|
+
].filter(Boolean).join(", ");
|
|
90
|
+
console.log(` ${String(row.conversations).padStart(5)} ${row.value} (${outcome})`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
67
93
|
}
|
|
68
94
|
|
|
69
95
|
const TESTERS_USAGE = "Usage: vatio testers [web|whatsapp|instagram] [--json]\n" +
|
package/lib/commands/team.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// team — who is in the workspace, and as what: what the inbox's Team page does,
|
|
2
2
|
// for a coding agent that is asked to "add Ana as a supervisor". The owner's
|
|
3
|
-
// alone, like the page. A person is named by their email
|
|
4
|
-
//
|
|
3
|
+
// alone, like the page. A person is named by their email, or by their number
|
|
4
|
+
// when they are on the team by their WhatsApp alone; the platform keys them by
|
|
5
|
+
// membership, which the list gives.
|
|
5
6
|
|
|
6
7
|
import { deployClient } from "./deploy.mjs";
|
|
7
8
|
import { errorCode } from "../http.mjs";
|
|
@@ -21,8 +22,10 @@ function explain(error) {
|
|
|
21
22
|
const ROLES = ["supervisor", "business", "developer"];
|
|
22
23
|
const USAGE = `Usage: vatio team [list] [--json]\n` +
|
|
23
24
|
` vatio team invite EMAIL --role ${ROLES.join("|")} [--code CODE | --recovery-code CODE] [--json]\n` +
|
|
24
|
-
|
|
25
|
-
"
|
|
25
|
+
" vatio team invite --whatsapp +56912345678 --name NAME [--code CODE | --recovery-code CODE] [--json]\n" +
|
|
26
|
+
" a supervisor by their WhatsApp alone: the agent knows them by that number; no email, no inbox\n" +
|
|
27
|
+
` vatio team role EMAIL|PHONE ${ROLES.join("|")} [--code CODE | --recovery-code CODE] [--json]\n` +
|
|
28
|
+
" vatio team rm EMAIL|PHONE [--json]\n" +
|
|
26
29
|
" vatio team resend EMAIL [--json]\n" +
|
|
27
30
|
" With a second factor on your account, --code is the 6-digit code from your authenticator app.\n" +
|
|
28
31
|
" vatio team questions [--to EMAIL...|--none] [--template NAME [--language CODE]|--no-template] [--json]";
|
|
@@ -44,6 +47,18 @@ export async function team(config, args) {
|
|
|
44
47
|
const role = takeValue(args, "--role");
|
|
45
48
|
const code = takeValue(args, "--code");
|
|
46
49
|
const recoveryCode = takeValue(args, "--recovery-code");
|
|
50
|
+
const whatsapp = takeValue(args, "--whatsapp");
|
|
51
|
+
const name = takeValue(args, "--name");
|
|
52
|
+
if (whatsapp) {
|
|
53
|
+
if (!name || role || args.length > 0) fail(`--whatsapp takes --name, and no email or --role: always a supervisor.\n\n${USAGE}`);
|
|
54
|
+
const answer = await invite(client, { whatsapp, name, code, recovery_code: recoveryCode }).catch(explain);
|
|
55
|
+
if (!json) {
|
|
56
|
+
console.log(`${paint("green", "✓")} ${name} is on the team by WhatsApp (${whatsapp}). Nothing was sent to them: ` +
|
|
57
|
+
"the agent knows them from their first message from that number.");
|
|
58
|
+
console.log("");
|
|
59
|
+
}
|
|
60
|
+
return print(answer, workspace, json);
|
|
61
|
+
}
|
|
47
62
|
const email = args.shift();
|
|
48
63
|
if (!email || args.length > 0) fail(USAGE);
|
|
49
64
|
// The platform would make an unknown role a supervisor; here it is asked for.
|
|
@@ -73,8 +88,9 @@ export async function team(config, args) {
|
|
|
73
88
|
answer = await client.removeMember(member.id).catch(explain);
|
|
74
89
|
}
|
|
75
90
|
if (!json) {
|
|
76
|
-
const
|
|
77
|
-
|
|
91
|
+
const who = label(member);
|
|
92
|
+
const done = { role: `${who} is now ${role}`, resend: `Sent ${who} the invitation again`,
|
|
93
|
+
rm: `Removed ${who}: they no longer reach this workspace`, remove: `Removed ${who}` }[sub];
|
|
78
94
|
console.log(`${paint("green", "✓")} ${done}.`);
|
|
79
95
|
console.log("");
|
|
80
96
|
}
|
|
@@ -84,21 +100,28 @@ export async function team(config, args) {
|
|
|
84
100
|
fail(USAGE);
|
|
85
101
|
}
|
|
86
102
|
|
|
103
|
+
// By email, or by number for someone on WhatsApp alone (they have no email).
|
|
87
104
|
async function memberByEmail(client, email) {
|
|
88
105
|
const wanted = email.trim().toLowerCase();
|
|
106
|
+
const digits = wanted.replace(/\D/g, "");
|
|
89
107
|
const list = await client.members().catch(explain);
|
|
90
|
-
const member = (list.data ?? []).find((row) =>
|
|
108
|
+
const member = (list.data ?? []).find((row) =>
|
|
109
|
+
(row.email && String(row.email).toLowerCase() === wanted) ||
|
|
110
|
+
(row.phone_number && digits.length >= 8 && String(row.phone_number).replace(/\D/g, "") === digits));
|
|
91
111
|
if (!member) fail(`${wanted} is not on this workspace's team (vatio team list).`);
|
|
92
112
|
return member;
|
|
93
113
|
}
|
|
94
114
|
|
|
115
|
+
const label = (member) => member.email ?? `${member.name ?? "someone"} (WhatsApp ${member.phone_number})`;
|
|
116
|
+
|
|
95
117
|
function print(answer, workspace, json) {
|
|
96
118
|
if (json) return console.log(JSON.stringify(answer, null, 2));
|
|
97
119
|
const members = answer.data ?? [];
|
|
98
120
|
console.log(`Team on workspace ${workspace}:`);
|
|
99
121
|
if (answer.owner) console.log(` owner ${answer.owner.email}`);
|
|
100
122
|
for (const member of members) {
|
|
101
|
-
|
|
123
|
+
const note = member.whatsapp_only ? " (WhatsApp only, no inbox)" : member.pending ? " (has not signed in yet)" : "";
|
|
124
|
+
console.log(` ${member.role.padEnd(11)} ${label(member)}${note}`);
|
|
102
125
|
}
|
|
103
126
|
if (members.length === 0) console.log(" No one else. Invite someone: vatio team invite EMAIL --role supervisor");
|
|
104
127
|
}
|
package/lib/help.mjs
CHANGED
|
@@ -91,7 +91,7 @@ it made obsolete, moves it on. \`vatio rollback\` undoes the last change.
|
|
|
91
91
|
The chat you are in, or any chat in the workspace
|
|
92
92
|
(web, WhatsApp, ...): messages, tool calls, channel,
|
|
93
93
|
and what was read of each file (truncated, unreadable)
|
|
94
|
-
chat export --from DATE [--to DATE] [--team] [--channel NAME] [--out FILE]
|
|
94
|
+
chat export --from DATE [--to DATE] [--team] [--channel NAME] [--campaign NAME] [--out FILE]
|
|
95
95
|
What people said and were answered between two
|
|
96
96
|
dates, redacted by Vatio, one conversation per
|
|
97
97
|
line as JSON: your customers', or your team's own
|
|
@@ -100,8 +100,10 @@ it made obsolete, moves it on. \`vatio rollback\` undoes the last change.
|
|
|
100
100
|
chat reply CHAT_ID "TEXT" Write in a customer's conversation as a person on the
|
|
101
101
|
team: the agent stays out of it until
|
|
102
102
|
chat release CHAT_ID hands it back to the agent
|
|
103
|
-
analytics [--days N]
|
|
104
|
-
|
|
103
|
+
analytics [--days N] [--campaign NAME]
|
|
104
|
+
The inbox's Analytics: conversations, messages, replies
|
|
105
|
+
Vatio saved, after hours, questions to the team, and
|
|
106
|
+
the campaigns and pages they came from
|
|
105
107
|
testers [web|whatsapp|instagram] | rm whatsapp|instagram ID
|
|
106
108
|
Who reaches your team's version on Vatio's shared
|
|
107
109
|
number and account
|
|
@@ -173,9 +175,12 @@ it made obsolete, moves it on. \`vatio rollback\` undoes the last change.
|
|
|
173
175
|
team invite EMAIL --role supervisor|business|developer [--code CODE]
|
|
174
176
|
Invite them and email them. Needs a second factor on your
|
|
175
177
|
account: --code is your authenticator app's code
|
|
176
|
-
team
|
|
178
|
+
team invite --whatsapp PHONE --name NAME [--code CODE]
|
|
179
|
+
A supervisor by their WhatsApp alone: no email, no
|
|
180
|
+
inbox; the agent knows them by that number
|
|
181
|
+
team role EMAIL|PHONE supervisor|business|developer [--code CODE]
|
|
177
182
|
Change what they reach; the same second factor
|
|
178
|
-
team rm EMAIL
|
|
183
|
+
team rm EMAIL|PHONE Take their access away
|
|
179
184
|
team resend EMAIL Email the invitation again
|
|
180
185
|
team questions [--to EMAIL...|--none] [--template NAME [--language CODE]|--no-template]
|
|
181
186
|
Who the agent asks when it cannot answer a customer
|