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
// Assistant › Phone (LIN-852, mockup A): how calls reach this assistant. Its numbers as the same cards as Workspace
// settings › Phone numbers (the sentence, Forwarding with Test, how calls reach its number), without Answered by: the
// page is the assistant's. Add a number gives a number to this assistant. The carrier, the own phone system and who
// answers a number stay on Workspace settings › Phone numbers, the full list, linked below.
import type { Assistant } from '@linedesk/db/types'
import { T, useT } from '@linedesk/i18n/react'
import { useState } from 'react'
import type { PhoneSetupStatus } from '../auth.ts'
import { useAssistants, useRows } from '../store.tsx'
import { appLink } from '../ui/AppLink.tsx'
import { Card } from '../ui/form.tsx'
import { Button } from '../ui/kit.tsx'
import { ListEmpty } from '../ui/list.tsx'
import { sectionHash } from '../ui/SettingsLayout.tsx'
import { AddNumberDialog, NumberList, usePhoneStatus } from './PhoneNumbers.tsx'
type Props = {
assistant: Assistant
canEdit: boolean
phoneSetup: PhoneSetupStatus | null
extraNumberCents: number | null
}
export function AssistantPhone({ assistant, canEdit, phoneSetup, extraNumberCents }: Props) {
const t = useT()
const assistants = useAssistants()
// Numbers that name no assistant are the first (default) one's.
const isDefault = assistants[0]?.id === assistant.id
const numbers = useRows('phone_numbers')
.filter(n => n.assistant_id === assistant.id || (!n.assistant_id && isDefault))
.sort((a, b) => a.created_at.localeCompare(b.created_at))
const { status } = usePhoneStatus(canEdit, phoneSetup)
const canAdd = canEdit && !!status?.available
const [adding, setAdding] = useState(false)
const add = (variant: 'primary' | 'secondary') => (
<Button size="sm" variant={variant} icon="plus" onClick={() => setAdding(true)}>
{t('settings.assistant.phone.add')}
</Button>
)
return (
<>
<NumberList
numbers={numbers}
assistants={assistants}
canEdit={canEdit}
page={`assistant/${assistant.id}`}
answeredBy={false}
empty={
<Card className="pn-empty">
<ListEmpty>{t('settings.assistant.phone.empty', { name: assistant.name })}</ListEmpty>
{canAdd && add('primary')}
</Card>
}
/>
<div className="pn-foot">
<p className="help">
<T k="settings.assistant.phone.allNumbers" values={{ link: appLink(sectionHash('workspace', 'phone')) }} />
</p>
{canAdd && numbers.length > 0 && add('secondary')}
</div>
{adding && (
<AddNumberDialog
status={status}
extraNumberCents={extraNumberCents}
assistant={assistant}
onClose={() => setAdding(false)}
/>
)}
</>
)
}