@velaro/cli 1.4.179 → 1.4.181
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/bin/velaro.js +4 -0
- package/lib/commands/contacts.js +34 -0
- package/lib/commands/public-api.js +53 -0
- package/lib/commands/signup-form.js +110 -0
- package/package.json +1 -1
package/bin/velaro.js
CHANGED
|
@@ -39,6 +39,7 @@ import { copilotStudioCommand } from '../lib/commands/copilotstudio.js';
|
|
|
39
39
|
import { applePayPresetCommand } from '../lib/commands/apple-pay-preset.js';
|
|
40
40
|
import { integrationCommand } from '../lib/commands/integration.js';
|
|
41
41
|
import { appointmentsCommand } from '../lib/commands/appointments.js';
|
|
42
|
+
import { publicApiCommand } from '../lib/commands/public-api.js';
|
|
42
43
|
import { bookingDefaultsCommand } from '../lib/commands/booking-defaults.js';
|
|
43
44
|
import { bookingCommand } from '../lib/commands/booking.js';
|
|
44
45
|
import { reportCommand } from '../lib/commands/report.js';
|
|
@@ -101,6 +102,7 @@ import { statusNotifyCommand } from '../lib/commands/status-notify.js';
|
|
|
101
102
|
import { callbackCommand } from '../lib/commands/callback.js';
|
|
102
103
|
import { cobrowseCommand } from '../lib/commands/cobrowse.js';
|
|
103
104
|
import { callpresenceCommand } from '../lib/commands/callpresence.js';
|
|
105
|
+
import { signupFormCommand } from '../lib/commands/signup-form.js';
|
|
104
106
|
import { authorityCommand } from '../lib/commands/authority.js';
|
|
105
107
|
import { caseCommand } from '../lib/commands/case.js';
|
|
106
108
|
import { dealCommand } from '../lib/commands/deal.js';
|
|
@@ -198,6 +200,7 @@ await (registerStaffCommands ? registerStaffCommands(baseYargs) : baseYargs)
|
|
|
198
200
|
.command(applePayPresetCommand)
|
|
199
201
|
.command(integrationCommand)
|
|
200
202
|
.command(appointmentsCommand)
|
|
203
|
+
.command(publicApiCommand)
|
|
201
204
|
.command(bookingDefaultsCommand)
|
|
202
205
|
.command(bookingCommand)
|
|
203
206
|
.command(reportCommand)
|
|
@@ -263,6 +266,7 @@ await (registerStaffCommands ? registerStaffCommands(baseYargs) : baseYargs)
|
|
|
263
266
|
// The staff build already registers a cobrowse group that includes seats/seat set; only the public build adds this one.
|
|
264
267
|
.command(registerStaffCommands ? { command: 'cobrowse-seats-in-staff-group', describe: false, builder: (y) => y, handler: () => {} } : cobrowseCommand)
|
|
265
268
|
.command(callpresenceCommand)
|
|
269
|
+
.command(signupFormCommand)
|
|
266
270
|
.command(authorityCommand)
|
|
267
271
|
.command(caseCommand)
|
|
268
272
|
.command(dealCommand)
|
package/lib/commands/contacts.js
CHANGED
|
@@ -44,6 +44,25 @@ async function searchHandler(argv) {
|
|
|
44
44
|
console.log('');
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
// POST api/v1/contacts -> PublicApiController.UpsertContact (same call Make/Zapier use)
|
|
48
|
+
async function upsertHandler(argv) {
|
|
49
|
+
const body = { email: argv.email };
|
|
50
|
+
for (const k of ['firstName', 'lastName', 'phone', 'company', 'jobTitle']) if (argv[k] !== undefined) body[k] = argv[k];
|
|
51
|
+
if (argv.tag) body.tags = [].concat(argv.tag);
|
|
52
|
+
const r = await request('POST', 'api/v1/contacts', body);
|
|
53
|
+
console.log(`
|
|
54
|
+
${r.created ? 'Created' : 'Updated'} contact #${r.id} (${r.email})${r.tags?.length ? ' tags: ' + r.tags.join(', ') : ''}
|
|
55
|
+
`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// POST api/v1/contacts/tag -> PublicApiController.TagContact
|
|
59
|
+
async function tagByEmailHandler(argv) {
|
|
60
|
+
const r = await request('POST', 'api/v1/contacts/tag', { email: argv.email, tag: argv.tag });
|
|
61
|
+
console.log(`
|
|
62
|
+
Tagged contact #${r.contactId} with "${r.tag}"
|
|
63
|
+
`);
|
|
64
|
+
}
|
|
65
|
+
|
|
47
66
|
// GET Contacts/{id} -> ContactsController.GetContact
|
|
48
67
|
async function getHandler(argv) {
|
|
49
68
|
const c = await request('GET', `Contacts/${argv.id}`);
|
|
@@ -190,6 +209,21 @@ export const contactsCommand = {
|
|
|
190
209
|
.option('pageSize', { type: 'number', default: 50 }),
|
|
191
210
|
handler: runCommand(searchHandler),
|
|
192
211
|
})
|
|
212
|
+
.command({
|
|
213
|
+
command: 'upsert',
|
|
214
|
+
describe: 'Create or update a contact by email (REST: POST /api/v1/contacts)',
|
|
215
|
+
builder: (y2) => y2.option('email', { type: 'string', demandOption: true })
|
|
216
|
+
.option('firstName', { type: 'string' }).option('lastName', { type: 'string' })
|
|
217
|
+
.option('phone', { type: 'string' }).option('company', { type: 'string' })
|
|
218
|
+
.option('jobTitle', { type: 'string' }).option('tag', { type: 'string', array: true, describe: 'Tag name (repeatable)' }),
|
|
219
|
+
handler: runCommand(upsertHandler),
|
|
220
|
+
})
|
|
221
|
+
.command({
|
|
222
|
+
command: 'tag-by-email',
|
|
223
|
+
describe: 'Tag a contact by email, creating the tag if new (REST: POST /api/v1/contacts/tag)',
|
|
224
|
+
builder: (y2) => y2.option('email', { type: 'string', demandOption: true }).option('tag', { type: 'string', demandOption: true }),
|
|
225
|
+
handler: runCommand(tagByEmailHandler),
|
|
226
|
+
})
|
|
193
227
|
.command({
|
|
194
228
|
command: 'get <id>',
|
|
195
229
|
describe: 'Show a contact profile (with tags + recent notes)',
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { request } from '../api.js';
|
|
2
|
+
|
|
3
|
+
// velaro public-api — read the public REST API (api/v1) the same way Make / Zapier / integrators do.
|
|
4
|
+
// Scopes: read:conversations, read:appointments, read:agents. Site comes from the signed-in session.
|
|
5
|
+
function qs(o) {
|
|
6
|
+
const p = new URLSearchParams(Object.entries(o).filter(([, v]) => v !== undefined && v !== ''));
|
|
7
|
+
const s = p.toString();
|
|
8
|
+
return s ? `?${s}` : '';
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async function show(path) {
|
|
12
|
+
try {
|
|
13
|
+
const r = await request('GET', path);
|
|
14
|
+
console.log(JSON.stringify(r, null, 2));
|
|
15
|
+
} catch (err) {
|
|
16
|
+
console.error(`Request failed: ${err && err.message ? err.message : err}`);
|
|
17
|
+
process.exitCode = 1;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function send(method, path, body) {
|
|
22
|
+
try {
|
|
23
|
+
const r = await request(method, path, body);
|
|
24
|
+
console.log(JSON.stringify(r, null, 2));
|
|
25
|
+
} catch (err) {
|
|
26
|
+
console.error(`Request failed: ${err && err.message ? err.message : err}`);
|
|
27
|
+
process.exitCode = 1;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const publicApiCommand = {
|
|
32
|
+
command: 'public-api <subcommand>',
|
|
33
|
+
describe: 'Read conversations, appointments, agents and teams via the public REST API (api/v1)',
|
|
34
|
+
builder: (yargs) =>
|
|
35
|
+
yargs
|
|
36
|
+
.command('conversations [id]', 'List conversations or fetch one', {
|
|
37
|
+
status: { type: 'string' }, from: { type: 'string' }, to: { type: 'string' },
|
|
38
|
+
page: { type: 'number' }, 'page-size': { type: 'number' },
|
|
39
|
+
}, (a) => show(a.id ? `/api/v1/conversations/${a.id}` : `/api/v1/conversations${qs({ status: a.status, from: a.from, to: a.to, page: a.page, pageSize: a['page-size'] })}`))
|
|
40
|
+
.command('appointments [id]', 'List booked appointments or fetch one', {
|
|
41
|
+
status: { type: 'string' }, from: { type: 'string' }, to: { type: 'string' },
|
|
42
|
+
page: { type: 'number' }, 'page-size': { type: 'number' },
|
|
43
|
+
}, (a) => show(a.id ? `/api/v1/appointments/${a.id}` : `/api/v1/appointments${qs({ status: a.status, from: a.from, to: a.to, page: a.page, pageSize: a['page-size'] })}`))
|
|
44
|
+
.command('agents', 'List the site agents', {}, () => show('/api/v1/agents'))
|
|
45
|
+
.command('teams', 'List the site teams', {}, () => show('/api/v1/teams'))
|
|
46
|
+
.command('webhooks', 'List outbound webhook subscriptions', {}, () => show('/api/v1/webhooks'))
|
|
47
|
+
.command('webhook-create <url>', 'Create a webhook (secret is shown once)', { events: { type: 'string', describe: 'comma separated: contact_tag_added,conversation_started,conversation_closed' } },
|
|
48
|
+
(a) => send('POST', '/api/v1/webhooks', { url: a.url, events: a.events ? a.events.split(',') : undefined }))
|
|
49
|
+
.command('webhook-delete <id>', 'Delete a webhook', {}, (a) => send('DELETE', `/api/v1/webhooks/${a.id}`))
|
|
50
|
+
.command('note <contactId> <text>', 'Add a note to a contact', {}, (a) => send('POST', `/api/v1/contacts/${a.contactId}/notes`, { note: a.text }))
|
|
51
|
+
.demandCommand(1, 'Specify: conversations | appointments | agents | teams | webhooks | webhook-create | webhook-delete | note'),
|
|
52
|
+
handler: () => {},
|
|
53
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { messagingGet, messagingPost } from '../api.js';
|
|
2
|
+
import { runCommand } from '../run.js';
|
|
3
|
+
import { readFileSync } from 'node:fs';
|
|
4
|
+
|
|
5
|
+
// -- velaro signup-form ----------------------------------------------------------------------------------------------
|
|
6
|
+
// Signup forms, popups and slide-ins are the LIST-GROWTH LAYER of a survey (Survey.GrowthConfigJson), not a separate
|
|
7
|
+
// form system: fields, validation, consent wording, versions and submissions are the survey's. This group reads and
|
|
8
|
+
// writes only that layer, plus its stats and signups. Backend: velaro-messaging SurveysController (Surveys/...).
|
|
9
|
+
// The site always comes from the credential. Needs the Email Growth package (the server answers 403 naming it).
|
|
10
|
+
|
|
11
|
+
const BOLD = '\x1b[1m';
|
|
12
|
+
const DIM = '\x1b[2m';
|
|
13
|
+
const RST = '\x1b[0m';
|
|
14
|
+
|
|
15
|
+
const parseConfig = (s) => { try { return JSON.parse(s); } catch { throw new Error('growth config is not valid JSON'); } };
|
|
16
|
+
|
|
17
|
+
async function findSurvey(id) {
|
|
18
|
+
const all = (await messagingGet('/Surveys/list')) ?? [];
|
|
19
|
+
const s = all.find((x) => x.id === Number(id));
|
|
20
|
+
if (!s) throw new Error(`Survey ${id} not found`);
|
|
21
|
+
return s;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const isGrowth = (s) => { if (!s.growthConfigJson) return false; try { return !!JSON.parse(s.growthConfigJson).enabled; } catch { return false; } };
|
|
25
|
+
|
|
26
|
+
async function listHandler(argv) {
|
|
27
|
+
const all = ((await messagingGet('/Surveys/list')) ?? []).filter(isGrowth);
|
|
28
|
+
if (argv.json) { console.log(JSON.stringify(all.map((s) => ({ id: s.id, name: s.name, publicSlug: s.publicSlug, growth: JSON.parse(s.growthConfigJson) })), null, 2)); return; }
|
|
29
|
+
if (!all.length) { console.log('\n No signup forms yet. Turn on "List growth" on a survey (velaro signup-form set).\n'); return; }
|
|
30
|
+
console.log(`\n${BOLD}Signup forms${RST}`);
|
|
31
|
+
for (const s of all) {
|
|
32
|
+
const g = JSON.parse(s.growthConfigJson);
|
|
33
|
+
console.log(` #${s.id} ${s.name} ${DIM}${g.display?.type ?? 'popup'} / ${g.display?.trigger ?? 'timed'} list ${g.list?.listId ?? '-'} slug ${s.publicSlug ?? '(no shareable link yet)'}${RST}`);
|
|
34
|
+
}
|
|
35
|
+
console.log('');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function getHandler(argv) {
|
|
39
|
+
const s = await findSurvey(argv.id);
|
|
40
|
+
const out = { id: s.id, name: s.name, publicSlug: s.publicSlug, allowStandaloneAccess: s.allowStandaloneAccess, consentEnabled: s.consentEnabled, growth: s.growthConfigJson ? JSON.parse(s.growthConfigJson) : null };
|
|
41
|
+
console.log(JSON.stringify(out, null, 2));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function setHandler(argv) {
|
|
45
|
+
const s = await findSurvey(argv.id);
|
|
46
|
+
let cfg = s.growthConfigJson ? JSON.parse(s.growthConfigJson) : { enabled: false };
|
|
47
|
+
if (argv.file) cfg = parseConfig(readFileSync(argv.file, 'utf8'));
|
|
48
|
+
if (argv.config) cfg = parseConfig(argv.config);
|
|
49
|
+
if (argv.enable !== undefined) cfg.enabled = argv.enable;
|
|
50
|
+
const body = { ...s, growthConfigJson: JSON.stringify(cfg) };
|
|
51
|
+
const saved = await messagingPost('/Surveys', body);
|
|
52
|
+
if (cfg.enabled && !saved.allowStandaloneAccess) await messagingPost(`/Surveys/${saved.id}/standalone-link`);
|
|
53
|
+
console.log(argv.json ? JSON.stringify(saved, null, 2) : `Saved signup form settings on survey ${saved.id}.`);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function statsHandler(argv) {
|
|
57
|
+
const r = await messagingGet(`/Surveys/${argv.id}/growth/stats?days=${argv.days}`);
|
|
58
|
+
if (argv.json) { console.log(JSON.stringify(r, null, 2)); return; }
|
|
59
|
+
console.log(`\n${BOLD}Form ${argv.id}, last ${argv.days} days${RST}`);
|
|
60
|
+
console.log(` Views ${r.views} Dismissals ${r.dismissals} Signups ${r.submissions} Conversion ${r.conversionRate}%`);
|
|
61
|
+
console.log(` Subscribed ${r.subscribed} Awaiting confirmation ${r.pendingConfirmation} Confirmed ${r.confirmed} Suppressed ${r.suppressed}\n`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function submissionsHandler(argv) {
|
|
65
|
+
const q = `page=${argv.page}&pageSize=${argv.pageSize}${argv.status ? `&status=${encodeURIComponent(argv.status)}` : ''}`;
|
|
66
|
+
const r = await messagingGet(`/Surveys/${argv.id}/growth/submissions?${q}`);
|
|
67
|
+
if (argv.json) { console.log(JSON.stringify(r, null, 2)); return; }
|
|
68
|
+
console.log(`\n${BOLD}Signups for form ${argv.id}${RST} ${DIM}(${r.total} total, page ${r.page})${RST}`);
|
|
69
|
+
for (const i of r.items) console.log(` ${i.submittedAt} ${i.contactEmail ?? '-'} ${i.optInStatus} consent record #${i.consentRecordId ?? '-'}`);
|
|
70
|
+
console.log('');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function snippetHandler(argv) {
|
|
74
|
+
const s = await findSurvey(argv.id);
|
|
75
|
+
if (!s.publicSlug || !s.allowStandaloneAccess) throw new Error('Enable the shareable link first (velaro signup-form set <id> --enable).');
|
|
76
|
+
const host = argv.host || 'https://messaging.velaro.com';
|
|
77
|
+
const embedded = s.growthConfigJson && JSON.parse(s.growthConfigJson).display?.type === 'embedded';
|
|
78
|
+
console.log(`<script async src="${host}/messenger/forms.js" data-form="${s.publicSlug}"></script>`);
|
|
79
|
+
if (embedded) console.log(`<div data-velaro-form="${s.publicSlug}"></div>`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const signupFormCommand = {
|
|
83
|
+
command: 'signup-form <subcommand>',
|
|
84
|
+
describe: 'Signup forms and popups: the list-growth layer of a survey (display rules, list, double opt-in, stats, signups)',
|
|
85
|
+
builder: (y) => y
|
|
86
|
+
.command({ command: 'list', describe: 'List the surveys that have the list-growth layer on', builder: (a) => a.option('json', { type: 'boolean' }), handler: runCommand(listHandler) })
|
|
87
|
+
.command({ command: 'get <id>', describe: 'Show one form (survey id) and its growth settings', builder: (a) => a.positional('id', { type: 'number' }), handler: runCommand(getHandler) })
|
|
88
|
+
.command({
|
|
89
|
+
command: 'set <id>',
|
|
90
|
+
describe: 'Change the list-growth settings of a survey (read-modify-write; the survey itself is untouched)',
|
|
91
|
+
builder: (a) => a.positional('id', { type: 'number' })
|
|
92
|
+
.option('file', { type: 'string', describe: 'JSON file with the growth settings' })
|
|
93
|
+
.option('config', { type: 'string', describe: 'Growth settings as a JSON string' })
|
|
94
|
+
.option('enable', { type: 'boolean', describe: 'Switch the layer on or off' })
|
|
95
|
+
.option('json', { type: 'boolean' }),
|
|
96
|
+
handler: runCommand(setHandler),
|
|
97
|
+
})
|
|
98
|
+
.command({ command: 'stats <id>', describe: 'Views, dismissals, signups and conversion', builder: (a) => a.positional('id', { type: 'number' }).option('days', { type: 'number', default: 30 }).option('json', { type: 'boolean' }), handler: runCommand(statsHandler) })
|
|
99
|
+
.command({
|
|
100
|
+
command: 'submissions <id>',
|
|
101
|
+
describe: 'Signups with opt-in status and consent record id (paginated)',
|
|
102
|
+
builder: (a) => a.positional('id', { type: 'number' }).option('page', { type: 'number', default: 1 }).option('page-size', { type: 'number', default: 25, alias: 'pageSize' })
|
|
103
|
+
.option('status', { type: 'string', describe: 'subscribed | pending_confirmation | confirmed | suppressed | list_sync_failed' }).option('json', { type: 'boolean' }),
|
|
104
|
+
handler: runCommand(submissionsHandler),
|
|
105
|
+
})
|
|
106
|
+
.command({ command: 'snippet <id>', describe: 'Print the one-line install snippet', builder: (a) => a.positional('id', { type: 'number' }).option('host', { type: 'string' }), handler: runCommand(snippetHandler) })
|
|
107
|
+
.demandCommand(1, 'Specify a signup-form subcommand.')
|
|
108
|
+
.strict(),
|
|
109
|
+
handler: () => {},
|
|
110
|
+
};
|
package/package.json
CHANGED