Skip to content

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.

1.8 KB
Raw Blame
// The inbox header's status: green only when the server has what the assistant needs to answer.
import { expect, test } from 'vitest'
import { db } from '../src/db.ts'
import { pipelinesSetUp, voiceReady } from '../src/provider-settings.ts'
import { anonymous, createWorkspace, request } from './helpers.ts'

const livekit = { LIVEKIT_URL: 'ws://livekit.test:7880', LIVEKIT_API_KEY: 'key', LIVEKIT_API_SECRET: 'secret' }
const voice = { DEEPGRAM_API_KEY: 'dg', OPENROUTER_API_KEY: 'or', ELEVENLABS_API_KEY: 'el' }

test('voice is ready only with LiveKit and a speech, language model and voice provider', async () => {
  expect(await voiceReady(db, { ...voice })).toBe(false)
  expect(await voiceReady(db, { ...livekit })).toBe(false)
  expect(await voiceReady(db, { ...livekit, DEEPGRAM_API_KEY: 'dg', OPENROUTER_API_KEY: 'or' })).toBe(false)
  expect(await voiceReady(db, { ...livekit, ...voice })).toBe(true)
})

test('a realtime model alone also answers calls; with both set up, each assistant picks one', async () => {
  const realtime = { OPENAI_REALTIME_API_KEY: 'rt' }
  expect(await voiceReady(db, { ...livekit, ...realtime })).toBe(true)
  expect(await pipelinesSetUp(db, { ...realtime })).toEqual({ realtime: true, three_stage: false })
  expect(await pipelinesSetUp(db, { ...voice })).toEqual({ realtime: false, three_stage: true })
  expect(await pipelinesSetUp(db, { ...voice, ...realtime })).toEqual({ realtime: true, three_stage: true })
})

test('any member can ask; nobody signed out can', async () => {
  const ws = await createWorkspace('Brightwater Plumbing & Heating')
  const res = await request(ws.owner, 'GET', '/v1/assistant/status')
  expect(res.status).toBe(200)
  expect(typeof res.body.voiceReady).toBe('boolean')
  expect((await request(anonymous, 'GET', '/v1/assistant/status')).status).toBe(401)
})