@workover/cli 0.26.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 +2312 -5
- 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/lib.mjs +56 -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,458 @@
|
|
|
1
|
+
// Support's email follow-ups from a terminal: `workover support email ...` and the MCP server's
|
|
2
|
+
// `workover_support_*email*` tools (WO-1752, admin walk at real widths, M3; Support settings > Email).
|
|
3
|
+
//
|
|
4
|
+
// THE SAME FILE ships in @workover/cli (apps/cli/support-email.mjs) and @workover/mcp
|
|
5
|
+
// (apps/mcp/support-email.mjs), because the two packages are published separately and neither may
|
|
6
|
+
// depend on the other. `apps/mcp/support-email.test.mjs` fails when the copies differ.
|
|
7
|
+
//
|
|
8
|
+
// Everything the Email page sets: whether Support emails a visitor the replies they did not see, how
|
|
9
|
+
// long it waits first, whether it emails only verified addresses, the From name and Reply-to, the
|
|
10
|
+
// do-not-email list, and a test email to yourself. Every call goes to a route opened to tokens
|
|
11
|
+
// holding the `support` scope (`workover login --support`); changing anything is for workspace
|
|
12
|
+
// owners and admins, which the api decides. Setting what is already set changes nothing.
|
|
13
|
+
//
|
|
14
|
+
// `call(path, { method, body })` does the requests and resolves the parsed JSON, or throws an Error
|
|
15
|
+
// whose `.status` is the HTTP status and whose message is the API's own sentence. The renderers
|
|
16
|
+
// return lines, for a terminal or an MCP text result alike.
|
|
17
|
+
|
|
18
|
+
import { apiError, resolveWorkspace } from './site-setup.mjs';
|
|
19
|
+
|
|
20
|
+
/** The Messenger whose follow-ups these are: Support has to exist first. */
|
|
21
|
+
async function messengerOf(call, workspace) {
|
|
22
|
+
const ws = await resolveWorkspace(call, workspace);
|
|
23
|
+
const status = await call(`/messenger/agent-setup?organizationId=${encodeURIComponent(ws.id)}`);
|
|
24
|
+
const id = status?.messenger?.id;
|
|
25
|
+
if (!id) throw apiError(404, 'Support is not set up in this workspace yet. Run `workover support setup` first.');
|
|
26
|
+
return { ws, messengerId: id };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A wait as minutes: `30` or `30m` is 30, `2h` is 120, `1h30m` is 90. Anything else is refused with
|
|
31
|
+
* the forms there are; the api refuses a wait outside its limits with the limits.
|
|
32
|
+
*/
|
|
33
|
+
export function parseWait(value) {
|
|
34
|
+
if (typeof value === 'number' && Number.isFinite(value)) return Math.round(value);
|
|
35
|
+
const text = String(value ?? '').trim().toLowerCase();
|
|
36
|
+
if (/^\d+$/.test(text)) return Number(text);
|
|
37
|
+
const m = /^(?:(\d+)\s*h)?\s*(?:(\d+)\s*m(?:in)?)?$/.exec(text);
|
|
38
|
+
if (m && (m[1] || m[2])) return Number(m[1] || 0) * 60 + Number(m[2] || 0);
|
|
39
|
+
throw apiError(400, `Give the wait as minutes or hours, like 5m, 30 or 2h (not "${value}").`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* When the Messenger asks a visitor for their email (a Messenger setting, beside the follow-ups that
|
|
44
|
+
* need it): `away` at hand-off or while the team is away (the default), `first` after their first
|
|
45
|
+
* message, `never`. `handoff` is read as `away`. (Journey "Visitor gets an answer", M12: the only way
|
|
46
|
+
* to set it from a terminal was `support config set` with an undocumented key.)
|
|
47
|
+
*/
|
|
48
|
+
export const ASK_EMAIL = ['away', 'first', 'never'];
|
|
49
|
+
export function parseAskEmail(value) {
|
|
50
|
+
const v = String(value ?? '').trim().toLowerCase();
|
|
51
|
+
if (v === 'handoff' || v === 'hand-off') return 'away';
|
|
52
|
+
if (ASK_EMAIL.includes(v)) return v;
|
|
53
|
+
throw apiError(400, `Give when to ask for the email as away (at hand-off, or while you're away), first or never (not "${value}").`);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const draftPath = (messengerId) => `/messenger/${encodeURIComponent(messengerId)}/draft`;
|
|
57
|
+
|
|
58
|
+
/** The live askEmail, from the editor's draft read (which carries the live settings). */
|
|
59
|
+
async function askEmailOf(call, messengerId) {
|
|
60
|
+
const d = await call(draftPath(messengerId)).catch(() => null);
|
|
61
|
+
return d?.live?.askEmail ?? null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Set askEmail live through the editor's draft. Refused while the draft holds anything else, so this
|
|
66
|
+
* never sets someone's unpublished Messenger edits live with it.
|
|
67
|
+
*/
|
|
68
|
+
async function setAskEmail(call, messengerId, askEmail) {
|
|
69
|
+
const d = await call(draftPath(messengerId));
|
|
70
|
+
const others = (d?.fields ?? []).filter((f) => f !== 'askEmail');
|
|
71
|
+
if (others.length)
|
|
72
|
+
throw apiError(
|
|
73
|
+
409,
|
|
74
|
+
`The Messenger has unpublished changes (${others.join(', ')}). Publish or discard them first (workover support config publish, or discard), so this does not set them live. Nothing was changed.`
|
|
75
|
+
);
|
|
76
|
+
if (d?.live?.askEmail === askEmail && !d?.dirty) return;
|
|
77
|
+
await call(draftPath(messengerId), { method: 'PUT', body: { askEmail } });
|
|
78
|
+
await call(`${draftPath(messengerId)}/publish`, { method: 'POST' });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** The follow-up settings, the do-not-email list and the recent follow-ups. */
|
|
82
|
+
export async function getEmail(call, { workspace } = {}) {
|
|
83
|
+
const { ws, messengerId } = await messengerOf(call, workspace);
|
|
84
|
+
const res = await call(`/messenger/${messengerId}/email`);
|
|
85
|
+
return { workspace: ws, ...res, askEmail: await askEmailOf(call, messengerId) };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Change any of: `enabled`, `wait` (as parseWait reads it), `onlyVerified`, `fromName`, `replyTo`
|
|
90
|
+
* (an empty name or address goes back to the default). What is not given keeps its value; with
|
|
91
|
+
* nothing given this only reads. Safe to repeat.
|
|
92
|
+
*/
|
|
93
|
+
export async function setEmail(
|
|
94
|
+
call,
|
|
95
|
+
{ workspace, enabled, wait, onlyVerified, fromName, replyTo, askEmail, sentFrom, address, newEmails } = {}
|
|
96
|
+
) {
|
|
97
|
+
const ask = askEmail !== undefined ? parseAskEmail(askEmail) : undefined;
|
|
98
|
+
const body = {};
|
|
99
|
+
if (newEmails !== undefined) {
|
|
100
|
+
const v = String(newEmails).trim().toLowerCase();
|
|
101
|
+
if (!['off', 'support', 'default'].includes(v)) throw apiError(400, 'Use --new-emails off, support or default.');
|
|
102
|
+
body.newEmails = v === 'default' ? null : v;
|
|
103
|
+
}
|
|
104
|
+
if (address !== undefined) body.emailLocal = String(address).trim().toLowerCase();
|
|
105
|
+
if (sentFrom !== undefined) {
|
|
106
|
+
const v = String(sentFrom).trim().toLowerCase();
|
|
107
|
+
if (!v || v === 'default') body.emailDomainId = null;
|
|
108
|
+
else {
|
|
109
|
+
const { messengerId } = await messengerOf(call, workspace);
|
|
110
|
+
const list = await call(`/messenger/${messengerId}/email/domains`);
|
|
111
|
+
const d = (list.domains ?? []).find((x) => x.domain === v);
|
|
112
|
+
if (!d) throw apiError(404, `No sending domain ${v}. Connect it first: workover support email domain add ${v}`);
|
|
113
|
+
body.emailDomainId = d.id;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (enabled !== undefined) body.enabled = Boolean(enabled);
|
|
117
|
+
if (wait !== undefined) body.delayMinutes = parseWait(wait);
|
|
118
|
+
if (onlyVerified !== undefined) body.onlyVerified = Boolean(onlyVerified);
|
|
119
|
+
if (fromName !== undefined) body.fromName = String(fromName).trim() || null;
|
|
120
|
+
if (replyTo !== undefined) body.replyTo = String(replyTo).trim() || null;
|
|
121
|
+
if (!Object.keys(body).length && ask === undefined) return getEmail(call, { workspace });
|
|
122
|
+
const { ws, messengerId } = await messengerOf(call, workspace);
|
|
123
|
+
if (ask !== undefined) await setAskEmail(call, messengerId, ask);
|
|
124
|
+
const askNow = ask ?? (await askEmailOf(call, messengerId));
|
|
125
|
+
const res = Object.keys(body).length
|
|
126
|
+
? await call(`/messenger/${messengerId}/email`, { method: 'PUT', body })
|
|
127
|
+
: await call(`/messenger/${messengerId}/email`);
|
|
128
|
+
return {
|
|
129
|
+
workspace: ws,
|
|
130
|
+
changed: [...Object.keys(body), ...(ask !== undefined ? ['askEmail'] : [])],
|
|
131
|
+
...res,
|
|
132
|
+
askEmail: askNow,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Add an address to the do-not-email list (`remove: true` takes it off). Safe to repeat. */
|
|
137
|
+
export async function doNotEmail(call, { workspace, email, remove = false }) {
|
|
138
|
+
const address = String(email ?? '').trim();
|
|
139
|
+
if (!address) throw apiError(400, 'Give the email address.');
|
|
140
|
+
const { ws, messengerId } = await messengerOf(call, workspace);
|
|
141
|
+
const res = remove
|
|
142
|
+
? await call(`/messenger/${messengerId}/email/do-not-email?email=${encodeURIComponent(address)}`, {
|
|
143
|
+
method: 'DELETE',
|
|
144
|
+
})
|
|
145
|
+
: await call(`/messenger/${messengerId}/email/do-not-email`, { method: 'PUT', body: { email: address } });
|
|
146
|
+
return { workspace: ws, email: address, removed: remove, ...res };
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Send a sample follow-up to the signed-in person's own address. A real send. */
|
|
150
|
+
export async function sendTestEmail(call, { workspace } = {}) {
|
|
151
|
+
const { ws, messengerId } = await messengerOf(call, workspace);
|
|
152
|
+
const res = await call(`/messenger/${messengerId}/email/test`, { method: 'POST', body: {} });
|
|
153
|
+
return { workspace: ws, ...res };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const waitText = (minutes) => {
|
|
157
|
+
const m = Number(minutes) || 0;
|
|
158
|
+
if (m < 60 || m % 60) return `${m} minute${m === 1 ? '' : 's'}`;
|
|
159
|
+
const h = m / 60;
|
|
160
|
+
return `${h} hour${h === 1 ? '' : 's'}`;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const ASK_EMAIL_TEXT = {
|
|
164
|
+
away: 'at hand-off, or while you are away (away)',
|
|
165
|
+
first: 'after their first message (first)',
|
|
166
|
+
never: 'never (never)',
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
export function renderEmail(res) {
|
|
170
|
+
const out = ['', ` Email follow-ups for ${res.workspace?.name ?? 'this workspace'}:`, ''];
|
|
171
|
+
out.push(
|
|
172
|
+
` Email replies they haven't seen: ${res.enabled ? 'on' : 'off'}${
|
|
173
|
+
res.disabledOnServer ? ' (paused on the server: nothing is sent until it is switched back on there)' : ''
|
|
174
|
+
}`
|
|
175
|
+
);
|
|
176
|
+
out.push(` Wait before emailing: ${waitText(res.delayMinutes)}`);
|
|
177
|
+
out.push(` Only verified emails: ${res.onlyVerified ? 'yes' : 'no'}`);
|
|
178
|
+
out.push(` From: ${res.from ?? '(default)'}`);
|
|
179
|
+
out.push(` New emails: ${res.newEmails ?? 'the workspace default'}`);
|
|
180
|
+
// When the server takes replies, every follow-up carries a signed reply address for its
|
|
181
|
+
// conversation, and that, not the From address, is where a visitor's reply goes.
|
|
182
|
+
out.push(
|
|
183
|
+
` Reply-to: ${
|
|
184
|
+
res.conversationReplyTo
|
|
185
|
+
? `${res.conversationReplyTo} (one per conversation, so replies land in it)`
|
|
186
|
+
: res.replyTo || '(the From address)'
|
|
187
|
+
}`
|
|
188
|
+
);
|
|
189
|
+
if (res.askEmail)
|
|
190
|
+
out.push(` Ask visitors for their email: ${ASK_EMAIL_TEXT[res.askEmail] ?? res.askEmail}`);
|
|
191
|
+
const list = res.doNotEmail ?? [];
|
|
192
|
+
out.push('', ` Do not email (${list.length}):`);
|
|
193
|
+
out.push(...(list.length ? list.map((e) => ` ${e}`) : [' (nobody)']));
|
|
194
|
+
const day = res.last24h;
|
|
195
|
+
if (day) out.push('', ` Last 24 hours: ${day.sent} sent, ${day.pending} waiting, ${day.skipped} skipped, ${day.failed} failed`);
|
|
196
|
+
if (!res.enabled)
|
|
197
|
+
out.push('', ' Turn them on with `workover support email --on`, then send yourself one with `workover support email test`.');
|
|
198
|
+
out.push('');
|
|
199
|
+
return out;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export function renderEmailSaved(res) {
|
|
203
|
+
return ['', ` ✓ Saved (${(res.changed ?? []).join(', ') || 'nothing changed'}).`, ...renderEmail(res).slice(1)];
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export function renderDoNotEmail(res) {
|
|
207
|
+
return [
|
|
208
|
+
'',
|
|
209
|
+
res.removed
|
|
210
|
+
? ` ✓ ${res.email} can get follow-ups again.`
|
|
211
|
+
: ` ✓ ${res.email} gets no follow-ups from Support.`,
|
|
212
|
+
` The do-not-email list has ${(res.doNotEmail ?? []).length} address${(res.doNotEmail ?? []).length === 1 ? '' : 'es'}.`,
|
|
213
|
+
'',
|
|
214
|
+
];
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// ── Sending domains (Support settings > Email > Sending domains), ported from the ScaleMath dashboard ──
|
|
218
|
+
|
|
219
|
+
const domainsPath = (messengerId) => `/messenger/${encodeURIComponent(messengerId)}/email/domains`;
|
|
220
|
+
|
|
221
|
+
/** The workspace's sending domains, each with its records (looked up now), setup and test. Owners and admins. */
|
|
222
|
+
export async function listDomains(call, { workspace } = {}) {
|
|
223
|
+
const { ws, messengerId } = await messengerOf(call, workspace);
|
|
224
|
+
return { workspace: ws, ...(await call(domainsPath(messengerId))) };
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
async function domainByName(call, workspace, name) {
|
|
228
|
+
const { ws, messengerId } = await messengerOf(call, workspace);
|
|
229
|
+
const v = String(name ?? '').trim().toLowerCase();
|
|
230
|
+
if (!v) throw apiError(400, 'Give the domain, like acme.com.');
|
|
231
|
+
const list = await call(domainsPath(messengerId));
|
|
232
|
+
const d = (list.domains ?? []).find((x) => x.domain === v);
|
|
233
|
+
if (!d) throw apiError(404, `No sending domain ${v}. Connect it first: workover support email domain add ${v}`);
|
|
234
|
+
return { ws, messengerId, d, list };
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* One domain action: `add` connects it (the records to add come back), `check` checks verification
|
|
239
|
+
* and looks every record up, `test` sends you a test email from it, `forward <local>` has customers
|
|
240
|
+
* reply to <local>@domain (forwarded to the address answered; `local: null` stops it), `receives`
|
|
241
|
+
* turns replies at reply.<domain> on or off, `bounce` turns the custom bounce domain (optional) on or
|
|
242
|
+
* off, `remove` removes it. Owners and admins.
|
|
243
|
+
*/
|
|
244
|
+
export async function domainAction(call, { workspace, action, domain, local, on } = {}) {
|
|
245
|
+
if (action === 'add') {
|
|
246
|
+
const { ws, messengerId } = await messengerOf(call, workspace);
|
|
247
|
+
const d = await call(domainsPath(messengerId), { method: 'POST', body: { domain: String(domain ?? '').trim() } });
|
|
248
|
+
return { workspace: ws, action, domain: d };
|
|
249
|
+
}
|
|
250
|
+
const { ws, messengerId, d } = await domainByName(call, workspace, domain);
|
|
251
|
+
const at = `${domainsPath(messengerId)}/${d.id}`;
|
|
252
|
+
if (action === 'check') return { workspace: ws, action, domain: await call(`${at}/check`, { method: 'POST', body: {} }) };
|
|
253
|
+
if (action === 'test') return { workspace: ws, action, domain: await call(`${at}/test`, { method: 'POST', body: {} }) };
|
|
254
|
+
if (action === 'forward')
|
|
255
|
+
return {
|
|
256
|
+
workspace: ws,
|
|
257
|
+
action,
|
|
258
|
+
domain: await call(`${at}/forwarding`, { method: 'PUT', body: { local: local === null ? null : String(local ?? '').trim() } }),
|
|
259
|
+
};
|
|
260
|
+
if (action === 'receives' || action === 'bounce') {
|
|
261
|
+
if (typeof on !== 'boolean') throw apiError(400, 'Choose one: --on or --off.');
|
|
262
|
+
return { workspace: ws, action, domain: await call(`${at}/${action}`, { method: 'PUT', body: { on } }) };
|
|
263
|
+
}
|
|
264
|
+
if (action === 'remove') {
|
|
265
|
+
await call(at, { method: 'DELETE' });
|
|
266
|
+
return { workspace: ws, action, removed: d.domain };
|
|
267
|
+
}
|
|
268
|
+
throw apiError(400, 'Use add, check, test, forward, receives, bounce or remove.');
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** "New emails by default": `off` or `support`. Owners and admins. */
|
|
272
|
+
export async function setNewEmailsDefault(call, { workspace, newEmails } = {}) {
|
|
273
|
+
const v = String(newEmails ?? '').trim().toLowerCase();
|
|
274
|
+
if (v !== 'off' && v !== 'support') throw apiError(400, 'Use off or support.');
|
|
275
|
+
const { ws, messengerId } = await messengerOf(call, workspace);
|
|
276
|
+
await call(`/messenger/${messengerId}/email/defaults`, { method: 'PUT', body: { newEmails: v } });
|
|
277
|
+
return { workspace: ws, newEmailsDefault: v };
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const NEW_EMAIL_WORDS = { off: 'Not taken', support: 'Into Support' };
|
|
281
|
+
const STATE_WORDS = { found: '✓ In place', elsewhere: 'Change to this value', missing: 'Add this record', unknown: 'Checking…' };
|
|
282
|
+
const MARK = { done: '✓', waiting: '◔', todo: '○' };
|
|
283
|
+
const STATUS_WORDS = { verified: 'Verified', failed: 'Failed', pending: 'Waiting for DNS' };
|
|
284
|
+
|
|
285
|
+
export function renderDomain(d) {
|
|
286
|
+
const out = [` ${d.domain} (${STATUS_WORDS[d.status] ?? d.status})`];
|
|
287
|
+
if (d.lastError) out.push(` ${d.lastError}`);
|
|
288
|
+
if (d.setup) {
|
|
289
|
+
out.push(` ${d.setup.headline}`);
|
|
290
|
+
for (const step of d.setup.steps) out.push(` ${MARK[step.state] ?? '○'} ${step.label} · ${step.note}`);
|
|
291
|
+
}
|
|
292
|
+
const toDo = (d.records ?? []).filter((r) => r.state !== 'found').length;
|
|
293
|
+
out.push(
|
|
294
|
+
'',
|
|
295
|
+
toDo ? ` DNS records: ${toDo} of ${d.records.length} to add or change` : ` DNS records: all ${d.records.length} in place`
|
|
296
|
+
);
|
|
297
|
+
for (const r of d.records ?? []) out.push(` ${r.type.padEnd(5)} ${r.name} ${r.value} [${STATE_WORDS[r.state] ?? r.state}]`);
|
|
298
|
+
if (d.replyAddress && d.forwardTo) {
|
|
299
|
+
out.push('', ` Customers reply to ${d.replyAddress}. Forward every email in that mailbox to:`, ` ${d.forwardTo}`);
|
|
300
|
+
if (d.forwardConfirm && !d.forwardSeenAt)
|
|
301
|
+
out.push(
|
|
302
|
+
` Gmail asks to confirm it${d.forwardConfirm.code ? `: code ${d.forwardConfirm.code}` : ''}.${d.forwardConfirm.link ? ` ${d.forwardConfirm.link}` : ''}`
|
|
303
|
+
);
|
|
304
|
+
out.push(
|
|
305
|
+
d.forwardSeenAt
|
|
306
|
+
? ` ✓ Forwarding works. Emails ask customers to reply to ${d.replyAddress}.`
|
|
307
|
+
: ' Waiting for the first forwarded email. Until then, emails keep the shared reply address, so no reply is lost.'
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
if (d.receives) out.push(` Replies at ${d.replyHost}: ${d.mxOk ? 'on' : `waiting for its record (${d.mxNote ?? 'not checked'})`}`);
|
|
311
|
+
out.push(
|
|
312
|
+
d.mailFrom
|
|
313
|
+
? ` Bounce domain: ${d.mailFrom} (SPF aligns as well as DKIM)`
|
|
314
|
+
: ` Bounce domain: shared (optional: workover support email domain bounce ${d.domain} --on)`
|
|
315
|
+
);
|
|
316
|
+
if (d.test?.replyAt) out.push(` ✓ Test email replied to (${d.test.replyVia ?? 'reply'})`);
|
|
317
|
+
else if (d.test?.sentAt) out.push(` Test email sent to ${d.test.to}: reply to it to check replies come back.`);
|
|
318
|
+
return out;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export function renderDomains(res) {
|
|
322
|
+
const out = ['', ` Email for ${res.workspace?.name ?? 'this workspace'}:`, ''];
|
|
323
|
+
out.push(` New emails by default: ${NEW_EMAIL_WORDS[res.newEmailsDefault] ?? res.newEmailsDefault}`);
|
|
324
|
+
out.push(` Default sender: ${res.defaultFrom}`, '');
|
|
325
|
+
if (!res.domains?.length) out.push(' No sending domains yet. Connect one: workover support email domain add acme.com');
|
|
326
|
+
for (const d of res.domains ?? []) out.push(...renderDomain(d), '');
|
|
327
|
+
out.push('');
|
|
328
|
+
return out;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export function renderDomainAction(res) {
|
|
332
|
+
if (res.action === 'remove') return ['', ` ✓ Removed ${res.removed}. Brands using it fall back to the default.`, ''];
|
|
333
|
+
return ['', ...renderDomain(res.domain), ''];
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export function renderTestEmail(res) {
|
|
337
|
+
return ['', ` ✓ Sent a test follow-up to ${res.to} ("${res.subject}", through ${res.provider}).`, ''];
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const WORKSPACE = {
|
|
341
|
+
type: 'string',
|
|
342
|
+
description: 'The workspace, by slug or id. Needed only when the account has more than one.',
|
|
343
|
+
};
|
|
344
|
+
const SCOPE =
|
|
345
|
+
' Needs a token from `workover login --support`; without it this returns a permission error naming that command.';
|
|
346
|
+
|
|
347
|
+
/** The MCP server's email follow-up tools, listed with the other Support tools (index.mjs). */
|
|
348
|
+
export const EMAIL_TOOL_DEFS = [
|
|
349
|
+
{
|
|
350
|
+
name: 'workover_support_email',
|
|
351
|
+
description:
|
|
352
|
+
"Support's email follow-ups: whether it emails a visitor the replies they did not see after they leave, how long it waits, whether only verified addresses get them, the From name and Reply-to, the do-not-email list, and the last 24 hours." +
|
|
353
|
+
SCOPE,
|
|
354
|
+
inputSchema: { type: 'object', properties: { workspace: WORKSPACE } },
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
name: 'workover_support_set_email',
|
|
358
|
+
description:
|
|
359
|
+
'Change the email follow-ups (owners and admins): `enabled`, `wait` (like "5m", "30" or "2h"), `onlyVerified`, `fromName` and `replyTo` ("" goes back to the default), and `askEmail`, when the Messenger asks a visitor for their email: `away` (at hand-off, or while the team is away; the default), `first` (after their first message) or `never`. askEmail is set live, and is refused while the Messenger has other unpublished changes. What is left out keeps its value. Safe to repeat.' +
|
|
360
|
+
SCOPE,
|
|
361
|
+
inputSchema: {
|
|
362
|
+
type: 'object',
|
|
363
|
+
properties: {
|
|
364
|
+
workspace: WORKSPACE,
|
|
365
|
+
enabled: { type: 'boolean' },
|
|
366
|
+
wait: { type: 'string', description: 'How long to wait before emailing: 5m, 30, 2h.' },
|
|
367
|
+
onlyVerified: { type: 'boolean' },
|
|
368
|
+
fromName: { type: 'string' },
|
|
369
|
+
replyTo: { type: 'string' },
|
|
370
|
+
askEmail: { type: 'string', enum: ['away', 'first', 'never'] },
|
|
371
|
+
sentFrom: { type: 'string', description: 'A connected sending domain, or "default".' },
|
|
372
|
+
address: { type: 'string', description: 'The part before the @ at the sending domain, like support.' },
|
|
373
|
+
newEmails: { type: 'string', enum: ['off', 'support', 'default'] },
|
|
374
|
+
},
|
|
375
|
+
},
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
name: 'workover_support_do_not_email',
|
|
379
|
+
description:
|
|
380
|
+
'Add an address to the do-not-email list so Support sends it no follow-ups, or take it off with `remove: true` (owners and admins). Safe to repeat.' +
|
|
381
|
+
SCOPE,
|
|
382
|
+
inputSchema: {
|
|
383
|
+
type: 'object',
|
|
384
|
+
properties: { workspace: WORKSPACE, email: { type: 'string' }, remove: { type: 'boolean' } },
|
|
385
|
+
required: ['email'],
|
|
386
|
+
},
|
|
387
|
+
},
|
|
388
|
+
{
|
|
389
|
+
name: 'workover_support_email_domains',
|
|
390
|
+
description:
|
|
391
|
+
"Support's sending domains (owners and admins): each domain's DNS records to add and whether each is in place now, DKIM, SPF and DMARC, where the setup stands, forwarding of the brand's own mailbox and the last test email; the default sender; and \"New emails by default\"." +
|
|
392
|
+
SCOPE,
|
|
393
|
+
inputSchema: { type: 'object', properties: { workspace: WORKSPACE } },
|
|
394
|
+
},
|
|
395
|
+
{
|
|
396
|
+
name: 'workover_support_email_domain',
|
|
397
|
+
description:
|
|
398
|
+
'Act on a sending domain (owners and admins): `add` connects it and answers the DNS records to add, `check` checks verification and looks every record up now, `test` sends you a test email from it (reply to it to prove replies come back), `forward` has customers reply to `local`@domain, which you forward to the address answered (`local: ""` stops it), `receives` turns replies at reply.<domain> on or off (`on`), `bounce` turns the custom bounce domain at bounce.<domain> on or off (`on`; optional, DKIM alone passes DMARC), `remove` removes it.' +
|
|
399
|
+
SCOPE,
|
|
400
|
+
inputSchema: {
|
|
401
|
+
type: 'object',
|
|
402
|
+
properties: {
|
|
403
|
+
workspace: WORKSPACE,
|
|
404
|
+
action: { type: 'string', enum: ['add', 'check', 'test', 'forward', 'receives', 'bounce', 'remove'] },
|
|
405
|
+
domain: { type: 'string', description: 'The domain, like acme.com.' },
|
|
406
|
+
local: { type: 'string', description: 'For forward: the part before the @, like support; "" stops it.' },
|
|
407
|
+
on: { type: 'boolean', description: 'For receives and bounce.' },
|
|
408
|
+
},
|
|
409
|
+
required: ['action', 'domain'],
|
|
410
|
+
},
|
|
411
|
+
},
|
|
412
|
+
{
|
|
413
|
+
name: 'workover_support_test_email',
|
|
414
|
+
description:
|
|
415
|
+
"Send a sample follow-up to the signed-in person's own address, ending with their signature, and say where it went (owners and admins). A real send." +
|
|
416
|
+
SCOPE,
|
|
417
|
+
inputSchema: { type: 'object', properties: { workspace: WORKSPACE } },
|
|
418
|
+
},
|
|
419
|
+
];
|
|
420
|
+
|
|
421
|
+
/** The email tools' names, for the MCP dispatcher. */
|
|
422
|
+
export const EMAIL_TOOLS = new Set(EMAIL_TOOL_DEFS.map((t) => t.name));
|
|
423
|
+
|
|
424
|
+
/** One email tool, run: the lines to answer with. Throws as `call` does. */
|
|
425
|
+
export async function runEmailTool(call, name, args = {}) {
|
|
426
|
+
const workspace = args.workspace === undefined || args.workspace === null ? undefined : String(args.workspace);
|
|
427
|
+
if (name === 'workover_support_email') return renderEmail(await getEmail(call, { workspace }));
|
|
428
|
+
if (name === 'workover_support_set_email')
|
|
429
|
+
return renderEmailSaved(
|
|
430
|
+
await setEmail(call, {
|
|
431
|
+
workspace,
|
|
432
|
+
enabled: args.enabled,
|
|
433
|
+
wait: args.wait,
|
|
434
|
+
onlyVerified: args.onlyVerified,
|
|
435
|
+
fromName: args.fromName,
|
|
436
|
+
replyTo: args.replyTo,
|
|
437
|
+
askEmail: args.askEmail,
|
|
438
|
+
sentFrom: args.sentFrom,
|
|
439
|
+
address: args.address,
|
|
440
|
+
newEmails: args.newEmails,
|
|
441
|
+
})
|
|
442
|
+
);
|
|
443
|
+
if (name === 'workover_support_email_domains') return renderDomains(await listDomains(call, { workspace }));
|
|
444
|
+
if (name === 'workover_support_email_domain')
|
|
445
|
+
return renderDomainAction(
|
|
446
|
+
await domainAction(call, {
|
|
447
|
+
workspace,
|
|
448
|
+
action: args.action,
|
|
449
|
+
domain: args.domain,
|
|
450
|
+
local: args.action === 'forward' && (args.local === '' || args.local === null) ? null : args.local,
|
|
451
|
+
on: args.on,
|
|
452
|
+
})
|
|
453
|
+
);
|
|
454
|
+
if (name === 'workover_support_do_not_email')
|
|
455
|
+
return renderDoNotEmail(await doNotEmail(call, { workspace, email: args.email, remove: args.remove === true }));
|
|
456
|
+
if (name === 'workover_support_test_email') return renderTestEmail(await sendTestEmail(call, { workspace }));
|
|
457
|
+
throw apiError(400, `Unknown tool: ${name}`);
|
|
458
|
+
}
|