The open-source AI receptionist for businesses. Answers every call, books the appointment and hands over to a person when needed. You own the code and the data.
TypeScript ai-receptionistanswering-serviceappointment-bookinglivekitlocal-firstmcpopen-sourceself-hostedsiptelephonytypescriptvoice-agentvoice-ai
// Business info (LIN-809): the topics of the support mail review not yet reviewed, as "Suggested" rows of Questions and
// answers, right after the open questions. A suggestion opens with its question and answer filled in from the topic;
// Add to answers puts it into the About text on the server (mail.reviewTopic accept) and into the page's draft;
// Dismiss drops it. Data and writes: integrations/mailReview.ts (the Support email page reviews the same topics).
import type { MailTopic } from '@linedesk/actions'
import { useT } from '@linedesk/i18n/react'
import { useState } from 'react'
import { draftOf, stateOf, type TopicDraft, useMailReview } from '../integrations/mailReview.ts'
import { Input, Textarea } from '../ui/form.tsx'
import { Badge, Button } from '../ui/kit.tsx'
import { ListLine } from '../ui/FeatureLine.tsx'
export type Suggestion = { index: number; topic: MailTopic }
/** The topics still to review, the ones most support emails were about first; none until the analysis is done. */
export function openSuggestions(topics: readonly MailTopic[] | undefined): Suggestion[] {
return (topics ?? [])
.map((topic, index) => ({ index, topic }))
.filter(s => stateOf(s.topic) === 'open')
.sort((a, b) => b.topic.conversations - a.topic.conversations)
}
/** The suggestions of the latest analysis and the review that accepts or drops them; none for members (not read). */
export function useSuggestions(toast: (text: string) => void, canReview: boolean) {
const review = useMailReview(toast, canReview)
const done = review.analysis?.status === 'done'
return { items: done ? openSuggestions(review.analysis?.topics) : [], review }
}
type RowProps = {
s: Suggestion
assistantId: string
canEdit: boolean
open: boolean
onOpen: (open: boolean) => void
review: ReturnType<typeof useMailReview>
/** After the server added it: the page's draft gets the line too. */
onAccepted: (question: string, answer: string) => void
}
/** One suggestion as a line of the list; Review opens it in place to adjust and add, or dismiss. */
export function SuggestedRow({ s, assistantId, canEdit, open, onOpen, review, onAccepted }: RowProps) {
const t = useT()
const [draft, setDraft] = useState<TopicDraft>(() => draftOf(s.topic))
const busy = review.busy === s.index
async function accept() {
if (await review.accept(s.index, draft, assistantId)) onAccepted(draft.question.trim(), draft.answer.trim())
}
return (
<ListLine
className="kn-q"
open={open}
onToggle={() => onOpen(!open)}
label={t('settings.knowledge.sugg.review')}
title={draftOf(s.topic).question}
aside={t('settings.knowledge.sugg.from', { count: s.topic.conversations })}
description={s.topic.answer}
before={
<Badge tone="info" dot>
{t('settings.knowledge.sugg.badge')}
</Badge>
}
>
<Input
value={draft.question}
disabled={!canEdit}
aria-label={t('settings.knowledge.panel.question')}
onChange={e => setDraft(d => ({ ...d, question: e.target.value }))}
/>
<Textarea
rows={3}
value={draft.answer}
disabled={!canEdit}
aria-label={t('settings.knowledge.panel.answer')}
onChange={e => setDraft(d => ({ ...d, answer: e.target.value }))}
/>
<div className="kn-qedit-foot">
<Button
size="sm"
variant="ghost"
disabled={!canEdit || busy}
onClick={() => void review.drop(s.index)}
title={t('settings.knowledge.sugg.dismissTip')}
>
{t('settings.review.questions.dismiss')}
</Button>
<Button
size="sm"
variant="primary"
busy={busy}
disabled={!canEdit || !draft.question.trim() || !draft.answer.trim()}
onClick={() => void accept()}
title={t('settings.knowledge.sugg.addTip')}
>
{t('settings.knowledge.sugg.add')}
</Button>
</div>
</ListLine>
)
}