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
// The desktop app's part of the sign-in page (LIN-903): its loopback port rides in the address, and the code goes
// only to 127.0.0.1 on that port; the phone apps' hand-back is unchanged.
import { expect, test } from 'vitest'
import { appReturnUrl, readAppSignInPage } from './appSignIn.ts'
const challenge = 'a'.repeat(43)
const mac = { userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) Chrome/142 Safari/537.36', maxTouchPoints: 0 }
const at = (pathname: string, search: string, nav = mac) => readAppSignInPage({ pathname, search }, nav)
test('the start and the return read the desktop app’s port; a bad port counts as none', () => {
expect(at('/app-sign-in', `?provider=google&challenge=${challenge}&port=51234`)).toEqual({
step: 'start',
provider: 'google',
challenge,
port: 51234,
})
expect(at('/app-sign-in', `?provider=google&challenge=${challenge}`)).toMatchObject({ port: null })
for (const port of ['80', '99999', '5123x', '-1', '1023'])
expect(at('/app-sign-in', `?provider=google&challenge=${challenge}&port=${port}`)).toMatchObject({ port: null })
expect(at('/app-sign-in', '?done=1&port=51234')).toEqual({ step: 'done', error: null, port: 51234 })
// On a phone or tablet the port never counts: another app there could listen on it.
const android = {
userAgent: 'Mozilla/5.0 (Linux; Android 15; Pixel 9) Chrome/142 Mobile Safari/537.36',
maxTouchPoints: 5,
}
const ipad = { ...mac, maxTouchPoints: 5 }
const iphone = { userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 18_0 like Mac OS X) Safari/604.1', maxTouchPoints: 5 }
const tablet = { userAgent: 'Mozilla/5.0 (X11; Linux x86_64) Chrome/142 Safari/537.36', maxTouchPoints: 10 }
for (const phone of [android, ipad, iphone, tablet])
expect(at('/app-sign-in', `?provider=google&challenge=${challenge}&port=51234`, phone)).toMatchObject({
port: null,
})
const windows = { userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/142', maxTouchPoints: 0 }
expect(at('/app-sign-in', '?done=1&port=51234', windows)).toMatchObject({ port: 51234 })
expect(at('/app-sign-in/back', '?desktop=1')).toEqual({ step: 'back', desktop: true })
expect(at('/app-sign-in/back', '?code=x')).toEqual({ step: 'back', desktop: false })
})
test('the code goes to the loopback port for the desktop app, to the server for the phone apps', () => {
const code = 'c'.repeat(43)
expect(appReturnUrl({ code }, 51234, 'https://app.linedesk.ai')).toBe(
`http://127.0.0.1:51234/app-sign-in/back?code=${code}`,
)
expect(appReturnUrl({ code }, null, 'https://app.linedesk.ai')).toBe(
`https://app.linedesk.ai/app-sign-in/back?code=${code}`,
)
expect(appReturnUrl({ error: 'cancelled' }, 51234, 'https://app.linedesk.ai')).toBe(
'http://127.0.0.1:51234/app-sign-in/back?error=cancelled',
)
})