@workover/cli 0.27.0 → 0.29.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/bin/workover.mjs +2244 -4
- package/contacts.mjs +1561 -0
- package/domains.mjs +417 -0
- package/email-studio.mjs +829 -0
- package/feedback-board.mjs +321 -0
- package/journeys.mjs +409 -0
- package/package.json +20 -1
- package/support-agent-tests.mjs +424 -0
- package/support-config.mjs +302 -0
- package/support-email.mjs +458 -0
- package/support-fields.mjs +294 -0
- package/support-freshdesk.mjs +176 -0
- package/support-inbox.mjs +313 -0
- package/support-label-rules.mjs +136 -0
- package/support-labels.mjs +244 -0
- package/support-outcomes.mjs +276 -0
- package/support-outside-bot.mjs +145 -0
- package/support-setup.mjs +660 -0
- package/support-signatures.mjs +156 -0
- package/support-sources.mjs +233 -0
- package/support-walter.mjs +310 -0
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
// The Messenger's settings from a terminal, through the editor's one draft: `workover support config
|
|
2
|
+
// get|set|publish|discard` and the MCP server's `workover_support_config*` tools (WO-1752, S46).
|
|
3
|
+
//
|
|
4
|
+
// THE SAME FILE ships in @workover/cli (apps/cli/support-config.mjs) and @workover/mcp
|
|
5
|
+
// (apps/mcp/support-config.mjs), because the two packages are published separately and neither
|
|
6
|
+
// may depend on the other. `apps/mcp/support-config.test.mjs` fails when the copies differ.
|
|
7
|
+
//
|
|
8
|
+
// The Messenger editor in the app keeps one draft: edits on any tab land in it, and nothing reaches
|
|
9
|
+
// visitors until "Save and set live". These calls work on that same draft, so a person and an agent
|
|
10
|
+
// see each other's pending changes. `set` changes the draft only; `publish` sets it live in one
|
|
11
|
+
// change; `discard` throws it away. Every step is safe to repeat and answers what is pending, so an
|
|
12
|
+
// agent can check its result: after `publish`, `dirty` is false and `live` holds the new values.
|
|
13
|
+
//
|
|
14
|
+
// S44 adds `appearance` (the dark theme's color, the font and the launcher logo) to the settings,
|
|
15
|
+
// and "Import your style": `workover support style import <url> [--apply]` and the MCP server's
|
|
16
|
+
// `workover_support_style_import`, which read a site's brand color, dark color, font and logo and
|
|
17
|
+
// lay them over the same draft.
|
|
18
|
+
//
|
|
19
|
+
// `call(path, { method, body })` does the requests and resolves the parsed JSON, or throws an Error
|
|
20
|
+
// whose `.status` is the HTTP status and whose message is the API's own sentence. The renderers
|
|
21
|
+
// return lines, for a terminal or an MCP text result alike.
|
|
22
|
+
|
|
23
|
+
import { apiError, resolveWorkspace } from './site-setup.mjs';
|
|
24
|
+
|
|
25
|
+
/** The settings the Messenger editor holds in its draft, as PATCH messenger/:id names them. */
|
|
26
|
+
export const CONFIG_FIELDS = [
|
|
27
|
+
'name',
|
|
28
|
+
'enabled',
|
|
29
|
+
'color',
|
|
30
|
+
'greeting',
|
|
31
|
+
'intro',
|
|
32
|
+
'replyTime',
|
|
33
|
+
'askEmail',
|
|
34
|
+
'askRating',
|
|
35
|
+
'hours',
|
|
36
|
+
'origins',
|
|
37
|
+
'allowLink',
|
|
38
|
+
'theme',
|
|
39
|
+
'position',
|
|
40
|
+
'launcher',
|
|
41
|
+
'agentEnabled',
|
|
42
|
+
'agentName',
|
|
43
|
+
'minConfidence',
|
|
44
|
+
'limits',
|
|
45
|
+
'appearance',
|
|
46
|
+
'inbound',
|
|
47
|
+
'notice',
|
|
48
|
+
'startButton',
|
|
49
|
+
'sounds',
|
|
50
|
+
'readReceipts',
|
|
51
|
+
// Help and Updates, Closed conversations and Home's switches, kept in their own stores but
|
|
52
|
+
// drafted with the rest (walk round 2, major 3).
|
|
53
|
+
'sections',
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
/** What `sections` takes: the parts the editor drafts besides the Messenger's own settings. */
|
|
57
|
+
export const SECTIONS_HELP =
|
|
58
|
+
'sections {tabs: {help?, updates?, updatesProjectId?}, thread: {closedStaysClosed?}, home: {showFaces?, typingIntro?}} ' +
|
|
59
|
+
'drafts the Help and Updates tabs, whether a closed conversation stays closed, and Home\'s faces and typing intro. ' +
|
|
60
|
+
'Example: {"sections":{"thread":{"closedStaysClosed":true}}}.';
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Who sees the Messenger, and where (S47), inside `launcher`. A change to `launcher` keeps the parts
|
|
64
|
+
* it leaves out, and null clears one, so `{"launcher":{"spacing":null}}` touches nothing else.
|
|
65
|
+
*/
|
|
66
|
+
export const LAUNCHER_PARTS_HELP =
|
|
67
|
+
'Inside launcher (S47): audience {launcher|launchDirect|spaces: {visitors?, users?}} gives Users ' +
|
|
68
|
+
'(people the site signs in with identity verification) their own values, and a missing users value ' +
|
|
69
|
+
'follows visitors (the visitors launcher value is launcher.show; spaces values are {help?, updates?}). ' +
|
|
70
|
+
'conditions {launcher|start: {match: "all"|"any", rules: [...]}} shows the launcher, or lets people ' +
|
|
71
|
+
'start a conversation, only when the rules hold: {"type":"url","op":"contains|not_contains|equals|matches","value":"/pricing"} ' +
|
|
72
|
+
'(matches: * is anything) or {"type":"attribute","key":"plan","op":"equals|not_equals|contains|gt|lt|exists|not_exists","value":"pro"}, ' +
|
|
73
|
+
'which counts signed attributes only. spacing {side, bottom} is the launcher\'s distance from the corner ' +
|
|
74
|
+
'in px (0 to 200, default 20; phones keep 20). Parts left out are kept; null clears one. ' +
|
|
75
|
+
'Example: {"launcher":{"audience":{"launcher":{"users":false}},"conditions":{"launcher":{"match":"all","rules":[{"type":"url","op":"contains","value":"/pricing"}]}}}}.';
|
|
76
|
+
|
|
77
|
+
/** The Messenger these settings belong to: Support has to exist first. */
|
|
78
|
+
async function messengerOf(call, workspace) {
|
|
79
|
+
const ws = await resolveWorkspace(call, workspace);
|
|
80
|
+
const status = await call(`/messenger/agent-setup?organizationId=${encodeURIComponent(ws.id)}`);
|
|
81
|
+
const id = status?.messenger?.id;
|
|
82
|
+
if (!id) throw apiError(404, 'Support is not set up in this workspace yet. Run `workover support setup` first.');
|
|
83
|
+
return { ws, messengerId: id };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const draftPath = (messengerId) => `/messenger/${encodeURIComponent(messengerId)}/draft`;
|
|
87
|
+
|
|
88
|
+
/** Only the fields the draft takes; anything else is refused by name, so a typo is never silently dropped. */
|
|
89
|
+
export function pickChanges(changes) {
|
|
90
|
+
if (!changes || typeof changes !== 'object' || Array.isArray(changes))
|
|
91
|
+
throw apiError(400, 'Give the settings to change as an object, such as {"color":"#3e63dd"}.');
|
|
92
|
+
const out = {};
|
|
93
|
+
for (const [k, v] of Object.entries(changes)) {
|
|
94
|
+
if (v === undefined) continue;
|
|
95
|
+
if (!CONFIG_FIELDS.includes(k)) throw apiError(400, `"${k}" is not a Messenger setting. One of: ${CONFIG_FIELDS.join(', ')}. Nothing was changed.`);
|
|
96
|
+
out[k] = v;
|
|
97
|
+
}
|
|
98
|
+
if (!Object.keys(out).length) throw apiError(400, 'Nothing to change: give at least one setting.');
|
|
99
|
+
return out;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** The draft: what is pending, the settings with it laid over, and the live ones. */
|
|
103
|
+
export async function configGet(call, { workspace } = {}) {
|
|
104
|
+
const { ws, messengerId } = await messengerOf(call, workspace);
|
|
105
|
+
const draft = await call(draftPath(messengerId));
|
|
106
|
+
return { workspace: ws, ...draft };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Lay settings over the draft. Visitors see nothing until `configPublish`. With `publish: true` the
|
|
111
|
+
* draft is set live straight after, in the same call.
|
|
112
|
+
*/
|
|
113
|
+
export async function configSet(call, { workspace, changes, publish = false } = {}) {
|
|
114
|
+
const body = pickChanges(changes);
|
|
115
|
+
const { ws, messengerId } = await messengerOf(call, workspace);
|
|
116
|
+
const draft = await call(draftPath(messengerId), { method: 'PUT', body });
|
|
117
|
+
if (!publish) return { workspace: ws, published: null, ...draft };
|
|
118
|
+
const res = await call(`${draftPath(messengerId)}/publish`, { method: 'POST' });
|
|
119
|
+
return { workspace: ws, published: res.published, ...res.draft };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Set the draft live in one change. With nothing pending it changes nothing (`published: []`). */
|
|
123
|
+
export async function configPublish(call, { workspace } = {}) {
|
|
124
|
+
const { ws, messengerId } = await messengerOf(call, workspace);
|
|
125
|
+
const res = await call(`${draftPath(messengerId)}/publish`, { method: 'POST' });
|
|
126
|
+
return { workspace: ws, published: res.published, ...res.draft };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Throw the draft away. Visitors keep seeing the live settings. */
|
|
130
|
+
export async function configDiscard(call, { workspace } = {}) {
|
|
131
|
+
const { ws, messengerId } = await messengerOf(call, workspace);
|
|
132
|
+
const draft = await call(draftPath(messengerId), { method: 'DELETE' });
|
|
133
|
+
return { workspace: ws, ...draft };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* "Import your style" (S44): read a site's brand color, dark color, font and logo. With `apply` the
|
|
138
|
+
* suggestions go into the draft (never live: publish does that). Safe to repeat: the same site gives
|
|
139
|
+
* the same suggestions, and the same logo the same reference.
|
|
140
|
+
*/
|
|
141
|
+
export async function styleImport(call, { workspace, url, apply = false } = {}) {
|
|
142
|
+
if (typeof url !== 'string' || !url.trim())
|
|
143
|
+
throw apiError(400, 'Give your site’s address, such as `workover support style import example.com`.');
|
|
144
|
+
const { ws, messengerId } = await messengerOf(call, workspace);
|
|
145
|
+
const res = await call(`/messenger/${encodeURIComponent(messengerId)}/appearance/import`, {
|
|
146
|
+
method: 'POST',
|
|
147
|
+
body: { url: url.trim(), apply: apply === true },
|
|
148
|
+
});
|
|
149
|
+
return { workspace: ws, ...res };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// ------------------------------------------------------------------ rendering
|
|
153
|
+
|
|
154
|
+
const shown = (v) => (typeof v === 'string' ? JSON.stringify(v) : JSON.stringify(v ?? null));
|
|
155
|
+
|
|
156
|
+
/** What is pending, field by field: the live value and the draft's. */
|
|
157
|
+
export function renderConfig(res, { via = 'cli' } = {}) {
|
|
158
|
+
const where = res.workspace?.name ?? 'this workspace';
|
|
159
|
+
const out = [''];
|
|
160
|
+
if (Array.isArray(res.published)) {
|
|
161
|
+
out.push(
|
|
162
|
+
res.published.length
|
|
163
|
+
? ` ✓ Set live in ${where}: ${res.published.join(', ')}. Visitors see it on their next page load.`
|
|
164
|
+
: ` ✓ Nothing was pending in ${where}; nothing changed.`,
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
if (!res.dirty) {
|
|
168
|
+
if (!Array.isArray(res.published)) out.push(` No unsaved changes to the Messenger in ${where}.`);
|
|
169
|
+
out.push('');
|
|
170
|
+
return out;
|
|
171
|
+
}
|
|
172
|
+
out.push(` Unsaved changes to the Messenger in ${where} (visitors do not see them yet):`);
|
|
173
|
+
for (const f of res.fields || []) {
|
|
174
|
+
out.push(` ${f}: ${shown(res.live?.[f])} → ${shown(res.config?.[f])}`);
|
|
175
|
+
}
|
|
176
|
+
for (const f of res.sectionFields || []) {
|
|
177
|
+
const [part, key] = f.split('.');
|
|
178
|
+
// The live value before the arrow (walk round 3, m8); an older api does not send it.
|
|
179
|
+
const from = res.sectionsLive?.[part] ? `${shown(res.sectionsLive[part][key])} ` : '';
|
|
180
|
+
out.push(` ${f}: ${from}→ ${shown(res.sections?.[part]?.[key])}`);
|
|
181
|
+
}
|
|
182
|
+
// An agent on the MCP server is told its own tools, not the CLI's commands (walk round 3, m8).
|
|
183
|
+
out.push(
|
|
184
|
+
'',
|
|
185
|
+
via === 'mcp'
|
|
186
|
+
? ' workover_support_config_publish sets them live; workover_support_config_discard throws them away.'
|
|
187
|
+
: ' `workover support config publish` sets them live; `discard` throws them away.',
|
|
188
|
+
'',
|
|
189
|
+
);
|
|
190
|
+
return out;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** What an import found, and whether it is in the draft now. */
|
|
194
|
+
export function renderStyleImport(res, { via = 'cli' } = {}) {
|
|
195
|
+
const where = res.workspace?.name ?? 'this workspace';
|
|
196
|
+
const f = res.found || {};
|
|
197
|
+
const out = ['', ` Read ${res.url}:`];
|
|
198
|
+
const rows = [
|
|
199
|
+
['Brand color', f.color],
|
|
200
|
+
['Dark theme color', f.colorDark],
|
|
201
|
+
['Font', f.family ? (f.font === 'site' ? `${f.family} (Match my site)` : `${f.font} (like ${f.family})`) : null],
|
|
202
|
+
['Launcher logo', f.logo ? 'found and stored' : null],
|
|
203
|
+
];
|
|
204
|
+
for (const [label, value] of rows) out.push(` ${label}: ${value ?? 'none found'}`);
|
|
205
|
+
if (!Object.keys(res.changes || {}).length) {
|
|
206
|
+
out.push(
|
|
207
|
+
'',
|
|
208
|
+
via === 'mcp'
|
|
209
|
+
? ' Nothing to change: set the colors by hand with workover_support_config.'
|
|
210
|
+
: ' Nothing to change: set the colors by hand with `workover support config set`.',
|
|
211
|
+
'',
|
|
212
|
+
);
|
|
213
|
+
return out;
|
|
214
|
+
}
|
|
215
|
+
out.push(
|
|
216
|
+
'',
|
|
217
|
+
res.applied
|
|
218
|
+
? ` ✓ Added to the Messenger's unsaved changes in ${where}. ${via === 'mcp' ? 'workover_support_config_publish' : '`workover support config publish`'} sets them live.`
|
|
219
|
+
: ' Nothing was changed. Run it again with --apply to add these to the draft.',
|
|
220
|
+
'',
|
|
221
|
+
);
|
|
222
|
+
return out;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// ------------------------------------------------------------------ MCP tools
|
|
226
|
+
|
|
227
|
+
/** MCP replies name the MCP tools, not the CLI's commands (admin setup walk round 3, m8). */
|
|
228
|
+
const MCP = { via: 'mcp' };
|
|
229
|
+
|
|
230
|
+
const WORKSPACE = {
|
|
231
|
+
type: ['string', 'number'],
|
|
232
|
+
description: 'The workspace, by slug or id. Needed only when the account has more than one.',
|
|
233
|
+
};
|
|
234
|
+
const SCOPE =
|
|
235
|
+
' Needs a token from `workover login --support`; without it this returns a permission error naming that command.';
|
|
236
|
+
|
|
237
|
+
/** The MCP server's Messenger settings tools, listed with the other Support tools (index.mjs). */
|
|
238
|
+
export const CONFIG_TOOL_DEFS = [
|
|
239
|
+
{
|
|
240
|
+
name: 'workover_support_config',
|
|
241
|
+
description:
|
|
242
|
+
"The Messenger's settings through the editor's draft, the same draft the app's Messenger editor shows. Without `changes` it reads what is pending (`fields`), the live values and the draft's. With `changes` it lays them over the draft; visitors see nothing until it is published (pass `publish: true` to do both at once, or call workover_support_config_publish). Safe to repeat; a value equal to the live one leaves the draft. A refused value names its field and changes nothing." +
|
|
243
|
+
SCOPE,
|
|
244
|
+
inputSchema: {
|
|
245
|
+
type: 'object',
|
|
246
|
+
properties: {
|
|
247
|
+
workspace: WORKSPACE,
|
|
248
|
+
changes: {
|
|
249
|
+
type: 'object',
|
|
250
|
+
description: `Settings to change, by name: ${CONFIG_FIELDS.join(', ')}. Example: {"color":"#3e63dd","greeting":"Hi there"}. ${LAUNCHER_PARTS_HELP} ${SECTIONS_HELP}`,
|
|
251
|
+
},
|
|
252
|
+
publish: { type: 'boolean', description: 'Set the draft live straight after the change.' },
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
name: 'workover_support_config_publish',
|
|
258
|
+
description:
|
|
259
|
+
"Set the Messenger's draft live, every pending setting in one change, then drop the draft. With nothing pending it changes nothing. Ask the person first: this changes the chat on their live site." +
|
|
260
|
+
SCOPE,
|
|
261
|
+
inputSchema: { type: 'object', properties: { workspace: WORKSPACE } },
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
name: 'workover_support_config_discard',
|
|
265
|
+
description: "Throw away the Messenger's draft; visitors keep seeing the live settings. Safe to repeat." + SCOPE,
|
|
266
|
+
inputSchema: { type: 'object', properties: { workspace: WORKSPACE } },
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
name: 'workover_support_style_import',
|
|
270
|
+
description:
|
|
271
|
+
"Read a site's brand color, dark theme color, font and logo for the Messenger (\"Import your style\"). Without `apply` it only reports what it found; with `apply: true` it lays them over the Messenger's draft, which visitors do not see until workover_support_config_publish. Safe to repeat." +
|
|
272
|
+
SCOPE,
|
|
273
|
+
inputSchema: {
|
|
274
|
+
type: 'object',
|
|
275
|
+
properties: {
|
|
276
|
+
workspace: WORKSPACE,
|
|
277
|
+
url: { type: 'string', description: 'The site, such as example.com or https://example.com.' },
|
|
278
|
+
apply: { type: 'boolean', description: 'Add what was found to the draft.' },
|
|
279
|
+
},
|
|
280
|
+
required: ['url'],
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
];
|
|
284
|
+
|
|
285
|
+
export const CONFIG_TOOLS = new Set(CONFIG_TOOL_DEFS.map((t) => t.name));
|
|
286
|
+
|
|
287
|
+
/** Runs one of CONFIG_TOOLS and answers its lines. Throws what the api threw. */
|
|
288
|
+
export async function configTool(call, name, args = {}) {
|
|
289
|
+
const workspace = args.workspace === undefined || args.workspace === null ? undefined : String(args.workspace);
|
|
290
|
+
if (name === 'workover_support_config') {
|
|
291
|
+
if (args.changes === undefined || args.changes === null) return renderConfig(await configGet(call, { workspace }), MCP);
|
|
292
|
+
if (args.publish !== undefined && typeof args.publish !== 'boolean') throw apiError(400, 'publish is true or false. Nothing was changed.');
|
|
293
|
+
return renderConfig(await configSet(call, { workspace, changes: args.changes, publish: args.publish === true }), MCP);
|
|
294
|
+
}
|
|
295
|
+
if (name === 'workover_support_config_publish') return renderConfig(await configPublish(call, { workspace }), MCP);
|
|
296
|
+
if (name === 'workover_support_config_discard') return renderConfig(await configDiscard(call, { workspace }), MCP);
|
|
297
|
+
if (name === 'workover_support_style_import') {
|
|
298
|
+
if (args.apply !== undefined && typeof args.apply !== 'boolean') throw apiError(400, 'apply is true or false. Nothing was changed.');
|
|
299
|
+
return renderStyleImport(await styleImport(call, { workspace, url: args.url, apply: args.apply === true }), MCP);
|
|
300
|
+
}
|
|
301
|
+
throw apiError(400, `Unknown tool: ${name}`);
|
|
302
|
+
}
|