diff --git a/README.md b/README.md index 007a3348..d32839aa 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ These distinctions help set expectations when evaluating AiLoom for a support wo | Area | Available today | Not included today | | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- | -| Widget content | Safe Markdown, citations, fixed yes/no handoff controls, optional email capture, feedback, and CSAT form | Generic message cards, carousels, model-defined quick replies, and configurable form schemas | +| Widget content | Safe Markdown, citations, handoff controls, optional email capture, feedback, CSAT, and admin-authored welcome cards/carousels, quick replies, and bounded forms | Model-generated cards, carousels, and actions inside assistant messages | | Knowledge gaps | Ranked repeat-wording report for low/no-retrieval widget escalations, with bot/date filters, daily counts, example conversations, and links to knowledge review and corrections | Semantic topic clustering and scheduled gap digests | | Agent operations | Shared inbox, manual assignment/release, priority, notifications, live replies, and historical first-response metrics | Rule-based auto-routing, agent availability/presence, load balancing, SLA targets, timers, and breach escalation | @@ -150,6 +150,13 @@ group. This is exact repeat-wording grouping, not semantic clustering. Admins ca conversation, test retrieval, review existing corrections, and open the bot's add-knowledge flow; customer messages are not copied into a source automatically. +Widget welcome interactions are authored by workspace admins. Card destinations and optional +images must use HTTPS; carousel, quick-reply, and form definitions are bounded and schema-validated. +Quick replies send their configured prompt through the normal visitor-message path. Form answers +are serialized as plain text into that same conversation and are processed by the configured AI +and support team, so admins should not request passwords, payment details, or other sensitive +information. The model cannot define or trigger widget actions. + ## A support workflow, step by step The screenshots and recordings use synthetic demo data. Each step shows what an operator or diff --git a/apps/admin/src/features/bots/bots.spec.tsx b/apps/admin/src/features/bots/bots.spec.tsx index fd4eba87..b61c1b9d 100644 --- a/apps/admin/src/features/bots/bots.spec.tsx +++ b/apps/admin/src/features/bots/bots.spec.tsx @@ -26,6 +26,7 @@ import { BotCreateForm } from './components/bot-create-form'; import { BotGeneralForm } from './components/bot-general-form'; import { BotInstall } from './components/bot-install'; import { BotInstructions } from './components/bot-instructions'; +import { BotInteractionsForm } from './components/bot-interactions-form'; import { BotModelForm } from './components/bot-model-form'; import { BotsList } from './components/bots-list'; import { buildEmbedSnippet } from './embed-snippet'; @@ -78,6 +79,7 @@ const BOT: BotDto = { avatarUrl: null, privacyUrl: null, }, + widgetInteractions: { cards: [], quickReplies: [], form: null }, createdAt: '2026-01-01T00:00:00Z', updatedAt: '2026-01-01T00:00:00Z', }; @@ -150,6 +152,36 @@ describe('BotAppearanceForm', () => { }); }); +describe('BotInteractionsForm', () => { + it('lets admins configure a fixed quick reply and saves its exact prompt', async () => { + const calls = mockApi(botRoutes()); + renderWithQuery(asRole(ADMIN, )); + + await screen.findByRole('heading', { name: 'Welcome interactions' }); + await userEvent.click(screen.getByRole('button', { name: 'Add quick reply' })); + await userEvent.type(screen.getByLabelText('Button label'), 'Track an order'); + await userEvent.type(screen.getByLabelText('Message sent'), 'Where is my order?'); + await userEvent.click(screen.getByRole('button', { name: 'Save interactions' })); + + await screen.findByText('Saved.'); + expect(calls.find((call) => call.method === 'PATCH')?.body).toMatchObject({ + widgetInteractions: { + cards: [], + quickReplies: [{ label: 'Track an order', prompt: 'Where is my order?' }], + form: null, + }, + }); + }); + + it('keeps the editor read-only for agents', async () => { + mockApi(botRoutes()); + renderWithQuery(asRole(AGENT, )); + + const add = await screen.findByRole('button', { name: 'Add card' }); + expect(add).toBeDisabled(); + }); +}); + describe('BotModelForm', () => { const modelRoutes = (): Record => ({ ...botRoutes(), diff --git a/apps/admin/src/features/bots/components/bot-interactions-form.tsx b/apps/admin/src/features/bots/components/bot-interactions-form.tsx new file mode 100644 index 00000000..24c2e0c0 --- /dev/null +++ b/apps/admin/src/features/bots/components/bot-interactions-form.tsx @@ -0,0 +1,506 @@ +// SPDX-License-Identifier: AGPL-3.0-only +import { useState } from 'react'; + +import { FormAlert } from '@/components/form-alert'; +import { hasRole, useWorkspaceRole } from '@/components/role-gate'; +import { Button } from '@/components/ui/button'; +import { Input } from '@/components/ui/input'; +import { Label } from '@/components/ui/label'; +import { Skeleton } from '@/components/ui/skeleton'; +import { errorMessage } from '@/lib/error-message'; +import type { WidgetInteractions } from '@app/shared'; + +import { useBot, useUpdateBot } from '../api'; + +type FormConfig = NonNullable; +type FormField = FormConfig['fields'][number]; + +function newId(prefix: string): string { + try { + return `${prefix}-${crypto.randomUUID().slice(0, 8)}`; + } catch { + return `${prefix}-${String(Date.now())}`; + } +} + +function TextControl({ + id, + label, + value, + maxLength, + disabled, + type = 'text', + onChange, +}: { + id: string; + label: string; + value: string; + maxLength: number; + disabled: boolean; + type?: 'text' | 'url'; + onChange: (value: string) => void; +}) { + return ( +
+ + { + onChange(event.target.value); + }} + /> +
+ ); +} + +export function BotInteractionsForm({ + workspaceId, + botId, +}: { + workspaceId: string; + botId: string; +}) { + const isAdmin = hasRole(useWorkspaceRole(), 'admin'); + const bot = useBot(workspaceId, botId); + const update = useUpdateBot(workspaceId, botId); + const [draft, setDraft] = useState(null); + + if (bot.isError) return ; + if (bot.data === undefined) return ; + + const interactions = draft ?? bot.data.widgetInteractions; + const form = interactions.form; + const patch = (next: WidgetInteractions): void => { + setDraft(next); + }; + const patchCard = (index: number, values: Partial): void => { + patch({ + ...interactions, + cards: interactions.cards.map((card, current) => + current === index ? { ...card, ...values } : card, + ), + }); + }; + const patchReply = ( + index: number, + values: Partial, + ): void => { + patch({ + ...interactions, + quickReplies: interactions.quickReplies.map((reply, current) => + current === index ? { ...reply, ...values } : reply, + ), + }); + }; + const patchForm = (values: Partial): void => { + if (form === null) return; + patch({ ...interactions, form: { ...form, ...values } }); + }; + const patchField = (index: number, next: FormField): void => { + if (form === null) return; + patchForm({ + fields: form.fields.map((field, current) => (current === index ? next : field)), + }); + }; + const addField = (): void => { + if (form === null || form.fields.length >= 5) return; + patchForm({ + fields: [...form.fields, { id: newId('field'), label: '', type: 'text', required: false }], + }); + }; + + return ( +
{ + event.preventDefault(); + update.mutate({ widgetInteractions: interactions }); + }} + > +
+

Welcome interactions

+

+ Add helpful links, suggested questions, and a short support form. These appear before a + visitor starts chatting. +

+
+ +
+ Cards + {interactions.cards.map((card, index) => ( +
+ { + patchCard(index, { title }); + }} + /> + { + patchCard(index, { linkLabel }); + }} + /> + { + patchCard(index, { description }); + }} + /> + { + patchCard(index, { linkUrl }); + }} + /> + { + patchCard(index, { imageUrl: value.trim() === '' ? null : value }); + }} + /> + { + patchCard(index, { imageAlt }); + }} + /> + +
+ ))} + +
+ +
+ Quick replies +

+ Selecting one sends its configured prompt as a visitor message. +

+ {interactions.quickReplies.map((reply, index) => ( +
+ { + patchReply(index, { label }); + }} + /> + { + patchReply(index, { prompt }); + }} + /> + +
+ ))} + +
+ +
+ Support form + {form === null ? ( + + ) : ( + <> +
+ { + patchForm({ title }); + }} + /> + { + patchForm({ submitLabel }); + }} + /> + { + patchForm({ description }); + }} + /> +
+ {form.fields.map((field, index) => ( + { + patchField(index, next); + }} + onRemove={() => { + patchForm({ fields: form.fields.filter((_, i) => i !== index) }); + }} + /> + ))} + + +

+ Submitted answers are added to the conversation and processed by this bot’s configured + AI and support team. Do not ask for passwords, payment details, or other sensitive + information. +

+ + )} +
+ + +
+ + {update.isSuccess && ( + + Saved. + + )} +
+ + ); +} + +function FormFieldEditor({ + field, + disabled, + onChange, + onRemove, +}: { + field: FormField; + disabled: boolean; + onChange: (next: FormField) => void; + onRemove: () => void; +}) { + const id = `form-field-${field.id}`; + const setType = (value: string): void => { + const next: FormField = + value === 'select' + ? { + id: field.id, + label: field.label, + type: 'select', + required: field.required, + options: ['Option 1', 'Option 2'], + } + : { + id: field.id, + label: field.label, + type: value === 'email' ? 'email' : 'text', + required: field.required, + }; + onChange(next); + }; + + return ( +
+ { + onChange({ ...field, label }); + }} + /> +
+ + +
+ {field.type === 'select' && ( +
+ +