@velaro/cli 1.4.180 → 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 +2 -0
- package/lib/commands/contacts.js +34 -0
- package/lib/commands/public-api.js +53 -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';
|
|
@@ -199,6 +200,7 @@ await (registerStaffCommands ? registerStaffCommands(baseYargs) : baseYargs)
|
|
|
199
200
|
.command(applePayPresetCommand)
|
|
200
201
|
.command(integrationCommand)
|
|
201
202
|
.command(appointmentsCommand)
|
|
203
|
+
.command(publicApiCommand)
|
|
202
204
|
.command(bookingDefaultsCommand)
|
|
203
205
|
.command(bookingCommand)
|
|
204
206
|
.command(reportCommand)
|
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
|
+
};
|
package/package.json
CHANGED